This commit is contained in:
liguo
2024-06-25 23:52:08 +08:00
parent 3a1da0ae18
commit eeefe81062
8 changed files with 143 additions and 1 deletions
+2
View File
@@ -160,3 +160,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
/config.json
/.idea/
+9 -1
View File
@@ -1 +1,9 @@
# comfyUI-siliconflow-api-2lab
# DeepSeek
Unofficial implementation of siliconflow API for ComfyUI
# How to use
- apply api key in :https://cloud.siliconflow.cn/
- add api key in config.json
# example
see workflow folder
+18
View File
@@ -0,0 +1,18 @@
from .siliconflow import FreeChat,PaidChat
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
FreeChat.NAME: FreeChat,
PaidChat.NAME: PaidChat,
}
# display name
NODE_DISPLAY_NAME_MAPPINGS = {
PaidChat.NAME: "Siliconflow paid chat",
FreeChat.NAME: "Siliconflow free chat",
}
__all__ = [NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS]
+3
View File
@@ -0,0 +1,3 @@
{
"API_KEY": "your key"
}
+18
View File
@@ -0,0 +1,18 @@
# NAMESPACE
import os
from pathlib import Path
PROJECT_NAME= '2lab'
def get_project_name(name):
return '{} ({})'.format(name, PROJECT_NAME)
def get_project_category(sub_dirs = None):
start = "🦊" + PROJECT_NAME
if sub_dirs is None:
return start
else:
return "{}/{}".format(start,sub_dirs)
# PATH
project_root = Path(__file__).parent
+1
View File
@@ -0,0 +1 @@
openai
+92
View File
@@ -0,0 +1,92 @@
import os
import json
from openai import OpenAI
from .constants import get_project_category, get_project_name, project_root
configFile = os.path.join(project_root, 'config.json')
with open(configFile, 'r') as file:
data = file.read()
json_data = json.loads(data)
key = json_data["API_KEY"]
NODE_CATEGORY = get_project_category("llm")
class FreeChat:
NAME = get_project_name('FreeChat')
CATEGORY = NODE_CATEGORY
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "doWork"
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"prompt": ("STRING", {"multiline": True}),
"model": (["Qwen/Qwen2-7B-Instruct",
"Qwen/Qwen2-1.5B-Instruct",
"Qwen/Qwen1.5-7B-Chat",
"THUDM/glm-4-9b-chat",
"THUDM/chatglm3-6b",
"01-ai/Yi-1.5-9B-Chat-16K",
"01-ai/Yi-1.5-6B-Chat"
],{"default": "Qwen/Qwen2-7B-Instruct"}),
},
}
def doWork(self, prompt, model):
client = OpenAI(api_key=key, base_url="https://api.siliconflow.cn/v1")
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": prompt},
],
stream=False
)
print(response.choices[0].message.content)
return {"result": (response.choices[0].message.content,)}
class PaidChat:
NAME = get_project_name('PaidChat')
CATEGORY = NODE_CATEGORY
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "doWork"
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"prompt": ("STRING", {"multiline": True}),
"model": (["Qwen/Qwen2-72B-Instruct",
"Qwen/Qwen2-57B-A14B-Instruct",
"Qwen/Qwen1.5-110B-Chat",
"Qwen/Qwen1.5-32B-Chat",
"Qwen/Qwen1.5-14B-Chat",
"deepseek-ai/DeepSeek-Coder-V2-Instruct",
"deepseek-ai/DeepSeek-V2-Chat",
"deepseek-ai/deepseek-llm-67b-chat",
"01-ai/Yi-1.5-34B-Chat-16K"
],{"default": "Qwen/Qwen2-72B-Instruct"}),
},
}
def doWork(self, prompt, model):
client = OpenAI(api_key=key, base_url="https://api.siliconflow.cn/v1")
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": prompt},
],
stream=False
)
print(response.choices[0].message.content)
return {"result": (response.choices[0].message.content,)}
Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB