diff --git a/README.md b/README.md index d8b4756..7703208 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ git clone --depth=1 https://github.com/OpenLMLab/MOSS.git request_llms/moss # 参考wiki:https://github.com/binary-husky/gpt_academic/wiki/%E9%80%82%E9%85%8DRWKV-Runner # 【可选步骤IV】确保config.py配置文件的AVAIL_LLM_MODELS包含了期望的模型,目前支持的全部模型如下(jittorllms系列目前仅支持docker方案): -AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] +AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] ```

diff --git a/config.py b/config.py index f578aa8..38d0519 100644 --- a/config.py +++ b/config.py @@ -87,7 +87,8 @@ DEFAULT_FN_GROUPS = ['对话', '编程', '学术', '智能体'] # 模型选择是 (注意: LLM_MODEL是默认选中的模型, 它*必须*被包含在AVAIL_LLM_MODELS列表中 ) LLM_MODEL = "gpt-3.5-turbo" # 可选 ↓↓↓ -AVAIL_LLM_MODELS = ["gpt-3.5-turbo-16k", "gpt-3.5-turbo", "azure-gpt-3.5", +AVAIL_LLM_MODELS = ["gpt-3.5-turbo-1106","gpt-4-1106-preview", + "gpt-3.5-turbo-16k", "gpt-3.5-turbo", "azure-gpt-3.5", "api2d-gpt-3.5-turbo", 'api2d-gpt-3.5-turbo-16k', "gpt-4", "gpt-4-32k", "azure-gpt-4", "api2d-gpt-4", "chatglm3", "moss", "newbing", "claude-2"] diff --git a/crazy_functional.py b/crazy_functional.py index 2d7fa74..e82f399 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -349,18 +349,29 @@ def get_crazy_functions(): print('Load function plugin failed') try: - from crazy_functions.图片生成 import 图片生成 + from crazy_functions.图片生成 import 图片生成, 图片生成_DALLE3 function_plugins.update({ "图片生成(先切换模型到openai或api2d)": { "Group": "对话", "Color": "stop", "AsButton": False, "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) - "ArgsReminder": "在这里输入分辨率, 如256x256(默认)", # 高级参数输入区的显示提示 - "Info": "图片生成 | 输入参数字符串,提供图像的内容", + "ArgsReminder": "在这里输入分辨率, 如1024x1024(默认),支持 256x256, 512x512, 1024x1024", # 高级参数输入区的显示提示 + "Info": "使用DALLE2生成图片 | 输入参数字符串,提供图像的内容", "Function": HotReload(图片生成) }, }) + function_plugins.update({ + "图片生成_DALLE3(先切换模型到openai或api2d)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "在这里输入分辨率, 如1024x1024(默认),支持 1024x1024, 1792x1024, 1024x1792", # 高级参数输入区的显示提示 + "Info": "使用DALLE3生成图片 | 输入参数字符串,提供图像的内容", + "Function": HotReload(图片生成_DALLE3) + }, + }) except: print('Load function plugin failed') diff --git a/crazy_functions/图片生成.py b/crazy_functions/图片生成.py index 1b7dff5..95b4481 100644 --- a/crazy_functions/图片生成.py +++ b/crazy_functions/图片生成.py @@ -3,7 +3,7 @@ from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive import datetime -def gen_image(llm_kwargs, prompt, resolution="256x256"): +def gen_image(llm_kwargs, prompt, resolution="1024x1024", model="dall-e-2"): import requests, json, time, os from request_llms.bridge_all import model_info @@ -23,6 +23,7 @@ def gen_image(llm_kwargs, prompt, resolution="256x256"): 'prompt': prompt, 'n': 1, 'size': resolution, + 'model': model, 'response_format': 'url' } response = requests.post(url, headers=headers, json=data, proxies=proxies) @@ -58,7 +59,7 @@ def 图片生成(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro chatbot.append(("这是什么功能?", "[Local Message] 生成图像, 请先把模型切换至gpt-*或者api2d-*。如果中文效果不理想, 请尝试英文Prompt。正在处理中 .....")) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新 if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg") - resolution = plugin_kwargs.get("advanced_arg", '256x256') + resolution = plugin_kwargs.get("advanced_arg", '1024x1024') image_url, image_path = gen_image(llm_kwargs, prompt, resolution) chatbot.append([prompt, f'图像中转网址:
`{image_url}`
'+ @@ -67,3 +68,29 @@ def 图片生成(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro f'本地文件预览:
' ]) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 界面更新 + +@CatchException +def 图片生成_DALLE3(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): + """ + txt 输入栏用户输入的文本,例如需要翻译的一段话,再例如一个包含了待处理文件的路径 + llm_kwargs gpt模型参数,如温度和top_p等,一般原样传递下去就行 + plugin_kwargs 插件模型的参数,暂时没有用武之地 + chatbot 聊天显示框的句柄,用于显示给用户 + history 聊天历史,前情提要 + system_prompt 给gpt的静默提醒 + web_port 当前软件运行的端口号 + """ + history = [] # 清空历史,以免输入溢出 + chatbot.append(("这是什么功能?", "[Local Message] 生成图像, 请先把模型切换至gpt-*或者api2d-*。如果中文效果不理想, 请尝试英文Prompt。正在处理中 .....")) + yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新 + if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg") + resolution = plugin_kwargs.get("advanced_arg", '1024x1024') + image_url, image_path = gen_image(llm_kwargs, prompt, resolution) + chatbot.append([prompt, + f'图像中转网址:
`{image_url}`
'+ + f'中转网址预览:
' + f'本地文件地址:
`{image_path}`
'+ + f'本地文件预览:
' + ]) + yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 界面更新 + diff --git a/crazy_functions/多智能体.py b/crazy_functions/多智能体.py index 99b3e86..3fab4c3 100644 --- a/crazy_functions/多智能体.py +++ b/crazy_functions/多智能体.py @@ -19,6 +19,11 @@ from crazy_functions.agent_fns.persistent import GradioMultiuserManagerForPersis from crazy_functions.agent_fns.auto_agent import AutoGenMath import time +def remove_model_prefix(llm): + if llm.startswith('api2d-'): llm = llm.replace('api2d-', '') + if llm.startswith('azure-'): llm = llm.replace('azure-', '') + return llm + @CatchException def 多智能体终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): @@ -32,10 +37,16 @@ def 多智能体终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_ web_port 当前软件运行的端口号 """ # 检查当前的模型是否符合要求 - supported_llms = ['gpt-3.5-turbo-16k', 'gpt-4', 'gpt-4-32k', - 'api2d-gpt-3.5-turbo-16k', 'api2d-gpt-4'] + supported_llms = [ + 'gpt-3.5-16k', + 'gpt-3.5-turbo-16k', + 'gpt-3.5-turbo-1106', + 'gpt-4', + 'gpt-4-32k', + 'gpt-4-1106-preview', + ] llm_kwargs['api_key'] = select_api_key(llm_kwargs['api_key'], llm_kwargs['llm_model']) - if llm_kwargs['llm_model'] not in supported_llms: + if remove_model_prefix(llm_kwargs['llm_model']) not in supported_llms: chatbot.append([f"处理任务: {txt}", f"当前插件只支持{str(supported_llms)}, 当前模型{llm_kwargs['llm_model']}."]) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 return diff --git a/docs/translate_english.json b/docs/translate_english.json index 850cae5..44361f0 100644 --- a/docs/translate_english.json +++ b/docs/translate_english.json @@ -265,7 +265,7 @@ "例如chatglm&gpt-3.5-turbo&api2d-gpt-4": "e.g. chatglm&gpt-3.5-turbo&api2d-gpt-4", "先切换模型到openai或api2d": "Switch the model to openai or api2d first", "在这里输入分辨率": "Enter the resolution here", - "如256x256": "e.g. 256x256", + "如1024x1024": "e.g. 1024x1024", "默认": "Default", "建议您复制一个config_private.py放自己的秘密": "We suggest you to copy a config_private.py file to keep your secrets, such as API and proxy URLs, from being accidentally uploaded to Github and seen by others.", "如API和代理网址": "Such as API and proxy URLs", diff --git a/docs/translate_japanese.json b/docs/translate_japanese.json index ae86dc0..29ebcc9 100644 --- a/docs/translate_japanese.json +++ b/docs/translate_japanese.json @@ -854,7 +854,7 @@ "查询版本和用户意见": "バージョンとユーザーの意見を検索する", "提取摘要": "要約を抽出する", "在gpt输出代码的中途": "GPTがコードを出力する途中で", - "如256x256": "256x256のように", + "如1024x1024": "1024x1024のように", "概括其内容": "内容を要約する", "剩下的情况都开头除去": "残りの場合はすべて先頭を除去する", "至少一个线程任务意外失败": "少なくとも1つのスレッドタスクが予期しない失敗をした", diff --git a/docs/translate_traditionalchinese.json b/docs/translate_traditionalchinese.json index a677f10..b75cbdb 100644 --- a/docs/translate_traditionalchinese.json +++ b/docs/translate_traditionalchinese.json @@ -1147,7 +1147,7 @@ "Y+回车=确认": "Y+回車=確認", "正在同时咨询ChatGPT和ChatGLM……": "正在同時諮詢ChatGPT和ChatGLM……", "根据 heuristic 规则": "根據heuristic規則", - "如256x256": "如256x256", + "如1024x1024": "如1024x1024", "函数插件区": "函數插件區", "*** API_KEY 导入成功": "*** API_KEY 導入成功", "请对下面的程序文件做一个概述文件名是": "請對下面的程序文件做一個概述文件名是", diff --git a/request_llms/bridge_all.py b/request_llms/bridge_all.py index 27b91c2..5da44b7 100644 --- a/request_llms/bridge_all.py +++ b/request_llms/bridge_all.py @@ -94,7 +94,7 @@ model_info = { "fn_with_ui": chatgpt_ui, "fn_without_ui": chatgpt_noui, "endpoint": openai_endpoint, - "max_token": 1024*16, + "max_token": 16385, "tokenizer": tokenizer_gpt35, "token_cnt": get_token_num_gpt35, }, @@ -112,7 +112,16 @@ model_info = { "fn_with_ui": chatgpt_ui, "fn_without_ui": chatgpt_noui, "endpoint": openai_endpoint, - "max_token": 1024 * 16, + "max_token": 16385, + "tokenizer": tokenizer_gpt35, + "token_cnt": get_token_num_gpt35, + }, + + "gpt-3.5-turbo-1106": {#16k + "fn_with_ui": chatgpt_ui, + "fn_without_ui": chatgpt_noui, + "endpoint": openai_endpoint, + "max_token": 16385, "tokenizer": tokenizer_gpt35, "token_cnt": get_token_num_gpt35, }, @@ -135,6 +144,15 @@ model_info = { "token_cnt": get_token_num_gpt4, }, + "gpt-4-1106-preview": { + "fn_with_ui": chatgpt_ui, + "fn_without_ui": chatgpt_noui, + "endpoint": openai_endpoint, + "max_token": 128000, + "tokenizer": tokenizer_gpt4, + "token_cnt": get_token_num_gpt4, + }, + "gpt-3.5-random": { "fn_with_ui": chatgpt_ui, "fn_without_ui": chatgpt_noui, @@ -186,7 +204,7 @@ model_info = { "fn_with_ui": chatgpt_ui, "fn_without_ui": chatgpt_noui, "endpoint": api2d_endpoint, - "max_token": 1024*16, + "max_token": 16385, "tokenizer": tokenizer_gpt35, "token_cnt": get_token_num_gpt35, }, diff --git a/request_llms/bridge_chatgpt.py b/request_llms/bridge_chatgpt.py index 9903da9..292de0a 100644 --- a/request_llms/bridge_chatgpt.py +++ b/request_llms/bridge_chatgpt.py @@ -351,6 +351,7 @@ def generate_payload(inputs, llm_kwargs, history, system_prompt, stream): model = random.choice([ "gpt-3.5-turbo", "gpt-3.5-turbo-16k", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613", "gpt-3.5-turbo-0301",