Skip to content

Commit

Permalink
Fixed linting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
moiz-stri committed Mar 14, 2024
1 parent 0832497 commit ff394b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 5 additions & 3 deletions libs/vertexai/langchain_google_vertexai/functions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _format_tool_to_vertex_function(tool: BaseTool) -> FunctionDescription:


def _format_tools_to_vertex_tool(
tools: List[Union[BaseTool, Type[BaseModel]]],
tools: List[Union[BaseTool, Type[BaseModel], dict]],
) -> List[VertexTool]:
"Format tool into the Vertex Tool instance."
function_declarations = []
Expand All @@ -64,12 +64,14 @@ def _format_tools_to_vertex_tool(
func = _format_tool_to_vertex_function(tool)
elif isinstance(tool, type) and issubclass(tool, BaseModel):
func = _format_pydantic_to_vertex_function(tool)
else:
elif isinstance(tool, dict):
func = {
"name": tool["name"],
"description": tool.get("description"),
"description": tool.pop("description"),
"parameters": _get_parameters_from_schema(tool["parameters"]),
}
else:
raise ValueError(f"Unsupported tool call type {tool}")
function_declarations.append(FunctionDeclaration(**func))

return [VertexTool(function_declarations=function_declarations)]
Expand Down
20 changes: 17 additions & 3 deletions libs/vertexai/tests/integration_tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ def test_tools() -> None:

@pytest.mark.extended
def test_custom_tool() -> None:
from langchain.agents import AgentExecutor, create_openai_functions_agent, tool
from langchain.agents import AgentExecutor, tool
from langchain.agents.format_scratchpad import (
format_to_openai_function_messages,
)

@tool
@tool("search", return_direct=True)
def search(query: str) -> str:
"""Look up things online."""
return "LangChain"
Expand All @@ -115,8 +118,19 @@ def search(query: str) -> str:
MessagesPlaceholder("agent_scratchpad"),
]
)
llm_with_tools = llm.bind(functions=tools)

agent = create_openai_functions_agent(llm, tools, prompt)
agent: Any = (
{
"input": lambda x: x["input"],
"agent_scratchpad": lambda x: format_to_openai_function_messages(
x["intermediate_steps"]
),
}
| prompt
| llm_with_tools
| _TestOutputParser()
)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

response = agent_executor.invoke({"input": "What is LangChain?"})
Expand Down

0 comments on commit ff394b4

Please sign in to comment.