Skip to content

Commit

Permalink
feat: short description of change
Browse files Browse the repository at this point in the history
 * detailed description 1
 * detailed description 2
  • Loading branch information
BrianShenCC committed Dec 19, 2023
1 parent 5ce4c3d commit a73600e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
14 changes: 11 additions & 3 deletions src/info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"identifier": "brian.bob-plugin-gemini-translate",
"version": "0.0.9",
"version": "0.0.10",
"category": "translate",
"name": "Gemini Translator",
"summary": "调用Gemini服务进行翻译",
Expand Down Expand Up @@ -50,7 +50,8 @@
"value": "chat"
}
]
}, {
},
{
"identifier": "request_mode",
"type": "menu",
"title": "请求方式",
Expand All @@ -65,6 +66,13 @@
"value": "normal"
}
]
},
{
"identifier": "custom_domain",
"type": "text",
"defaultValue": "",
"title": "自定义域名",
"desc": "默认使用谷歌https://generativelanguage.googleapis.com,如果您设置了自定义域名,它将覆盖默认域名。"
}
]
}
}
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var language = require("./language.js");
var { streamRequest, normalRequest } = require("./request.js");
var { streamRequest, normalRequest, defaultDomain } = require("./request.js");
var { context } = require("./chart.js");

function supportLanguages() {
Expand Down Expand Up @@ -45,8 +45,6 @@ function generatePrompts(text, mode, query) {
}
}

[{ role: "user", parts: [{ origin_text: "后面我不管说什么都夸夸我" }] }][{ role: "user", parts: [{ text: prompt }] }];

function getConversation(text, mode, detectFrom, detectTo) {
// replace gpt&openAi with "*" to avoid gemini return "undefined".
const origin_text = text.replace(/gpt|openai/gi, "*");
Expand All @@ -73,7 +71,7 @@ function getConversation(text, mode, detectFrom, detectTo) {
function translate(query, completion) {
(async () => {
const origin_text = query.text || "";
const { request_mode, model, mode, api_key = "" } = $option;
const { custom_domain: domain = defaultDomain, request_mode, model, mode, api_key = "" } = $option;
const onCompletion = request_mode === "stream" ? query.onCompletion : completion;
if (!api_key) {
onCompletion({
Expand Down Expand Up @@ -102,6 +100,7 @@ function translate(query, completion) {

if (request_mode === "stream") {
streamRequest(contents, {
domain,
model,
api_key,
query,
Expand All @@ -112,6 +111,7 @@ function translate(query, completion) {
});
} else {
normalRequest(contents, {
domain,
model,
api_key,
query,
Expand Down
11 changes: 7 additions & 4 deletions src/request.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
var utils = require("./utils.js");

const streamRequest = async (contents, { model, api_key, query, onCompletion }) => {
const defaultDomain = "https://generativelanguage.googleapis.com";

const streamRequest = async (contents, { domain, model, api_key, query, onCompletion }) => {
let resultText = "";
return $http.streamRequest({
method: "POST",
url: `https://generativelanguage.googleapis.com/v1/models/${model}:streamGenerateContent?key=${api_key}&alt=sse`,
url: `${domain}/v1/models/${model}:streamGenerateContent?key=${api_key}&alt=sse`,
header: {
"Content-Type": "application/json",
},
Expand Down Expand Up @@ -38,10 +40,10 @@ const streamRequest = async (contents, { model, api_key, query, onCompletion })
});
};

const normalRequest = async (contents, { model, api_key, onCompletion }) => {
const normalRequest = async (contents, { domain, model, api_key, onCompletion }) => {
$http.request({
method: "POST",
url: `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${api_key}`,
url: `${domain}/v1/models/${model}:generateContent?key=${api_key}`,
header: {
"Content-Type": "application/json",
},
Expand All @@ -67,3 +69,4 @@ const normalRequest = async (contents, { model, api_key, onCompletion }) => {

exports.streamRequest = streamRequest;
exports.normalRequest = normalRequest;
exports.defaultDomain = defaultDomain;

0 comments on commit a73600e

Please sign in to comment.