seawolf2357 commited on
Commit
57d8237
·
verified ·
1 Parent(s): da2d938

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -142,13 +142,22 @@ def analyze_character(lunIljin, OPENAI_API_KEY):
142
  "Content-Type": "application/json",
143
  "Authorization": f"Bearer {OPENAI_API_KEY}" # API 키가 정확히 입력되었는지 확인
144
  }
 
145
  response = requests.post(API_URL, headers=headers, json=payload)
 
146
  if response.status_code == 200:
147
  data = response.json()
148
  return data["choices"][0]["text"]
149
  else:
150
- return f"오류가 발생했습니다. 상태 코드: {response.status_code}"
151
-
 
 
 
 
 
 
 
152
 
153
  # 사주 분석 데이터 예시 (간소화된 버전)
154
  사주_데이터 = {
 
142
  "Content-Type": "application/json",
143
  "Authorization": f"Bearer {OPENAI_API_KEY}" # API 키가 정확히 입력되었는지 확인
144
  }
145
+
146
  response = requests.post(API_URL, headers=headers, json=payload)
147
+
148
  if response.status_code == 200:
149
  data = response.json()
150
  return data["choices"][0]["text"]
151
  else:
152
+ # 오류 메시지 반환 방식 개선
153
+ try:
154
+ error_data = response.json() # 오류 응답이 JSON 형태인 경우
155
+ error_message = error_data.get("error", {}).get("message", "API 호출에 실패했습니다.")
156
+ except ValueError:
157
+ error_message = "API 호출 실패: 응답을 JSON으로 파싱할 수 없습니다."
158
+
159
+ return f"오류가 발생했습니다. 상태 코드: {response.status_code}, 메시지: {error_message}"
160
+
161
 
162
  # 사주 분석 데이터 예시 (간소화된 버전)
163
  사주_데이터 = {