Skip to content

Commit

Permalink
✨feature(1.0.0): 支持模型选择
Browse files Browse the repository at this point in the history
  • Loading branch information
vacuityv committed Feb 1, 2024
1 parent 9eaf3d8 commit c57d773
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 63 deletions.
8 changes: 4 additions & 4 deletions appcast.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"identifier": "me.vacuity.chat.gptranslate",
"versions": [
{
"version": "0.1.2",
"desc": "https://github.com/vacuityv/bob-plugin-vac-gptranslate/releases/tag/0.1.2",
"sha256": "0ac0dc28eab03a3b008242d5cabe467b61fd8a8c85e40debe7196ce1b84b0dca",
"url": "https://github.com/vacuityv/bob-plugin-vac-gptranslate/releases/download/0.1.2/bob-plugin-vac-gptranslate.bobplugin",
"version": "1.0.0",
"desc": "https://github.com/vacuityv/bob-plugin-vac-gptranslate/releases/tag/1.0.0",
"sha256": "d259fbaeb1b25090b58e5cb0ff2476ad680d4850a21abb98c8e658d3385fa693",
"url": "https://github.com/vacuityv/bob-plugin-vac-gptranslate/releases/download/1.0.0/bob-plugin-vac-gptranslate.bobplugin",
"minBobVersion": "0.5.0"
}
]
Expand Down
22 changes: 13 additions & 9 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"identifier": "me.vacuity.chat.gptranslate",
"version": "0.1.2",
"version": "1.0.0",
"category": "translate",
"name": "GPTranslate",
"summary": "调用chatgpt实现翻译功能",
Expand All @@ -21,26 +21,30 @@
"title": "登录密码"
},
{
"identifier": "serverArea",
"identifier": "modelType",
"type": "menu",
"title": "服务器选择",
"defaultValue": "hk",
"title": "模型选择",
"defaultValue": "gpt3.5",
"menuValues": [
{
"title": "香港",
"value": "hk"
"title": "gpt3.5",
"value": "gpt3.5"
},
{
"title": "美国",
"value": "usa"
"title": "gpt4.0",
"value": "gpt4.0"
},
{
"title": "gemini-pro",
"value": "gemini-pro"
}
]
},
{
"identifier": "useStreamFlag",
"type": "menu",
"title": "流式传输",
"defaultValue": "false",
"defaultValue": "y",
"menuValues": [
{
"title": "不使用",
Expand Down
54 changes: 4 additions & 50 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ var langMap = {
'pl': '波兰语',
'ar': '阿拉伯语'
};

var hkHttp = "https://chat2.vacuity.me/vac-chat-api/chat/ext/loginTranslate";
var hkStream = "https://chat2.vacuity.me/vac-chat-api/chat/ext/loginStreamTranslate";
var hkWss = "wss://chat2.vacuity.me/vac-chat-api/stream/chat/chat";
var usaHttp = "https://chat.vacuity.me/vac-chat-api/chat/ext/loginTranslate";
var usaStream = "https://chat.vacuity.me/vac-chat-api/chat/ext/loginStreamTranslate";
var usaWss = "wss://chat.vacuity.me/vac-chat-api/stream/chat/chat";

var socket = '';
Expand Down Expand Up @@ -78,15 +73,9 @@ function translate(query, completion) {
}

function oldTranslate(query, completion) {

var area = $option.serverArea;
vacUrl = hkHttp;
if (area === 'usa') {
vacUrl = usaHttp;
}
$http.request({
method: "POST",
url: vacUrl,
url: usaHttp,
header: {
"Content-Type": "application/json;charset=UTF-8"
},
Expand Down Expand Up @@ -115,39 +104,6 @@ function oldTranslate(query, completion) {
}


function newTrans(query, completion) {

var area = $option.serverArea;
vacUrl = hkStream;
if (area === 'usa') {
vacUrl = usaStream;
}
resTxt = '';
$http.streamRequest({
method: "POST",
url: vacUrl,
header: {
"Content-Type": "application/json;charset=UTF-8"
},
body: initReqBody(query),
streamHandler: function (resp) {
var txt = resp.text;
resTxt = resTxt + txt;
translateResult = {
'toParagraphs': [resTxt]
}
query.onStream({'result': translateResult});
},
handler: function (data, rawData, response, error) {
query.onCompletion({
result: {
toParagraphs: [resTxt],
}
});
}
});
}


var websocket = null;

Expand All @@ -157,11 +113,7 @@ var signal = $signal.new()

function initWebsocket() {

var area = $option.serverArea;
vacUrl = hkWss;
if (area === 'usa') {
vacUrl = usaWss;
}
vacUrl = usaWss;

if (websocket == null) {
$log.info(`initWebsocket`)
Expand Down Expand Up @@ -274,12 +226,14 @@ function websocketTrans(query, completion) {
function initReqBody(query) {
var account = $option.loginAccount;
var password = $option.loginPassword;
var modelType = $option.modelType;
var content = query['text'];

return {
email: account,
password: password,
content: content,
modelType: modelType,
targetLanguage: langMap[query['to']],
translateFrom: 'bob'
};
Expand Down

0 comments on commit c57d773

Please sign in to comment.