-
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
49 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...h Agents/1 What are Agents: Agents as Content Generators and Reasoning Engines/1_agent.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,18 @@ | ||
# Importing necessary modules | ||
from langchain.agents import load_tools, initialize_agent | ||
from langchain.agents import AgentType | ||
from langchain.llms import OpenAI | ||
|
||
# Loading the language model to control the agent | ||
llm = OpenAI(model="gpt-3.5-turbo-instruct", temperature=0) | ||
|
||
# Loading some tools to use. The llm-math tool uses an LLM, so we pass that in. | ||
tools = load_tools(["google-search", "llm-math"], llm=llm) | ||
|
||
# Initializing an agent with the tools, the language model, and the type of agent we want to use. | ||
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True) | ||
|
||
# Testing the agent | ||
query = "What's the result of 1000 plus the number of goals scored in the soccer world cup in 2018?" | ||
response = agent.run(query) | ||
print(response) |
30 changes: 30 additions & 0 deletions
30
...1 What are Agents: Agents as Content Generators and Reasoning Engines/2_generate_story.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,30 @@ | ||
# Importing necessary modules | ||
from langchain.agents import initialize_agent, AgentType | ||
from langchain.llms import OpenAI | ||
from langchain.agents import Tool | ||
from langchain.prompts import PromptTemplate | ||
from langchain.chains import LLMChain | ||
|
||
prompt = PromptTemplate( | ||
input_variables=["query"], | ||
template="You're a renowned science fiction writer. {query}" | ||
) | ||
|
||
# Initialize the language model | ||
llm = OpenAI(model="gpt-3.5-turbo-instruct", temperature=0) | ||
llm_chain = LLMChain(llm=llm, prompt=prompt) | ||
|
||
tools = [ | ||
Tool( | ||
name='Science Fiction Writer', | ||
func=llm_chain.run, | ||
description='Use this tool for generating science fiction stories. Input should be a command about generating specific types of stories.' | ||
) | ||
] | ||
|
||
# Initializing an agent with the tools, the language model, and the type of agent we want to use. | ||
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True) | ||
|
||
# Testing the agent with the new prompt | ||
response = agent.run("Compose an epic science fiction saga about interstellar explorers") | ||
print(response) |
1 change: 1 addition & 0 deletions
1
...ts/1 What are Agents: Agents as Content Generators and Reasoning Engines/requirements.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 @@ | ||
pip install numexpr |