@lynn123411/dsh-chat-translate 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DETAILS.md +20 -6
- package/README.md +4 -4
- package/lib/client.js +11 -11
- package/lib/client.js.map +2 -2
- package/lib/index.js +33 -16
- package/lib/index.js.map +3 -3
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/prompt.d.ts +19 -15
- package/lib/types/server/adapters/openai.d.ts +16 -9
- package/lib/types/server/prompt-revision.d.ts +5 -5
- package/lib/types/server/sampling.d.ts +12 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
|
@@ -38,7 +38,7 @@ export declare const zh: {
|
|
|
38
38
|
readonly saveProbeOk: "设置已保存,通道连接正常";
|
|
39
39
|
readonly saveProbeFail: "设置已保存,但通道探测失败:{error}";
|
|
40
40
|
readonly promptTitle: "翻译提示词";
|
|
41
|
-
readonly promptDesc: "
|
|
41
|
+
readonly promptDesc: "拼在待译正文前面的那段指令。点「编辑」可以改写,改完点下面的「保存」生效;留空等于用内置默认。";
|
|
42
42
|
readonly promptEdit: "编辑";
|
|
43
43
|
readonly promptDone: "完成";
|
|
44
44
|
readonly promptRestore: "恢复默认";
|
package/lib/types/prompt.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 发给翻译模型的请求前缀,以及「打包成多段」时追加的那一段说明。
|
|
3
3
|
*
|
|
4
4
|
* 这段文字是配置页上可改的一项:Host 的 Config 里 `prompt` 存用户改写过的
|
|
5
5
|
* 那一份,空着就用 {@link DEFAULT_PROMPT}。两半边都读本模块——宿主半边拿它
|
|
6
|
-
*
|
|
6
|
+
* 拼请求前缀,浏览器半边拿它填满提示词输入框、并在「恢复默认」时放回原样。
|
|
7
|
+
*
|
|
8
|
+
* 请求里只有一条 user 消息:前缀在前,待译正文在后(见 `server/adapters/openai.ts`)。
|
|
7
9
|
*
|
|
8
10
|
* 内置默认的写法有几条是承载行为的,改文案时别把它们删掉:
|
|
9
11
|
*
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* -
|
|
14
|
-
*
|
|
15
|
-
* -
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
12
|
+
* - 两个短例排在最前,写成「输入/输出」的对话样式。示例决定模型把中文当
|
|
13
|
+
* 待译内容还是当抄写对象;排到规则后面、或写成「原文/译文」,模型会把示例
|
|
14
|
+
* 连同规则一起搬进译文。
|
|
15
|
+
* - 首句的动词是「原样抄写」,不是「翻译」或「整理」。写成后者时模型回到
|
|
16
|
+
* 改写模式,已经通顺的中文会被换一套说法。
|
|
17
|
+
* - 送来的每一段都交给模型(判据见 `client/chat/conclusion.ts`),所以
|
|
18
|
+
* 抄写后面必须留「只有句子读不通时才改那几句」:那是它唯一被允许改动
|
|
19
|
+
* 中文的入口。
|
|
20
|
+
* - 「保持 Markdown 记号」是必要提醒。宿主会按行签名把结构修回去
|
|
21
|
+
* (`pipeline/segments.ts`),提示词只管让模型少制造要修的地方,不逐条
|
|
22
|
+
* 规定行数、链接括号这些细节——那些由代码兜底。
|
|
20
23
|
*
|
|
21
24
|
* 代码围栏在送模型之前就被切掉了(`pipeline/segments.ts`),所以这里不提
|
|
22
|
-
*
|
|
25
|
+
* 围栏本身,只按括号形状描述打包标记:点名具体字符会让模型把整段约定当成
|
|
26
|
+
* 待译内容。
|
|
23
27
|
*/
|
|
24
28
|
export declare const DEFAULT_PROMPT: string;
|
|
25
29
|
/**
|
|
@@ -27,11 +31,11 @@ export declare const DEFAULT_PROMPT: string;
|
|
|
27
31
|
* 许合并。它是请求形状的约定,不是译文风格,所以跟着拼请求时自动追加,配置
|
|
28
32
|
* 页上只让人改上面那段正文指令。
|
|
29
33
|
*/
|
|
30
|
-
export declare const BATCH_PROMPT_CLAUSE = "
|
|
34
|
+
export declare const BATCH_PROMPT_CLAUSE = "\u4E0B\u9762\u6BCF\u6BB5\u90FD\u4EE5\u5355\u72EC\u4E00\u884C\u6807\u8BB0\u5F00\u5934\uFF0C\u6807\u8BB0\u7531\u4E24\u4E2A\u62EC\u53F7\u5939\u7740\u4E00\u4E2A\u7F16\u53F7\u3002\u6BCF\u6BB5\u5148\u539F\u6837\u8F93\u51FA\u90A3\u4E00\u884C\u6807\u8BB0\uFF0C\u518D\u5728\u4E0B\u4E00\u884C\u5199\u8FD9\u6BB5\u7684\u8BD1\u6587\uFF0C\u987A\u5E8F\u4E0D\u53D8\uFF0C\u6BB5\u4E0E\u6BB5\u4E0D\u8981\u5408\u5E76\u3002";
|
|
31
35
|
/**
|
|
32
36
|
* 当前生效的指令正文:用户改写过的优先,空白视为没写过。
|
|
33
37
|
* @param prompt - Config 里 `prompt` 的值,可能是空串。
|
|
34
|
-
* @returns
|
|
38
|
+
* @returns 拼在待译正文前面的那段文字。
|
|
35
39
|
*/
|
|
36
40
|
export declare function resolvePrompt(prompt: string | undefined): string;
|
|
37
41
|
/**
|
|
@@ -7,22 +7,29 @@ import type { KeyReader } from '../credentials.ts';
|
|
|
7
7
|
* ~/.dsh/.credentials.yaml (refs.TRANSLATE_API_KEY). Works with OpenAI,
|
|
8
8
|
* DeepSeek, Qwen, Ollama and any other service exposing the standard endpoint.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* 请求里只有一条 user 消息:指令在前、待译正文在后,与 Hy-MT 系列的训练分布
|
|
11
|
+
* 一致。指令正文连同它的写作要点住在 `src/prompt.ts`。
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* multi-part marker clause when the request packs several parts.
|
|
14
|
+
* 一条请求的前缀:配置页上那段指令,打包多段时再接上标记约定。
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* request.
|
|
16
|
+
* 导出是因为它就是模型在正文之前原样收到的那段文字——回归测试直接断言它,
|
|
17
|
+
* 而不是绕一圈发一个请求。
|
|
20
18
|
*
|
|
21
19
|
* @param mode - `plain` for one fragment, `blocks` for a packed multi-part request.
|
|
22
20
|
* @param prompt - the prompt as configured; blank means the built-in default.
|
|
23
|
-
* @returns the complete
|
|
21
|
+
* @returns the complete request prefix.
|
|
24
22
|
*/
|
|
25
|
-
export declare function
|
|
23
|
+
export declare function buildRequestPrefix(mode: 'plain' | 'blocks', prompt?: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* 一条请求的 user 消息:前缀在前,待译正文在后,中间空一行。
|
|
26
|
+
*
|
|
27
|
+
* @param mode - `plain` for one fragment, `blocks` for a packed multi-part request.
|
|
28
|
+
* @param text - the text to translate, markers included when packed.
|
|
29
|
+
* @param prompt - the prompt as configured; blank means the built-in default.
|
|
30
|
+
* @returns the user message content.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildUserMessage(mode: 'plain' | 'blocks', text: string, prompt?: string): string;
|
|
26
33
|
export declare class OpenAiCompatibleAdapter implements ITranslationAdapter {
|
|
27
34
|
readonly id = "openai";
|
|
28
35
|
readonly name = "OpenAI \u517C\u5BB9 (Chat Completions)";
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Bump it — and only here — whenever the built-in prompt in `src/prompt.ts`
|
|
3
3
|
* changes what the model is asked to do. Copy-only edits may ride.
|
|
4
4
|
*/
|
|
5
|
-
export declare const PROMPT_REVISION = "
|
|
5
|
+
export declare const PROMPT_REVISION = "r6";
|
|
6
6
|
/**
|
|
7
7
|
* Cache generation for the prompt currently in force.
|
|
8
8
|
*
|
|
9
|
-
* The digest
|
|
10
|
-
* one, the built-in default otherwise —
|
|
11
|
-
*
|
|
12
|
-
* and
|
|
9
|
+
* The digest covers the effective prompt — the reader's text when they wrote
|
|
10
|
+
* one, the built-in default otherwise — and the sampling parameters the request
|
|
11
|
+
* goes out with, so editing either one retires every translation the previous
|
|
12
|
+
* settings produced, and landing on the same settings again reuses the pool.
|
|
13
13
|
*
|
|
14
14
|
* @param prompt - the configured prompt; blank means the built-in default.
|
|
15
15
|
* @returns the generation string a cache document is written and matched under.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 采样参数:Hy-MT2-1.8B 的官方推荐值。
|
|
3
|
+
*
|
|
4
|
+
* 只发标准参数。官方推荐里还有 `top_k 20` 与 `repetition_penalty 1.05`,
|
|
5
|
+
* 它们是 vLLM 系服务的扩展,严格的 OpenAI 兼容端点收到会直接 400,所以不随
|
|
6
|
+
* 请求发出;用自建服务的人可以照这两个值在自己的服务上配。
|
|
7
|
+
*
|
|
8
|
+
* 同一段原文今天翻两次可能不一样,但同一段只翻一次(译文池按原文内容命中),
|
|
9
|
+
* 所以差异只出现在不同段落之间。
|
|
10
|
+
*/
|
|
11
|
+
export declare const SAMPLING_TEMPERATURE = 0.7;
|
|
12
|
+
export declare const SAMPLING_TOP_P = 0.6;
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Chat translate",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "Translates foreign prose in assistant replies into Simplified Chinese and keeps passages already in Chinese as they are; code blocks and thinking chains are untouched."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED