修改下拉框,并增加新的映射
This commit is contained in:
+83
-21
@@ -737,17 +737,79 @@ class RN_LLMAPI_Pro_Node():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def _load_config_json(self):
|
||||
try:
|
||||
cfg_path = os.path.join(os.path.dirname(__file__), "config", "ComfyUI_rn_translator-config.json")
|
||||
with open(cfg_path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
def _get_model_config(self, display_name):
|
||||
cfg = self._load_config_json()
|
||||
vllm = cfg.get("vllm") or {}
|
||||
llm = cfg.get("llm") or {}
|
||||
v_models = vllm.get("models") or {}
|
||||
l_models = llm.get("models") or {}
|
||||
model_cfg = v_models.get(display_name) or l_models.get(display_name)
|
||||
if isinstance(model_cfg, dict):
|
||||
return {
|
||||
"api_key": model_cfg.get("api_key") or "",
|
||||
"model": model_cfg.get("model") or "",
|
||||
"base_url": model_cfg.get("base_url") or "",
|
||||
"temperature": model_cfg.get("temperature"),
|
||||
"max_tokens": model_cfg.get("max_tokens"),
|
||||
"top_p": model_cfg.get("top_p"),
|
||||
}
|
||||
return None
|
||||
|
||||
def _fallback_model_name(self, display_name):
|
||||
mapping = {
|
||||
"Qwen2.5-32B-Instruct": "Qwen/Qwen2.5-32B-Instruct",
|
||||
"Qwen2.5-72B-Instruct": "Qwen/Qwen2.5-72B-Instruct",
|
||||
"Qwen2.5-VL-32B-Instruct": "Qwen/Qwen2.5-VL-32B-Instruct",
|
||||
"Qwen2.5-Omni-7B": "Qwen/Qwen2.5-Omni-7B",
|
||||
"Qwen3-32B": "Qwen/Qwen3-32B",
|
||||
"Qwen3-Embedding-8B": "Qwen/Qwen3-Embedding-8B",
|
||||
"Qwen3-Reranker-8B": "Qwen/Qwen3-Reranker-8B",
|
||||
"Qwen3-Coder-480B-A35B-Instruct": "Qwen/Qwen3-Coder-480B-A35B-Instruct",
|
||||
"DeepSeek-R1-Distill-Qwen-32B": "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
||||
"DeepSeek-R1-0528": "deepseek-ai/DeepSeek-R1-0528",
|
||||
"DeepSeek-V3-0324": "deepseek-ai/DeepSeek-V3-0324",
|
||||
"glm-4-9b-chat": "THUDM/glm-4-9b-chat",
|
||||
"GLM-4-32B-0414": "THUDM/GLM-4-32B-0414",
|
||||
"GLM-4.1V-9B-Thinking": "THUDM/GLM-4.1V-9B-Thinking",
|
||||
"GLM-4.6": "THUDM/GLM-4.6",
|
||||
"bge-m3": "BAAI/bge-m3",
|
||||
"bge-reranker-v2-m3": "BAAI/bge-reranker-v2-m3",
|
||||
}
|
||||
if not display_name:
|
||||
return ""
|
||||
if "/" in display_name:
|
||||
return display_name
|
||||
return mapping.get(display_name, display_name)
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"model": (["default",
|
||||
"doubao-seed-1-6-251015",
|
||||
"DeepSeek-V3",
|
||||
"Qwen3-235B-A22B-Instruct-2507",
|
||||
"gemini-2.5-flash",
|
||||
"gpt-5",
|
||||
"gemini-3-pro-preview"], {"default": "default"}),
|
||||
"model": (["Qwen2.5-32B-Instruct",
|
||||
"Qwen2.5-72B-Instruct",
|
||||
"Qwen2.5-VL-32B-Instruct",
|
||||
"Qwen2.5-Omni-7B",
|
||||
"Qwen3-32B",
|
||||
"Qwen3-Embedding-8B",
|
||||
"Qwen3-Reranker-8B",
|
||||
"Qwen3-Coder-480B-A35B-Instruct",
|
||||
"DeepSeek-R1-Distill-Qwen-32B",
|
||||
"DeepSeek-R1-0528",
|
||||
"DeepSeek-V3-0324",
|
||||
"glm-4-9b-chat",
|
||||
"GLM-4-32B-0414",
|
||||
"GLM-4.1V-9B-Thinking",
|
||||
"GLM-4.6",
|
||||
"bge-m3",
|
||||
"bge-reranker-v2-m3",
|
||||
], {"default": "Qwen2.5-VL-32B-Instruct"}),
|
||||
"role": ("STRING", {"multiline": True, "default": "You are a helpful assistant"}),
|
||||
"prompt": ("STRING", {"multiline": True, "default": "Hello"}),
|
||||
"temperature": ("FLOAT", {"default": 0.6}),
|
||||
@@ -765,14 +827,11 @@ class RN_LLMAPI_Pro_Node():
|
||||
|
||||
def rn_run_llmapi_pro(self, model, role, prompt, temperature, seed, api_baseurl='', api_key='', ref_image=None):
|
||||
cfg = get_config()
|
||||
vllm_cfg = get_vllm_config()
|
||||
if model == "default":
|
||||
model = ""
|
||||
has_visual = (ref_image is not None)
|
||||
selected_cfg = vllm_cfg if has_visual else cfg
|
||||
used_api_baseurl = (api_baseurl or selected_cfg.get("base_url"))
|
||||
used_api_key = (api_key or selected_cfg.get("api_key") or "")
|
||||
used_model = (model or selected_cfg.get("model") or ("qwen25-vl-32b-instruct" if has_visual else "gpt-4o-mini"))
|
||||
model_cfg = self._get_model_config(model) if hasattr(self, "_get_model_config") else None
|
||||
used_api_baseurl = api_baseurl or (model_cfg or {}).get("base_url") or cfg.get("base_url")
|
||||
used_api_key = api_key or (model_cfg or {}).get("api_key") or cfg.get("api_key") or ""
|
||||
base_model = (model_cfg or {}).get("model") or (self._fallback_model_name(model) if hasattr(self, "_fallback_model_name") else model) or model
|
||||
used_model = base_model
|
||||
client = OpenAI(api_key=used_api_key, base_url=used_api_baseurl)
|
||||
if ref_image is None:
|
||||
messages = [
|
||||
@@ -797,9 +856,12 @@ class RN_LLMAPI_Pro_Node():
|
||||
},
|
||||
]},
|
||||
]
|
||||
completion = client.chat.completions.create(model=used_model, messages=messages, temperature=temperature)
|
||||
if completion is not None and hasattr(completion, 'choices'):
|
||||
prompt = completion.choices[0].message.content
|
||||
else:
|
||||
prompt = 'Error'
|
||||
return (prompt,)
|
||||
try:
|
||||
completion = client.chat.completions.create(model=used_model, messages=messages, temperature=temperature)
|
||||
if completion is not None and hasattr(completion, 'choices'):
|
||||
result = completion.choices[0].message.content
|
||||
else:
|
||||
result = 'Error: No response from API'
|
||||
except Exception as e:
|
||||
result = f"API调用出错: {str(e)}"
|
||||
return (result,)
|
||||
|
||||
Reference in New Issue
Block a user