From 56f91948f81b6942c90057388c5bfd1ba4c1b1be Mon Sep 17 00:00:00 2001
From: Alex
Date: Sun, 9 Feb 2025 12:05:37 +0000
Subject: [PATCH 1/3] feat: improve logging
---
application/api/answer/routes.py | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/application/api/answer/routes.py b/application/api/answer/routes.py
index e877fac5..2df97b0d 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"]
@@ -210,6 +212,15 @@ def complete_stream(
):
try:
+ import sys
+
+ try:
+ logger.info(f"Stream question, inside complete_stream: {question}")
+ except Exception as e:
+ print(f"Error in logging: {str(e)}", file=sys.stderr)
+ print(traceback.format_exc(), file=sys.stderr)
+
+
response_full = ""
source_log_docs = []
answer = retriever.gen()
@@ -260,8 +271,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 +357,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 +391,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 +482,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 +537,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 +602,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 +640,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()},
)
From f639b052e395c7220cdee9ba9e238a3dbf2fa171 Mon Sep 17 00:00:00 2001
From: Alex
Date: Sun, 9 Feb 2025 12:08:19 +0000
Subject: [PATCH 2/3] fix: remove debugging code
---
application/api/answer/routes.py | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/application/api/answer/routes.py b/application/api/answer/routes.py
index 2df97b0d..a2e32eba 100644
--- a/application/api/answer/routes.py
+++ b/application/api/answer/routes.py
@@ -211,16 +211,7 @@ def complete_stream(
question, retriever, conversation_id, user_api_key, isNoneDoc=False,index=None
):
- try:
- import sys
-
- try:
- logger.info(f"Stream question, inside complete_stream: {question}")
- except Exception as e:
- print(f"Error in logging: {str(e)}", file=sys.stderr)
- print(traceback.format_exc(), file=sys.stderr)
-
-
+ try:
response_full = ""
source_log_docs = []
answer = retriever.gen()
From 568ab33a37a4476f27b7017b40ffd24dc733c079 Mon Sep 17 00:00:00 2001
From: Piotr Idzik <65706193+vil02@users.noreply.github.com>
Date: Sun, 9 Feb 2025 23:56:52 +0100
Subject: [PATCH 3/3] style: use underscore for an unused loop variable (#1593)
This addresses the SC2034 warning.
---
setup.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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