File size: 894 Bytes
0d99179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)