Conversation
|
|
||
| fields[name] = (annotation, default) | ||
|
|
||
| DynamicModel = create_model(f"{func.__name__}", **fields) |
There was a problem hiding this comment.
I am not sure if create_model will only work with pydantic model or dataclass, but not native class, unless we pass the parameter __config__=ConfigDict(arbitrary_types_allowed=True)?
Or we should explicitly warn against using parameters that are not validatable?
There was a problem hiding this comment.
I don't think we should support arbitrary types as at the end the llm will produce a json with arguments values. Added a custom exception for beter user experience
|
|
||
|
|
||
| def function_to_genai_tool( | ||
| tool: Union[Callable, dict], |
There was a problem hiding this comment.
nit: Shall we support the dict with a function key as well like {"type": "function", "function": {...}}, e.g., by
if "function" in tool:
tool = tool["function"]
There was a problem hiding this comment.
Where is such a format used?
There was a problem hiding this comment.
Yes I think this is part of openai API? https://platform.openai.com/docs/guides/function-calling#function-tool-example
- Core components for tool invocation and response modeling. - Helpers to convert Python functions to OpenAI and GenAI tool definitions. - A `Tool` actor for chat messages.
|
|
||
|
|
||
| def function_to_genai_tool( | ||
| tool: Union[Callable, dict], |
There was a problem hiding this comment.
Yes I think this is part of openai API? https://platform.openai.com/docs/guides/function-calling#function-tool-example
| describe_tools, | ||
| invoke_tool, | ||
| ) | ||
|
|
There was a problem hiding this comment.
Shall we add a test case for code like
from pydantic import BaseModel
# Pydantic or dataclass
class User(BaseModel):
name: str
age: int
def add_user(user: User):
"""Adds a new user to the database."""
pass
Toolactor for chat messages.