Обновить routers/client.py
This commit is contained in:
		
							parent
							
								
									7420460e2e
								
							
						
					
					
						commit
						0a34a3b935
					
				| 
						 | 
				
			
			@ -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")
 | 
			
		||||
 | 
			
		||||
    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}"}
 | 
			
		||||
		Loading…
	
		Reference in New Issue