import json
import pandas as pd
from chatlas import ChatOllama
from pydantic import BaseModel, Field
12 Chatlas: Structural Data
= ChatOllama(model="llama3.1:8b") chat
class Person(BaseModel):
str
name: int
age:
chat.extract_data("My name is Susan and I'm 13 years old",
=Person,
data_model )
{'name': 'Susan', 'age': 13}
class Person2(BaseModel):
"""A person"""
str = Field(description="Name")
name:
int = Field(description="Age, in years")
age:
list[str] = Field(
hobbies: ="List of hobbies. Should be exclusive and brief."
description )
chat.extract_data("My name is Susan and I'm 13 years old. I like swimmming.",
=Person2,
data_model )
{'name': 'Susan', 'age': 13, 'hobbies': ['swimming']}