from langchain.agents import load_tools from langchain.agents import initialize_agent from langchain.llms import OpenAI
1 2
# load the model llm = OpenAI(temperature=0)
1 2 3
# load in some tools to use os.environ["SERPAPI_API_KEY"] = "46eca3f76a945e3c452903dea2641511a1c512a786cbb0eXXXXXXXXXXX" tools = load_tools(["serpapi", "llm-math"], llm=llm)
1 2 3 4 5
# Finally let's initalize an agent with # 1. The tools # 2. The language model # 3. The type of agent we wangt to use agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
1
agent.run("哪个国家是世界上最强大的国家?现在最流行的大预言模型是什么模型?")
> Entering new AgentExecutor chain… I need to find out which country is the most powerful and what the most popular big prediction model is. Action: Search Action Input: “most powerful country in the world” and “most popular big prediction model” Observation:”The United States, China and Russia are seen as the world’s most powerful countries based on factors like economics, political influence and military …”] Thought:3m I need to find out more about the most popular big prediction model Action: Search Action Input: “most popular big prediction model” Observation: ‘Top 5 Predictive Analytics Models · Classification Model · Clustering Model · Forecast Model · Outliers Model · Time Series Model. Thought:I now know the final answer Final Answer: 美国、中国和俄罗斯被视为世界上最强大的国家,最流行的大预言模型是分类模型、聚类模型、预测模型、异常值模型和时间序列模型。 Finished chain. ‘美国、中国和俄罗斯被视为世界上最强大的国家,最流行的大预言模型是分类模型、聚类模型、预测模型、异常值模型和时间序列模型。’
> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.
Current conversation:
Human: Hi there!
AI:
> Finished chain.
" Hi there! It's nice to meet you. How can I help you today?"
1
conversation.predict(input="What was the first thing i said to you?")
1 2 3 4 5 6 7 8 9 10 11
> Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.
Current conversation: Human: Hi there! AI: Hi there! It's nice to meet you. How can I help you today? Human: What was the first thing i said to you? AI: