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

Replace 3.5 turbo with new 4o mini model released this week #475

Open
wants to merge 1 commit 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
6 changes: 3 additions & 3 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def register_user_if_not_exists(update: Update, context: CallbackContext,
n_used_tokens = db.get_user_attribute(user.id, "n_used_tokens")
if isinstance(n_used_tokens, int) or isinstance(n_used_tokens, float): # old format
new_n_used_tokens = {
"gpt-3.5-turbo": {
"gpt-4o-mini": {
"n_input_tokens": 0,
"n_output_tokens": n_used_tokens
}
Expand Down Expand Up @@ -185,7 +185,7 @@ async def _vision_message_handle_fn(
user_id = update.message.from_user.id
current_model = db.get_user_attribute(user_id, "current_model")

if current_model != "gpt-4-vision-preview" and current_model != "gpt-4o":
if current_model not in ["gpt-4-vision-preview", "gpt-4o", "gpt-4o-mini"]:
await update.message.reply_text(
"🥲 Images processing is only available for <b>gpt-4-vision-preview</b> and <b>gpt-4o</b> model. Please change your settings in /settings",
parse_mode=ParseMode.HTML,
Expand Down Expand Up @@ -566,7 +566,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", "gpt-4o-mini")

db.start_new_dialog(user_id)
await update.message.reply_text("Starting new dialog ✅")
Expand Down
14 changes: 7 additions & 7 deletions bot/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@


class ChatGPT:
def __init__(self, model="gpt-3.5-turbo"):
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}"
def __init__(self, model="gpt-4o-mini"):
assert model in {"text-davinci-003", "gpt-3.5-turbo-16k", "gpt-4o-mini", "gpt-4", "gpt-4o", "gpt-4-1106-preview", "gpt-4-vision-preview"}, f"Unknown model: {model}"
self.model = model

async def send_message(self, message, dialog_messages=[], chat_mode="assistant"):
Expand All @@ -37,7 +37,7 @@ async def send_message(self, message, dialog_messages=[], chat_mode="assistant")
answer = None
while answer is None:
try:
if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4", "gpt-4o", "gpt-4-1106-preview", "gpt-4-vision-preview"}:
if self.model in {"gpt-3.5-turbo-16k", "gpt-4o-mini", "gpt-4", "gpt-4o", "gpt-4-1106-preview", "gpt-4-vision-preview"}:
messages = self._generate_prompt_messages(message, dialog_messages, chat_mode)

r = await openai.ChatCompletion.acreate(
Expand Down Expand Up @@ -78,7 +78,7 @@ async def send_message_stream(self, message, dialog_messages=[], chat_mode="assi
answer = None
while answer is None:
try:
if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4","gpt-4o", "gpt-4-1106-preview"}:
if self.model in {"gpt-3.5-turbo-16k", "gpt-4o-mini", "gpt-4","gpt-4o", "gpt-4-1106-preview"}:
messages = self._generate_prompt_messages(message, dialog_messages, chat_mode)

r_gen = await openai.ChatCompletion.acreate(
Expand Down Expand Up @@ -186,7 +186,7 @@ async def send_vision_message_stream(
answer = None
while answer is None:
try:
if self.model == "gpt-4-vision-preview" or self.model == "gpt-4o":
if self.model in ["gpt-4-vision-preview", "gpt-4o", "gpt-4o-mini"]:
messages = self._generate_prompt_messages(
message, dialog_messages, chat_mode, image_buffer
)
Expand Down Expand Up @@ -289,13 +289,13 @@ def _postprocess_answer(self, answer):
answer = answer.strip()
return answer

def _count_tokens_from_messages(self, messages, answer, model="gpt-3.5-turbo"):
def _count_tokens_from_messages(self, messages, answer, model="gpt-4o-mini"):
encoding = tiktoken.encoding_for_model(model)

if model == "gpt-3.5-turbo-16k":
tokens_per_message = 4 # every message follows <im_start>{role/name}\n{content}<im_end>\n
tokens_per_name = -1 # if there's a name, the role is omitted
elif model == "gpt-3.5-turbo":
elif model == "gpt-4o-mini":
tokens_per_message = 4
tokens_per_name = -1
elif model == "gpt-4":
Expand Down
38 changes: 30 additions & 8 deletions config/models.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
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"]
available_text_models:
[
"gpt-4o-mini",
"gpt-3.5-turbo-16k",
"gpt-4-1106-preview",
"gpt-4-vision-preview",
"gpt-4",
"text-davinci-003",
"gpt-4o",
]

info:
gpt-4o-mini:
type: chat_completion
name: GPT-4O-MINI
description: ChatGPT 4o mini. It's <b>fast</b> and <b>cheap</b>. Ideal for everyday tasks.

price_per_1000_input_tokens: 0.00015
price_per_1000_output_tokens: 0.0006

scores:
Smart: 5
Fast: 5
Cheap: 5

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: Old. Dont use this.

price_per_1000_input_tokens: 0.0015
price_per_1000_output_tokens: 0.002
price_per_1000_input_tokens: 0.003
price_per_1000_output_tokens: 0.004

scores:
Smart: 3
Smart: 1
Fast: 5
Cheap: 5

Expand Down Expand Up @@ -92,8 +114,8 @@ info:
Cheap: 3

dalle-2:
type: image
price_per_1_image: 0.018 # 512x512
type: image
price_per_1_image: 0.018 # 512x512

whisper:
type: audio
Expand Down