from .model import InformationExtractedFromABillReceipt as PydanticModel from langchain.chains import LLMChain from langchain.chat_models import ChatOpenAI from langchain.output_parsers import PydanticOutputParser, OutputFixingParser from langchain.prompts import ( ChatPromptTemplate, HumanMessagePromptTemplate, ) model = ChatOpenAI(temperature=0) # Build categorizing chain human_message_prompt = HumanMessagePromptTemplate.from_template( "Parse through and find the following details from the text extracted from a travel " "bill\n" "{format_instructions}\n" "{text}" ) chat_prompt = ChatPromptTemplate.from_messages([human_message_prompt]) output_parser = PydanticOutputParser(pydantic_object=PydanticModel) fixing_parser = OutputFixingParser.from_llm(llm=model, parser=output_parser) chain = LLMChain(llm=model, prompt=chat_prompt, output_parser=fixing_parser)