From c94839f581f051ee0fc8ad806b92e0c0893129c6 Mon Sep 17 00:00:00 2001 From: Samon Yu Date: Thu, 17 Apr 2025 20:16:45 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E7=A1=85=E5=9F=BA?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E6=A8=A1=E5=9E=8B=E7=9A=84=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E8=A6=81=E6=B1=82=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?"siliconflow-"=E5=89=8D=E7=BC=80=E3=80=82=202.=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=A1=85=E5=9F=BA=E6=99=BA=E8=83=BD=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E8=AF=B7=E6=B1=82=E4=BB=A3=E7=A0=81=EF=BC=9A=202.1.?= =?UTF-8?q?=20=E6=A0=B9=E6=8D=AE=E6=96=87=E6=A1=A3=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E9=AB=98max=5Foutput=5Ftoken=E5=92=8C=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=9A=84max=5Ftoken=E3=80=82=202.2.=20=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=88=97=E8=A1=A8=EF=BC=8C=E8=A6=81=E6=B1=82?= =?UTF-8?q?=E8=87=AA=E5=B7=B1=E6=B7=BB=E5=8A=A0=E6=A8=A1=E5=9E=8B=E3=80=82?= =?UTF-8?q?=202.3.=20=E6=B7=BB=E5=8A=A0=E6=94=AF=E6=8C=81=E6=8E=A8?= =?UTF-8?q?=E7=90=86=E8=83=BD=E5=8A=9B=E7=9A=84=E6=A8=A1=E5=9E=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 12 +++--- request_llms/bridge_all.py | 82 ++++++++++++++------------------------ 2 files changed, 36 insertions(+), 58 deletions(-) diff --git a/config.py b/config.py index 5e6b4752..913cf266 100644 --- a/config.py +++ b/config.py @@ -48,8 +48,8 @@ AVAIL_LLM_MODELS = ["qwen-max", "o1-mini", "o1-mini-2024-09-12", "o1", "o1-2024- "gemini-1.5-pro", "chatglm3", "chatglm4", "deepseek-chat", "deepseek-coder", "deepseek-reasoner", - "deepseek-ai/DeepSeek-R1","deepseek-ai/DeepSeek-V3", - "Qwen/Qwen2.5-32B-Instruct","Qwen/Qwen2.5-14B-Instruct","Qwen/Qwen2.5-7B-Instruct", + "siliconflow-deepseek-ai/DeepSeek-R1","siliconflow-deepseek-ai/DeepSeek-V3", "siliconflow-Qwen/QwQ-32B", + "siliconflow-Qwen/Qwen2.5-32B-Instruct","siliconflow-Qwen/Qwen2.5-14B-Instruct" "volcengine-deepseek-r1-250120", "volcengine-deepseek-v3-241226", "dashscope-deepseek-r1", "dashscope-deepseek-v3", ] @@ -77,10 +77,12 @@ EMBEDDING_MODEL = "text-embedding-3-small" # 使用"one-api-*","vllm-*","ollama-*","openrouter-*"前缀直接使用非标准方式接入的模型,例如 # AVAIL_LLM_MODELS = ["one-api-claude-3-sonnet-20240229(max_token=100000)", "ollama-phi3(max_token=4096)","openrouter-openai/gpt-4o-mini","openrouter-openai/chatgpt-4o-latest"] # --- --- --- --- -# 硅基智能(Siliconflow) API 可以通过 https://cloud.siliconflow.cn/models 或 https://docs.siliconflow.cn/api-reference/chat-completions/chat-completions 获取模型名称,并放置在AVAIL_LLM_MODELS列表中。 +# 硅基智能(Siliconflow) API 可以通过 https://cloud.siliconflow.cn/models 或 https://docs.siliconflow.cn/api-reference/chat-completions/chat-completions 获取模型名称 +# 在模型名称前添加"siliconflow-"前缀,并放置在AVAIL_LLM_MODELS列表中。 # AVAIL_LLM_MODELS = [ -# "deepseek-ai/DeepSeek-R1","deepseek-ai/DeepSeek-V3", -# "Qwen/Qwen2.5-32B-Instruct","Qwen/Qwen2.5-14B-Instruct","Qwen/Qwen2.5-7B-Instruct" +# "siliconflow-deepseek-ai/DeepSeek-R1","siliconflow-deepseek-ai/DeepSeek-V3", "siliconflow-Qwen/QwQ-32B", +# "siliconflow-Qwen/Qwen2.5-32B-Instruct","siliconflow-Qwen/Qwen2.5-14B-Instruct","siliconflow-Qwen/Qwen2.5-7B-Instruct", +# "siliconflow-THUDM/GLM-Z1-32B-0414" # ] # --- --- --- --- diff --git a/request_llms/bridge_all.py b/request_llms/bridge_all.py index c24e445e..2e5478b6 100644 --- a/request_llms/bridge_all.py +++ b/request_llms/bridge_all.py @@ -1343,65 +1343,41 @@ for model in [m for m in AVAIL_LLM_MODELS if m.startswith("openrouter-")]: # -=-=-=-=-=-=- 硅基智能SiliconFlow在线API -=-=-=-=-=-=- -siliconflow_models = [ - "deepseek-ai/DeepSeek-R1", "Pro/deepseek-ai/DeepSeek-R1", "deepseek-ai/DeepSeek-V3", "Pro/deepseek-ai/DeepSeek-V3", - "deepseek-ai/DeepSeek-R1-Distill-Llama-70B", "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B", "deepseek-ai/DeepSeek-R1-Distill-Qwen-14B", - "deepseek-ai/DeepSeek-R1-Distill-Llama-8B", "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B", "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B", - "Pro/deepseek-ai/DeepSeek-R1-Distill-Llama-8B","Pro/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B","Pro/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B", - "meta-llama/Llama-3.3-70B-Instruct","AIDC-AI/Marco-o1","deepseek-ai/DeepSeek-V2.5", - "Qwen/Qwen2.5-72B-Instruct-128K","Qwen/Qwen2.5-72B-Instruct","Qwen/Qwen2.5-32B-Instruct","Qwen/Qwen2.5-14B-Instruct","Qwen/Qwen2.5-7B-Instruct", - "Qwen/Qwen2.5-Coder-32B-Instruct","Qwen/Qwen2.5-Coder-7B-Instruct", - "Qwen/Qwen2-7B-Instruct","Qwen/Qwen2-1.5B-Instruct","Qwen/QwQ-32B-Preview", - "TeleAI/TeleChat2", - "01-ai/Yi-1.5-34B-Chat-16K","01-ai/Yi-1.5-9B-Chat-16K","01-ai/Yi-1.5-6B-Chat", - "THUDM/glm-4-9b-chat","Vendor-A/Qwen/Qwen2.5-72B-Instruct", - "internlm/internlm2_5-7b-chat","internlm/internlm2_5-20b-chat", - "nvidia/Llama-3.1-Nemotron-70B-Instruct", - "meta-llama/Meta-Llama-3.1-405B-Instruct","meta-llama/Meta-Llama-3.1-70B-Instruct","meta-llama/Meta-Llama-3.1-8B-Instruct", - "google/gemma-2-27b-it","google/gemma-2-9b-it", - "Pro/Qwen/Qwen2.5-7B-Instruct","Pro/Qwen/Qwen2-7B-Instruct","Pro/Qwen/Qwen2-1.5B-Instruct", - "Pro/THUDM/chatglm3-6b","Pro/THUDM/glm-4-9b-chat", - "Pro/meta-llama/Meta-Llama-3.1-8B-Instruct", - "Pro/google/gemma-2-9b-it", +# 支持推理的模型系列,非完整模型名称 +inference_model_series = [ + "THUDM/GLM-Z1", "deepseek-ai/DeepSeek-R1", "Qwen/QwQ-32B" ] - -if any(item in siliconflow_models for item in AVAIL_LLM_MODELS): +for model in [m for m in AVAIL_LLM_MODELS if m.startswith("siliconflow-")]: + # 模型名称的格式为: + # "siliconflow-" + # 其中: + # "siliconflow-" 是前缀(必要),在实际请求中,会将其去掉。 + # "deepseek-ai/DeepSeek-R1" 是硅基智能提供的模型名(必要)。 + try: siliconflow_noui, siliconflow_ui = get_predict_function( api_key_conf_name="SILICONFLOW_API_KEY", - max_output_token=4096, + max_output_token=8192, disable_proxy=False, + # 去除前缀 + model_remove_prefix = ["siliconflow-"] + ) + # 判断是否具有推理能力 + enable_reasoning = any(item in model for item in inference_model_series) + model_info.update( + { + model: { + "fn_with_ui": siliconflow_ui, + "fn_without_ui": siliconflow_noui, + "endpoint": siliconflow_endpoint, + "can_multi_thread": True, + "max_token": 32000, + "tokenizer": tokenizer_gpt35, + "token_cnt": get_token_num_gpt35, + "enable_reasoning": enable_reasoning, + }, + } ) - for item in (set(siliconflow_models) & set(AVAIL_LLM_MODELS)): - if "DeepSeek-R1" in item: - model_info.update( - { - item: { - "fn_with_ui": siliconflow_ui, - "fn_without_ui": siliconflow_noui, - "endpoint": siliconflow_endpoint, - "can_multi_thread": True, - "max_token": 8000, - "tokenizer": tokenizer_gpt35, - "token_cnt": get_token_num_gpt35, - "enable_reasoning": True, - }, - } - ) - else: - model_info.update( - { - item: { - "fn_with_ui": siliconflow_ui, - "fn_without_ui": siliconflow_noui, - "endpoint": siliconflow_endpoint, - "can_multi_thread": True, - "max_token": 8000, - "tokenizer": tokenizer_gpt35, - "token_cnt": get_token_num_gpt35, - }, - } - ) except: logger.error(trimmed_format_exc())