feat: choose translation output language independently

This commit is contained in:
Blendman974 committed 2026-11-08 00:56:36 +01:00
1 parent 69bb92da7b
commit 26e570f0e1
8 files changed
+81 -27

No files matched your search

@@ -2,7 +2,7 @@ const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
function sharedEnv({ translationModel = '', openAiKey = '', assistantModel = 'openai-compatible' } = {}) {
function sharedEnv({ translationModel = '', targetLanguage = 'en', openAiKey = '', assistantModel = 'openai-compatible' } = {}) {
const compatible = [], unexpected = [];
const localLlm = {
streamLocalModel: () => unexpected.push('local'),
@@ -31,12 +31,16 @@ function sharedEnv({ translationModel = '', openAiKey = '', assistantModel = 'op
},
},
'../../ui/dashboard-settings': settings,
'./translate-settings': { translateModelSetting: { get: () => translationModel } },
'./translate-settings': {
translateModelSetting: { get: () => translationModel },
translateTargetLanguageSetting: { get: () => targetLanguage },
spokenLanguageName: code => ({ en: 'English', fr: 'French' })[code],
},
'../../prompts': {
CALCULATOR_REWRITE_SYSTEM_PROMPT: 'calculator system',
buildCalculatorRewriteUserMessage: spoken => `rewrite: ${spoken}`,
TRANSLATE_SYSTEM_PROMPT: 'translate system',
buildTranslateUserMessage: speech => `translate: ${speech}`,
buildTranslateSystemPrompt: language => `translate system: ${language}`,
buildTranslateUserMessage: (speech, context, language, target) => `translate: ${speech} into ${target}`,
},
});
return { load, compatible, unexpected };
@@ -78,7 +82,7 @@ test('Translate resolves and streams through the compatible provider without cha
assert.equal(options.baseUrl, 'https://provider.example/api/v1');
assert.equal(options.model, 'compatible-model');
assert.equal(options.maxTokens, 1024);
assert.equal(options.messages[0].content, 'translate: Hola');
assert.equal(options.messages[0].content, 'translate: Hola into English');
options.onTextDelta('Hello', '<english>Hello</english>');
options.onDone({ text: '<english>Hello</english>', content: [], stopReason: 'end_turn' });
assert.deepEqual(progress, ['Hello']);
@@ -107,3 +111,13 @@ test('Whitespace-only Translate override preserves Assistant routing', () => {
assert.equal(model.provider, 'openai-compatible');
assert.equal(model.model, 'compatible-model');
});
test('Translate streams with the selected output language in both prompts', () => {
const env = sharedEnv({ targetLanguage: 'fr' });
const { resolveTranslationModel, streamTranslation } = env.load('app/apps/translate/translate-llm.ts');
streamTranslation(resolveTranslationModel(), {
speech: 'Hello', context: [], language: 'English', onProgress() {}, onDone() {}, onError() {},
});
assert.equal(env.compatible[0].system, 'translate system: French');
assert.equal(env.compatible[0].messages[0].content, 'translate: Hello into French');
});