Spaces:
Sleeping
Sleeping
Update llm_app.py
Browse files- llm_app.py +26 -2
llm_app.py
CHANGED
|
@@ -83,6 +83,14 @@ class LLMCurriculumAssistant:
|
|
| 83 |
self.deepseek_api_key = os.environ.get("DEEPSEEK_API_KEY")
|
| 84 |
self.deepseek_base_url = "https://api.deepseek.com/v1/chat/completions"
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
# Create content selection prompt
|
| 87 |
content_selection_template = """Hi! I'm helping a student find the best curriculum slide for their question.
|
| 88 |
|
|
@@ -206,8 +214,16 @@ Thanks for your help! Here's what I'd tell the student:"""
|
|
| 206 |
}
|
| 207 |
|
| 208 |
response = requests.post(self.deepseek_base_url, headers=headers, json=data)
|
| 209 |
-
response.raise_for_status()
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
selection_response = response.json()["choices"][0]["message"]["content"]
|
| 212 |
print(f"DeepSeek Selection Response: {selection_response}")
|
| 213 |
|
|
@@ -269,8 +285,16 @@ Thanks for your help! Here's what I'd tell the student:"""
|
|
| 269 |
}
|
| 270 |
|
| 271 |
response = requests.post(self.deepseek_base_url, headers=headers, json=data)
|
| 272 |
-
response.raise_for_status()
|
| 273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
answer = response.json()["choices"][0]["message"]["content"].strip()
|
| 275 |
print(f"✅ DeepSeek answer generated: {answer[:100]}...")
|
| 276 |
|
|
|
|
| 83 |
self.deepseek_api_key = os.environ.get("DEEPSEEK_API_KEY")
|
| 84 |
self.deepseek_base_url = "https://api.deepseek.com/v1/chat/completions"
|
| 85 |
|
| 86 |
+
# Check if API key is available
|
| 87 |
+
if not self.deepseek_api_key:
|
| 88 |
+
print("❌ DEEPSEEK_API_KEY not found in environment variables")
|
| 89 |
+
print("Please set your DeepSeek API key as a HuggingFace secret named 'DEEPSEEK_API_KEY'")
|
| 90 |
+
raise Exception("DeepSeek API key not found")
|
| 91 |
+
|
| 92 |
+
print(f"✅ DeepSeek API key found: {self.deepseek_api_key[:20]}...")
|
| 93 |
+
|
| 94 |
# Create content selection prompt
|
| 95 |
content_selection_template = """Hi! I'm helping a student find the best curriculum slide for their question.
|
| 96 |
|
|
|
|
| 214 |
}
|
| 215 |
|
| 216 |
response = requests.post(self.deepseek_base_url, headers=headers, json=data)
|
|
|
|
| 217 |
|
| 218 |
+
if response.status_code == 401:
|
| 219 |
+
print("❌ DeepSeek API key is invalid or expired")
|
| 220 |
+
print("Please check your DeepSeek API key in HuggingFace secrets")
|
| 221 |
+
raise Exception("Invalid DeepSeek API key")
|
| 222 |
+
elif response.status_code != 200:
|
| 223 |
+
print(f"❌ DeepSeek API error: {response.status_code} - {response.text}")
|
| 224 |
+
raise Exception(f"DeepSeek API error: {response.status_code}")
|
| 225 |
+
|
| 226 |
+
response.raise_for_status()
|
| 227 |
selection_response = response.json()["choices"][0]["message"]["content"]
|
| 228 |
print(f"DeepSeek Selection Response: {selection_response}")
|
| 229 |
|
|
|
|
| 285 |
}
|
| 286 |
|
| 287 |
response = requests.post(self.deepseek_base_url, headers=headers, json=data)
|
|
|
|
| 288 |
|
| 289 |
+
if response.status_code == 401:
|
| 290 |
+
print("❌ DeepSeek API key is invalid or expired")
|
| 291 |
+
print("Please check your DeepSeek API key in HuggingFace secrets")
|
| 292 |
+
raise Exception("Invalid DeepSeek API key")
|
| 293 |
+
elif response.status_code != 200:
|
| 294 |
+
print(f"❌ DeepSeek API error: {response.status_code} - {response.text}")
|
| 295 |
+
raise Exception(f"DeepSeek API error: {response.status_code}")
|
| 296 |
+
|
| 297 |
+
response.raise_for_status()
|
| 298 |
answer = response.json()["choices"][0]["message"]["content"].strip()
|
| 299 |
print(f"✅ DeepSeek answer generated: {answer[:100]}...")
|
| 300 |
|