Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return appended entire schema #665

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions swarms/tools/base_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ def convert_tool_into_openai_schema(self):
"Converting tools into OpenAI function calling schema"
)

tool_schemas = []

for tool in self.tools:
# Transform the tool into a openai function calling schema
if self.check_func_if_have_docs(
Expand All @@ -398,7 +400,7 @@ def convert_tool_into_openai_schema(self):
logger.info(
f"Converting tool: {name} into a OpenAI certified function calling schema. Add documentation and type hints."
)
tool_schema_list = (
tool_schema = (
get_openai_function_schema_from_func(
tool, name=name, description=description
)
Expand All @@ -408,18 +410,21 @@ def convert_tool_into_openai_schema(self):
f"Tool {name} converted successfully into OpenAI schema"
)

# Transform the dictionary to a string
tool_schema_list = json.dumps(
tool_schema_list, indent=4
)

return tool_schema_list
tool_schemas.append(tool_schema)
else:
logger.error(
f"Tool {tool.__name__} does not have documentation or type hints, please add them to make the tool execution reliable."
)

return tool_schema_list
# Combine all tool schemas into a single schema
if tool_schemas:
combined_schema = {
"type": "function",
"functions": [schema["function"] for schema in tool_schemas]
}
return json.dumps(combined_schema, indent=4)

return None

def check_func_if_have_docs(self, func: callable):
if func.__doc__ is not None:
Expand Down
Loading