-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
11 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
... with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
...g Tools/4 Integrating Multiple Tools for Web Based Question Answering/1_multiple_tools.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from langchain.llms import OpenAI | ||
from langchain.agents import Tool, initialize_agent, AgentType | ||
|
||
from langchain.utilities import GoogleSearchAPIWrapper, PythonREPL | ||
|
||
|
||
search = GoogleSearchAPIWrapper() | ||
python_repl = PythonREPL() | ||
|
||
llm = OpenAI(model="gpt-3.5-turbo-instruct", temperature=0) | ||
|
||
|
||
|
||
toolkit = [ | ||
Tool( | ||
name="google-search", | ||
func=search.run, | ||
description="useful for when you need to search Google to answer questions about current events" | ||
), | ||
Tool( | ||
name="python_repl", | ||
description="A Python shell. Use this to execute Python commands. Input should be a valid Python command. Useful for saving strings to files.", | ||
func=python_repl.run | ||
) | ||
] | ||
|
||
|
||
agent = initialize_agent( | ||
toolkit, | ||
llm, | ||
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, | ||
verbose=True | ||
) | ||
|
||
agent.run("Find the birth date of Napoleon Bonaparte and save it to a file 'answer.txt'.") | ||
|
||
|
||
query = "Find when Napoleon Bonaparte died and append this information " \ | ||
"to the content of the 'answer.txt' file in a new line." | ||
|
||
agent.run(query) |
2 changes: 2 additions & 0 deletions
2
...orld Using Tools/4 Integrating Multiple Tools for Web Based Question Answering/answer.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
Napoleon Bonaparte died on May 5, 1821. |