age=13, fav_food=''), Person(name='Joey', age=12, fav_food='spinach'), Person(name='Caroline', age=23, fav_food='')])Using JsonSchema‚ÄãWe can also pass in JsonSchema instead of Pydantic classes to specify the desired structure. When we do this, our chain will output JSON corresponding to the properties described in the JsonSchema, instead of a Pydantic class.json_schema = {    "title": "Person",    "description": "Identifying information about a person.",    "type": "object",    "properties": {        "name": {"title": "Name", "description": "The person's name", "type": "string"},        "age": {"title": "Age", "description": "The person's age", "type": "integer"},        "fav_food": {            "title": "Fav Food",            "description": "The person's favorite food",            "type": "string",        },    },    "required": ["name", "age"],}chain = create_structured_output_chain(json_schema, llm, prompt, verbose=True)chain.run("Sally is 13")            > Entering new LLMChain chain...    Prompt after formatting:    System: You are a world class algorithm for extracting information in structured formats.    Human: Use the given format to extract information from the following input: Sally is 13    Human: Tip: Make sure to answer in the correct format        > Finished chain.    {'name': 'Sally', 'age': 13}Creating a generic OpenAI functions chain‚ÄãTo create a generic OpenAI functions chain, we can use the create_openai_fn_chain method. This is the same as create_structured_output_chain except that instead of taking a single output schema, it takes a sequence of function definitions.Functions can be passed in as:dicts conforming to OpenAI functions spec,Pydantic classes, in which case they should have docstring descriptions of the function they represent and descriptions for each of the parameters,Python functions, in which case they should have docstring descriptions of the function and args, along with type hints.See here for relevant reference docs.Using
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: ->: age=13, fav_food=''), Person(name='Joey', age=12, fav_food='spinach'), Person(name='Caroline', age=23, fav_food='')])Using JsonSchema‚ÄãWe can also pass in JsonSchema instead of Pydantic classes to specify the desired structure. When we do this, our chain will output JSON corresponding to the properties described in the JsonSchema, instead of a Pydantic class.json_schema = {    "title": "Person",    "description": "Identifying information about a person.",    "type": "object",    "properties": {        "name": {"title": "Name", "description": "The person's name", "type": "string"},        "age": {"title": "Age", "description": "The person's age", "type": "integer"},        "fav_food": {            "title": "Fav Food",            "description": "The person's favorite food",            "type": "string",        },    },    "required": ["name", "age"],}chain = create_structured_output_chain(json_schema, llm, prompt, verbose=True)chain.run("Sally is 13")            > Entering new LLMChain chain...    Prompt after formatting:    System: You are a world class algorithm for extracting information in structured formats.    Human: Use the given format to extract information from the following input: Sally is 13    Human: Tip: Make sure to answer in the correct format        > Finished chain.    {'name': 'Sally', 'age': 13}Creating a generic OpenAI functions chain‚ÄãTo create a generic OpenAI functions chain, we can use the create_openai_fn_chain method. This is the same as create_structured_output_chain except that instead of taking a single output schema, it takes a sequence of function definitions.Functions can be passed in as:dicts conforming to OpenAI functions spec,Pydantic classes, in which case they should have docstring descriptions of the function they represent and descriptions for each of the parameters,Python functions, in which case they should have docstring descriptions of the function and args, along with type hints.See here for relevant reference docs.Using