-
-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { fetch } from '@tauri-apps/api/http'; | ||
import { get } from '../global/config'; | ||
|
||
export const info = { | ||
name: "Open AI 代码解释", | ||
supportLanguage: { | ||
"zh-cn": "简体中文", | ||
"zh-tw": "繁体中文", | ||
"yue": '粤语', | ||
"ja": "日本語", | ||
"en": "英语", | ||
"ko": "韩语", | ||
"fr": "法语", | ||
"es": "西班牙语", | ||
"ru": "俄语", | ||
"de": "德语", | ||
}, | ||
needs: {} | ||
} | ||
|
||
export async function translate(text, from, to) { | ||
const { supportLanguage } = info; | ||
const domain = get('openai_domain', "api.openai.com"); | ||
const apikey = get('openai_apikey', ""); | ||
if (apikey == "") { | ||
return "请先配置apikey" | ||
} | ||
|
||
const headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${apikey}`, | ||
}; | ||
|
||
let systemPrompt = "You are a code explanation engine, you can only explain the code, do not interpret or translate it. Also, please report any bugs you find in the code to the author of the code."; | ||
let userPrompt = `用${supportLanguage[to]}解释此段代码、正则表达式或脚本。如果内容不是代码,请返回错误提示。如果代码有明显的错误,请指出:\n\n${text}` | ||
|
||
const body = { | ||
model: "gpt-3.5-turbo", | ||
temperature: 0, | ||
max_tokens: 1000, | ||
top_p: 1, | ||
frequency_penalty: 1, | ||
presence_penalty: 1, | ||
messages: [ | ||
{ role: "system", content: systemPrompt }, | ||
{ role: "user", content: userPrompt }, | ||
] | ||
}; | ||
|
||
const res = await fetch(`https://${domain}/v1/chat/completions`, { | ||
method: 'POST', | ||
headers: headers, | ||
body: { | ||
type: 'Json', | ||
payload: body | ||
} | ||
}) | ||
|
||
const { choices } = res.data; | ||
|
||
let target = choices[0].message.content.trim() | ||
|
||
return target | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { fetch } from '@tauri-apps/api/http'; | ||
import { get } from '../global/config'; | ||
|
||
export const info = { | ||
name: "Open AI 润色", | ||
supportLanguage: { | ||
"zh-cn": "简体中文", | ||
"zh-tw": "繁体中文", | ||
"yue": '粤语', | ||
"ja": "日本語", | ||
"en": "英语", | ||
"ko": "韩语", | ||
"fr": "法语", | ||
"es": "西班牙语", | ||
"ru": "俄语", | ||
"de": "德语", | ||
}, | ||
needs: {} | ||
} | ||
|
||
export async function translate(text, from, to) { | ||
const { supportLanguage } = info; | ||
const domain = get('openai_domain', "api.openai.com"); | ||
const apikey = get('openai_apikey', ""); | ||
if (apikey == "") { | ||
return "请先配置apikey" | ||
} | ||
|
||
const headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${apikey}`, | ||
}; | ||
|
||
let systemPrompt = "You are a text embellisher, you can only embellish the text, don't interpret it."; | ||
let userPrompt = `用${supportLanguage[to]}润色此句:\n\n${text}` | ||
|
||
const body = { | ||
model: "gpt-3.5-turbo", | ||
temperature: 0, | ||
max_tokens: 1000, | ||
top_p: 1, | ||
frequency_penalty: 1, | ||
presence_penalty: 1, | ||
messages: [ | ||
{ role: "system", content: systemPrompt }, | ||
{ role: "user", content: userPrompt }, | ||
] | ||
}; | ||
|
||
const res = await fetch(`https://${domain}/v1/chat/completions`, { | ||
method: 'POST', | ||
headers: headers, | ||
body: { | ||
type: 'Json', | ||
payload: body | ||
} | ||
}) | ||
|
||
const { choices } = res.data; | ||
|
||
let target = choices[0].message.content.trim() | ||
|
||
return target | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { fetch } from '@tauri-apps/api/http'; | ||
import { get } from '../global/config'; | ||
|
||
export const info = { | ||
name: "Open AI 总结", | ||
supportLanguage: { | ||
"zh-cn": "简体中文", | ||
"zh-tw": "繁体中文", | ||
"yue": '粤语', | ||
"ja": "日本語", | ||
"en": "英语", | ||
"ko": "韩语", | ||
"fr": "法语", | ||
"es": "西班牙语", | ||
"ru": "俄语", | ||
"de": "德语", | ||
}, | ||
needs: {} | ||
} | ||
|
||
export async function translate(text, from, to) { | ||
const { supportLanguage } = info; | ||
const domain = get('openai_domain', "api.openai.com"); | ||
const apikey = get('openai_apikey', ""); | ||
if (apikey == "") { | ||
return "请先配置apikey" | ||
} | ||
|
||
const headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${apikey}`, | ||
}; | ||
|
||
let systemPrompt = "You are a text summarizer, you can only summarize the text, don't interpret it."; | ||
let userPrompt = `用${supportLanguage[to]}总结这段文本:\n\n${text}` | ||
|
||
const body = { | ||
model: "gpt-3.5-turbo", | ||
temperature: 0, | ||
max_tokens: 1000, | ||
top_p: 1, | ||
frequency_penalty: 1, | ||
presence_penalty: 1, | ||
messages: [ | ||
{ role: "system", content: systemPrompt }, | ||
{ role: "user", content: userPrompt }, | ||
] | ||
}; | ||
|
||
const res = await fetch(`https://${domain}/v1/chat/completions`, { | ||
method: 'POST', | ||
headers: headers, | ||
body: { | ||
type: 'Json', | ||
payload: body | ||
} | ||
}) | ||
|
||
const { choices } = res.data; | ||
|
||
let target = choices[0].message.content.trim() | ||
|
||
return target | ||
} |