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

Fix DB issue and change default model to gpt-4o #490

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def register_user_if_not_exists(update: Update, context: CallbackContext,
user_semaphores[user.id] = asyncio.Semaphore(1)

if db.get_user_attribute(user.id, "current_model") is None:
db.set_user_attribute(user.id, "current_model", config.models["available_text_models"][0])
db.set_user_attribute(user.id, "current_model", config.models["default_text_model"])

# back compatibility for n_used_tokens field
n_used_tokens = db.get_user_attribute(user.id, "n_used_tokens")
Expand Down Expand Up @@ -459,11 +459,7 @@ async def fake_gen():
await update.message.reply_text(text, parse_mode=ParseMode.HTML)

async with user_semaphores[user_id]:
if current_model == "gpt-4-vision-preview" or current_model == "gpt-4o" or update.message.photo is not None and len(update.message.photo) > 0:

logger.error(current_model)
# What is this? ^^^

if update.message.photo:
if current_model != "gpt-4o" and current_model != "gpt-4-vision-preview":
current_model = "gpt-4o"
db.set_user_attribute(user_id, "current_model", "gpt-4o")
Expand All @@ -473,7 +469,7 @@ async def fake_gen():
else:
task = asyncio.create_task(
message_handle_fn()
)
)

user_tasks[user_id] = task

Expand Down Expand Up @@ -566,7 +562,7 @@ async def new_dialog_handle(update: Update, context: CallbackContext):

user_id = update.message.from_user.id
db.set_user_attribute(user_id, "last_interaction", datetime.now())
db.set_user_attribute(user_id, "current_model", "gpt-3.5-turbo")
db.set_user_attribute(user_id, "current_model", config.models["default_text_model"])

db.start_new_dialog(user_id)
await update.message.reply_text("Starting new dialog ✅")
Expand Down
2 changes: 1 addition & 1 deletion bot/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def add_new_user(

"current_dialog_id": None,
"current_chat_mode": "assistant",
"current_model": config.models["available_text_models"][0],
"current_model": config.models["default_text_model"],

"n_used_tokens": {},

Expand Down
2 changes: 1 addition & 1 deletion bot/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class ChatGPT:
def __init__(self, model="gpt-3.5-turbo"):
def __init__(self, model=config.models["default_text_model"]):
assert model in {"text-davinci-003", "gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4", "gpt-4o", "gpt-4-1106-preview", "gpt-4-vision-preview"}, f"Unknown model: {model}"
self.model = model

Expand Down
1 change: 1 addition & 0 deletions config/models.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
available_text_models: ["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4-1106-preview", "gpt-4-vision-preview", "gpt-4", "text-davinci-003", "gpt-4o"]
default_text_model: "gpt-4o"

info:
gpt-3.5-turbo:
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
version: "3"

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:
- ${MONGODB_PATH:-./mongodb}:/data/db
tmpfs:
- /data/configdb
# TODO: add auth

chatgpt_telegram_bot:
container_name: chatgpt_telegram_bot
command: python3 bot/bot.py
restart: always
restart: unless-stopped
build:
context: "."
dockerfile: Dockerfile
Expand All @@ -24,7 +24,7 @@ services:
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