From 61b8dbd0ce9eb2b240054c62173ca9815cb83a1e Mon Sep 17 00:00:00 2001 From: Karim Iskakov Date: Wed, 15 Nov 2023 17:45:57 +0300 Subject: [PATCH] Add GPT-4 Turbo --- README.md | 3 ++- bot/openai_utils.py | 9 ++++++--- config/models.yml | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7967654..e263d24 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ You can deploy your own bot, or use mine: [@chatgpt_karfly_bot](https://t.me/cha - Low latency replies (it usually takes about 3-5 seconds) - No request limits - Message streaming (watch demo) -- GPT-4 support +- GPT-4 and GPT-4 Turbo support - Group Chat support (/help_group_chat to get instructions) - DALLE 2 (choose 👩‍🎨 Artist mode to generate images) - Voice message recognition @@ -62,6 +62,7 @@ If you want to add payments to your bot and create profitable business – write - *8 Mar 2023*: Added voice message recognition with [OpenAI Whisper API](https://openai.com/blog/introducing-chatgpt-and-whisper-apis). Record a voice message and ChatGPT will answer you! - *2 Mar 2023*: Added support of [ChatGPT API](https://platform.openai.com/docs/guides/chat/introduction). - *1 Aug 2023*: Added OpenAI API Base to config (useful while using OpenAI-compatible API like [LocalAI](https://github.com/go-skynet/LocalAI)) +- *15 Nov 2023*: Added support of [GPT-4 Turbo](https://help.openai.com/en/articles/8555510-gpt-4-turbo) ## Bot commands - `/retry` – Regenerate last bot answer diff --git a/bot/openai_utils.py b/bot/openai_utils.py index 5122c60..cd3168e 100644 --- a/bot/openai_utils.py +++ b/bot/openai_utils.py @@ -22,7 +22,7 @@ OPENAI_COMPLETION_OPTIONS = { 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"}, f"Unknown model: {model}" + assert model in {"text-davinci-003", "gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4", "gpt-4-1106-preview"}, f"Unknown model: {model}" self.model = model async def send_message(self, message, dialog_messages=[], chat_mode="assistant"): @@ -33,7 +33,7 @@ class ChatGPT: answer = None while answer is None: try: - if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4"}: + if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4", "gpt-4-1106-preview"}: messages = self._generate_prompt_messages(message, dialog_messages, chat_mode) r = await openai.ChatCompletion.acreate( model=self.model, @@ -73,7 +73,7 @@ class ChatGPT: answer = None while answer is None: try: - if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4"}: + if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4", "gpt-4-1106-preview"}: messages = self._generate_prompt_messages(message, dialog_messages, chat_mode) r_gen = await openai.ChatCompletion.acreate( model=self.model, @@ -161,6 +161,9 @@ class ChatGPT: elif model == "gpt-4": tokens_per_message = 3 tokens_per_name = 1 + elif model == "gpt-4-1106-preview": + tokens_per_message = 3 + tokens_per_name = 1 else: raise ValueError(f"Unknown model: {model}") diff --git a/config/models.yml b/config/models.yml index 4d522c5..dc35f2d 100644 --- a/config/models.yml +++ b/config/models.yml @@ -1,4 +1,4 @@ -available_text_models: ["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4", "text-davinci-003"] +available_text_models: ["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4-1106-preview", "gpt-4", "text-davinci-003"] info: gpt-3.5-turbo: @@ -40,6 +40,19 @@ info: Fast: 2 Cheap: 2 + gpt-4-1106-preview: + type: chat_completion + name: GPT-4 Turbo + description: GPT-4 Turbo is a faster and cheaper version of GPT-4. It's as smart as GPT-4, so you should use it instead of GPT-4. + + price_per_1000_input_tokens: 0.01 + price_per_1000_output_tokens: 0.03 + + scores: + smart: 5 + fast: 4 + cheap: 3 + text-davinci-003: type: completion name: GPT-3.5