Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from langchain_core.output_parsers import JsonOutputParser
- from langchain_core.prompts import PromptTemplate
- from langchain_core.pydantic_v1 import BaseModel, Field
- from langchain_openai import ChatOpenAI
- model = ChatOpenAI(temperature=0)
- class Person(BaseModel):
- name: str = Field(description="The name of the person")
- lastname: str = Field(description="The lastname of the person")
- prompt = PromptTemplate(
- template="Extract information about a person.\n{format_instructions}\n{query}\n",
- input_variables=["query"],
- partial_variables={"format_instructions": parser.get_format_instructions()},
- )
- chain = prompt | model | JsonOutputParser(pydantic_object=Person)
- chain.invoke({"query": "There is a person called John Doe that lives in the city."})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement