Skip to content

Commit

Permalink
improve Dockerfile and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
n3d1117 committed Mar 18, 2023
1 parent 178e640 commit 03a317e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM python:3.9-alpine

RUN apt-get update && \
apt-get install ffmpeg -y && \
rm -rf /var/lib/apt/lists/*
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on

RUN useradd -m appuser
USER appuser
WORKDIR /home/appuser/app
RUN apk --no-cache add ffmpeg

COPY --chown=appuser . .
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt --no-cache-dir

CMD ["python", "bot/main.py"]
2 changes: 1 addition & 1 deletion bot/openai_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_chat_response(self, chat_id: int, query: str) -> Union[tuple[str, str],
Gets a response from the GPT-3 model.
:param chat_id: The chat ID
:param query: The query to send to the model
:return: The answer from the model and the number of tokens used
:return: The answer from the model and the number of tokens used, or an error message
"""
try:
if chat_id not in self.conversations or self.__max_age_reached(chat_id):
Expand Down
4 changes: 2 additions & 2 deletions bot/telegram_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async def transcribe(self, update: Update, context: ContextTypes.DEFAULT_TYPE):

# add guest chat request to guest usage tracker
allowed_user_ids = self.config['allowed_user_ids'].split(',')
if str(user_id) not in allowed_user_ids:
if str(user_id) not in allowed_user_ids and 'guests' in self.usage:
self.usage["guests"].add_transcription_seconds(audio_track.duration_seconds, transcription_price)

if self.config['voice_reply_transcript']:
Expand All @@ -241,7 +241,7 @@ async def transcribe(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
# add chat request to users usage tracker
self.usage[user_id].add_chat_tokens(total_tokens, self.config['token_price'])
# add guest chat request to guest usage tracker
if str(user_id) not in allowed_user_ids:
if str(user_id) not in allowed_user_ids and 'guests' in self.usage:
self.usage["guests"].add_chat_tokens(total_tokens, self.config['token_price'])

# Split into chunks of 4096 characters (Telegram's message limit)
Expand Down

0 comments on commit 03a317e

Please sign in to comment.