Skip to content

Commit

Permalink
Use logger instead of print where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
paulovcmedeiros committed Nov 10, 2023
1 parent b26fb7d commit 6b699c9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion gpt_buddy_bot/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from collections import defaultdict
from pathlib import Path

from loguru import logger

from . import GeneralConstants
from .chat_configs import ChatOptions
from .chat_context import EmbeddingBasedChatContext, FullHistoryChatContext
Expand Down Expand Up @@ -275,7 +277,8 @@ def start(self):
print()
print()
except (KeyboardInterrupt, EOFError):
print("Exiting chat.")
print("", end="\r")
logger.info("Exiting chat.")

def report_token_usage(self, current_chat: bool = True):
"""Report token usage and associated costs."""
Expand Down
4 changes: 3 additions & 1 deletion gpt_buddy_bot/command_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"""Commands supported by the package's script."""
import subprocess

from loguru import logger

from . import GeneralConstants
from .chat import Chat
from .chat_configs import ChatOptions
Expand Down Expand Up @@ -36,4 +38,4 @@ def run_on_ui(args):
check=True,
)
except (KeyboardInterrupt, EOFError):
print("Exiting.")
logger.info("Exiting.")
9 changes: 6 additions & 3 deletions gpt_buddy_bot/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING

import openai
from loguru import logger

from .chat_configs import OpenAiApiCallOptions

Expand All @@ -26,9 +27,11 @@ def retry_api_call(max_n_attempts=5, auth_error_msg="Problems connecting to Open

def on_error(error, n_attempts):
if n_attempts < max_n_attempts:
print(
f"\n > {error}. "
+ f"Making new attempt ({n_attempts+1}/{max_n_attempts})..."
logger.warning(
" > {}. Making new attempt ({}/{})...",
error,
n_attempts + 1,
max_n_attempts,
)
time.sleep(1)
else:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
scikit-learn = "^1.3.2"
scipy = "^1.11.3"
# Other dependencies
loguru = "^0.7.2"
numpy = "^1.26.1"
openai = "^0.28.1"
pandas = "^2.1.2"
Expand All @@ -44,12 +45,12 @@
pytest = "^7.4.3"
pytest-cov = "^4.1.0"
pytest-mock = "^3.12.0"
pytest-order = "^1.1.0"
python-lorem = "^1.3.0.post1"

##################
# Linter configs #
##################
pytest-order = "^1.1.0"

[tool.black]
line-length = 90
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def _mock_input(*args, **kwargs): # noqa: ARG001
raise KeyboardInterrupt
return user_input

mocker.patch("builtins.input", new=lambda _: _mock_input(user_input=user_input))
mocker.patch( # noqa: PT008
"builtins.input", new=lambda _: _mock_input(user_input=user_input)
)


@pytest.fixture(params=ChatOptions.get_allowed_values("model"))
Expand Down

0 comments on commit 6b699c9

Please sign in to comment.