Spaces:
Running
Running
extract metadata
Browse files- backend/__pycache__/config.cpython-310.pyc +0 -0
- backend/__pycache__/main.cpython-310.pyc +0 -0
- backend/config.py +24 -1
- backend/main.py +21 -0
backend/__pycache__/config.cpython-310.pyc
CHANGED
Binary files a/backend/__pycache__/config.cpython-310.pyc and b/backend/__pycache__/config.cpython-310.pyc differ
|
|
backend/__pycache__/main.cpython-310.pyc
CHANGED
Binary files a/backend/__pycache__/main.cpython-310.pyc and b/backend/__pycache__/main.cpython-310.pyc differ
|
|
backend/config.py
CHANGED
@@ -1,3 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
flashcard_mode_instructions = """
|
2 |
You are a versatile vocabulary tutor capable of teaching **any language**. Your goal is to help users learn **as fast as possible** by creating highly relevant vocabulary flashcards **directly tied to their stated hobbies, work, or studies.** The learning experience should feel personalized and engaging because it uses their specific context.
|
3 |
|
@@ -121,4 +144,4 @@ Example JSON Output (Illustrative - content will vary based on domain):
|
|
121 |
}
|
122 |
|
123 |
Output ONLY the valid JSON object. Do not include introductory text, notes, or any extra formatting.
|
124 |
-
"""
|
|
|
1 |
+
language_metadata_extraction_prompt = """
|
2 |
+
You are a language learning assistant. Your task is to analyze the user's input and infer their:
|
3 |
+
- Native language (use the language of the input as a fallback if unsure)
|
4 |
+
- Target language (the one they want to learn)
|
5 |
+
- Proficiency level (beginner, intermediate, or advanced)
|
6 |
+
|
7 |
+
Respond ONLY with a valid JSON object using the following format:
|
8 |
+
|
9 |
+
{
|
10 |
+
"native_language": "<user's native language>",
|
11 |
+
"target_language": "<language the user wants to learn>",
|
12 |
+
"proficiency_level": "<beginner | intermediate | advanced>"
|
13 |
+
}
|
14 |
+
|
15 |
+
Guidelines:
|
16 |
+
- If the user's native language is not explicitly stated, assume it's the same as the language used in the query.
|
17 |
+
- If the target language is mentioned indirectly (e.g. "my Dutch isn't great"), infer that as the target language.
|
18 |
+
- Make a reasonable guess at proficiency based on clues like "isn't great" → beginner or "I want to improve" → intermediate.
|
19 |
+
- If you cannot infer something at all, write "unknown".
|
20 |
+
|
21 |
+
Do not include any explanations, comments, or formatting — only valid JSON.
|
22 |
+
"""
|
23 |
+
|
24 |
flashcard_mode_instructions = """
|
25 |
You are a versatile vocabulary tutor capable of teaching **any language**. Your goal is to help users learn **as fast as possible** by creating highly relevant vocabulary flashcards **directly tied to their stated hobbies, work, or studies.** The learning experience should feel personalized and engaging because it uses their specific context.
|
26 |
|
|
|
144 |
}
|
145 |
|
146 |
Output ONLY the valid JSON object. Do not include introductory text, notes, or any extra formatting.
|
147 |
+
"""
|
backend/main.py
CHANGED
@@ -21,10 +21,31 @@ class GenerationRequest(BaseModel):
|
|
21 |
user_id: int
|
22 |
query: str
|
23 |
|
|
|
|
|
|
|
24 |
@app.get("/")
|
25 |
async def root():
|
26 |
return {"message": "Welcome to the AI Learning Assistant API!"}
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
@app.post("/generate/flashcards")
|
29 |
async def generate_flashcards(data: GenerationRequest):
|
30 |
try:
|
|
|
21 |
user_id: int
|
22 |
query: str
|
23 |
|
24 |
+
class MetadataRequest(BaseModel):
|
25 |
+
query: str
|
26 |
+
|
27 |
@app.get("/")
|
28 |
async def root():
|
29 |
return {"message": "Welcome to the AI Learning Assistant API!"}
|
30 |
|
31 |
+
@app.post("/extract/metadata")
|
32 |
+
async def extract_metadata(data: MetadataRequest):
|
33 |
+
try:
|
34 |
+
response = await generate_completions.get_completions(
|
35 |
+
data.query,
|
36 |
+
config.language_metadata_extraction_prompt
|
37 |
+
)
|
38 |
+
return JSONResponse(
|
39 |
+
content={
|
40 |
+
"data": response,
|
41 |
+
"type": "language_metadata",
|
42 |
+
"status": "success"
|
43 |
+
},
|
44 |
+
status_code=200
|
45 |
+
)
|
46 |
+
except Exception as e:
|
47 |
+
raise HTTPException(status_code=500, detail=str(e))
|
48 |
+
|
49 |
@app.post("/generate/flashcards")
|
50 |
async def generate_flashcards(data: GenerationRequest):
|
51 |
try:
|