Closed Clement-Lelievre closed 11 months ago
you can pass a pydantic schema to the function calling like this:
import openai
from pydantic import BaseModel, Field
class GeoSchema(BaseModel):
latitude: float = Field(..., description="The latitude component")
longitude : float = Field(..., description="The longitude component")
result = openai.ChatCompletetion.create(
model="gpt-3.5-turbo",
messages = [
{"role": "system" , "content": "You are a helpful Tour planning AI"},
{"role": "user", "content": "come up with a random location"}
],
functions=[{
"name": "random_place_finder", # this is your function name
"description": "gives the latitude and longitude of a random place on earth",
"parameters": GeoSchema.model_json_schema()
}],
function_call={"name": "random_place_finder"},
temperature=1)
Hi @SupreethRao99
thanks for the reply.
This looks to me more like an alternative/way to complement my proposal than a definitive enhancement, as your proposal still hardcodes the function name and description.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days.
This issue was closed because it has been stalled for 10 days with no activity.
Suggestion: how about leveraging Python dunders to better fill in the
functions
parameter of the request rather than hardcoding it? It'd be more Pythonic and maintainable. (This assumes that the function signature contains a docstring and type hints (so, is incompatible with lambdas).)name
: use the function name dunder (i.e.<function_name>.__name__
) (there could be a use case for this, e.g. if filtering on the keys ofglobals()
/locals()
)description
: use the function documentation dunder (i.e.<function_name>.__doc__
)parameters
: use the function annotations dunder (i.e.<function_name>.__annotations__
) to populate the argument types via a pre-built mapping__kwdefaults__
to populate automatically the default values of kwargsThis could also be implemented in the function-calling guide