a brunette and Alex is blonde."""# Run chainllm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo")chain = create_extraction_chain(schema, llm)chain.run(inp)    [{'name': 'Alex', 'height': 5, 'hair_color': 'blonde'},     {'name': 'Claudia', 'height': 6, 'hair_color': 'brunette'}]Option 1: OpenAI functions‚ÄãLooking under the hood‚ÄãLet's dig into what is happening when we call create_extraction_chain.The LangSmith trace shows that we call the function information_extraction on the input string, inp.This information_extraction function is defined here and returns a dict.We can see the dict in the model output: {      "info": [        {          "name": "Alex",          "height": 5,          "hair_color": "blonde"        },        {          "name": "Claudia",          "height": 6,          "hair_color": "brunette"        }      ]    }The create_extraction_chain then parses the raw LLM output for us using JsonKeyOutputFunctionsParser.This results in the list of JSON objects returned by the chain above:[{'name': 'Alex', 'height': 5, 'hair_color': 'blonde'}, {'name': 'Claudia', 'height': 6, 'hair_color': 'brunette'}]Multiple entity types‚ÄãWe can extend this further.Let's say we want to differentiate between dogs and people.We can add person_ and dog_ prefixes for each propertyschema = {    "properties": {        "person_name": {"type": "string"},        "person_height": {"type": "integer"},        "person_hair_color": {"type": "string"},        "dog_name": {"type": "string"},        "dog_breed": {"type": "string"},    },    "required": ["person_name", "person_height"],}chain = create_extraction_chain(schema, llm)inp = """Alex is 5 feet tall. Claudia is 1 feet taller Alex and jumps higher than him. Claudia is a brunette and Alex is blonde.Alex's dog Frosty is a labrador and likes to play hide and seek."""chain.run(inp)    [{'person_name': 'Alex',      'person_height': 5,      'person_hair_color': 'blonde',      'dog_name': 'Frosty',      'dog_breed': 'labrador'},
Open In Collab
Open In Collab ->: a brunette and Alex is blonde."""# Run chainllm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo")chain = create_extraction_chain(schema, llm)chain.run(inp)    [{'name': 'Alex', 'height': 5, 'hair_color': 'blonde'},     {'name': 'Claudia', 'height': 6, 'hair_color': 'brunette'}]Option 1: OpenAI functions‚ÄãLooking under the hood‚ÄãLet's dig into what is happening when we call create_extraction_chain.The LangSmith trace shows that we call the function information_extraction on the input string, inp.This information_extraction function is defined here and returns a dict.We can see the dict in the model output: {      "info": [        {          "name": "Alex",          "height": 5,          "hair_color": "blonde"        },        {          "name": "Claudia",          "height": 6,          "hair_color": "brunette"        }      ]    }The create_extraction_chain then parses the raw LLM output for us using JsonKeyOutputFunctionsParser.This results in the list of JSON objects returned by the chain above:[{'name': 'Alex', 'height': 5, 'hair_color': 'blonde'}, {'name': 'Claudia', 'height': 6, 'hair_color': 'brunette'}]Multiple entity types‚ÄãWe can extend this further.Let's say we want to differentiate between dogs and people.We can add person_ and dog_ prefixes for each propertyschema = {    "properties": {        "person_name": {"type": "string"},        "person_height": {"type": "integer"},        "person_hair_color": {"type": "string"},        "dog_name": {"type": "string"},        "dog_breed": {"type": "string"},    },    "required": ["person_name", "person_height"],}chain = create_extraction_chain(schema, llm)inp = """Alex is 5 feet tall. Claudia is 1 feet taller Alex and jumps higher than him. Claudia is a brunette and Alex is blonde.Alex's dog Frosty is a labrador and likes to play hide and seek."""chain.run(inp)    [{'person_name': 'Alex',      'person_height': 5,      'person_hair_color': 'blonde',      'dog_name': 'Frosty',      'dog_breed': 'labrador'},