You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/playground/tools/agent_with_tools_example.py

42 lines
635 B

import os
11 months ago
from dotenv import load_dotenv
11 months ago
from swarms import Agent, OpenAIChat
from swarms.tools.tool import tool
load_dotenv()
api_key = os.environ.get("OPENAI_API_KEY")
llm = OpenAIChat(api_key=api_key)
11 months ago
@tool
def search_api(query: str) -> str:
"""Search API
Args:
query (str): _description_
Returns:
str: _description_
"""
print(f"Searching API for {query}")
# Initialize the workflow
agent = Agent(
llm=llm,
max_loops=5,
tools=[search_api],
dashboard=True,
)
out = agent.run(
"Use the search api to find the best restaurants in New York"
" City."
)
print(out)