Zack Saadioui
8/24/2024
1
.with_structured_output()
1
.with_structured_output()
1
.with_structured_output()
1
.with_structured_output()
1 2 3 4 5
from langchain_core.pydantic_v1 import BaseModel, Field class Joke(BaseModel): setup: str = Field(description="The setup of the joke") punchline: str = Field(description="The punchline of the joke")
1 2 3 4 5 6 7
from langchain_openai import ChatOpenAI model = ChatOpenAI(model="gpt-3.5-turbo", temperature=0) structured_llm = model.with_structured_output(Joke) response = structured_llm.invoke("Tell me a joke about cats") print(response)
1
2
python
Joke(setup='Why did the cat sit on the computer?', punchline='Because it wanted to keep an eye on the mouse!')
1
setup
1
punchline
1
2
bash
pip install -qU langchain
1
.with_structured_output()
Copyright © Arsturn 2024