nanova commited on
Commit
ed9d3e7
·
1 Parent(s): 63850fe
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -62,15 +62,18 @@ def respond(
62
  print(f"[INFO] modelParam: temperature={temperature}, top_p={top_p}")
63
  print(f"[INFO] reqData: {data}")
64
 
65
- response = ""
66
-
67
- with requests.post(API_URL, headers=headers, json=data) as r:
68
- if r.status_code == 200:
69
- json_response = r.json()
70
- if 'choices' in json_response and len(json_response['choices']) > 0:
71
- response = json_response['choices'][0].get('message', {}).get('content', '')
72
- if response:
73
- yield response
 
 
 
74
 
75
 
76
  """
 
62
  print(f"[INFO] modelParam: temperature={temperature}, top_p={top_p}")
63
  print(f"[INFO] reqData: {data}")
64
 
65
+ try:
66
+ with requests.post(API_URL, headers=headers, json=data) as r:
67
+ if r.status_code == 200:
68
+ json_response = r.json()
69
+ if 'choices' in json_response and len(json_response['choices']) > 0:
70
+ response = json_response['choices'][0].get('message', {}).get('content', '')
71
+ if response:
72
+ return response
73
+ return "Service temporarily unavailable"
74
+ except Exception as e:
75
+ print(f"[ERROR] Request error: {e}")
76
+ return "Service error occurred"
77
 
78
 
79
  """