hints.See here for relevant reference docs.Using Pydantic classes‚Äãclass RecordPerson(BaseModel):    """Record some identifying information about a pe."""    name: str = Field(..., description="The person's name")    age: int = Field(..., description="The person's age")    fav_food: Optional[str] = Field(None, description="The person's favorite food")class RecordDog(BaseModel):    """Record some identifying information about a dog."""    name: str = Field(..., description="The dog's name")    color: str = Field(..., description="The dog's color")    fav_food: Optional[str] = Field(None, description="The dog's favorite food")prompt = ChatPromptTemplate.from_messages(    [        ("system", "You are a world class algorithm for recording entities."),        ("human", "Make calls to the relevant function to record the entities in the following input: {input}"),        ("human", "Tip: Make sure to answer in the correct format"),    ])chain = create_openai_fn_chain([RecordPerson, RecordDog], llm, prompt, verbose=True)chain.run("Harry was a chubby brown beagle who loved chicken")            > Entering new LLMChain chain...    Prompt after formatting:    System: You are a world class algorithm for recording entities.    Human: Make calls to the relevant function to record the entities in the following input: Harry was a chubby brown beagle who loved chicken    Human: Tip: Make sure to answer in the correct format        > Finished chain.    RecordDog(name='Harry', color='brown', fav_food='chicken')Using Python functions‚ÄãWe can pass in functions as Pydantic classes, directly as OpenAI function dicts, or Python functions. To pass Python function in directly, we'll want to make sure our parameters have type hints, we have a docstring, and we use Google Python style docstrings to describe the parameters.NOTE: To use Python functions, make sure the function arguments are of primitive types (str, float, int, bool) or that they are Pydantic objects.class
This walkthrough demonstrates how to incorporate OpenAI function-calling API's in a chain. We'll go over:
This walkthrough demonstrates how to incorporate OpenAI function-calling API's in a chain. We'll go over: ->: hints.See here for relevant reference docs.Using Pydantic classes‚Äãclass RecordPerson(BaseModel):    """Record some identifying information about a pe."""    name: str = Field(..., description="The person's name")    age: int = Field(..., description="The person's age")    fav_food: Optional[str] = Field(None, description="The person's favorite food")class RecordDog(BaseModel):    """Record some identifying information about a dog."""    name: str = Field(..., description="The dog's name")    color: str = Field(..., description="The dog's color")    fav_food: Optional[str] = Field(None, description="The dog's favorite food")prompt = ChatPromptTemplate.from_messages(    [        ("system", "You are a world class algorithm for recording entities."),        ("human", "Make calls to the relevant function to record the entities in the following input: {input}"),        ("human", "Tip: Make sure to answer in the correct format"),    ])chain = create_openai_fn_chain([RecordPerson, RecordDog], llm, prompt, verbose=True)chain.run("Harry was a chubby brown beagle who loved chicken")            > Entering new LLMChain chain...    Prompt after formatting:    System: You are a world class algorithm for recording entities.    Human: Make calls to the relevant function to record the entities in the following input: Harry was a chubby brown beagle who loved chicken    Human: Tip: Make sure to answer in the correct format        > Finished chain.    RecordDog(name='Harry', color='brown', fav_food='chicken')Using Python functions‚ÄãWe can pass in functions as Pydantic classes, directly as OpenAI function dicts, or Python functions. To pass Python function in directly, we'll want to make sure our parameters have type hints, we have a docstring, and we use Google Python style docstrings to describe the parameters.NOTE: To use Python functions, make sure the function arguments are of primitive types (str, float, int, bool) or that they are Pydantic objects.class