mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-21 06:35:02 +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
|
FROM python:3.9-alpine
|
||||||
|
|
||||||
RUN apt-get update && \
|
ENV PYTHONFAULTHANDLER=1 \
|
||||||
apt-get install ffmpeg -y && \
|
PYTHONUNBUFFERED=1 \
|
||||||
rm -rf /var/lib/apt/lists/*
|
PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
PIP_DISABLE_PIP_VERSION_CHECK=on
|
||||||
|
|
||||||
RUN useradd -m appuser
|
RUN apk --no-cache add ffmpeg
|
||||||
USER appuser
|
|
||||||
WORKDIR /home/appuser/app
|
|
||||||
|
|
||||||
COPY --chown=appuser . .
|
WORKDIR /app
|
||||||
|
COPY . .
|
||||||
RUN pip install -r requirements.txt --no-cache-dir
|
RUN pip install -r requirements.txt --no-cache-dir
|
||||||
|
|
||||||
CMD ["python", "bot/main.py"]
|
CMD ["python", "bot/main.py"]
|
||||||
@@ -28,7 +28,7 @@ class OpenAIHelper:
|
|||||||
Gets a response from the GPT-3 model.
|
Gets a response from the GPT-3 model.
|
||||||
:param chat_id: The chat ID
|
:param chat_id: The chat ID
|
||||||
:param query: The query to send to the model
|
: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:
|
try:
|
||||||
if chat_id not in self.conversations or self.__max_age_reached(chat_id):
|
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
|
# add guest chat request to guest usage tracker
|
||||||
allowed_user_ids = self.config['allowed_user_ids'].split(',')
|
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)
|
self.usage["guests"].add_transcription_seconds(audio_track.duration_seconds, transcription_price)
|
||||||
|
|
||||||
if self.config['voice_reply_transcript']:
|
if self.config['voice_reply_transcript']:
|
||||||
@@ -241,7 +241,7 @@ class ChatGPT3TelegramBot:
|
|||||||
# add chat request to users usage tracker
|
# add chat request to users usage tracker
|
||||||
self.usage[user_id].add_chat_tokens(total_tokens, self.config['token_price'])
|
self.usage[user_id].add_chat_tokens(total_tokens, self.config['token_price'])
|
||||||
# add guest chat request to guest usage tracker
|
# 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'])
|
self.usage["guests"].add_chat_tokens(total_tokens, self.config['token_price'])
|
||||||
|
|
||||||
# Split into chunks of 4096 characters (Telegram's message limit)
|
# Split into chunks of 4096 characters (Telegram's message limit)
|
||||||
|
|||||||
Reference in New Issue
Block a user