Spaces:
Runtime error
Runtime error
Update app/main.py
Browse files- app/main.py +15 -16
app/main.py
CHANGED
|
@@ -18,16 +18,16 @@ deployment_name = os.getenv("VITE_AZURE_LLM_DEPLOYMENT")
|
|
| 18 |
async def ask(payload: QuestionRequest):
|
| 19 |
question = payload.question
|
| 20 |
|
| 21 |
-
# 1️⃣
|
| 22 |
-
|
| 23 |
|
| 24 |
-
# 2️⃣ Generate reflection using Azure
|
| 25 |
messages = [
|
| 26 |
{
|
| 27 |
"role": "system",
|
| 28 |
"content": (
|
| 29 |
-
"You are a compassionate Islamic guide who offers short (≤3 lines)
|
| 30 |
-
"Speak with empathy, hope, and gentle wisdom. "
|
| 31 |
"Do NOT quote or refer to Qur’an verses, as they are provided separately."
|
| 32 |
),
|
| 33 |
},
|
|
@@ -39,19 +39,18 @@ async def ask(payload: QuestionRequest):
|
|
| 39 |
model=deployment_name,
|
| 40 |
messages=messages,
|
| 41 |
max_tokens=120,
|
| 42 |
-
temperature=0.8
|
| 43 |
)
|
| 44 |
-
|
| 45 |
except Exception as e:
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
# 3️⃣
|
| 49 |
-
return
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
}
|
| 55 |
|
| 56 |
|
| 57 |
@app.get("/")
|
|
|
|
| 18 |
async def ask(payload: QuestionRequest):
|
| 19 |
question = payload.question
|
| 20 |
|
| 21 |
+
# 1️⃣ Get ayahs from Qdrant
|
| 22 |
+
ayah_results = find_top_5_ayahs_qdrant(question)
|
| 23 |
|
| 24 |
+
# 2️⃣ Generate reflection using Azure LLM
|
| 25 |
messages = [
|
| 26 |
{
|
| 27 |
"role": "system",
|
| 28 |
"content": (
|
| 29 |
+
"You are a compassionate Islamic guide who offers short (≤3 lines) "
|
| 30 |
+
"spiritual reflections. Speak with empathy, hope, and gentle wisdom. "
|
| 31 |
"Do NOT quote or refer to Qur’an verses, as they are provided separately."
|
| 32 |
),
|
| 33 |
},
|
|
|
|
| 39 |
model=deployment_name,
|
| 40 |
messages=messages,
|
| 41 |
max_tokens=120,
|
| 42 |
+
temperature=0.8,
|
| 43 |
)
|
| 44 |
+
reflection_text = completion.choices[0].message.content
|
| 45 |
except Exception as e:
|
| 46 |
+
reflection_text = f"⚠️ Error generating reflection: {str(e)}"
|
| 47 |
+
|
| 48 |
+
# 3️⃣ Return structured response
|
| 49 |
+
return AnswerListResponse(
|
| 50 |
+
reflection=ReflectionResponse(reflection=reflection_text),
|
| 51 |
+
ayahs=ayah_results,
|
| 52 |
+
)
|
| 53 |
+
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
@app.get("/")
|