From 533e6705c839dab5b22927fef873071cf4b7f9c1 Mon Sep 17 00:00:00 2001 From: maccagnit <45689045+maccagnit@users.noreply.github.com> Date: Tue, 20 Jun 2023 10:47:19 +0200 Subject: [PATCH] Added GPT-3.5 16K chat functionality (#306) --- bot/openai_utils.py | 11 +++++++---- config/models.yml | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/bot/openai_utils.py b/bot/openai_utils.py index cdb0110..5a68302 100644 --- a/bot/openai_utils.py +++ b/bot/openai_utils.py @@ -16,7 +16,7 @@ OPENAI_COMPLETION_OPTIONS = { class ChatGPT: def __init__(self, model="gpt-3.5-turbo"): - assert model in {"text-davinci-003", "gpt-3.5-turbo", "gpt-4"}, f"Unknown model: {model}" + assert model in {"text-davinci-003", "gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4"}, f"Unknown model: {model}" self.model = model async def send_message(self, message, dialog_messages=[], chat_mode="assistant"): @@ -27,7 +27,7 @@ class ChatGPT: answer = None while answer is None: try: - if self.model in {"gpt-3.5-turbo", "gpt-4"}: + if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4"}: messages = self._generate_prompt_messages(message, dialog_messages, chat_mode) r = await openai.ChatCompletion.acreate( model=self.model, @@ -67,7 +67,7 @@ class ChatGPT: answer = None while answer is None: try: - if self.model in {"gpt-3.5-turbo", "gpt-4"}: + if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4"}: messages = self._generate_prompt_messages(message, dialog_messages, chat_mode) r_gen = await openai.ChatCompletion.acreate( model=self.model, @@ -146,9 +146,12 @@ class ChatGPT: def _count_tokens_from_messages(self, messages, answer, model="gpt-3.5-turbo"): encoding = tiktoken.encoding_for_model(model) - if model == "gpt-3.5-turbo": + if model == "gpt-3.5-turbo-16k": tokens_per_message = 4 # every message follows {role/name}\n{content}\n tokens_per_name = -1 # if there's a name, the role is omitted + elif model == "gpt-3.5-turbo": + tokens_per_message = 4 + tokens_per_name = -1 elif model == "gpt-4": tokens_per_message = 3 tokens_per_name = 1 diff --git a/config/models.yml b/config/models.yml index 70f423b..4d522c5 100644 --- a/config/models.yml +++ b/config/models.yml @@ -1,4 +1,4 @@ -available_text_models: ["gpt-3.5-turbo", "gpt-4", "text-davinci-003"] +available_text_models: ["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4", "text-davinci-003"] info: gpt-3.5-turbo: @@ -6,7 +6,7 @@ info: name: ChatGPT description: ChatGPT is that well-known model. It's fast and cheap. Ideal for everyday tasks. If there are some tasks it can't handle, try the GPT-4. - price_per_1000_input_tokens: 0.002 + price_per_1000_input_tokens: 0.0015 price_per_1000_output_tokens: 0.002 scores: @@ -14,6 +14,19 @@ info: Fast: 5 Cheap: 5 + gpt-3.5-turbo-16k: + type: chat_completion + name: GPT-16K + description: ChatGPT is that well-known model. It's fast and cheap. Ideal for everyday tasks. If there are some tasks it can't handle, try the GPT-4. + + price_per_1000_input_tokens: 0.003 + price_per_1000_output_tokens: 0.004 + + scores: + Smart: 3 + Fast: 5 + Cheap: 5 + gpt-4: type: chat_completion name: GPT-4