Skip to content

Commit 54a8af2

Browse files
committed
feat: support claude3 and claude3-5 models and custom prompt
1 parent 1158d7b commit 54a8af2

File tree

2 files changed

+59
-35
lines changed

2 files changed

+59
-35
lines changed

src/info.json

+34-34
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,6 @@
2121
"placeholderText": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
2222
}
2323
},
24-
{
25-
"identifier": "apiUrl",
26-
"type": "text",
27-
"title": "自定义 API Base URL",
28-
"desc": "如果您的网络环境需要代理才能访问 Claude API, 可在这里修改为反代 API 的地址",
29-
"textConfig": {
30-
"type": "visible",
31-
"placeholderText": "https://api.anthropic.com"
32-
}
33-
},
34-
{
35-
"identifier": "apiUrlPath",
36-
"type": "text",
37-
"title": "自定义 API URL Path",
38-
"desc": "发送请求的Path",
39-
"textConfig": {
40-
"type": "visible",
41-
"placeholderText": "/v1/messages"
42-
}
43-
},
44-
{
45-
"identifier": "request_mode",
46-
"type": "menu",
47-
"title": "请求方式",
48-
"defaultValue": "stream",
49-
"menuValues": [
50-
{
51-
"title": "流式请求",
52-
"value": "stream"
53-
}
54-
]
55-
},
5624
{
5725
"identifier": "model",
5826
"type": "menu",
@@ -85,10 +53,10 @@
8553
"identifier": "temperature",
8654
"type": "text",
8755
"title": "温度",
88-
"desc": "可选项。温度值越高,生成的文本越随机。默认值为 0.2(0~2)。",
56+
"desc": "可选项。温度值越高,生成的文本越随机。默认值为 0.7(0~2)。",
8957
"textConfig": {
9058
"type": "visible",
91-
"placeholderText": "0.2"
59+
"placeholderText": "0.7"
9260
}
9361
},
9462
{
@@ -122,6 +90,38 @@
12290
"$targetLang"
12391
]
12492
}
93+
},
94+
{
95+
"identifier": "apiUrl",
96+
"type": "text",
97+
"title": "自定义 API Base URL",
98+
"desc": "如果您的网络环境需要代理才能访问 Claude API, 可在这里修改为反代 API 的地址",
99+
"textConfig": {
100+
"type": "visible",
101+
"placeholderText": "https://api.anthropic.com"
102+
}
103+
},
104+
{
105+
"identifier": "apiUrlPath",
106+
"type": "text",
107+
"title": "自定义 API URL Path",
108+
"desc": "发送请求的Path",
109+
"textConfig": {
110+
"type": "visible",
111+
"placeholderText": "/v1/messages"
112+
}
113+
},
114+
{
115+
"identifier": "request_mode",
116+
"type": "menu",
117+
"title": "请求方式",
118+
"defaultValue": "stream",
119+
"menuValues": [
120+
{
121+
"title": "流式请求",
122+
"value": "stream"
123+
}
124+
]
125125
}
126126
]
127127
}

src/main.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function buildRequestBody(model, query) {
9999
model: model,
100100
messages: [{role: 'user', content: userPrompt}],
101101
system: systemPrompt,
102-
temperature: Number($option.temperature ?? 0.2),
102+
temperature: Number($option.temperature ?? 0.7),
103103
max_tokens: 4096,
104104
stream: true,
105105
};
@@ -116,6 +116,9 @@ function handleError(query, result) {
116116
const errorMessage =
117117
result.data && result.data.detail ? result.data.detail : '接口响应错误';
118118

119+
// Enhanced error logging
120+
$log.error(`Translation error: ${errorMessage}. Status code: ${statusCode}. Full response: ${JSON.stringify(result)}`);
121+
119122
query.onCompletion({
120123
error: {
121124
type: reason,
@@ -217,6 +220,27 @@ function handleResponse(query, targetText, responseObj) {
217220
* @type {Bob.Translate}
218221
*/
219222
function translate(query) {
223+
// Input validation
224+
if (!query || typeof query !== 'object') {
225+
return query.onCompletion({
226+
error: {
227+
type: 'param',
228+
message: 'Invalid query object',
229+
addtion: 'Query must be a valid object',
230+
},
231+
});
232+
}
233+
234+
if (!query.text || typeof query.text !== 'string' || query.text.trim() === '') {
235+
return query.onCompletion({
236+
error: {
237+
type: 'param',
238+
message: 'Invalid input text',
239+
addtion: 'Input text must be a non-empty string',
240+
},
241+
});
242+
}
243+
220244
if (!lang.langMap.get(query.detectTo)) {
221245
return query.onCompletion({
222246
error: {

0 commit comments

Comments
 (0)