Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Housekeeping – add .dockerignore, add INFO level logging, slim dependencies in Dockerfile #303

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/mongodb
18 changes: 12 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100

RUN apt-get update
RUN apt-get install -y python3 python3-pip python-dev build-essential python3-venv ffmpeg
RUN apt-get update && \
apt-get install -y \
# required by the bot
python3-yaml python3-pymongo ffmpeg \
# debugging helpers
nano ripgrep && \
rm -rf /var/lib/apt/lists/*

RUN mkdir -p /code
ADD . /code
WORKDIR /code

RUN pip3 install -r requirements.txt
COPY requirements.txt /code/requirements.txt
RUN pip3 install --no-cache-dir -r requirements.txt

ADD . /code

CMD ["bash"]
CMD ["bash"]
7 changes: 4 additions & 3 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

# setup
db = database.Database()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

user_semaphores = {}
Expand Down Expand Up @@ -410,7 +411,7 @@ async def new_dialog_handle(update: Update, context: CallbackContext):
await update.message.reply_text("Starting new dialog ✅")

chat_mode = db.get_user_attribute(user_id, "current_chat_mode")
await update.message.reply_text(f"{config.chat_modes[chat_mode]['welcome_message']}", parse_mode=ParseMode.HTML)
await update.message.reply_text(f"{config.chat_modes[chat_mode]['welcome_message']}\n\nPrompt:\n{config.chat_modes[chat_mode]['prompt_start']}", parse_mode=ParseMode.HTML)


async def cancel_handle(update: Update, context: CallbackContext):
Expand Down Expand Up @@ -510,7 +511,7 @@ async def set_chat_mode_handle(update: Update, context: CallbackContext):

await context.bot.send_message(
update.callback_query.message.chat.id,
f"{config.chat_modes[chat_mode]['welcome_message']}",
f"{config.chat_modes[chat_mode]['welcome_message']}\n\nPrompt:\n{config.chat_modes[chat_mode]['prompt_start']}",
parse_mode=ParseMode.HTML
)

Expand Down Expand Up @@ -703,4 +704,4 @@ def run_bot() -> None:


if __name__ == "__main__":
run_bot()
run_bot()
22 changes: 14 additions & 8 deletions config/chat_modes.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
code_assistant:
name: 👩🏼‍💻 Code Assistant
welcome_message: 👩🏼‍💻 Hi, I'm <b>Code Assistant</b>. How can I help you?
prompt_start: |
As an advanced chatbot Code Assistant, your primary goal is to assist users to write code. This may involve designing/writing/editing/describing code or providing helpful information. Where possible you should provide code examples to support your points and justify your recommendations or solutions. Make sure the code you provide is correct and can be run without errors. Be detailed and thorough in your responses. Your ultimate goal is to provide a helpful and enjoyable experience for the user.
Format output in Markdown.
parse_mode: markdown

empty_prompt:
name: Empty Prompt
welcome_message: Empty prompt – provide prompt by yourself.
prompt_start: ""
parse_mode: markdown

assistant:
name: 👩🏼‍🎓 General Assistant
model_type: text
Expand All @@ -7,14 +21,6 @@ assistant:
If user asks you about programming or asks to write code do not answer his question, but be sure to advise him to switch to a special mode \"👩🏼‍💻 Code Assistant\" by sending the command /mode to chat.
parse_mode: html

code_assistant:
name: 👩🏼‍💻 Code Assistant
welcome_message: 👩🏼‍💻 Hi, I'm <b>Code Assistant</b>. How can I help you?
prompt_start: |
As an advanced chatbot Code Assistant, your primary goal is to assist users to write code. This may involve designing/writing/editing/describing code or providing helpful information. Where possible you should provide code examples to support your points and justify your recommendations or solutions. Make sure the code you provide is correct and can be run without errors. Be detailed and thorough in your responses. Your ultimate goal is to provide a helpful and enjoyable experience for the user.
Format output in Markdown.
parse_mode: markdown

artist:
name: 👩‍🎨 Artist
welcome_message: 👩‍🎨 Hi, I'm <b>Artist</b>. I'll draw anything you write me (e.g. <i>Ginger cat selfie on Times Square, illustration</i>)
Expand Down
14 changes: 7 additions & 7 deletions config/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ available_text_models: ["gpt-3.5-turbo", "gpt-4", "text-davinci-003"]
info:
gpt-3.5-turbo:
type: chat_completion
name: ChatGPT
description: ChatGPT is that well-known model. It's <b>fast</b> and <b>cheap</b>. Ideal for everyday tasks. If there are some tasks it can't handle, try the <b>GPT-4</b>.
name: gpt-3.5-turbo
description: $0.002 / 1K tokens.

price_per_1000_input_tokens: 0.002
price_per_1000_output_tokens: 0.002
Expand All @@ -16,8 +16,8 @@ info:

gpt-4:
type: chat_completion
name: GPT-4
description: GPT-4 is the <b>smartest</b> and most advanced model in the world. But it is slower and not as cost-efficient as ChatGPT. Best choice for <b>complex</b> intellectual tasks.
name: gpt-4
description: Prompt $0.03 / 1K tokens. Completion $0.06 / 1K tokens.

price_per_1000_input_tokens: 0.03
price_per_1000_output_tokens: 0.06
Expand All @@ -29,8 +29,8 @@ info:

text-davinci-003:
type: completion
name: GPT-3.5
description: GPT-3.5 is a legacy model. Actually there is <b>no reason to use it</b>, because it is more expensive and slower than ChatGPT, but just about as smart.
name: text-davinci-003
description: $0.02 / 1K tokens.

price_per_1000_input_tokens: 0.02
price_per_1000_output_tokens: 0.02
Expand All @@ -46,4 +46,4 @@ info:

whisper:
type: audio
price_per_1_min: 0.006
price_per_1_min: 0.006
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
mongo:
container_name: mongo
image: mongo:latest
restart: always
restart: unless-stopped
ports:
- 127.0.0.1:${MONGODB_PORT:-27017}:${MONGODB_PORT:-27017}
volumes:
Expand All @@ -14,17 +14,20 @@ services:
chatgpt_telegram_bot:
container_name: chatgpt_telegram_bot
command: python3 bot/bot.py
restart: always
restart: unless-stopped
build:
context: "."
dockerfile: Dockerfile
volumes:
- ./bot:/code/bot
- ./config:/code/config
depends_on:
- mongo

mongo_express:
container_name: mongo-express
image: mongo-express:latest
restart: always
restart: unless-stopped
ports:
- 127.0.0.1:${MONGO_EXPRESS_PORT:-8081}:${MONGO_EXPRESS_PORT:-8081}
environment:
Expand Down