Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,19 +20,7 @@ async def root():
|
|
| 20 |
async def health_check():
|
| 21 |
return {"status": "OK"}
|
| 22 |
|
| 23 |
-
|
| 24 |
-
@app.get("/api/fastAI")
|
| 25 |
-
async def fast_ai_endpoint(user: str, model: str = "llama3-70b", system: str = "Answer as concisely as possible."):
|
| 26 |
-
"""Get a response from the Snova AI service."""
|
| 27 |
-
FastAI.model = model
|
| 28 |
-
FastAI.system = system
|
| 29 |
-
try:
|
| 30 |
-
response = await asyncio.to_thread(FastAI.generate_response, user)
|
| 31 |
-
return JSONResponse(content={"response": response})
|
| 32 |
-
except Exception as e:
|
| 33 |
-
raise HTTPException(status_code=500, detail=f"Error during Snova AI request: {e}")
|
| 34 |
-
|
| 35 |
-
|
| 36 |
@app.get("/api/search")
|
| 37 |
async def search(
|
| 38 |
q: str,
|
|
@@ -163,7 +151,21 @@ async def llm_chat(
|
|
| 163 |
except Exception as e:
|
| 164 |
raise HTTPException(status_code=500, detail=f"Error during LLM chat: {e}")
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
|
|
|
| 167 |
@app.get("/api/answers")
|
| 168 |
async def answers(q: str, proxy: Optional[str] = None):
|
| 169 |
"""Get instant answers for a query."""
|
|
|
|
| 20 |
async def health_check():
|
| 21 |
return {"status": "OK"}
|
| 22 |
|
| 23 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
@app.get("/api/search")
|
| 25 |
async def search(
|
| 26 |
q: str,
|
|
|
|
| 151 |
except Exception as e:
|
| 152 |
raise HTTPException(status_code=500, detail=f"Error during LLM chat: {e}")
|
| 153 |
|
| 154 |
+
fast_ai = FastAI()
|
| 155 |
+
|
| 156 |
+
@app.get("/api/fastAI")
|
| 157 |
+
async def fast_ai_endpoint(user: str, model: str = "llama3-70b", system: str = "Answer as concisely as possible."):
|
| 158 |
+
"""Get a response from the Snova AI service."""
|
| 159 |
+
fast_ai.model = model
|
| 160 |
+
fast_ai.system = system
|
| 161 |
+
try:
|
| 162 |
+
# Use asyncio.to_thread to run generate_response in a separate thread
|
| 163 |
+
response = await asyncio.to_thread(fast_ai.generate_response, user)
|
| 164 |
+
return JSONResponse(content={"response": response})
|
| 165 |
+
except Exception as e:
|
| 166 |
+
raise HTTPException(status_code=500, detail=f"Error during Snova AI request: {e}")
|
| 167 |
|
| 168 |
+
|
| 169 |
@app.get("/api/answers")
|
| 170 |
async def answers(q: str, proxy: Optional[str] = None):
|
| 171 |
"""Get instant answers for a query."""
|