Spaces:
Running
on
A10G
Running
on
A10G
Zhen Ye
commited on
Commit
·
1eea4fe
1
Parent(s):
e16d22f
fix: Handle empty GPT responses and log outputs
Browse files- app.py +1 -0
- utils/gpt_distance.py +5 -1
app.py
CHANGED
|
@@ -592,6 +592,7 @@ async def reason_track(
|
|
| 592 |
try:
|
| 593 |
# estimate_distance_gpt reads the file from disk
|
| 594 |
results = await asyncio.to_thread(estimate_distance_gpt, input_path, track_list)
|
|
|
|
| 595 |
except Exception as e:
|
| 596 |
logging.exception("GPT reasoning failed")
|
| 597 |
_safe_delete(input_path)
|
|
|
|
| 592 |
try:
|
| 593 |
# estimate_distance_gpt reads the file from disk
|
| 594 |
results = await asyncio.to_thread(estimate_distance_gpt, input_path, track_list)
|
| 595 |
+
logging.info(f"GPT Output for Video Track Update:\n{results}")
|
| 596 |
except Exception as e:
|
| 597 |
logging.exception("GPT reasoning failed")
|
| 598 |
_safe_delete(input_path)
|
utils/gpt_distance.py
CHANGED
|
@@ -122,7 +122,11 @@ def estimate_distance_gpt(
|
|
| 122 |
with urllib.request.urlopen(req) as response:
|
| 123 |
resp_data = json.loads(response.read().decode('utf-8'))
|
| 124 |
|
| 125 |
-
content = resp_data['choices'][0]['message']
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
# Clean potential markdown headers if GPT ignores instruction
|
| 127 |
if content.startswith("```json"):
|
| 128 |
content = content[7:]
|
|
|
|
| 122 |
with urllib.request.urlopen(req) as response:
|
| 123 |
resp_data = json.loads(response.read().decode('utf-8'))
|
| 124 |
|
| 125 |
+
content = resp_data['choices'][0]['message'].get('content')
|
| 126 |
+
if not content:
|
| 127 |
+
logger.warning("GPT returned empty content. Full response: %s", resp_data)
|
| 128 |
+
return {}
|
| 129 |
+
|
| 130 |
# Clean potential markdown headers if GPT ignores instruction
|
| 131 |
if content.startswith("```json"):
|
| 132 |
content = content[7:]
|