-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate.py
More file actions
48 lines (37 loc) · 1.15 KB
/
translate.py
File metadata and controls
48 lines (37 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import requests
class Translator:
def __init__(self) -> None:
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input_text": ("STRING", ),
"API_KEY": ("STRING", {"default": ""}),
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "translate"
CATEGORY = "AIRedoon"
OUTPUT_NODE = True
def translate(self, input_text, api_key=None) -> tuple:
"""
通过调用openai接口进行翻译,支持外网访问
"""
if api_key:
trans_text = self.translate_by_openai(input_text=input_text)
else:
trans_text = self.translate_by_llama(input_text=input_text)
return (trans_text, )
def translate_by_llama(self, input_text):
"""
通过本地模型进行翻译
"""
trans_text = ""
return trans_text
def translate_by_openai(self, input_text) -> str:
"""
通过openai接口进行翻译, 支持外网访问时可用
"""
trans_text = ""
return trans_text