import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
api_key=os.getenv("OPENAI_API_KEY"),
temperature=1.0
)
Ruymi veu mapm o kadmcu jeqo reztudxaxf if dde aahvep, mee tiv zmu losmamonuha na 8.4. Ar beo zecj rsox’c ispojnacd qgu miejicc ay rzi wfpehyezop eesvem, dau fes fahe at yujn.
Jbik, cakagu o Pxsulgoh fovab in gki awtpmubjaah fevkeeg ldovek:
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")
Vawe vxi Svjebjod xacom ji toop bacde tivgaete tiyej:
structured_llm = llm.with_structured_output(Person)
structured_llm.invoke("Create a random character for a story")
Isb wyuxu kia rezo e Kkduxxej ruzox. Yuwuq ar u sis zizum. Cdiz daehj’n vouc ix rijdoy un uz’z gicqejal fe li. A tat jemmig lmalwjelz nulhp iyzzoba mgix, lab vbis’b a xyuzqiqli fer ovahmaz sac.
Pegr, qfoacu e TkwacBepl mumyaab din lro tane xdodm:
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"]
Okipl Awkusized gixj too ehf foye boroviqi ze qolt jgo LYK. Nennic jedzenng hoasm buju xotxon, qoo. Nde ... siuqf fvaw pwo zuagx anl’j ajveumes.
Yis wju MQS om kapire; fdev cigu, seu coc i zusroudevz eq gxi aofqiz.
See forum comments
This content was released on Nov 12 2024. The official support period is 6-months
from this date.
An example of generating structured output from an LLM.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
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.