From ac9bd206e72eafcd653fb778e20da1593dd0003a Mon Sep 17 00:00:00 2001 From: Kevin Rohling Date: Sat, 13 Jan 2024 16:38:48 -0800 Subject: [PATCH] update duckduckgo search library version --- bondai/agents/agent.py | 2 +- bondai/tools/python_repl_tool.py | 15 +++++---- bondai/tools/website/query.py | 8 ++--- requirements.txt | 2 +- tests/getting-started/example-1.py | 53 ++++++++++-------------------- 5 files changed, 32 insertions(+), 48 deletions(-) diff --git a/bondai/agents/agent.py b/bondai/agents/agent.py index 72bf047..0b4f6d2 100644 --- a/bondai/agents/agent.py +++ b/bondai/agents/agent.py @@ -31,7 +31,7 @@ ) -DEFAULT_MAX_TOOL_RETRIES = 3 +DEFAULT_MAX_TOOL_RETRIES = 5 DEFAULT_MAX_TOOL_RESPONSE_TOKENS = 2000 DEFAULT_SYSTEM_PROMPT_TEMPLATE = load_local_resource( __file__, os.path.join("prompts", "react_agent_system_prompt_template.md") diff --git a/bondai/tools/python_repl_tool.py b/bondai/tools/python_repl_tool.py index a3b437a..ebccc88 100644 --- a/bondai/tools/python_repl_tool.py +++ b/bondai/tools/python_repl_tool.py @@ -10,12 +10,13 @@ TOOL_NAME = "python_repl" TOOL_DESCRIPTION = ( "This tool allows you to execute Python code. " - "Specify your Python code in the 'code' parameter and it will return the result." + "Specify your Python code in the 'script' parameter and it will return the result." + "Note that you MUST provide the 'script' parameter to use this tool." ) class Parameters(BaseModel): - code: str + script: str thought: str @@ -49,12 +50,14 @@ def __init__(self, execution_timeout: int = DEFAULT_EXECUTION_TIMEOUT): self._execution_timeout = execution_timeout def run(self, arguments: Dict) -> str: - code = arguments.get("code") + script = arguments.get("script") - if code is None: - raise Exception("'code' parameter is required") + if script is None: + raise Exception( + "To use the 'python_repl' tool you must provide the 'script' parameter." + ) - result, stdout, stderr = self.execute_code(code) + result, stdout, stderr = self.execute_code(script) response = "" diff --git a/bondai/tools/website/query.py b/bondai/tools/website/query.py index 333e80e..050a3d0 100644 --- a/bondai/tools/website/query.py +++ b/bondai/tools/website/query.py @@ -47,12 +47,12 @@ def __init__( self._embedding_model = embedding_model def run(self, arguments: Dict) -> str: - url = arguments["url"] - question = arguments["question"] + url = arguments.get("url") + question = arguments.get("question") - if url is None: + if not url: raise Exception("url is required") - if question is None: + if not question: raise Exception("question is required") try: diff --git a/requirements.txt b/requirements.txt index 5a22964..38459b5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,7 @@ charset-normalizer==3.2.0 click==8.1.7 cssselect==1.2.0 distro==1.8.0 -duckduckgo-search==3.9.8 +duckduckgo-search==4.2.0 faiss-cpu==1.7.4 fake-useragent==1.2.1 Flask==3.0.0 diff --git a/tests/getting-started/example-1.py b/tests/getting-started/example-1.py index 2e7b263..b0d23e9 100644 --- a/tests/getting-started/example-1.py +++ b/tests/getting-started/example-1.py @@ -1,42 +1,23 @@ -# from bondai.agents import Agent -# from bondai.models.openai import DefaultOpenAIConnectionParams -# from bondai.tools.search import DuckDuckGoSearchTool -# from bondai.tools.website import WebsiteQueryTool -# from bondai.tools.file import FileWriteTool +from bondai.agents import Agent, AgentEventNames +from bondai.tools import PythonREPLTool +from bondai.tools.search import DuckDuckGoSearchTool +from bondai.tools.website import WebsiteQueryTool +from bondai.models.openai import OpenAILLM, OpenAIModelNames -# DefaultOpenAIConnectionParams.configure_openai_connection(api_key="") +task = "I want you to find the U.S. GDP from 2000 to 2010 and then use Python to save a line chart to a file named chart.png." +llm = OpenAILLM(OpenAIModelNames.GPT4_0613) -# task = """I want you to research the usage of Metformin as a drug to treat aging and aging related illness. -# You should only use reputable information sources, ideally peer reviewed scientific studies. -# I want you to summarize your findings in a document named metformin.md and includes links to reference and resources you used to find the information. -# Additionally, the last section of your document you should provide a recommendation for a 43 year old male, in good health and who regularly exercises as to whether he would benefit from taking Metformin. -# You should explain your recommendation and justify it with sources. -# Finally, you should highlight potential risks and tradeoffs from taking the medication.""" - -# Agent(tools=[ -# DuckDuckGoSearchTool(), -# WebsiteQueryTool(), -# FileWriteTool() -# ]).run(task) - -from bondai.agents import Agent -from bondai.models.openai import ( - OpenAILLM, - OpenAIConnectionParams, - OpenAIConnectionType, - OpenAIModelNames, +agent = Agent( + llm=llm, tools=[DuckDuckGoSearchTool(), WebsiteQueryTool(), PythonREPLTool()] ) - -connection_params = OpenAIConnectionParams( - connection_type=OpenAIConnectionType.AZURE, - api_key="", - api_version="", - azure_endpoint="", - azure_deployment="", +# agent.on(AgentEventNames.TOOL_SELECTED, lambda _, m: print(f"Selected tool: {m.tool_name}({str(m.tool_arguments)})")) +agent.on( + AgentEventNames.TOOL_COMPLETED, + lambda _, m: print( + f"Tool: {m.tool_name}({str(m.tool_arguments)})\nOutput: {m.tool_output}\nError: {m.error}" + ), ) - -llm = OpenAILLM(model=OpenAIModelNames.GPT4_32K, connection_params=connection_params) - -agent = Agent(llm=llm) +result = agent.run(task) +print(result)