翻译前置语言判断
This commit is contained in:
@@ -8,6 +8,7 @@ from requests import RequestException
|
||||
from retry import retry
|
||||
|
||||
from app.core.config import QWEN_API_KEY
|
||||
from app.service.chat_robot.script.service.CallQWen import get_language
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -93,7 +94,13 @@ def get_translation_from_llama3(text):
|
||||
|
||||
# prompt = f"System: {prefix_for_llama}\nUser:[{text}]"
|
||||
|
||||
# 创建请求的负载
|
||||
# 先获取用户输入文本的语言
|
||||
language = get_language(text)
|
||||
|
||||
if 'English' in language:
|
||||
return text
|
||||
|
||||
# 创建请求的负载 translator是自定义的翻译模型
|
||||
payload = {
|
||||
"model": "translator",
|
||||
"prompt": f"[{text}]",
|
||||
@@ -117,6 +124,26 @@ def get_translation_from_llama3(text):
|
||||
print(response.text)
|
||||
|
||||
|
||||
# 在llama3中创建一个翻译模型
|
||||
# def create_model_with_llama(text):
|
||||
# url = "http://localhost:11434/api/create"
|
||||
# # url = "http://10.1.1.240:1143/api/generate"
|
||||
#
|
||||
# # prompt = f"System: {prefix_for_llama}\nUser:[{text}]"
|
||||
#
|
||||
# # 创建翻译器的配置文件
|
||||
# payload = {
|
||||
# "model": "translator",
|
||||
# "modelfile": "FROM llama3\nSYSTEM Translate everything within the brackets [] into English."
|
||||
# "Never translate or modify any English input."
|
||||
# "The input must be fully translated into coherent English sentences."
|
||||
# }
|
||||
#
|
||||
# # 将负载转换为 JSON 格式
|
||||
# headers = {'Content-Type': 'application/json'}
|
||||
# response = requests.post(url, data=json.dumps(payload), headers=headers)
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function"""
|
||||
text = get_translation_from_llama3("[火焰]")
|
||||
|
||||
Reference in New Issue
Block a user