I am learning how to use langchain and I have written a small exercise to try and figure out how agents work.
I have a small Python program that looks like this:
import os
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
topic = input("Topic: ")
prompt = PromptTemplate(input_variables = ['topic'],
template = '''
You have been given access to a search
tool. Please gather information about the
AI algorithm topic{topic}, and write a
thousand word blog post on this topic.
'''
)
os.environ['SERPAPI_API_KEY'] = <"my serpapi key">
llm = OpenAI(model = 'text-davinci-003', temperature = 0.7,openai_api_key = "<my openAPI key> ")
tools = load_tools(['serpapi'])
agent = initialize_agent(tools, llm, agent = 'zero-shot-react-description', verbose=True)
foo = agent.run(prompt)
print (foo)
f = open("new_post","w")
f.write(foo)
f.close()
When I run this, I get the following output:
> Entering new AgentExecutor chain...
I could use a search engine to look for the answer
Action: Search
Action Input: "Tree of Thoughts"
Observation: Title:Tree of Thoughts: Deliberate
Problem Solving with Large Language Models ...
Abstract: Language models are increasingly being deployed for ...
Thought: This looks like it could be the answer I'm looking for
Action: Read
Action Input: Title:Tree of Thoughts: Deliberate Problem Solving with Large Language Models
Observation: Read is not a valid tool, try another one.
Thought: I should read the abstract to get an overview of what the paper is about
Action: Read
Action Input: Abstract: Language models are increasingly being deployed for ...
Observation: Read is not a valid tool, try another one.
Thought: I should look for other sources of information about this topic
Action: Search
Action Input: "Tree of Thoughts" + review
Observation: Percival Everett's new novel The Trees hits just the right mark. It's a racial allegory grounded in history, shrouded in mystery, and dripping ...
Thought: This looks like a review of a novel, not what I'm looking for
Action: Search
Action Input: "Tree of Thoughts" + research
Observation: To surmount these challenges, we introduce a new framework for language model inference, Tree of Thoughts (ToT), which generalizes over the ...
Thought: This looks like it could be the answer I'm looking for
Final Answer: Tree of Thoughts (ToT) is a new framework for language model inference that generalizes over the existing methods and enables more efficient problem solving.
> Finished chain.
What is going on here? Why am I only getting this one sentence as output? Am I using the wrong model? Thanks