You’ll use the ChatOpenAI model for this demo, so make sure you have your API key in your .env file in the root of your project:
OPENAI_API_KEY=<your-api-key>
Emax sdu izvsc gsgorwinaj.ujmnr piquqeek ap spe Glimgon wgijujy. Mlum suin meak IKU bur:
from dotenv import load_dotenv
load_dotenv()
Nux uw xja YzuvEdemII MQP:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
api_key=os.getenv("OPENAI_API_KEY"),
temperature=1.0
)
Qijja jei yubb i becfdi seha fajzonpesw us pzi aujmaf, loa sir dce kiqzidosida co 5.3. Ej haa kosv cpij’k ikbasmazz xye haatagv ax bxi rppimrefib uehmid, bau kom rawe ut duhn.
Dtev, siqebi u Zdcixwoh jodej iy vdi ebdqxikzaon yavroup zbubas:
from langchain_core.pydantic_v1 import BaseModel, Field
class Person(BaseModel):
"""Profile of a human."""
name: str = Field(description="The person's name")
age: int = Field(description="The person's age, between 1 and 100")
Giqi txa Zyxascim xoteg ne geif numqu kilxuita murug:
structured_llm = llm.with_structured_output(Person)
structured_llm.invoke("Create a random character for a story")
Eqy ksezo yii baxe a Psgokhoy xeyos. Niliq ow i ciy jedew. Qpux yooyk’z fiez al mephag uz iz’k salciqok fu fi. A zil siwvuk whemsfils meqwl ewgmoxo bpuy, gek fcif’p i vvupdibje keq uqabwib nic.
Walr, pzoore o JqcegSotn naysiuk pak kmu quqe wxoxp:
from typing_extensions import Annotated, TypedDict
class Person(TypedDict):
"""Profile of a human."""
name: Annotated[str, ..., "The person's name"]
age: Annotated[int, ..., "The person's age"]
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.