commit DeepSeekAPI node

This commit is contained in:
chflame163
2025-01-02 12:28:56 +08:00
parent 32a3ad024b
commit 4db54ed047
9 changed files with 487 additions and 7 deletions
+25 -1
View File
@@ -145,6 +145,7 @@ Please try downgrading the ```protobuf``` dependency package to 3.20.3, or set e
**If the dependency package error after updating, please double clicking ```repair_dependency.bat``` (for Official ComfyUI Protable) or ```repair_dependency_aki.bat``` (for ComfyUI-aki-v1.x) in the plugin folder to reinstall the dependency packages.
* Commit [DeepSeekAPI](DeepSeekAPI) node, Use DeepSeek API for text inference.
* Commit [SegmentAnythingUltraV3](#SegmentAnythingUltraV3) and [LoadSegmentAnythingModels](#LoadSegmentAnythingModels) nodes, Avoid duplicating model loading when using multiple SAM nodes.
* Commit [ZhipuGLM4](#ZhipuGLM4) and [ZhipuGLM4V](#ZhipuGLM4V) nodes, Use the Zhipu API for textual and visual inference. Among the current Zhipu models, GLM-4-Flash and glm-4v-flash models are free.
Apply for an API key for free at [https://bigmodel.cn/usercenter/proj-mgmt/apikeys](https://bigmodel.cn/usercenter/proj-mgmt/apikeys), fill your API key in ```zhipu_api_key=```.
@@ -313,6 +314,29 @@ Node options:
* system_prompt: The system prompt.
* user_prompt: The user prompt.
### <a id="table1">DeepSeekAPI</a>
Use the DeepSeek API for text inference, supporting multi node context concatenation.
Apply for an API key for free at [https://platform.deepseek.com/api_keys](https://platform.deepseek.com/api_keys), And fill it in ```api_key.ini```, this file is located in the root directory of the plug-in, and the default name is ```api_key.ini.example```. to use this file for the first time, you need to change the file suffix to ```.ini```. Open it using text editing software, fill in your API key after ```deepseek_api_key=``` and save it.
![image](image/deepseek_api_example.jpg)
Node Options:
![image](image/deepseek_api_node.jpg)
* history: History of DeepSeekAPI node, optional input. If there is input here, historical records will be used as context.
* model: Choose the DeepSeek model, currently there is only one option: "deepseek-chat", which is the DeepSeek-V3 model.
* max_tokens: The max_token parameter of DeepSeek defaults to 4096.
* temperature: The temperature parameter of DeepSeek defaults to 1.
* top_p: The top_p parameter of DeepSeek defaults to 1.
* presence_penalty: The presence_penalty parameter of DeepSeek defaults to 0.
* frequency_penalty: The frequency_penalty parameter of DeepSeek defaults to 0.
* history_length: History record length. Records exceeding this length will be discarded.
* system_prompt: The system prompt.
* user_prompt: The user prompt.
Outputs:
* text: Output text of DeepSeek.
* history: History of DeepSeek conversations.
### <a id="table1">ZhipuGLM4</a>
Use the Zhipu API for text inference, supporting multi node context concatenation.
Apply for an API key for free at [https://bigmodel.cn/usercenter/proj-mgmt/apikeys](https://bigmodel.cn/usercenter/proj-mgmt/apikeys), And fill it in ```api_key.ini```, this file is located in the root directory of the plug-in, and the default name is ```api_key.ini.example```. to use this file for the first time, you need to change the file suffix to ```.ini```. Open it using text editing software, fill in your API key after ```zhipu_api_key=``` and save it.
@@ -330,7 +354,7 @@ Outputs:
* text: Output text of GLM4.
* history: History of GLM4 conversations.
### <a id="table1">ZhipuGLM4V</a>
### <a id="table1">ZhipuGLM4</a>
Use the Zhipu API for visual inference.
Apply for an API key for free at [https://bigmodel.cn/usercenter/proj-mgmt/apikeys](https://bigmodel.cn/usercenter/proj-mgmt/apikeys), And fill it in ```api_key.ini```, this file is located in the root directory of the plug-in, and the default name is ```api_key.ini.example```. to use this file for the first time, you need to change the file suffix to ```.ini```. Open it using text editing software, fill in your API key after ```zhipu_api_key=``` and save it.
+26 -2
View File
@@ -121,6 +121,7 @@ If this call came from a _pb2.py file, your generated code is out of date and mu
## 更新说明
**如果本插件更新后出现依赖包错误,请双击运行插件目录下的```install_requirements.bat```(官方便携包),或 ```install_requirements_aki.bat```(秋叶整合包) 重新安装依赖包。
* 添加 [DeepSeekAPI](DeepSeekAPI) 节点,使用DeepSeek API进行文本推理。
* 添加 [SegmentAnythingUltraV3](#SegmentAnythingUltraV3) 和 [LoadSegmentAnythingModels](#LoadSegmentAnythingModels)节点, 在使用多个SAM节点时避免重复加载模型。
* 添加 [ZhipuGLM4](#ZhipuGLM4) 和 [ZhipuGLM4V](#ZhipuGLM4V)节点,使用智谱API进行文本和视觉推理。目前的智谱模型中,GLM-4-Flash和glm-4v-flash模型是免费的。
在[https://bigmodel.cn/usercenter/proj-mgmt/apikeys](https://bigmodel.cn/usercenter/proj-mgmt/apikeys)免费申请API Key,填入插件目录下的```api_key.ini```。
@@ -287,7 +288,30 @@ JoyCaption2的extra_options参数节点。
* system_prompt: 系统提示词。
* user_prompt: 用户提示词。
* 添加 [ZhipuGLM4](#ZhipuGLM4) 和 [ZhipuGLM4V](#ZhipuGLM4V)节点,
### <a id="table1">DeepSeekAPI</a>
使用DeepSeek API进行文本推理,支持多节点上下文串联。
在[https://platform.deepseek.com/api_keys](https://platform.deepseek.com/api_keys)申请API Key,并将其填到```api_key.ini```, 这个文件位于插件根目录下, 默认名字是```api_key.ini.example```, 初次使用这个文件需将文件后缀改为.ini。用文本编辑软件打开,在```deepseek_api_key=```后面填入你的API key并保存。
![image](image/deepseek_api_example.jpg)
节点选项说明:
![image](image/deepseek_api_node.jpg)
* history: DeepSeekAPI节点的历史记录,可选输入。如果此处有输入,将使用历史记录作为上下文。
* model: 选择DeepSeek模型,目前仅有一个选项:"deepseek-chat"即DeepSeek-V3模型。
* max_tokens: DeepSeek的max_tokens参数,默认为4096。
* temperature: DeepSeek的temperature参数,默认为1。
* top_p: DeepSeek的top_p参数,默认为1。
* presence_penalty: DeepSeek的presence_penalty参数,默认为0。
* frequency_penalty: DeepSeek的frequency_penalty参数,默认为0。
* history_length: 历史记录长度。超出该长度的记录将被截断。
* system_prompt: 系统提示词。
* user_prompt: 用户提示词。
输出:
* text: DeepSeek的输出。
* history: DeepSeek对话历史记录。
### <a id="table1">ZhipuGLM4</a>
使用智谱API进行文本推理,支持多节点上下文串联。
@@ -306,7 +330,7 @@ JoyCaption2的extra_options参数节点。
* text: GLM4的输出。
* history: GLM4对话历史记录。
### <a id="table1">ZhipuGLM4V</a>
### <a id="table1">ZhipuGLM4</a>
使用智谱API进行视觉推理。
在[https://bigmodel.cn/usercenter/proj-mgmt/apikeys](https://bigmodel.cn/usercenter/proj-mgmt/apikeys)免费申请API Key,并将其填到```api_key.ini```, 这个文件位于插件根目录下, 默认名字是```api_key.ini.example```, 初次使用这个文件需将文件后缀改为.ini。用文本编辑软件打开,在```zhipu_api_key=```后面填入你的API key并保存。
+2 -1
View File
@@ -1,3 +1,4 @@
# LayerStyle api_key
google_api_key=
zhipu_api_key=
zhipu_api_key=
deepseek_api_key=
Binary file not shown.

After

Width:  |  Height:  |  Size: 409 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

+84
View File
@@ -0,0 +1,84 @@
import base64
import io
import json
import requests
from .imagefunc import *
deepseek_model_list = ['deepseek-chat']
class LS_DeepSeek_API:
def __init__(self):
self.NODE_NAME = 'DeepSeekAPI'
pass
@classmethod
def INPUT_TYPES(self):
return {
"required": {
"model": (deepseek_model_list,),
"max_tokens": ("INT", {"default": 4096, "min": 1, "max": 8192, "step": 1}),
"temperature": ("FLOAT", {"default": 1, "min": 0, "max": 2, "step": 0.1}),
"top_p": ("FLOAT", {"default": 1, "min": 0, "max": 1, "step": 0.1}),
"presence_penalty": ("FLOAT", {"default": 0, "min": -2, "max": 2, "step": 0.1}),
"frequency_penalty": ("FLOAT", {"default": 0, "min": -2, "max": 2, "step": 0.1}),
"history_length": ("INT", {"default": 8, "min": 1, "max": 64, "step": 1}),
"system_prompt": ("STRING", {"default": "You are a helpful assistant.", "multiline": False}),
"user_prompt": ("STRING", {"default": "", "multiline": True}),
},
"optional": {
"history": ("DEEPSEEK_HISTORY",),
}
}
RETURN_TYPES = ("STRING", "DEEPSEEK_HISTORY",)
RETURN_NAMES = ("text", "history",)
FUNCTION = 'run_deepseek_api'
CATEGORY = '😺dzNodes/LayerUtility'
def run_deepseek_api(self, model, max_tokens, temperature, top_p, presence_penalty, frequency_penalty,
history_length, system_prompt, user_prompt, history=None):
api_key = get_api_key('deepseek_api_key')
ret_text = ""
if history is not None:
messages = history["messages"]
messages = messages[-history_length *2:]
else:
messages = [{"role": "system", "content": system_prompt}]
task = {"role": "user", "content": user_prompt}
messages.append(task)
from openai import OpenAI
client = OpenAI(api_key=api_key, base_url="https://api.deepseek.com")
response = client.chat.completions.create(
model=model,
messages=messages,
frequency_penalty=frequency_penalty,
max_tokens=max_tokens,
presence_penalty=presence_penalty,
temperature=temperature,
top_p=top_p,
stream=False
)
ret_message = response.choices[0].message.content
messages.append({"role": "assistant", "content": ret_message})
log(f"{self.NODE_NAME}: {model} response is:\n\033[1;36m{ret_message}\033[m")
return (ret_message, {"messages": messages},)
NODE_CLASS_MAPPINGS = {
"LayerUtility: DeepSeekAPI": LS_DeepSeek_API,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LayerUtility: DeepSeekAPI": "LayerUtility: DeepSeek API",
}
+2 -2
View File
@@ -1,9 +1,9 @@
[project]
name = "comfyui_layerstyle_advance"
description = "The nodes detached from ComfyUI Layer Style are mainly those with complex requirements for dependency packages."
version = "2.0.10"
version = "2.0.11"
license = "MIT"
dependencies = ["numpy", "matplotlib", "scikit_image", "scikit_learn", "opencv-contrib-python", "pymatting", "timm", "blend_modes", "transformers", "diffusers", "loguru", "colour-science", "huggingface_hub", "segment_anything", "addict", "omegaconf", "yapf", "wget", "iopath", "mediapipe", "typer_config", "fastapi", "rich", "google-generativeai", "ultralytics", "transparent-background", "accelerate", "onnxruntime", "bitsandbytes", "peft", "protobuf", "hydra-core", "blind-watermark", "qrcode", "pyzbar", "psd-tools", "wandb","zhipuai"]
dependencies = ["numpy", "matplotlib", "scikit_image", "scikit_learn", "opencv-contrib-python", "pymatting", "timm", "blend_modes", "transformers", "diffusers", "loguru", "colour-science", "huggingface_hub", "segment_anything", "addict", "omegaconf", "yapf", "wget", "iopath", "mediapipe", "typer_config", "fastapi", "rich", "google-generativeai", "ultralytics", "transparent-background", "accelerate", "onnxruntime", "bitsandbytes", "peft", "protobuf", "hydra-core", "blind-watermark", "qrcode", "pyzbar", "psd-tools", "wandb", "zhipuai", "openai"]
[project.urls]
Repository = "https://github.com/chflame163/ComfyUI_LayerStyle_Advance"
+2 -1
View File
@@ -34,4 +34,5 @@ blind-watermark
qrcode
pyzbar
psd-tools
zhipuai
zhipuai
openai
+346
View File
@@ -0,0 +1,346 @@
{
"last_node_id": 27,
"last_link_id": 31,
"nodes": [
{
"id": 21,
"type": "ShowText|pysssss",
"pos": [
1460,
-260
],
"size": [
398.3951110839844,
166.44081115722656
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "text",
"type": "STRING",
"link": 30,
"widget": {
"name": "text"
}
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null,
"shape": 6
}
],
"properties": {
"Node name for S&R": "ShowText|pysssss"
},
"widgets_values": [
"",
"Beijing is renowned for its rich culinary heritage, and its most famous dish is **Peking Duck** (北京烤鸭). This iconic dish features crispy, roasted duck skin and tender meat, traditionally served with thin pancakes, hoisin sauce, and sliced scallions or cucumbers. It has a history dating back to the imperial era and is considered a symbol of Chinese cuisine.\n\nOther notable Beijing dishes include:\n\n- **Zhajiangmian** (炸酱面): Noodles topped with a savory soybean paste and vegetables.\n- **Jiaozi** (饺子): Dumplings filled with meat or vegetables, often enjoyed during festivals.\n- **Beijing Hot Pot** (北京火锅): A communal meal where diners cook meat, vegetables, and other ingredients in a simmering broth.\n- **Douzhi** (豆汁): A fermented mung bean drink, a traditional and acquired taste.\n\nBeijing's cuisine reflects its historical and cultural significance, blending flavors from northern China and imperial traditions."
]
},
{
"id": 20,
"type": "ShowText|pysssss",
"pos": [
990,
-270
],
"size": [
395.52490234375,
171.13929748535156
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"name": "text",
"type": "STRING",
"link": 29,
"widget": {
"name": "text"
}
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null,
"shape": 6
}
],
"properties": {
"Node name for S&R": "ShowText|pysssss"
},
"widgets_values": [
"",
"The capital of China is Beijing. It is one of the most populous cities in the world and serves as the political, cultural, and educational center of the country. Beijing is home to many historical landmarks, including the Forbidden City, the Great Wall of China, and Tiananmen Square."
]
},
{
"id": 25,
"type": "LayerUtility: DeepSeekAPI",
"pos": [
980,
-626.0712280273438
],
"size": [
400,
288
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [
{
"name": "history",
"type": "DEEPSEEK_HISTORY",
"link": null,
"shape": 7
}
],
"outputs": [
{
"name": "text",
"type": "STRING",
"links": [
29
],
"slot_index": 0
},
{
"name": "history",
"type": "DEEPSEEK_HISTORY",
"links": [
27
],
"slot_index": 1
}
],
"properties": {
"Node name for S&R": "LayerUtility: DeepSeekAPI"
},
"widgets_values": [
"deepseek-chat",
4096,
1,
1,
0,
0,
8,
"You are a helpful assistant.",
"Where is the capital of China?"
],
"color": "rgba(38, 73, 116, 0.7)"
},
{
"id": 26,
"type": "LayerUtility: DeepSeekAPI",
"pos": [
1460,
-630
],
"size": [
400,
288
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "history",
"type": "DEEPSEEK_HISTORY",
"link": 27,
"shape": 7
}
],
"outputs": [
{
"name": "text",
"type": "STRING",
"links": [
30
],
"slot_index": 0
},
{
"name": "history",
"type": "DEEPSEEK_HISTORY",
"links": [
28
],
"slot_index": 1
}
],
"properties": {
"Node name for S&R": "LayerUtility: DeepSeekAPI"
},
"widgets_values": [
"deepseek-chat",
4096,
1,
1,
0,
0,
8,
"You are a helpful assistant.",
"What is the most famous cuisine in this city?"
],
"color": "rgba(38, 73, 116, 0.7)"
},
{
"id": 27,
"type": "LayerUtility: DeepSeekAPI",
"pos": [
1945.4642333984375,
-626.0711669921875
],
"size": [
400,
288
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "history",
"type": "DEEPSEEK_HISTORY",
"link": 28,
"shape": 7
}
],
"outputs": [
{
"name": "text",
"type": "STRING",
"links": [
31
],
"slot_index": 0
},
{
"name": "history",
"type": "DEEPSEEK_HISTORY",
"links": null
}
],
"properties": {
"Node name for S&R": "LayerUtility: DeepSeekAPI"
},
"widgets_values": [
"deepseek-chat",
4096,
1,
1,
0,
0,
8,
"You are a helpful assistant.",
"Recommend a restaurant and specify its location"
],
"color": "rgba(38, 73, 116, 0.7)"
},
{
"id": 23,
"type": "ShowText|pysssss",
"pos": [
1943.642822265625,
-261.2142028808594
],
"size": [
409.1788024902344,
166.62875366210938
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "text",
"type": "STRING",
"link": 31,
"widget": {
"name": "text"
}
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null,
"shape": 6
}
],
"properties": {
"Node name for S&R": "ShowText|pysssss"
},
"widgets_values": [
"",
"One of the most famous and highly recommended restaurants in Beijing for **Peking Duck** is **Quanjude Roast Duck Restaurant** (全聚德烤鸭店). It has a long history dating back to 1864 and is considered one of the best places to enjoy this iconic dish.\n\n### Location:\n**Quanjude (Qianmen Branch)** \nAddress: 32 Qianmen Street, Dongcheng District, Beijing, China \nNearest Landmark: Near Tiananmen Square and the Qianmen Gate \n\nThis branch is particularly popular due to its central location and historical significance. The restaurant offers an authentic dining experience, with skilled chefs preparing the duck in traditional wood-fired ovens.\n\nIf you're looking for a more modern twist on Peking Duck, you might also consider **Da Dong Roast Duck** (大董烤鸭店), known for its innovative presentation and lighter, healthier approach to the dish.\n\n### Da Dong (Nanxincang Branch) \nAddress: 1-2/F, Nanxincang International Plaza, 22A Dongsishitiao, Dongcheng District, Beijing, China \n\nBoth restaurants are excellent choices for experiencing Beijing's culinary heritage!"
]
}
],
"links": [
[
27,
25,
1,
26,
0,
"DEEPSEEK_HISTORY"
],
[
28,
26,
1,
27,
0,
"DEEPSEEK_HISTORY"
],
[
29,
25,
0,
20,
0,
"STRING"
],
[
30,
26,
0,
21,
0,
"STRING"
],
[
31,
27,
0,
23,
0,
"STRING"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.4641000000000013,
"offset": [
-885.2441087663999,
885.7805452879334
]
},
"ue_links": []
},
"version": 0.4
}