MossaabDev commited on
Commit
1043f8b
·
verified ·
1 Parent(s): 1f7e4a8

Update app/main.py

Browse files
Files changed (1) hide show
  1. 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️⃣ Find top 5 related ayahs using Qdrant
22
- verses = find_top_5_ayahs_qdrant(question)
23
 
24
- # 2️⃣ Generate reflection using Azure OpenAI
25
  messages = [
26
  {
27
  "role": "system",
28
  "content": (
29
- "You are a compassionate Islamic guide who offers short (≤3 lines) spiritual reflections. "
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
- reflection = completion.choices[0].message.content
45
  except Exception as e:
46
- reflection = f"⚠️ Error generating reflection: {str(e)}"
47
-
48
- # 3️⃣ Combine reflection + verses
49
- return {
50
- "results": [
51
- {"type": "reflection", "answer": reflection},
52
- *verses # Append ayahs from Qdrant
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("/")