Обновить routers/client.py

This commit is contained in:
Alex55 2025-04-23 16:27:29 +03:00
parent 7420460e2e
commit 0a34a3b935
1 changed files with 24 additions and 0 deletions

View File

@ -341,3 +341,27 @@ async def jobs_delete(data: jobs_delete, x_api_key: str = Header(...), db: Sessi
raise HTTPException(status_code=400, detail="Error processing data") raise HTTPException(status_code=400, detail="Error processing data")
return {"status": "ok", "message": "Data received", "user_id": user_id, "job_id": job_id} return {"status": "ok", "message": "Data received", "user_id": user_id, "job_id": job_id}
class QuestionRequest(BaseModel):
question: str
client_name: str
token: str
@router.post("/ask_question")
async def ask_question(data: QuestionRequest):
try:
response = requests.get(
f"https://devnet.turboapply.ai/api/qaRequest/?question={data.question}",
headers={"token": data.token}
)
response.raise_for_status()
external_data = response.json()
content = external_data['result']['choices'][0]['message']['content']
result = content.split(":")[-1].strip()
except Exception as e:
raise HTTPException(status_code=502, detail=f"Error from external API: {str(e)}")
return {"answer": f"{result}"}