Created
April 21, 2023 04:12
-
-
Save idontcalculate/96ba42031b9610c69bdae7917554c347 to your computer and use it in GitHub Desktop.
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
from langchain.llms import OpenAI | |
from langchain.agents import Tool | |
from langchain.utilities import GoogleSearchAPIWrapper | |
from langchain.prompts import PromptTemplate | |
from langchain.chains import LLMChain | |
from langchain.agents import initialize_agent | |
llm = OpenAI(temperature=0) | |
prompt = PromptTemplate( | |
input_variables=["query"], | |
template="{query}" | |
) | |
llm_chain = LLMChain(llm=llm, prompt=prompt) | |
search =GoogleSearchAPIWrapper() | |
tools = [ | |
Tool( | |
name = "Search", | |
func=search.run, | |
description="useful for when you need to answer questions about current events", | |
return_direct=True | |
), | |
Tool( | |
name='Language Model', | |
func=llm_chain.run, | |
description='use this tool for general purpose queries' | |
), | |
Tool( | |
name='Wolfram Alpha', | |
func=llm_chain.run, | |
description='use this tool when you need computational logic' | |
) | |
] | |
conversational_agent = initialize_agent( | |
tools, | |
llm, | |
agent="zero-shot-react-description", | |
verbose=True | |
) | |
conversational_agent("How many days until the next Solar exclipse?") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment