diff --git a/bot/bot.py b/bot/bot.py index 7e464ec..906b9ce 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, @@ -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() ) @@ -673,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)) @@ -703,4 +707,4 @@ def run_bot() -> None: if __name__ == "__main__": - run_bot() \ No newline at end of file + run_bot() 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/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. 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 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