update ChatGLMNode

This commit is contained in:
AlekPet
2025-05-17 16:03:11 +03:00
parent eff8b1209f
commit c81bc1e882
6 changed files with 200 additions and 27 deletions
+1
View File
@@ -0,0 +1 @@
config.json
+151 -1
View File
@@ -2,13 +2,163 @@
Translation is carried out with the help of artificial intelligence using GLM models.
<details>
<summary><strong>Language Codes List</strong></summary>
- af – Afrikaans
- sq – Albanian
- am – Amharic
- ar – Arabic
- hy – Armenian
- as – Assamese
- ay – Aymara
- az – Azerbaijani
- bm – Bambara
- eu – Basque
- be – Belarusian
- bn – Bengali
- bho – Bhojpuri
- bs – Bosnian
- bg – Bulgarian
- ca – Catalan
- ceb – Cebuano
- ny – Chichewa
- zh-CN – Chinese (Simplified)
- zh-TW – Chinese (Traditional)
- co – Corsican
- hr – Croatian
- cs – Czech
- da – Danish
- dv – Divehi
- doi – Dogri
- nl – Dutch
- en – English
- eo – Esperanto
- et – Estonian
- ee – Ewe
- tl – Filipino
- fi – Finnish
- fr – French
- fy – Frisian
- gl – Galician
- ka – Georgian
- de – German
- el – Greek
- gn – Guarani
- gu – Gujarati
- ht – Haitian Creole
- ha – Hausa
- haw – Hawaiian
- iw – Hebrew
- hi – Hindi
- hmn – Hmong
- hu – Hungarian
- is – Icelandic
- ig – Igbo
- ilo – Ilocano
- id – Indonesian
- ga – Irish
- it – Italian
- ja – Japanese
- jw – Javanese
- kn – Kannada
- kk – Kazakh
- km – Khmer
- rw – Kinyarwanda
- gom – Konkani
- ko – Korean
- kri – Krio
- ku – Kurdish (Kurmanji)
- ckb – Kurdish (Sorani)
- ky – Kyrgyz
- lo – Lao
- la – Latin
- lv – Latvian
- ln – Lingala
- lt – Lithuanian
- lg – Luganda
- lb – Luxembourgish
- mk – Macedonian
- mai – Maithili
- mg – Malagasy
- ms – Malay
- ml – Malayalam
- mt – Maltese
- mi – Maori
- mr – Marathi
- mni-Mtei – Meiteilon (Manipuri)
- lus – Mizo
- mn – Mongolian
- my – Myanmar (Burmese)
- ne – Nepali
- no – Norwegian
- or – Odia (Oriya)
- om – Oromo
- ps – Pashto
- fa – Persian
- pl – Polish
- pt – Portuguese
- pa – Punjabi
- qu – Quechua
- ro – Romanian
- ru – Russian
- sm – Samoan
- sa – Sanskrit
- gd – Scots Gaelic
- nso – Sepedi
- sr – Serbian
- st – Sesotho
- sn – Shona
- sd – Sindhi
- si – Sinhala
- sk – Slovak
- sl – Slovenian
- so – Somali
- es – Spanish
- su – Sundanese
- sw – Swahili
- sv – Swedish
- tg – Tajik
- ta – Tamil
- tt – Tatar
- te – Telugu
- th – Thai
- ti – Tigrinya
- ts – Tsonga
- tr – Turkish
- tk – Turkmen
- ak – Twi
- uk – Ukrainian
- ur – Urdu
- ug – Uyghur
- uz – Uzbek
- vi – Vietnamese
- cy – Welsh
- xh – Xhosa
- yi – Yiddish
- yo – Yoruba
- zu – Zulu
</details>
### Install and use:
1. Install my custom nodes in ComfyUI, used [HERE](https://github.com/AlekPet/ComfyUI_Custom_Nodes_AlekPet#installing)
2. To use ChatGMLNode, you need to register on the site [bigmodel.cn](https://bigmodel.cn/) and get an API key. Free model is the `'glm-4-flash'`!
3. Inside folder **ChatGMLNode** find file `config.json` and add API key geting in point 2, and change `"ZHIPUAI_API_KEY": "your_api_key"` on your API Key.
3. Inside folder **ChatGMLNode** find file `config.json.example` rename to config.json and add API key geting in point 2 in propertu `"ZHIPUAI_API_KEY": "your_api_key"` on your API Key.
4. Run comfyui and add node `ChatGLM4TranslateCLIPTextEncodeNode` or `ChatGLM4TranslateTextNode`.
Optional: You can also set initial language values ​​when creating nodes in the file `config.json`.
```json
{
"__comment": "Register on the site https://bigmodel.cn and get a key and add it to the field ZHIPUAI_API_KEY. Change default translate languages ​​'from' and 'to' you use",
"from_translate": "ru",
"to_translate": "en",
"ZHIPUAI_API_KEY": "your_api_key"
}
```
> Includes:
> **ChatGLM4TranslateCLIPTextEncodeNode** - translate text, and return CONDITIONING
+41 -21
View File
@@ -13,34 +13,52 @@ ALL_CODES_LANGS = ['af', 'sq', 'am', 'ar', 'hy', 'as', 'ay', 'az', 'bm', 'eu', '
ENDPOINT_URL = "https://open.bigmodel.cn/api/paas/v4/chat/completions"
ZHIPUAI_API_KEY = None
def getConfigData():
# Directory node and config file
dir_node = os.path.dirname(__file__)
config_path = os.path.join(os.path.abspath(dir_node), "config.json")
config = {
"__comment": "Register on the site https://bigmodel.cn and get a key and add it to the field ZHIPUAI_API_KEY. Change default translate languages ​​'from' and 'to' you use",
"from_translate": "ru",
"to_translate": "en",
"ZHIPUAI_API_KEY": "your_api_key"
}
# Directory node and config file
dir_node = os.path.dirname(__file__)
config_path = os.path.join(os.path.abspath(dir_node), "config.json")
# Load config.js file
if not os.path.exists(config_path):
print("[ChatGLMNode] File config.js file not found! Create default config.json...")
with open(config_path, "w", encoding="utf-8") as f:
json.dump(config, f, ensure_ascii=False, indent=4)
return config
else:
with open(config_path, "r") as f:
config = json.load(f)
return config
# =====
# Load config.js file
if not os.path.exists(config_path):
print("File config.js file not found! Reinstall extensions!")
else:
with open(config_path, "r") as f:
CONFIG = json.load(f)
def checkPropValue(obj, key, not_include = []):
checkVal = lambda v: v is None or v.strip() == "" or v in not_include
# GET ZHIPUAI_API_KEY from json
ZHIPUAI_API_KEY = CONFIG.get("ZHIPUAI_API_KEY")
# =====
prop_val = obj.get(key)
if checkVal(prop_val):
obj.update(getConfigData())
return True if checkVal(obj.get(key)) else False
else:
return False
CONFIG = getConfigData()
def createRequest(payload):
global ZHIPUAI_API_KEY
global CONFIG
if (
ZHIPUAI_API_KEY is None
or ZHIPUAI_API_KEY.strip() == ""
or ZHIPUAI_API_KEY == "your_api_key"
):
if checkPropValue(CONFIG, "ZHIPUAI_API_KEY", ["your_api_key"]):
raise ValueError("ZHIPUAI_API_KEY value is empty or missing")
ZHIPUAI_API_KEY = CONFIG.get("ZHIPUAI_API_KEY")
# Headers
headers = {
"Authorization": f"Bearer {ZHIPUAI_API_KEY}",
@@ -92,15 +110,17 @@ def translate(prompt, srcTrans, toTrans, model, max_tokens, temperature, top_p):
class ChatGLM4TranslateCLIPTextEncodeNode:
@classmethod
def INPUT_TYPES(self):
from_lng = CONFIG.get("from_translate") if CONFIG.get("from_translate") in ALL_CODES_LANGS else "ru"
to_lng = CONFIG.get("to_translate") if CONFIG.get("to_translate") in ALL_CODES_LANGS else "en"
return {
"required": {
"from_translate": (
ALL_CODES_LANGS,
{"default": "ru", "tooltip": "Translation from"},
{"default": from_lng, "tooltip": "Translation from"},
),
"to_translate": (
ALL_CODES_LANGS,
{"default": "en", "tooltip": "Translation to"},
{"default": to_lng, "tooltip": "Translation to"},
),
"model": (
[
-4
View File
@@ -1,4 +0,0 @@
{
"__comment": "Register on the site https://bigmodel.cn and get a key and add it to the field ZHIPUAI_API_KEY",
"ZHIPUAI_API_KEY": "your_api_key"
}
+6
View File
@@ -0,0 +1,6 @@
{
"__comment": "Register on the site https://bigmodel.cn and get a key and add it to the field ZHIPUAI_API_KEY. Change default translate languages ​​'from' and 'to' you use",
"from_translate": "ru",
"to_translate": "en",
"ZHIPUAI_API_KEY": "your_api_key"
}
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui_custom_nodes_alekpet"
description = "Nodes: PoseNode, PainterNode, TranslateTextNode, TranslateCLIPTextEncodeNode, DeepTranslatorTextNode, DeepTranslatorCLIPTextEncodeNode, ArgosTranslateTextNode, ArgosTranslateCLIPTextEncodeNode, ChatGLM4TranslateCLIPTextEncodeNode, ChatGLM4TranslateTextNode, ChatGLM4InstructNode, ChatGLM4InstructMediaNode, DeepLXTranslateTextNode, DeepLXTranslateCLIPTextEncodeNode, PreviewTextNode, HexToHueNode, ColorsCorrectNode, IDENode."
version = "1.0.66"
version = "1.0.67"
license = { file = "LICENSE" }
[project.urls]