Update api/utils.py
Browse files16 unmodified lines171819202021222334 unmodified lines58596061626364656667686970717273747576777879808182838485868788899016 unmodified lines messages = [msg.dict() for msg in request.messages]
try: async for content in AmigoChat.generate_response( async for content in await AmigoChat.generate_response( model=request.model, messages=messages, stream=True34 unmodified lines except Exception as e: logger.error(f"Error in streaming response: {e}") raise HTTPException(status_code=500, detail=str(e))
async def process_non_streaming_response(request: ChatRequest): logger.info("Processing non-streaming response with AmigoChat") messages = [msg.dict() for msg in request.messages]
try: content = await AmigoChat.generate_response( model=request.model, messages=messages, stream=False )
return { "id": f"chatcmpl-{uuid.uuid4()}", "object": "chat.completion", "created": int(datetime.now().timestamp()), "model": request.model, "choices": [ { "index": 0, "message": {"role": "assistant", "content": content}, "finish_reason": "stop", } ], "usage": None, }
except Exception as e: logger.error(f"Error in non-streaming response: {e}") raise HTTPException(status_code=500, detail=str(e))api/utils.py+31-1