Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,17 @@ Schema:
|
|
| 16 |
- quantity: Number of items as integer
|
| 17 |
"""
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def extract_all(user_input):
|
| 20 |
messages = [
|
| 21 |
{"role": "system", "content": system_prompt},
|
|
@@ -41,6 +52,7 @@ def extract_all(user_input):
|
|
| 41 |
|
| 42 |
try:
|
| 43 |
parsed = json.loads(response)
|
|
|
|
| 44 |
return json.dumps(parsed, indent=2, ensure_ascii=False)
|
| 45 |
except json.JSONDecodeError:
|
| 46 |
return response
|
|
|
|
| 16 |
- quantity: Number of items as integer
|
| 17 |
"""
|
| 18 |
|
| 19 |
+
def clean_result(parsed):
|
| 20 |
+
for order in parsed.get("orders", []):
|
| 21 |
+
if "price" in order:
|
| 22 |
+
# "$29.99" → 29.99
|
| 23 |
+
price = str(order["price"]).replace("$", "").replace(",", "").strip()
|
| 24 |
+
try:
|
| 25 |
+
order["price"] = float(price)
|
| 26 |
+
except ValueError:
|
| 27 |
+
pass
|
| 28 |
+
return parsed
|
| 29 |
+
|
| 30 |
def extract_all(user_input):
|
| 31 |
messages = [
|
| 32 |
{"role": "system", "content": system_prompt},
|
|
|
|
| 52 |
|
| 53 |
try:
|
| 54 |
parsed = json.loads(response)
|
| 55 |
+
parsed = clean_result(parsed) # ← додай цей рядок
|
| 56 |
return json.dumps(parsed, indent=2, ensure_ascii=False)
|
| 57 |
except json.JSONDecodeError:
|
| 58 |
return response
|