Spaces:
Running
Running
seawolf2357
commited on
Commit
β’
d98fe87
1
Parent(s):
57d8237
Update app.py
Browse files
app.py
CHANGED
@@ -126,37 +126,31 @@ def get_lunar_info(solYear, solMonth, solDay, solHour):
|
|
126 |
return {"Error": "API νΈμΆμ μ€ν¨νμ΅λλ€."}, "μ 보 μμ", "<p>API νΈμΆμ μ€ν¨νμ΅λλ€.</p>"
|
127 |
|
128 |
|
129 |
-
|
130 |
def analyze_character(lunIljin, OPENAI_API_KEY):
|
131 |
-
API_URL = "https://api.openai.com/v1/chat/completions"
|
132 |
payload = {
|
133 |
-
"model": "gpt-4-0125-preview", #
|
134 |
-
"
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
140 |
}
|
141 |
headers = {
|
142 |
"Content-Type": "application/json",
|
143 |
-
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
144 |
}
|
145 |
-
|
146 |
response = requests.post(API_URL, headers=headers, json=payload)
|
147 |
-
|
148 |
if response.status_code == 200:
|
149 |
data = response.json()
|
150 |
-
|
|
|
151 |
else:
|
152 |
-
# μ€λ₯ λ©μμ§
|
153 |
-
|
154 |
-
|
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 |
# μ¬μ£Ό λΆμ λ°μ΄ν° μμ (κ°μνλ λ²μ )
|
|
|
126 |
return {"Error": "API νΈμΆμ μ€ν¨νμ΅λλ€."}, "μ 보 μμ", "<p>API νΈμΆμ μ€ν¨νμ΅λλ€.</p>"
|
127 |
|
128 |
|
|
|
129 |
def analyze_character(lunIljin, OPENAI_API_KEY):
|
130 |
+
API_URL = "https://api.openai.com/v1/chat/completions"
|
131 |
payload = {
|
132 |
+
"model": "gpt-4-0125-preview", # λͺ¨λΈ μ΄λ¦ νμΈ νμ
|
133 |
+
"messages": [{
|
134 |
+
"role": "system",
|
135 |
+
"content": "λΉμ μ μ¬μ£Ό νμμ λν΄ μ€λͺ
νλ μ±λ΄μ
λλ€."
|
136 |
+
}, {
|
137 |
+
"role": "user",
|
138 |
+
"content": f"μΌμ£Ό '{lunIljin}'μ λν μ±κ²©κ³Ό νΉμ§μ μ€λͺ
ν΄μ£ΌμΈμ."
|
139 |
+
}],
|
140 |
}
|
141 |
headers = {
|
142 |
"Content-Type": "application/json",
|
143 |
+
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
144 |
}
|
|
|
145 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
146 |
if response.status_code == 200:
|
147 |
data = response.json()
|
148 |
+
# λνν API μλ΅μμ μ μ ν λ©μμ§ μΆμΆ
|
149 |
+
return data["choices"][0]["message"]["content"]
|
150 |
else:
|
151 |
+
# μ€λ₯ λ©μμ§ κ°μ
|
152 |
+
return f"μ€λ₯κ° λ°μνμ΅λλ€. μν μ½λ: {response.status_code}, λ©μμ§: {response.json().get('error', {}).get('message', 'Unknown error')}"
|
153 |
+
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
|
156 |
# μ¬μ£Ό λΆμ λ°μ΄ν° μμ (κ°μνλ λ²μ )
|