Back to Llama Index

Import and initialize our tool spec

llama-index-integrations/tools/llama-index-tools-yelp/examples/yelp.ipynb

0.14.21973 B
Original Source
python
import os

os.environ["OPENAI_API_KEY"] = "sk-your-key"
python
# Import and initialize our tool spec
from llama_index.tools.yelp.base import YelpToolSpec
from llama_index.tools.tool_spec.load_and_search.base import LoadAndSearchToolSpec

tool_spec = YelpToolSpec(api_key="your-key", client_id="your-id")
python
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

# Create the Agent with our tools
tools = tool_spec.to_tool_list()
agent = FunctionAgent(
    tools=[
        *LoadAndSearchToolSpec.from_defaults(tools[0]).to_tool_list(),
        *LoadAndSearchToolSpec.from_defaults(tools[1]).to_tool_list(),
    ],
    llm=OpenAI(model="gpt-4.1"),
)

# Create a context for the agent
from llama_index.core.workflow import Context

ctx = Context(agent)

print(await agent.run("what good resturants are in toronto", ctx=ctx))
print(await agent.run("what are the details of lao lao bar", ctx=ctx))