Spaces:
Sleeping
Sleeping
Update app.py
#2
by Muthuraja18 - opened
app.py
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from groq import Groq
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 9 |
+
|
| 10 |
+
MODEL_NAME = "openai/gpt-oss-20b"
|
| 11 |
+
|
| 12 |
+
class Query(BaseModel):
|
| 13 |
+
question: str
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
knowledge = """
|
| 17 |
+
Platform Features:
|
| 18 |
+
- AI Quiz Game
|
| 19 |
+
- MCQ Exam System
|
| 20 |
+
- Leaderboard Ranking
|
| 21 |
+
- Analytics Dashboard
|
| 22 |
+
- Exam Reports
|
| 23 |
+
|
| 24 |
+
Leaderboard ranking is based on:
|
| 25 |
+
1. Score
|
| 26 |
+
2. Completion time
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@app.post("/support")
|
| 31 |
+
def support(q: Query):
|
| 32 |
+
|
| 33 |
+
prompt = f"""
|
| 34 |
+
You are AI support for an AI Game & Exam platform.
|
| 35 |
+
|
| 36 |
+
Knowledge:
|
| 37 |
+
{knowledge}
|
| 38 |
+
|
| 39 |
+
User Question:
|
| 40 |
+
{q.question}
|
| 41 |
+
|
| 42 |
+
Answer clearly.
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
response = client.chat.completions.create(
|
| 46 |
+
model=MODEL_NAME,
|
| 47 |
+
messages=[
|
| 48 |
+
{"role":"system","content":"You are a helpful AI support assistant."},
|
| 49 |
+
{"role":"user","content":prompt}
|
| 50 |
+
]
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
return {"answer": response.choices[0].message.content}
|