From edcd22f8b9a78c961134a1f670528056f009ccc3 Mon Sep 17 00:00:00 2001 From: yym68686 Date: Tue, 7 Nov 2023 14:56:48 +0800 Subject: [PATCH] Add support for gpt-3.5-turbo-1106 model. Change the default model for search to gpt-3.5-turbo-1106. update g4f version to 0.1.8.0 --- bot.py | 29 +++++++++++++++++------------ chatgpt2api/chatgpt2api.py | 11 +++++++---- config.py | 2 +- requirements.txt | 2 +- test/test.py | 15 +++++++++++++++ test/test_Faucet.py | 1 + 6 files changed, 42 insertions(+), 18 deletions(-) diff --git a/bot.py b/bot.py index 9ff3ad18..05999345 100644 --- a/bot.py +++ b/bot.py @@ -156,24 +156,29 @@ async def delete_message(update, context, messageid, delay=10): InlineKeyboardButton("gpt-3.5-turbo-16k", callback_data="gpt-3.5-turbo-16k"), ], [ - InlineKeyboardButton("gpt-3.5-turbo-0301", callback_data="gpt-3.5-turbo-0301"), - ], - [ - InlineKeyboardButton("gpt-3.5-turbo-0613", callback_data="gpt-3.5-turbo-0613"), + InlineKeyboardButton("gpt-3.5-turbo-1106", callback_data="gpt-3.5-turbo-1106"), ], + # [ + # InlineKeyboardButton("gpt-3.5-turbo-0301", callback_data="gpt-3.5-turbo-0301"), + # ], + # [ + # InlineKeyboardButton("gpt-3.5-turbo-0613", callback_data="gpt-3.5-turbo-0613"), + # ], [ InlineKeyboardButton("gpt-4", callback_data="gpt-4"), - InlineKeyboardButton("gpt-4-0314", callback_data="gpt-4-0314"), - ], - [ InlineKeyboardButton("gpt-4-32k", callback_data="gpt-4-32k"), - InlineKeyboardButton("gpt-4-32k-0314", callback_data="gpt-4-32k-0314"), - ], - [ - InlineKeyboardButton("gpt-4-0613", callback_data="gpt-4-0613"), - InlineKeyboardButton("gpt-4-32k-0613", callback_data="gpt-4-32k-0613"), + # InlineKeyboardButton("gpt-4-0314", callback_data="gpt-4-0314"), ], + # [ + # InlineKeyboardButton("gpt-4-32k", callback_data="gpt-4-32k"), + # InlineKeyboardButton("gpt-4-32k-0314", callback_data="gpt-4-32k-0314"), + # ], + # [ + # InlineKeyboardButton("gpt-4-0613", callback_data="gpt-4-0613"), + # InlineKeyboardButton("gpt-4-32k-0613", callback_data="gpt-4-32k-0613"), + # ], [ + InlineKeyboardButton("claude-2", callback_data="claude-2"), InlineKeyboardButton("claude-2-web", callback_data="claude-2-web"), ], [ diff --git a/chatgpt2api/chatgpt2api.py b/chatgpt2api/chatgpt2api.py index af701181..b1b48902 100644 --- a/chatgpt2api/chatgpt2api.py +++ b/chatgpt2api/chatgpt2api.py @@ -41,6 +41,7 @@ def get_filtered_keys_from_object(obj: object, *keys: str) -> Set[str]: "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo-16k-0613", "gpt-4", "gpt-4-0314", @@ -49,6 +50,7 @@ def get_filtered_keys_from_object(obj: object, *keys: str) -> Set[str]: "gpt-4-0613", "gpt-4-32k-0613", "claude-2-web", + "claude-2", ] @@ -84,9 +86,9 @@ def __init__( else 7000 if "gpt-4" in engine else 15000 - if "gpt-3.5-turbo-16k" in engine + if "gpt-3.5-turbo-16k" in engine or "gpt-3.5-turbo-1106" in engine else 99000 - if "claude-2-web" in engine + if "claude-2-web" in engine or "claude-2" in engine else 4000 ) self.truncate_limit: int = truncate_limit or ( @@ -95,9 +97,9 @@ def __init__( else 6500 if "gpt-4" in engine else 14500 - if "gpt-3.5-turbo-16k" in engine + if "gpt-3.5-turbo-16k" in engine or "gpt-3.5-turbo-1106" in engine else 98500 - if "claude-2-web" in engine + if "claude-2-web" in engine or "claude-2" in engine else 3400 ) self.temperature: float = temperature @@ -178,6 +180,7 @@ def get_token_count(self, convo_id: str = "default") -> int: ) tiktoken.model.MODEL_TO_ENCODING["gpt-4"] = "cl100k_base" tiktoken.model.MODEL_TO_ENCODING["claude-2-web"] = "cl100k_base" + tiktoken.model.MODEL_TO_ENCODING["claude-2"] = "cl100k_base" encoding = tiktoken.encoding_for_model(self.engine) diff --git a/config.py b/config.py index ed6361b1..367e77be 100644 --- a/config.py +++ b/config.py @@ -9,7 +9,7 @@ if os.environ.get('GOOGLE_API_KEY', None) == None and os.environ.get('GOOGLE_CSE_ID', None) == None: USE_GOOGLE = False temperature = float(os.environ.get('temperature', '0.5')) -GPT_ENGINE = os.environ.get('GPT_ENGINE', 'gpt-3.5-turbo-16k') +GPT_ENGINE = os.environ.get('GPT_ENGINE', 'gpt-3.5-turbo-1106') # DEFAULT_SEARCH_MODEL = os.environ.get('DEFAULT_SEARCH_MODEL', 'gpt-3.5-turbo-16k') SEARCH_USE_GPT = (os.environ.get('SEARCH_USE_GPT', "True") == "False") == False API_URL = os.environ.get('API_URL', 'https://api.openai.com/v1/chat/completions') diff --git a/requirements.txt b/requirements.txt index 7cc7e499..1fd06f8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,4 @@ unstructured[pdf] duckduckgo-search==3.8.5 langchain==0.0.271 oauth2client==3.0.0 -g4f==0.1.7.9 \ No newline at end of file +g4f==0.1.8.0 \ No newline at end of file diff --git a/test/test.py b/test/test.py index dfab8ad5..fcf221a8 100644 --- a/test/test.py +++ b/test/test.py @@ -5,3 +5,18 @@ content_list = [item["content"] for item in my_list] print(content_list) + +engine = "gpt-3.5-turbo-1106" +truncate_limit = ( + 30500 + if "gpt-4-32k" in engine + else 6500 + if "gpt-4" in engine + else 14500 + if "gpt-3.5-turbo-16k" in engine or "gpt-3.5-turbo-1106" in engine + else 98500 + if ("claude-2-web" or "claude-2") in engine + else 3400 +) + +print(truncate_limit) diff --git a/test/test_Faucet.py b/test/test_Faucet.py index 6aa836e5..1e7fe240 100644 --- a/test/test_Faucet.py +++ b/test/test_Faucet.py @@ -6,5 +6,6 @@ def gptsearch(result, llm): response = response.content return response +chainllm = ChatOpenAI(temperature=0.5, openai_api_base="https://openkey.cloud/v1", model_name="gpt-4", openai_api_key="sk-ucUnnmqI9DdtsAXG8OKxOFxD5dnSrU3E3ZQh4PJa1dgQ7KzE") print(gptsearch("鲁迅和周树人为什么打架", chainllm)) \ No newline at end of file