Spaces:
Sleeping
Sleeping
Commit ·
85054c1
1
Parent(s): e0f70b2
Specify format
Browse files
categories/travel_cab/__init__.py
CHANGED
|
@@ -23,8 +23,8 @@ model = ChatOpenAI(
|
|
| 23 |
# Build categorizing chain
|
| 24 |
system_message_prompt = SystemMessagePromptTemplate.from_template(
|
| 25 |
"You are an information extraction engine that outputs details from OCR processed "
|
| 26 |
-
"documents such as date/time/place of departure and arrival.
|
| 27 |
-
"
|
| 28 |
"{format_instructions}"
|
| 29 |
)
|
| 30 |
human_message_prompt = HumanMessagePromptTemplate.from_template("{text}")
|
|
@@ -35,4 +35,82 @@ output_parser = PydanticOutputParser(pydantic_object=PydanticModel)
|
|
| 35 |
fixing_parser = OutputFixingParser.from_llm(llm=model, parser=output_parser)
|
| 36 |
chain = LLMChain(
|
| 37 |
llm=model, prompt=chat_prompt, output_parser=fixing_parser
|
| 38 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# Build categorizing chain
|
| 24 |
system_message_prompt = SystemMessagePromptTemplate.from_template(
|
| 25 |
"You are an information extraction engine that outputs details from OCR processed "
|
| 26 |
+
"documents such as date/time/place of departure and arrival. Fields with formats "
|
| 27 |
+
"specified as date, time, or datetime should be ISO 8601 compliant.\n"
|
| 28 |
"{format_instructions}"
|
| 29 |
)
|
| 30 |
human_message_prompt = HumanMessagePromptTemplate.from_template("{text}")
|
|
|
|
| 35 |
fixing_parser = OutputFixingParser.from_llm(llm=model, parser=output_parser)
|
| 36 |
chain = LLMChain(
|
| 37 |
llm=model, prompt=chat_prompt, output_parser=fixing_parser
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
if __name__ == '__main__':
|
| 41 |
+
misformatted_output = '''{
|
| 42 |
+
"place_from": "Adarsh Palm Retreat, Bellandur, Bengaluru, Karnataka 560103, India",
|
| 43 |
+
"date_from": "08/05/2023",
|
| 44 |
+
"time_from": "10:05 AM",
|
| 45 |
+
"place_to": "135, Residency Rd, Shanthala Nagar, Ashok Nagar, Bengaluru, Karnataka 560025, India",
|
| 46 |
+
"date_to": "08/05/2023",
|
| 47 |
+
"time_to": "11:05 AM",
|
| 48 |
+
"amount": 474.54
|
| 49 |
+
}'''
|
| 50 |
+
formatted_prompt = chain.prompt.format_prompt(
|
| 51 |
+
text='''08/05/2023, 14:56 Gmail - [Personal] Your Wednesday morning trip with Uber
|
| 52 |
+
https://mail.google.com/mail/u/0/?ik=9af0dfed43&view=pt&search=all&permthid=thread-f:1764850071084777313&simpl=msg-f:1764850071084777313 1/3
|
| 53 |
+
Total ₹474.54
|
| 54 |
+
May 3, 2023
|
| 55 |
+
We hope you enjoyed your ride
|
| 56 |
+
this morning.Thanks for riding, Dhruv
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
P a y t m
|
| 61 |
+
5/3/23 11:06 AMDhruv Kumar <gargdhruv36@gmail.com>
|
| 62 |
+
[Personal] Your W ednesday morning trip with Uber
|
| 63 |
+
1 message
|
| 64 |
+
Uber Receipts <noreply@uber .com> 3 May 2023 at 1 1:06
|
| 65 |
+
To: gargdhruv36@gmail.com
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
T o t a l ₹ 4 7 4 . 5 4
|
| 69 |
+
Trip Charge ₹474.54
|
| 70 |
+
Subtotal ₹474.54
|
| 71 |
+
Rider Promotion -₹5.27
|
| 72 |
+
Fare Adjustment ₹5.27
|
| 73 |
+
P a y m e n t s
|
| 74 |
+
₹474.54
|
| 75 |
+
A temporary hold of ₹474.54 was placed on your payment method Paytm. This is not a charge
|
| 76 |
+
and will be removed. It should disappear from your bank statement shortly. Learn More
|
| 77 |
+
Visit the trip page for more information, including invoices (where available)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
08/05/2023, 14:56 Gmail - [Personal] Your Wednesday morning trip with Uber
|
| 81 |
+
https://mail.google.com/mail/u/0/?ik=9af0dfed43&view=pt&search=all&permthid=thread-f:1764850071084777313&simpl=msg-f:1764850071084777313 2/3
|
| 82 |
+
License Plate: KA05AM2236You rode with SHANKARA NAGA
|
| 83 |
+
5 . 0 0
|
| 84 |
+
R a t i n g
|
| 85 |
+
Rate or tip
|
| 86 |
+
|
| 87 |
+
10:05 AM
|
| 88 |
+
WMGP+PM2, Adarsh Palm
|
| 89 |
+
Retreat, Bellandur, Bengaluru,
|
| 90 |
+
Karnataka 560103, India
|
| 91 |
+
11:05 AM
|
| 92 |
+
135, Residency Rd,
|
| 93 |
+
Shanthala Nagar , Ashok
|
| 94 |
+
Nagar , Bengaluru, Karnataka
|
| 95 |
+
560025, India
|
| 96 |
+
Uber Go 15.77 kilometers | 1 h 0 min
|
| 97 |
+
Report lost item › Contact support›
|
| 98 |
+
My trips › The total of ₹474.54 has a GST of ₹38.52 included.
|
| 99 |
+
Switch Payment Method
|
| 100 |
+
Download PDF
|
| 101 |
+
|
| 102 |
+
08/05/2023, 14:56 Gmail - [Personal] Your Wednesday morning trip with Uber
|
| 103 |
+
https://mail.google.com/mail/u/0/?ik=9af0dfed43&view=pt&search=all&permthid=thread-f:1764850071084777313&simpl=msg-f:1764850071084777313 3/3
|
| 104 |
+
Forgot password
|
| 105 |
+
Privacy
|
| 106 |
+
Terms
|
| 107 |
+
Uber India Systems Private
|
| 108 |
+
Limited
|
| 109 |
+
Fares are inclusive of GST. Please download the tax invoice from the trip detail page for a full tax breakdown.
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
''',
|
| 113 |
+
format_instructions=fixing_parser.get_format_instructions()
|
| 114 |
+
)
|
| 115 |
+
# print("Parsed:", fixing_parser.parse(misformatted_output))
|
| 116 |
+
print("Using fixing parser:", fixing_parser.parse_with_prompt(misformatted_output, formatted_prompt))
|