feat: configure an independent OpenAI translation model

This commit is contained in:
Blendman974 committed 2026-11-08 00:48:54 +01:00
1 parent 6df52021c8
commit 69bb92da7b
5 files changed
+52 -9

No files matched your search

+5 -3
View File
@@ -4,6 +4,7 @@ import {
resolveTranslateLanguage,
resolveTranslateProvider,
translateLanguageSetting,
translateModelSetting,
translateProviderSetting,
translateShowOriginalSetting,
} from "./translate-settings";
@@ -11,7 +12,7 @@ import { MIC_ICON } from "../transcribe/transcribe-app";
import { transcriptTimestamp } from "../transcribe/transcribe";
import { type ContinuousCaptureOptions } from "../../ui/layers";
import { openSettingsSubMenu } from "../../ui/dashboard/settings-panel";
import { enumSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
import { enumSettingMenuItem, textSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
import {
createInProcessWindow,
YieldAtRootLayer,
@@ -28,8 +29,8 @@ const TRAY_ICON_ID = "translate";
const NO_PROVIDER_PROBLEM =
"Translate needs a transcription provider that understands any language: add an ElevenLabs, OpenAI, or Soniox API key (Settings > API Keys), or a Whisper server URL (Settings > Voice).";
const NO_MODEL_PROBLEM = global.isIOS
? "Translate needs a language model: configure a cloud or OpenAI-compatible model in Settings > Assistant."
: "Translate needs a language model: configure one in Settings > Assistant, or download the on-phone model.";
? "Translate needs a language model: set an OpenAI model in Translate settings and add its API key, or configure a cloud or OpenAI-compatible model in Settings > Assistant."
: "Translate needs a language model: set an OpenAI model in Translate settings and add its API key, or configure one in Settings > Assistant, or download the on-phone model.";
export type TranslateAppOptions = InProcessAppOptions & {
/** Begin (or retarget) continuous mic capture, kept on while the window is open. */
@@ -84,6 +85,7 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
openSettingsSubMenu(ctx, "Translate settings", [
enumSettingMenuItem(translateLanguageSetting, { onChange: startCapture }),
enumSettingMenuItem(translateProviderSetting, { onChange: startCapture }),
textSettingMenuItem(translateModelSetting),
toggleSettingMenuItem(translateShowOriginalSetting),
]);
},
+8 -2
View File
@@ -1,6 +1,6 @@
/**
* Streamed translation against the assistant's configured model (Settings >
* Assistant). Each call translates one stretch of speech into English; see
* Streamed translation against Translate's OpenAI override, or the assistant's
* configured model when no override is set. Each call translates one stretch of speech into English; see
* TranslationModel for how stretches are batched and given context.
*/
import { streamAnthropicMessage } from "../../native/anthropic";
@@ -14,6 +14,7 @@ import {
assistantOpenAiCompatibleModelSetting, assistantOpenAiCompatibleUrlSetting, openAiApiKeySetting,
} from "../../ui/dashboard-settings";
import { TRANSLATE_SYSTEM_PROMPT, buildTranslateUserMessage } from "../../prompts";
import { translateModelSetting } from "./translate-settings";
import { type TranslationTurn } from "./translation-model";
/**
@@ -23,6 +24,11 @@ import { type TranslationTurn } from "./translation-model";
* for whichever API key is set, else the on-phone model.
*/
export function resolveTranslationModel(): ResolvedAssistantModel | null {
const translationModel = translateModelSetting.get().trim();
if (translationModel) {
const apiKey = openAiApiKeySetting.get().trim();
return apiKey ? { selection: "auto", provider: "openai", model: translationModel, apiKey } : null;
}
const selection = assistantModelSetting.get();
return resolveAssistantModel(selection === "hermes" ? "auto" : selection, {
anthropic: anthropicApiKeySetting.get(),
+12 -1
View File
@@ -1,4 +1,4 @@
import { ConfigSettingBoolean, ConfigSettingEnum, voiceProviderSetting, type VoiceProvider } from "../../ui/dashboard-settings";
import { ConfigSettingBoolean, ConfigSettingEnum, ConfigSettingString, voiceProviderSetting, type VoiceProvider } from "../../ui/dashboard-settings";
/**
* The transcription providers that recognize any spoken language, in picker
@@ -106,3 +106,14 @@ export const translateShowOriginalSetting = new ConfigSettingBoolean({
defaultValue: false,
description: "Show what was said, dimmed, above each translation.",
});
/** Empty preserves the existing Assistant-based routing. */
export const translateModelSetting = new ConfigSettingString({
id: "translate-model",
label: "Translation model (OpenAI)",
storageKey: "translate.model",
defaultValue: "",
inputKind: "text",
normalize: (value) => value.trim(),
description: "OpenAI model ID used only by Translate, for example gpt-4o-mini. Uses the OpenAI key from Settings > API Keys. Leave empty to use the Assistant model. Changes apply to subsequent translation requests; Assistant settings are unchanged.",
});