Skip to content

Instantly share code, notes, and snippets.

@hwchase17
Created September 18, 2023 22:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hwchase17/cef931095e083f888b2beb7963053017 to your computer and use it in GitHub Desktop.
Save hwchase17/cef931095e083f888b2beb7963053017 to your computer and use it in GitHub Desktop.
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
from langchain.llms import OpenAI
llm = OpenAI(temperature=0, model="gpt-3.5-turbo-instruct")
from metaphor_python import Metaphor
client = Metaphor("")
from langchain.agents import tool
@tool
def search(query: str):
"""Call search engine with a query."""
return client.search(query, use_autoprompt=True, num_results=5)
@tool
def get_contents(page_id: str):
"""Get contents of a webpage.
The id passed in should be a single id as fetched from `search` and ONLY this ID (no commentary).
"""
return client.get_contents(page_id)
@tool
def find_similar(url: str):
"""Get search results similar to a given URL.
The url passed in should be a URL returned from `search`
There should NOT be quotation marks around the URL
"""
return client.find_similar(url, num_results=5)
tools = [search, get_contents, find_similar]
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, )
agent.run("Find the hottest AI agent startups and what they do")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment