From 89e8f385b4665aaf53e78f4038fe63265178ea30 Mon Sep 17 00:00:00 2001 From: yubai Date: Sun, 9 Apr 2023 15:36:03 +0800 Subject: [PATCH] bugfix for azure chatgpt adapting --- bot/chatgpt/chat_gpt_bot.py | 7 ++++--- bot/chatgpt/chat_gpt_session.py | 4 ++-- config-template.json | 3 ++- config.py | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bot/chatgpt/chat_gpt_bot.py b/bot/chatgpt/chat_gpt_bot.py index 158392d..b7b86a6 100644 --- a/bot/chatgpt/chat_gpt_bot.py +++ b/bot/chatgpt/chat_gpt_bot.py @@ -151,6 +151,7 @@ class AzureChatGPTBot(ChatGPTBot): def compose_args(self): args = super().compose_args() - args["engine"] = args["model"] - del(args["model"]) - return args \ No newline at end of file + args["deployment_id"] = conf().get("azure_deployment_id") + #args["engine"] = args["model"] + #del(args["model"]) + return args diff --git a/bot/chatgpt/chat_gpt_session.py b/bot/chatgpt/chat_gpt_session.py index afbe6a5..90fe064 100644 --- a/bot/chatgpt/chat_gpt_session.py +++ b/bot/chatgpt/chat_gpt_session.py @@ -55,7 +55,7 @@ def num_tokens_from_messages(messages, model): except KeyError: logger.debug("Warning: model not found. Using cl100k_base encoding.") encoding = tiktoken.get_encoding("cl100k_base") - if model == "gpt-3.5-turbo": + if model == "gpt-3.5-turbo" or model == "gpt-35-turbo": return num_tokens_from_messages(messages, model="gpt-3.5-turbo-0301") elif model == "gpt-4": return num_tokens_from_messages(messages, model="gpt-4-0314") @@ -76,4 +76,4 @@ def num_tokens_from_messages(messages, model): if key == "name": num_tokens += tokens_per_name num_tokens += 3 # every reply is primed with <|start|>assistant<|message|> - return num_tokens \ No newline at end of file + return num_tokens diff --git a/config-template.json b/config-template.json index 528bd60..926017a 100644 --- a/config-template.json +++ b/config-template.json @@ -1,5 +1,6 @@ { "open_ai_api_key": "YOUR API KEY", + "open_ai_api_base": "", "model": "gpt-3.5-turbo", "proxy": "", "single_chat_prefix": ["bot", "@bot"], @@ -14,4 +15,4 @@ "conversation_max_tokens": 1000, "expires_in_seconds": 3600, "character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。" -} \ No newline at end of file +} diff --git a/config.py b/config.py index 56bff7e..0520eb3 100644 --- a/config.py +++ b/config.py @@ -16,6 +16,7 @@ available_setting = { # chatgpt模型, 当use_azure_chatgpt为true时,其名称为Azure上model deployment名称 "model": "gpt-3.5-turbo", "use_azure_chatgpt": False, # 是否使用azure的chatgpt + "azure_deployment_id": "", #azure 模型部署名称 # Bot触发配置 "single_chat_prefix": ["bot", "@bot"], # 私聊时文本需要包含该前缀才能触发机器人回复