ankur-bohra's picture
Add ISO8601 guide
c0ab6fd
raw
history blame contribute delete
989 Bytes
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. Fields with formats specified as date, time, or datetime should be ISO 8601 "
"compliant.\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)