From 6600bb19fe733253f5a608e0e04a05e34ddb7502 Mon Sep 17 00:00:00 2001 From: Manu Date: Sat, 8 Jun 2024 10:27:13 +0200 Subject: [PATCH] toolkit python repl --- ...ple Tools for Web Based Question Answering | 11 ----- .../1_multiple_tools.py | 41 +++++++++++++++++++ .../answer.txt | 2 + 3 files changed, 43 insertions(+), 11 deletions(-) delete mode 100644 1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering create mode 100644 1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering/1_multiple_tools.py create mode 100644 1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering/answer.txt diff --git a/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering deleted file mode 100644 index db6e5a9..0000000 --- a/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering +++ /dev/null @@ -1,11 +0,0 @@ -from langchain import LLMChain, PromptTemplate -from langchain.llms import OpenAI - -llm = OpenAI(temperature=0) - -template = """You are an assistant that answers the following question correctly and honestly: {question}\n\n""" -prompt_template = PromptTemplate(input_variables=["question"], template=template) - -question_chain = LLMChain(llm=llm, prompt=prompt_template) - -question_chain.run("what is the latest fast and furious movie?") \ No newline at end of file diff --git a/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering/1_multiple_tools.py b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering/1_multiple_tools.py new file mode 100644 index 0000000..4723a0e --- /dev/null +++ b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering/1_multiple_tools.py @@ -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) \ No newline at end of file diff --git a/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering/answer.txt b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering/answer.txt new file mode 100644 index 0000000..4881713 --- /dev/null +++ b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/7 Making LLMs Interact with the World Using Tools/4 Integrating Multiple Tools for Web Based Question Answering/answer.txt @@ -0,0 +1,2 @@ + +Napoleon Bonaparte died on May 5, 1821. \ No newline at end of file