mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-21 14:44:50 +01:00
improve Dockerfile and bug fixes
This commit is contained in:
14
Dockerfile
14
Dockerfile
@@ -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"]
|
||||
@@ -28,7 +28,7 @@ class OpenAIHelper:
|
||||
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):
|
||||
|
||||
@@ -214,7 +214,7 @@ class ChatGPT3TelegramBot:
|
||||
|
||||
# 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']:
|
||||
@@ -241,7 +241,7 @@ class ChatGPT3TelegramBot:
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user