Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

feat(config): let the local LLM endpoint and model follow the UI language

booboosui2cbea136145c
diff --git a/app/src/main/java/net/kuafuai/andee/config/VoiceConfig.kt b/app/src/main/java/net/kuafuai/andee/config/VoiceConfig.kt
index e3d3463..8db317b 100644
--- a/app/src/main/java/net/kuafuai/andee/config/VoiceConfig.kt
+++ b/app/src/main/java/net/kuafuai/andee/config/VoiceConfig.kt
@@ -77,6 +77,34 @@ data class VoiceConfig(
const val DEFAULT_LLM_MODEL = "deepseek-flash"
const val DEFAULT_REASONING_EFFORT = "high"
+ /**
+ * The same two defaults for an **English** card, pointing at OpenAI.
+ *
+ * The 本机 tab's hint *is* the value a blank row resolves to, so the two
+ * cannot be allowed to disagree: a card that advertises an OpenAI `Model`
+ * / `Base URL` and then, when the user leaves the boxes empty, quietly
+ * calls DeepSeek would be lying in the one place a user reads to decide
+ * what to type. [llmBaseUrlDefault] / [llmModelDefault] pick by
+ * [uiLanguage], and both the hint and the resolved config go through
+ * them — that is the whole point of tying these to the language rather
+ * than to the build.
+ *
+ * **CodeFlying is deliberately not switched by language.** Its model is
+ * whatever the hosted backend serves; an English build inventing
+ * `gpt-4o-mini` at that endpoint would name a model CodeFlying does not
+ * have. See [brainConfig].
+ */
+ const val DEFAULT_LLM_BASE_URL_EN = "https://api.openai.com/v1"
+ const val DEFAULT_LLM_MODEL_EN = "gpt-4o-mini"
+
+ /** [DEFAULT_LLM_BASE_URL] for a Chinese card, [DEFAULT_LLM_BASE_URL_EN] for an English one. */
+ fun llmBaseUrlDefault(context: Context): String =
+ if (uiLanguage(context) == LANG_EN) DEFAULT_LLM_BASE_URL_EN else DEFAULT_LLM_BASE_URL
+
+ /** [DEFAULT_LLM_MODEL] for a Chinese card, [DEFAULT_LLM_MODEL_EN] for an English one. */
+ fun llmModelDefault(context: Context): String =
+ if (uiLanguage(context) == LANG_EN) DEFAULT_LLM_MODEL_EN else DEFAULT_LLM_MODEL
+
/**
* CodeFlying is available iff the build was configured with ENABLED and
* a non-empty DOMAIN. ENABLED alone with no DOMAIN silently falls back
@@ -260,6 +288,11 @@ data class VoiceConfig(
.orEmpty().trim().ifEmpty { DEFAULT_REASONING_EFFORT },
)
}
+ // Language-dependent defaults: the blank-row fallback must be the
+ // value the 本机 tab's hint advertised, or an English card would
+ // promise OpenAI in the placeholder and then call DeepSeek.
+ val defaultBaseUrl = llmBaseUrlDefault(context)
+ val defaultModel = llmModelDefault(context)
return BrainConfig(
mode = mode,
apiKey = p.getString("llm_api_key", "").orEmpty().trim(),
@@ -267,9 +300,9 @@ data class VoiceConfig(
// and a trailing slash from the settings field would produce a
// double slash, which some gateways 404 on.
baseUrl = p.getString("llm_base_url", "")
- .orEmpty().trim().trimEnd('/').ifEmpty { DEFAULT_LLM_BASE_URL },
- model = p.getString("llm_model", DEFAULT_LLM_MODEL)
- .orEmpty().trim().ifEmpty { DEFAULT_LLM_MODEL },
+ .orEmpty().trim().trimEnd('/').ifEmpty { defaultBaseUrl },
+ model = p.getString("llm_model", defaultModel)
+ .orEmpty().trim().ifEmpty { defaultModel },
thinking = p.getString("llm_thinking", defaultThinking())
?.trim()?.lowercase() != "disabled",
reasoningEffort = p.getString("llm_reasoning_effort", DEFAULT_REASONING_EFFORT)
@@ -443,16 +476,25 @@ data class VoiceConfig(
"device_name" to hc.deviceName,
"brain" to bc.mode,
"show_hub" to if (showHub(context)) "on" else "off",
- // llm_api_key / llm_base_url are the 本机 tab's rows — the
- // user's own DeepSeek credentials. They stay visible no matter
- // which backend is active, because switching to CodeFlying and
- // back must not look like the local-tab fields were wiped. The
- // compiled CodeFlying key never flows through these prefs; it
- // comes from BuildConfig at [brainConfig] time, so showing the
- // saved values here cannot leak it.
+ // llm_api_key / llm_base_url / llm_model are the 本机 tab's rows —
+ // the user's own credentials and the endpoint they point at.
+ // They stay visible no matter which backend is active, because
+ // switching to CodeFlying and back must not look like the
+ // local-tab fields were wiped. The compiled CodeFlying key never
+ // flows through these prefs; it comes from BuildConfig at
+ // [brainConfig] time, so showing the saved values here cannot
+ // leak it.
+ //
+ // All three show saved-or-empty, never the resolved value. The
+ // empty box is how the row says "the default is in use", and it
+ // is the only state in which the hint is visible at all —
+ // printing the resolved default into the box would be text, not
+ // a placeholder, and the row's language-aware hint
+ // ([llmModelDefault]: DeepSeek for a Chinese card, OpenAI for an
+ // English one) could never be seen.
"llm_api_key" to p.getString("llm_api_key", "").orEmpty(),
"llm_base_url" to p.getString("llm_base_url", "").orEmpty(),
- "llm_model" to bc.model,
+ "llm_model" to p.getString("llm_model", "").orEmpty(),
// Round-tripped as the wire words rather than a boolean: this map
// feeds SettingsUi's pickers and the picker's value is what comes
// back to [save], which only speaks String.
diff --git a/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt b/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt
index ff7f1ce..c1b73b7 100644
--- a/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt
+++ b/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt
@@ -640,13 +640,29 @@ class SettingsUi(
// ---- 本机 tab: LLM + 火山 voice rows ----
val localBlock = block(panel)
- field(localBlock, "llm_api_key", "DeepSeek Key", hint = "sk-…", secret = true)
- field(localBlock, "llm_model", lctx.getString(R.string.settings_llm_model), hint = VoiceConfig.DEFAULT_LLM_MODEL)
+ // The hint *is* the value a blank row resolves to, so the hint and the
+ // resolved config come from the same language-aware pair — see
+ // [VoiceConfig.llmModelDefault]. An English card advertises an OpenAI
+ // model / base URL and, if the user never saves one, actually calls it;
+ // a Chinese card stays on DeepSeek.
+ field(
+ localBlock,
+ "llm_api_key",
+ lctx.getString(R.string.settings_llm_api_key),
+ hint = "sk-…",
+ secret = true,
+ )
+ field(
+ localBlock,
+ "llm_model",
+ lctx.getString(R.string.settings_llm_model),
+ hint = VoiceConfig.llmModelDefault(context),
+ )
field(
localBlock,
"llm_base_url",
lctx.getString(R.string.settings_llm_base_url),
- hint = VoiceConfig.DEFAULT_LLM_BASE_URL,
+ hint = VoiceConfig.llmBaseUrlDefault(context),
)
rowLabel(localBlock, lctx.getString(R.string.settings_llm_thinking))
diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml
index eec94a4..03790d0 100644
--- a/app/src/main/res/values-en/strings.xml
+++ b/app/src/main/res/values-en/strings.xml
@@ -83,6 +83,7 @@
<string name="settings_device_name">Device name</string>
<string name="settings_device_name_hint">What the hub should call this device</string>
<string name="settings_brain_cloud_note">The brain lives on a hub you run yourself; this device only acts.</string>
+ <string name="settings_llm_api_key">API key</string>
<string name="settings_llm_model">Model</string>
<string name="settings_llm_base_url">Base URL</string>
<string name="settings_llm_thinking">Deep thinking</string>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index fc78629..54912b3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -60,6 +60,7 @@
<string name="settings_device_name">设备名</string>
<string name="settings_device_name_hint">Hub 那边怎么称呼这台设备</string>
<string name="settings_brain_cloud_note">大脑在你自己搭的 Hub 那边,这台设备只负责动手。</string>
+ <string name="settings_llm_api_key">接口密钥</string>
<string name="settings_llm_model">模型</string>
<string name="settings_llm_base_url">接口地址</string>
<string name="settings_llm_thinking">深度思考</string>