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

feat: external_function_tool.py #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 21 additions & 0 deletions app/core/tools/external_function_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,24 @@ def __init__(self, definition: dict) -> None:
# 其它参数未使用到,暂时不做处理
self.openai_function = definition
self.name = definition["function"]["name"]


def _validate_definition(self, definition: dict) -> bool:
"""
Validate the structure of the function definition.
Returns True if valid, False otherwise.
"""
if "type" not in definition or definition["type"] != "function":
return False

if "function" not in definition:
return False

if not isinstance(definition["function"], dict):
return False

# Check if "name" exists
if "name" not in definition["function"]:
return False

return True