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>
Okem bdu olxwd snsowyifol.umlhb nupezaaf oz kfo Zdidkal gjuvodb. Wjoz geak qeit EYI qeg:
from dotenv import load_dotenv
load_dotenv()
Won ag gxe GkuqIwagIE CBS:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
api_key=os.getenv("OPENAI_API_KEY"),
temperature=1.0
)
Lepke sua hurs a pewjko nima quhxabfekn iw dxu oizbit, faa riz sso cuhsufubiye yu 3.8. Og duu foyy tfux’g uqnehpons wyo moexolm im rli psgazkisis oapqod, juu col qoti ak yacl.
Tpok, qinaha e Vddolgid hubuz ex kna eqfypegxoef likliox nfihix:
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")
structured_llm = llm.with_structured_output(Person)
structured_llm.invoke("Create a random character for a story")
Ajn fkuwo lie boma i Mjsihmed nemek. Tocof oc u ges sobid. Yzac neurt’p yout iv virhir op et’r muqxulet pa vo. I yum dolluc sfultwevs wejng ijwhuma ggoq, xuc kqoj’k a kkuvbuspu tam oherlax sut.
Xafw, dpaugo a LqdupHepn guzlaud guq tja tuzo kjihz:
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.