diff --git a/application/api/answer/routes.py b/application/api/answer/routes.py index e877fac5..a2e32eba 100644 --- a/application/api/answer/routes.py +++ b/application/api/answer/routes.py @@ -3,10 +3,11 @@ import datetime import json import os import traceback +import logging from bson.dbref import DBRef from bson.objectid import ObjectId -from flask import Blueprint, current_app, make_response, request, Response +from flask import Blueprint, make_response, request, Response from flask_restx import fields, Namespace, Resource @@ -18,6 +19,7 @@ from application.llm.llm_creator import LLMCreator from application.retriever.retriever_creator import RetrieverCreator from application.utils import check_required_fields, limit_chat_history +logger = logging.getLogger(__name__) mongo = MongoDB.get_client() db = mongo["docsgpt"] @@ -209,7 +211,7 @@ def complete_stream( question, retriever, conversation_id, user_api_key, isNoneDoc=False,index=None ): - try: + try: response_full = "" source_log_docs = [] answer = retriever.gen() @@ -260,8 +262,8 @@ def complete_stream( data = json.dumps({"type": "end"}) yield f"data: {data}\n\n" except Exception as e: - current_app.logger.error(f"Error in stream: {str(e)}") - current_app.logger.error(traceback.format_exc()) + logger.error(f"Error in stream: {str(e)}") + logger.error(traceback.format_exc()) data = json.dumps( { "type": "error", @@ -346,7 +348,7 @@ class Stream(Resource): source = {} user_api_key = None - current_app.logger.info( + logger.info( f"/stream - request_data: {data}, source: {source}", extra={"data": json.dumps({"request_data": data, "source": source})}, ) @@ -380,14 +382,14 @@ class Stream(Resource): except ValueError: message = "Malformed request body" - current_app.logger.error(f"/stream - error: {message}") + logger.error(f"/stream - error: {message}") return Response( error_stream_generate(message), status=400, mimetype="text/event-stream", ) except Exception as e: - current_app.logger.error( + logger.error( f"/stream - error: {str(e)} - traceback: {traceback.format_exc()}", extra={"error": str(e), "traceback": traceback.format_exc()}, ) @@ -471,7 +473,7 @@ class Answer(Resource): prompt = get_prompt(prompt_id) - current_app.logger.info( + logger.info( f"/api/answer - request_data: {data}, source: {source}", extra={"data": json.dumps({"request_data": data, "source": source})}, ) @@ -526,7 +528,7 @@ class Answer(Resource): ) except Exception as e: - current_app.logger.error( + logger.error( f"/api/answer - error: {str(e)} - traceback: {traceback.format_exc()}", extra={"error": str(e), "traceback": traceback.format_exc()}, ) @@ -591,7 +593,7 @@ class Search(Resource): source = {} user_api_key = None - current_app.logger.info( + logger.info( f"/api/answer - request_data: {data}, source: {source}", extra={"data": json.dumps({"request_data": data, "source": source})}, ) @@ -629,7 +631,7 @@ class Search(Resource): doc["source"] = "None" except Exception as e: - current_app.logger.error( + logger.error( f"/api/search - error: {str(e)} - traceback: {traceback.format_exc()}", extra={"error": str(e), "traceback": traceback.format_exc()}, ) diff --git a/setup.sh b/setup.sh index c39f1f0f..3b2c7855 100755 --- a/setup.sh +++ b/setup.sh @@ -31,7 +31,7 @@ check_and_start_docker() { # Wait for Docker to be fully operational with animated dots echo -n "Waiting for Docker to start" while ! docker system info > /dev/null 2>&1; do - for i in {1..3}; do + for _ in {1..3}; do echo -n "." sleep 1 done