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

Validate pydantic models if declared #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adivik2000
Copy link
Contributor

This PR addresses the following issue.

Say we have a Pydantic Model like

class GameEntry(BaseModel):
    """Entry for the Name, Place, Animal, Thing game."""
    letter: str = Field(..., description="The starting letter for the entries.")
    name: str = Field(..., description="A name that starts with the given letter.")
    place: str = Field(..., description="A place that starts with the given letter.")
    animal: str = Field(..., description="An animal that starts with the given letter.")
    thing: str = Field(..., description="A thing that starts with the given letter.")

A function like this

def player_says(entry: GameEntry):
  f"Entry for letter {entry.letter} is: ({entry.name}, {entry.place}, {entry.animal}, {entry.thing})"

A typical function call with the class instance would return this perfectly but when we're using openai function calling, this would throw an attribute error as the function_arguments that we parse and use is a dict and not a pydantic model. Hence added a small functionality that validates the arguments with the models if defined and calls(in chat_complete_execute_fn) with the respective classes. The function can be now used as is, without any modification or extra validation in the function.

Took help of GPT for this one. Open to feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant