recall the failed call
This commit is contained in:
17
total_app.py
17
total_app.py
@@ -29,7 +29,7 @@ with open(EDSS_INSTRUCTIONS_PATH, 'r') as f:
|
||||
EDSS_INSTRUCTIONS = f.read().strip()
|
||||
|
||||
# === RUN INFERENCE 2 ===
|
||||
def run_inference(patient_text):
|
||||
def run_inference(patient_text, max_retries=3):
|
||||
prompt = f'''Du bist ein medizinischer Assistent, der spezialisiert darauf ist, EDSS-Scores (Expanded Disability Status Scale) sowie alle Unterkategorien aus klinischen Berichten zu extrahieren.
|
||||
### Regeln für die Ausgabe:
|
||||
1. **Reason**: Erstelle eine prägnante Zusammenfassung (max. 400 Zeichen) der Befunde auf **DEUTSCH**, die zur Einstufung führen.
|
||||
@@ -65,8 +65,8 @@ Patientenbericht:
|
||||
'''
|
||||
|
||||
start_time = time.time()
|
||||
for attempt in range(max_retries + 1):
|
||||
try:
|
||||
# Make API call using OpenAI client
|
||||
response = client.chat.completions.create(
|
||||
messages=[
|
||||
{
|
||||
@@ -83,12 +83,11 @@ Patientenbericht:
|
||||
temperature=0.0,
|
||||
response_format={"type": "json_object"}
|
||||
)
|
||||
# Extract content from response
|
||||
content = response.choices[0].message.content
|
||||
# Check if content is None or empty
|
||||
|
||||
if content is None or content.strip() == "":
|
||||
raise ValueError("API returned empty or None response content")
|
||||
# Parse the JSON response
|
||||
|
||||
parsed = json.loads(content)
|
||||
inference_time = time.time() - start_time
|
||||
return {
|
||||
@@ -96,8 +95,14 @@ Patientenbericht:
|
||||
"result": parsed,
|
||||
"inference_time_sec": inference_time
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"Inference error: {e}")
|
||||
print(f"Attempt {attempt + 1} failed: {e}")
|
||||
if attempt < max_retries:
|
||||
time.sleep(2 ** attempt) # Exponential backoff
|
||||
continue
|
||||
else:
|
||||
print("All retries exhausted.")
|
||||
return {
|
||||
"success": False,
|
||||
"error": str(e),
|
||||
|
||||
Reference in New Issue
Block a user