V 3.0.1 LaiTool V3.0.1-preview.4
This commit is contained in:
@@ -12,6 +12,8 @@ let fspromises = require('fs').promises
|
||||
import { SoftwareService } from '../../define/db/service/SoftWare/softwareService'
|
||||
import { isEmpty } from 'lodash'
|
||||
import { ValidateJson } from '../../define/Tools/validate'
|
||||
import { GetOpenAISuccessResponse } from '../../define/response/openAIResponse'
|
||||
import { successMessage } from './generalTools'
|
||||
|
||||
let { Signer } = require('@volcengine/openapi')
|
||||
|
||||
@@ -191,6 +193,10 @@ export class Translate {
|
||||
return await this.TranslateReturnNowTencent(value)
|
||||
} else if (this.translationBusiness.includes('aliyun')) {
|
||||
return await this.TranslateReturnNowAliyun(value)
|
||||
} else if (this.translationBusiness.includes('laitool')) {
|
||||
return await this.TranslateReturnNowGPT(value)
|
||||
} else {
|
||||
throw new Error('未知的翻译API,请检查设置')
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
@@ -227,6 +233,8 @@ export class Translate {
|
||||
} else if (this.translationBusiness.includes('aliyun')) {
|
||||
// 阿里云翻译
|
||||
return await this.TranslatePromptAliyun(value)
|
||||
} else {
|
||||
throw new Error('反推这边不支持GPT翻译,请选择其他的翻译API')
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
@@ -236,6 +244,139 @@ export class Translate {
|
||||
}
|
||||
}
|
||||
|
||||
//#region LaiTool GPT翻译
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value 使用laitool GPT翻译
|
||||
*/
|
||||
async TranslateReturnNowGPT(value) {
|
||||
try {
|
||||
// 判断该当前的翻译API
|
||||
let translateData = value[0]
|
||||
let from = value[1]
|
||||
let to = value[2]
|
||||
if (value[3]) {
|
||||
throw new Error('使用GPT翻译不支持拆分')
|
||||
}
|
||||
let model = this.translationAppId
|
||||
let token = this.translationSecret
|
||||
|
||||
let data = {
|
||||
model: model,
|
||||
messages: []
|
||||
}
|
||||
// 开始调用GPT进行翻译
|
||||
if (from == 'en' && to == "zh") {
|
||||
data.messages.push({
|
||||
"role": "system",
|
||||
"content": '我想让你充当英译中专家,用中文100%还原描述,不要加其他的联想,只翻译字面意思,请检查所有信息是否准确,并在回答时保持简活,不需要任何其他反馈。'
|
||||
})
|
||||
// 添加示例
|
||||
data.messages.push({
|
||||
"role": "user",
|
||||
"content": 'A woman in her twenties with messy hair and a look of shock and despair. She is wearing a simple white shirt and jeans. Her face shows mixed emotions. The background is a dim and quiet room. The historical background is modern. The screen content is a close-up of the woman’s face with tear marks.'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "assistant",
|
||||
"content": '一位二十多岁的女人,头发凌乱,表情震惊和绝望。她穿着一件简单的白色衬衫和牛仔裤。她的脸上显示出复杂的情感。背景是一个昏暗安静的房间。历史背景是现代的。屏幕内容是女人脸部的特写,带有泪痕。'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "user",
|
||||
"content": 'A twenty-something woman with short curly hair, smiling, wearing a casual white shirt and jeans, sitting on a comfortable sofa with a cup of coffee in her hand. She is in a small and cozy living room with a few books on the bookshelf, modern interior design, and natural light pouring into the room in the late afternoon. Screen content: Part of the sofa cushions.'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "assistant",
|
||||
"content": '一位二十多岁的女性,留着短卷发,面带微笑,穿着休闲的白色衬衫和牛仔裤,手拿一杯咖啡,坐在一个舒适的沙发上。她所在的是一个小而温馨的客厅,书架上有几本书,现代室内设计,下午晚些时候,自然光线洒进房间。屏幕内容:沙发垫的一部分。'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "user",
|
||||
"content": 'In a modern city, a streamlined car is parked on the street. A man in his thirties, with short brown hair combed back, a calm, confident look, tall and thin in a clean white shirt and black pants, sits in the car. The interior of the car is clean and modern, and the background is blurred to highlight the man\'s calm demeanor. The man\'s cell phone is ringing. The scene is set in the present.'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "assistant",
|
||||
"content": '在现代城市,一辆流线型轿车停在街上。一个三十多岁的男人,短短的棕色头发梳向后,神情冷静,自信,穿着干净的白衬衫和黑裤子,身材高挑瘦长,坐在车里。车内干净而现代,背景模糊,以突出男人平静的神态。男人的手机正在响。场景设定在现在。'
|
||||
})
|
||||
} else if (from == 'zh' && to == "en") {
|
||||
data.messages.push({
|
||||
"role": "system",
|
||||
"content": '我想让你充当中译英专家,用中文100%还原描述,不要加其他的联想,只翻译字面意思,请检查所有信息是否准确,并在回答时保持简活,不需要任何其他反馈。'
|
||||
})
|
||||
// 添加示例
|
||||
data.messages.push({
|
||||
"role": "user",
|
||||
"content": '一位二十多岁的女人,头发凌乱,表情震惊和绝望。她穿着一件简单的白色衬衫和牛仔裤。她的脸上显示出复杂的情感。背景是一个昏暗安静的房间。历史背景是现代的。屏幕内容是女人脸部的特写,带有泪痕。'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "assistant",
|
||||
"content": 'A woman in her twenties with messy hair and a look of shock and despair. She is wearing a simple white shirt and jeans. Her face shows mixed emotions. The background is a dim and quiet room. The historical background is modern. The screen content is a close-up of the woman’s face with tear marks.'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "user",
|
||||
"content": '一位二十多岁的女性,留着短卷发,面带微笑,穿着休闲的白色衬衫和牛仔裤,手拿一杯咖啡,坐在一个舒适的沙发上。她所在的是一个小而温馨的客厅,书架上有几本书,现代室内设计,下午晚些时候,自然光线洒进房间。屏幕内容:沙发垫的一部分。'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "assistant",
|
||||
"content": 'A twenty-something woman with short curly hair, smiling, wearing a casual white shirt and jeans, sitting on a comfortable sofa with a cup of coffee in her hand. She is in a small and cozy living room with a few books on the bookshelf, modern interior design, and natural light pouring into the room in the late afternoon. Screen content: Part of the sofa cushions.'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "user",
|
||||
"content": '在现代城市,一辆流线型轿车停在街上。一个三十多岁的男人,短短的棕色头发梳向后,神情冷静,自信,穿着干净的白衬衫和黑裤子,身材高挑瘦长,坐在车里。车内干净而现代,背景模糊,以突出男人平静的神态。男人的手机正在响。场景设定在现在。'
|
||||
})
|
||||
data.messages.push({
|
||||
"role": "assistant",
|
||||
"content": 'In a modern city, a streamlined car is parked on the street. A man in his thirties, with short brown hair combed back, a calm, confident look, tall and thin in a clean white shirt and black pants, sits in the car. The interior of the car is clean and modern, and the background is blurred to highlight the man\'s calm demeanor. The man\'s cell phone is ringing. The scene is set in the present.'
|
||||
})
|
||||
} else {
|
||||
throw new Error("GPT翻译只支持中英互译")
|
||||
}
|
||||
|
||||
data.messages.push({
|
||||
role: 'user',
|
||||
content: translateData
|
||||
})
|
||||
|
||||
let config = {
|
||||
method: 'post',
|
||||
maxBodyLength: Infinity,
|
||||
url: this.translationBusiness,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
data: JSON.stringify(data)
|
||||
}
|
||||
let res = await axios.request(config)
|
||||
// 将返回的数据进行拼接数据处理
|
||||
|
||||
let res_data = []
|
||||
let content = GetOpenAISuccessResponse(res.data)
|
||||
|
||||
if (to == 'zh') {
|
||||
res_data.push({
|
||||
src: translateData,
|
||||
dst: content
|
||||
})
|
||||
} else if (to == 'en') {
|
||||
res_data.push({
|
||||
src: content,
|
||||
dst: translateData
|
||||
})
|
||||
}
|
||||
|
||||
// 直接返回数据
|
||||
return {
|
||||
code: 1,
|
||||
to: to,
|
||||
data: res_data
|
||||
}
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
/**
|
||||
* 阿里云翻译写入队列中
|
||||
* @param {*} value
|
||||
|
||||
Reference in New Issue
Block a user