Skip to content

Commit

Permalink
#10 add logging instead of print()
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Gavryliuk committed Jan 3, 2024
1 parent abbb8e3 commit 8d0504a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions daily_dragon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import logging

from openai import OpenAI

import prompts

logger = logging.getLogger(__name__)

LANGUAGES = {'Chinese', 'Japanese'}


Expand All @@ -16,15 +20,15 @@ def __init__(self):
def get_daily_word(self):
prompt = prompts.get_daily_word_prompt()
prompt = prompt.format(language=self.language)
print(f"Language: {self.language}")
logger.info(f"Language: {self.language}")
completion = self.openai_client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": f"You are a teacher of {self.language}."},
{"role": "user", "content": f"${prompt}"}
]
)
print(completion)
logger.info(completion)
return completion.choices[0].message.content

def set_language(self, language: str):
Expand Down
3 changes: 2 additions & 1 deletion daily_dragon_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
if TELEGRAM_TOKEN is None or TELEGRAM_TOKEN == '':
raise ValueError('TELEGRAM_TOKEN not found in .env file')

logger = logging.getLogger(__name__)
daily_dragon = DailyDragon()


Expand All @@ -25,7 +26,7 @@

async def random_word(update: Update, context: ContextTypes.DEFAULT_TYPE):
username = update.effective_user.username
print(f'User {username} requested daily word')
logger.info(f'User {username} requested daily word')
if username == RAINY_BABE:
daily_dragon.set_language('Japanese')
daily_word_response = daily_dragon.get_daily_word()
Expand Down

0 comments on commit 8d0504a

Please sign in to comment.