[BUG] Error while convering custom function to openai function
Closed this issue · 2 comments
Occupying-Mars commented
Describe the bug
When creating a new custom functions its trying to parse the function in a wrong way
To Reproduce
Create a new custom function examples here
https://medium.com/@kyeg/the-swarms-tool-system-functions-pydantic-basemodels-as-tools-and-radical-customization-c2a2e227b8ca
and try to run it
Expected behavior
should just perform the function call
possible fix
read the agent.py file in the sdk and edit this one line
if all(callable(tool) for tool in self.tools):
line 1611
it worked for me
Additional context
my code
from swarms import Agent, OpenAIChat, tool
from pydantic import BaseModel
import requests
from bs4 import BeautifulSoup
class SearchResult(BaseModel):
title: str
url: str
snippet: str
@tool(name="websearch", description="websearch tool")
def web_search(query: str) -> list[SearchResult]:
"""
Perform a web search for the given query.
Args:
query (str): The search query.
Returns:
list[SearchResult]: A list of search results.
"""
url = f"https://www.google.com/search?q={query}"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
print("yo yo honey singha")
results = []
for g in soup.find_all('div', class_='g'):
anchors = g.find_all('a')
if anchors:
link = anchors[0]['href']
title = g.find('h3', class_='r')
snippet = g.find('div', class_='s')
if title and snippet:
results.append(SearchResult(
title=title.text,
url=link,
snippet=snippet.text
))
print(results[:5], "results")
return results[:5] # Return top 5 results
# Initializing the agent with the OpenAI instance and other parameters
agent = Agent(
agent_name="web search agent",
system_prompt="This agent performs web searches based on user requests.",
sop_list=["Perform web search", "Return results"],
llm=OpenAIChat(),
max_loops="auto",
interactive=True,
verbose=True,
output_type=str,
metadata_output_type="json",
function_calling_format_type="OpenAI",
tools=[web_search],
)
# Defining the task
task = "Search for recent advancements in artificial intelligence."
# Running the agent with the specified task
out = agent.run(task)
print(out)
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.
github-actions commented
Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap.
kyegomez commented
@Occupying-Mars excuse me for the issue, I broke that in the last update, fixing now.