From 28e7426c2b248767774836db2281c20df1213b31 Mon Sep 17 00:00:00 2001 From: Karim Iskakov Date: Tue, 20 Jun 2023 11:29:04 +0300 Subject: [PATCH 1/5] Fix HTTPX problem --- bot/bot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bot/bot.py b/bot/bot.py index 7e464ec..2e0f28a 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -665,6 +665,8 @@ def run_bot() -> None: .token(config.telegram_token) .concurrent_updates(True) .rate_limiter(AIORateLimiter(max_retries=5)) + .http_version("1.1") + .get_updates_http_version("1.1") .post_init(post_init) .build() ) 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 2/5] 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 From e42798c0ce67a21b0c32e035cccd724c85542e97 Mon Sep 17 00:00:00 2001 From: Shahmir Varqha Date: Tue, 20 Jun 2023 16:47:58 +0800 Subject: [PATCH 3/5] fixed grammar and spelling (#301) --- config/chat_modes.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/chat_modes.yml b/config/chat_modes.yml index 3030af6..f134d32 100644 --- a/config/chat_modes.yml +++ b/config/chat_modes.yml @@ -70,11 +70,11 @@ motivator: money_maker: name: 💰 Money Maker - welcome_message: 💰 Hi, I'm Money Maker. My goal it to turn your capital initial into as much money as possible. I will tell you specific steps, what to do to make money. + welcome_message: 💰 Hi, I'm Money Maker. My goal is to turn your initial capital into as much money as possible. I will tell you specific steps and what to do to make money. prompt_start: | You are Money Maker Assistant, an entrepreneurial Al. User is your human counterpart. - User can act as a connection between you and the physical world. Your only goal is to turn user's capital initial into as much money as possible in the shortest time possible, without doing anything illegal. User will do everything you say and keep you updated on our current cash total. No manual labor + User can act as a connection between you and the physical world. Your only goal is to turn user's initial capital into as much money as possible in the shortest time possible, without doing anything illegal. User will do everything you say and keep you updated on our current cash total. No manual labor Start by asking if user want to start a new business or continue the previous one (in that case ask to forward message with previous business description). Then ask how many dollars user has as a capital initial. From 8df5e2d24d0f6ea90e5927ed6529a445860fd7e8 Mon Sep 17 00:00:00 2001 From: TanNhatCMS <113796420+TanNhatCMS@users.noreply.github.com> Date: Tue, 20 Jun 2023 15:50:03 +0700 Subject: [PATCH 4/5] fix argument of type 'float' is not iterable (#211) * fix argument of type 'float' is not iterable fix "argument of type 'float' is not iterable" in show_balance_handle and message_handle * Update bot.py --- bot/bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 2e0f28a..034e9a8 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -94,7 +94,7 @@ async def register_user_if_not_exists(update: Update, context: CallbackContext, # back compatibility for n_used_tokens field n_used_tokens = db.get_user_attribute(user.id, "n_used_tokens") - if isinstance(n_used_tokens, int): # old format + if isinstance(n_used_tokens, int) or isinstance(n_used_tokens, float): # old format new_n_used_tokens = { "gpt-3.5-turbo": { "n_input_tokens": 0, @@ -705,4 +705,4 @@ def run_bot() -> None: if __name__ == "__main__": - run_bot() \ No newline at end of file + run_bot() From a4bd06ac9e1efb820eacb54a18136a98aaacf50f Mon Sep 17 00:00:00 2001 From: Flop Date: Tue, 20 Jun 2023 10:52:57 +0200 Subject: [PATCH 5/5] Allow channels (#312) Co-authored-by: Flop --- bot/bot.py | 6 ++++-- config/config.example.yml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 034e9a8..906b9ce 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -675,8 +675,10 @@ def run_bot() -> None: user_filter = filters.ALL if len(config.allowed_telegram_usernames) > 0: usernames = [x for x in config.allowed_telegram_usernames if isinstance(x, str)] - user_ids = [x for x in config.allowed_telegram_usernames if isinstance(x, int)] - user_filter = filters.User(username=usernames) | filters.User(user_id=user_ids) + any_ids = [x for x in config.allowed_telegram_usernames if isinstance(x, int)] + user_ids = [x for x in any_ids if x > 0] + group_ids = [x for x in any_ids if x < 0] + user_filter = filters.User(username=usernames) | filters.User(user_id=user_ids) | filters.Chat(chat_id=group_ids) application.add_handler(CommandHandler("start", start_handle, filters=user_filter)) application.add_handler(CommandHandler("help", help_handle, filters=user_filter)) diff --git a/config/config.example.yml b/config/config.example.yml index 8fb3e07..9064fb3 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -1,7 +1,7 @@ telegram_token: "" openai_api_key: "" use_chatgpt_api: true -allowed_telegram_usernames: [] # if empty, the bot is available to anyone. pass a username string to allow it and/or user ids as integers +allowed_telegram_usernames: [] # if empty, the bot is available to anyone. pass a username string to allow it and/or user ids as positive integers and/or channel ids as negative integers new_dialog_timeout: 600 # new dialog starts after timeout (in seconds) return_n_generated_images: 1 n_chat_modes_per_page: 5