From 8ac88e482d99edb5c12fe5843e9b624c3b97c234 Mon Sep 17 00:00:00 2001 From: Anton Dubovik Date: Mon, 11 Sep 2023 15:50:28 +0100 Subject: [PATCH] Fixed SAST findings --- client/client_adapter.py | 9 +++++---- utils/printing.py | 20 -------------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/client/client_adapter.py b/client/client_adapter.py index 66bbb77..fe5a0c7 100644 --- a/client/client_adapter.py +++ b/client/client_adapter.py @@ -1,4 +1,5 @@ import json +import logging from typing import List import openai @@ -12,9 +13,9 @@ from utils.args import get_host_port_args from utils.cli import select_option from utils.input import make_input -from utils.printing import print_ai, print_error -from utils.printing import print_exception as print_exc -from utils.printing import print_info +from utils.printing import print_ai, print_error, print_info + +log = logging.getLogger(__name__) DEFAULT_API_VERSION = "2023-03-15-preview" @@ -32,7 +33,7 @@ def get_available_models(base_url: str) -> List[str]: def print_exception(exc: Exception) -> None: - print_exc() + log.exception(exc) if isinstance(exc, OpenAIError): print_error(json.dumps(exc.json_body, indent=2)) else: diff --git a/utils/printing.py b/utils/printing.py index 19703e6..60b42e8 100644 --- a/utils/printing.py +++ b/utils/printing.py @@ -1,7 +1,4 @@ -import traceback - from colorama import Back, Fore, Style -from langchain.schema import AIMessage, BaseMessage, HumanMessage, SystemMessage def get_input(prefix: str = "") -> str: @@ -37,20 +34,3 @@ def print_human(msg: str, **args): def print_ai(msg: str, **args): print(Fore.BLUE + msg + Style.RESET_ALL, flush=True, **args) - - -def print_exception(): - print(Fore.RED, flush=True) - traceback.print_exc() - print(Style.RESET_ALL, flush=True) - - -def print_base_message(msg: BaseMessage, **args): - if isinstance(msg, HumanMessage): - print_human(msg.content, **args) - elif isinstance(msg, AIMessage): - print_ai(msg.content, **args) - elif isinstance(msg, SystemMessage): - print_system(msg.content, **args) - else: - print(msg.content, **args)