Skip to content

Commit

Permalink
update duckduckgo search library version
Browse files Browse the repository at this point in the history
  • Loading branch information
krohling committed Jan 14, 2024
1 parent 44955c7 commit ac9bd20
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bondai/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 9 additions & 6 deletions bondai/tools/python_repl_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 = ""

Expand Down
8 changes: 4 additions & 4 deletions bondai/tools/website/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 17 additions & 36 deletions tests/getting-started/example-1.py
Original file line number Diff line number Diff line change
@@ -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="<OPENAI-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)

0 comments on commit ac9bd20

Please sign in to comment.