Update extract_insights.py
Browse files- extract_insights.py +19 -0
extract_insights.py
CHANGED
@@ -9,6 +9,7 @@ import logging
|
|
9 |
from datetime import datetime
|
10 |
import os
|
11 |
import tiktoken
|
|
|
12 |
|
13 |
|
14 |
app = FastAPI()
|
@@ -158,6 +159,22 @@ def receipt_radar_prompt(raw_text:str)->str:
|
|
158 |
"""
|
159 |
return system_prompt
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
def adjust_prompt_tokens_v1(prompt: str) -> str:
|
162 |
max_tokens = 127500
|
163 |
encoding = tiktoken.encoding_for_model('gpt-4o-mini')
|
@@ -210,6 +227,7 @@ async def process_synchronous_job(user_id,email,message_id,raw_text):
|
|
210 |
insert_data['email'] = email
|
211 |
insert_data['user_id'] = user_id
|
212 |
insert_data['message_id'] = message_id
|
|
|
213 |
print("Printing user_id")
|
214 |
print(user_id)
|
215 |
|
@@ -228,5 +246,6 @@ async def process_synchronous_job(user_id,email,message_id,raw_text):
|
|
228 |
.execute()
|
229 |
)
|
230 |
|
|
|
231 |
except Exception as e:
|
232 |
print(f"Error occurred during processing: {e}")
|
|
|
9 |
from datetime import datetime
|
10 |
import os
|
11 |
import tiktoken
|
12 |
+
import re
|
13 |
|
14 |
|
15 |
app = FastAPI()
|
|
|
159 |
"""
|
160 |
return system_prompt
|
161 |
|
162 |
+
|
163 |
+
|
164 |
+
def parse_number(num_str):
|
165 |
+
# Remove commas and strip any unnecessary whitespace
|
166 |
+
cleaned_str = re.sub(r'[^\d.]', '', num_str.strip())
|
167 |
+
try:
|
168 |
+
# Convert to float
|
169 |
+
return float(cleaned_str)
|
170 |
+
except ValueError:
|
171 |
+
# Handle the case where the conversion fails
|
172 |
+
print(f"Error: {num_str} is not a valid number.")
|
173 |
+
return None
|
174 |
+
|
175 |
+
|
176 |
+
|
177 |
+
|
178 |
def adjust_prompt_tokens_v1(prompt: str) -> str:
|
179 |
max_tokens = 127500
|
180 |
encoding = tiktoken.encoding_for_model('gpt-4o-mini')
|
|
|
227 |
insert_data['email'] = email
|
228 |
insert_data['user_id'] = user_id
|
229 |
insert_data['message_id'] = message_id
|
230 |
+
insert_data['total_cost'] = parse_number(insert_data['total_cost'])
|
231 |
print("Printing user_id")
|
232 |
print(user_id)
|
233 |
|
|
|
246 |
.execute()
|
247 |
)
|
248 |
|
249 |
+
print(update_status_response)
|
250 |
except Exception as e:
|
251 |
print(f"Error occurred during processing: {e}")
|