Upload folder using huggingface_hub
Browse files- core/prompts.py +21 -18
- services/flashcard_service.py +14 -4
core/prompts.py
CHANGED
|
@@ -251,33 +251,36 @@ def get_flashcard_explanation_prompt(question: str, language: str = "Japanese")
|
|
| 251 |
# Language-specific instructions for explanations
|
| 252 |
if language == "Japanese":
|
| 253 |
language_instruction = """
|
| 254 |
-
LANGUAGE: JAPANESE
|
| 255 |
-
- Provide the explanation in Japanese language
|
| 256 |
-
- Use appropriate Japanese terminology and expressions
|
| 257 |
-
- Ensure the explanation is natural and clear in Japanese
|
| 258 |
-
- Use polite form (です/ます) for formal educational content"""
|
| 259 |
else: # English
|
| 260 |
language_instruction = """
|
| 261 |
-
LANGUAGE: ENGLISH
|
| 262 |
-
- Provide the explanation in English language
|
| 263 |
-
- Use clear, professional English terminology
|
| 264 |
-
- Ensure the explanation is grammatically correct and natural
|
| 265 |
-
- Use appropriate academic language for educational content"""
|
| 266 |
|
| 267 |
# Create comprehensive explanation prompt with PDF context
|
| 268 |
return f"""You are an expert tutor. Based on the uploaded PDF document, provide a detailed explanation for the following question:
|
| 269 |
|
| 270 |
-
{language_instruction}
|
|
|
|
|
|
|
| 271 |
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
2. Context from the PDF document that supports the answer
|
| 277 |
-
3. Additional relevant information that enhances understanding
|
| 278 |
-
4. Examples or analogies if helpful
|
| 279 |
|
| 280 |
-
Keep the explanation educational and detailed, drawing specifically from the PDF content."""
|
| 281 |
|
| 282 |
|
| 283 |
def get_mindmap_system_prompt() -> str:
|
|
|
|
| 251 |
# Language-specific instructions for explanations
|
| 252 |
if language == "Japanese":
|
| 253 |
language_instruction = """
|
| 254 |
+
LANGUAGE: JAPANESE
|
| 255 |
+
- Provide the explanation in Japanese language
|
| 256 |
+
- Use appropriate Japanese terminology and expressions
|
| 257 |
+
- Ensure the explanation is natural and clear in Japanese
|
| 258 |
+
- Use polite form (です/ます) for formal educational content"""
|
| 259 |
else: # English
|
| 260 |
language_instruction = """
|
| 261 |
+
LANGUAGE: ENGLISH
|
| 262 |
+
- Provide the explanation in English language
|
| 263 |
+
- Use clear, professional English terminology
|
| 264 |
+
- Ensure the explanation is grammatically correct and natural
|
| 265 |
+
- Use appropriate academic language for educational content"""
|
| 266 |
|
| 267 |
# Create comprehensive explanation prompt with PDF context
|
| 268 |
return f"""You are an expert tutor. Based on the uploaded PDF document, provide a detailed explanation for the following question:
|
| 269 |
|
| 270 |
+
{language_instruction}
|
| 271 |
+
|
| 272 |
+
Question: {question}
|
| 273 |
|
| 274 |
+
OUTPUT FORMAT:
|
| 275 |
+
- Provide the explanation as a SINGLE continuous paragraph.
|
| 276 |
+
- Do NOT use any newlines (\\n), bullet points, or numbered lists.
|
| 277 |
+
- Do NOT use any markdown formatting like bold (**), italics (*), or headers (#).
|
| 278 |
+
- The output must be simple, plain text only.
|
| 279 |
|
| 280 |
+
REQUIREMENTS:
|
| 281 |
+
Include a clear, comprehensive explanation that helps the student understand the concept, using context from the PDF document, additional relevant information, and examples or analogies.
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
+
Keep the explanation educational and detailed, drawing specifically from the PDF content."""
|
| 284 |
|
| 285 |
|
| 286 |
def get_mindmap_system_prompt() -> str:
|
services/flashcard_service.py
CHANGED
|
@@ -186,7 +186,8 @@ class FlashcardService:
|
|
| 186 |
response = await asyncio.to_thread(
|
| 187 |
self.openai_client.chat.completions.create,
|
| 188 |
model="gpt-4o-mini",
|
| 189 |
-
messages=messages
|
|
|
|
| 190 |
)
|
| 191 |
|
| 192 |
# Clean up OpenAI file (non-blocking)
|
|
@@ -195,7 +196,11 @@ class FlashcardService:
|
|
| 195 |
uploaded_file.id
|
| 196 |
)
|
| 197 |
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
finally:
|
| 200 |
# Remove temp file (non-blocking)
|
| 201 |
if os.path.exists(tmp_path):
|
|
@@ -210,9 +215,14 @@ class FlashcardService:
|
|
| 210 |
response = await asyncio.to_thread(
|
| 211 |
self.openai_client.chat.completions.create,
|
| 212 |
model="gpt-4o-mini",
|
| 213 |
-
messages=messages
|
|
|
|
| 214 |
)
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
except Exception as e:
|
| 218 |
logger.error(f"Explanation generation failed: {str(e)}")
|
|
|
|
| 186 |
response = await asyncio.to_thread(
|
| 187 |
self.openai_client.chat.completions.create,
|
| 188 |
model="gpt-4o-mini",
|
| 189 |
+
messages=messages,
|
| 190 |
+
temperature=0.3
|
| 191 |
)
|
| 192 |
|
| 193 |
# Clean up OpenAI file (non-blocking)
|
|
|
|
| 196 |
uploaded_file.id
|
| 197 |
)
|
| 198 |
|
| 199 |
+
content = response.choices[0].message.content or ""
|
| 200 |
+
# Clean up: remove newlines, markdown bolding, and extra spaces
|
| 201 |
+
content = content.replace("\n", " ").replace("**", "").replace("__", "")
|
| 202 |
+
content = " ".join(content.split())
|
| 203 |
+
return content
|
| 204 |
finally:
|
| 205 |
# Remove temp file (non-blocking)
|
| 206 |
if os.path.exists(tmp_path):
|
|
|
|
| 215 |
response = await asyncio.to_thread(
|
| 216 |
self.openai_client.chat.completions.create,
|
| 217 |
model="gpt-4o-mini",
|
| 218 |
+
messages=messages,
|
| 219 |
+
temperature=0.3
|
| 220 |
)
|
| 221 |
+
content = response.choices[0].message.content or ""
|
| 222 |
+
# Clean up: remove newlines, markdown bolding, and extra spaces
|
| 223 |
+
content = content.replace("\n", " ").replace("**", "").replace("__", "")
|
| 224 |
+
content = " ".join(content.split())
|
| 225 |
+
return content
|
| 226 |
|
| 227 |
except Exception as e:
|
| 228 |
logger.error(f"Explanation generation failed: {str(e)}")
|