Update extract_insights.py
Browse files- extract_insights.py +42 -37
extract_insights.py
CHANGED
|
@@ -188,40 +188,45 @@ async def process_synchronous_job(user_id,email,message_id,raw_text):
|
|
| 188 |
Background task to process the batch job
|
| 189 |
"""
|
| 190 |
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
Background task to process the batch job
|
| 189 |
"""
|
| 190 |
|
| 191 |
+
try:
|
| 192 |
+
prompt = receipt_radar_prompt(raw_text)
|
| 193 |
+
|
| 194 |
+
completion = client.chat.completions.create(
|
| 195 |
+
model="gpt-4o-mini",
|
| 196 |
+
messages=[
|
| 197 |
+
{
|
| 198 |
+
"role": "user",
|
| 199 |
+
"content": prompt
|
| 200 |
+
}
|
| 201 |
+
],
|
| 202 |
+
response_format={"type": "json_object"},
|
| 203 |
+
temperature=0.1
|
| 204 |
+
)
|
| 205 |
+
print("Printing GPT response")
|
| 206 |
+
print(completion.choices[0].message)
|
| 207 |
+
|
| 208 |
+
# inserting data into supabase
|
| 209 |
+
insert_data = json.loads(completion.choices[0].message.content)
|
| 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 |
+
|
| 216 |
+
insert_response = (
|
| 217 |
+
supabase.table("receipt_radar_structured_data_duplicate")
|
| 218 |
+
.insert(insert_data)
|
| 219 |
+
.execute()
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
update_status_response = (
|
| 223 |
+
supabase.table("receipt_ocr_data")
|
| 224 |
+
.update({"status": "processing completed"})
|
| 225 |
+
.eq("message_id", message_id)
|
| 226 |
+
.eq("user_id", user_id)
|
| 227 |
+
.eq("email", email)
|
| 228 |
+
.execute()
|
| 229 |
+
)
|
| 230 |
+
|
| 231 |
+
except Exception as e:
|
| 232 |
+
print(f"Error occurred during processing: {e}")
|