LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
Harden Azure OpenAI provider support
nash_sufe605c2931eb
diff --git a/src/components/settings/llm-presets.ts b/src/components/settings/llm-presets.tsindex 58e06d11..72fe4898 100644--- a/src/components/settings/llm-presets.ts+++ b/src/components/settings/llm-presets.ts@@ -1,3 +1,5 @@+import type { AzureModelFamily } from "@/stores/wiki-store"+/*** Curated LLM provider presets.*@@ -42,6 +44,8 @@ export interface LlmPreset {defaultModel?: string/** Azure OpenAI api-version query parameter. Azure deployments vary by resource. */azureApiVersion?: string+ /** Azure deployment names are arbitrary, so users can declare GPT-5/o-series behavior explicitly. */+ azureModelFamily?: AzureModelFamily/*** Curated list of model ids the UI shows as clickable chips above the* Model input. The user can still type a custom value — the input staysdiff --git a/src/components/settings/preset-resolver.test.ts b/src/components/settings/preset-resolver.test.tsindex f8140150..c911aa09 100644--- a/src/components/settings/preset-resolver.test.ts+++ b/src/components/settings/preset-resolver.test.ts@@ -50,4 +50,24 @@ describe("resolveConfig", () => {expect(resolved.reasoning).toEqual({ mode: "off" })})++ it("carries Azure API version and model family overrides", () => {+ const preset: LlmPreset = {+ id: "azure",+ label: "Azure OpenAI",+ provider: "azure",+ baseUrl: "https://resource.openai.azure.com",+ defaultModel: "wiki-main",+ azureApiVersion: "2024-10-21",+ }++ const resolved = resolveConfig(+ preset,+ { azureApiVersion: "2025-01-01-preview", azureModelFamily: "gpt5" },+ fallbackConfig(),+ )++ expect(resolved.azureApiVersion).toBe("2025-01-01-preview")+ expect(resolved.azureModelFamily).toBe("gpt5")+ })})diff --git a/src/components/settings/preset-resolver.ts b/src/components/settings/preset-resolver.tsindex d1dbf1f8..dc26ba82 100644--- a/src/components/settings/preset-resolver.ts+++ b/src/components/settings/preset-resolver.ts@@ -53,6 +53,7 @@ export function resolveConfig(ollamaUrl: fallback.ollamaUrl,customEndpoint: ov.baseUrl ?? preset.baseUrl ?? "",azureApiVersion: ov.azureApiVersion ?? preset.azureApiVersion ?? AZURE_OPENAI_API_VERSION,+ azureModelFamily: ov.azureModelFamily ?? preset.azureModelFamily ?? "auto",maxContextSize,reasoning,}diff --git a/src/components/settings/sections/llm-provider-section.tsx b/src/components/settings/sections/llm-provider-section.tsxindex 44544a63..bd8c86a8 100644--- a/src/components/settings/sections/llm-provider-section.tsx+++ b/src/components/settings/sections/llm-provider-section.tsx@@ -125,10 +125,11 @@ function PresetRow({const apiMode = ov.apiMode ?? preset.apiMode ?? "chat_completions"const baseUrl = ov.baseUrl ?? preset.baseUrl ?? ""const azureApiVersion = ov.azureApiVersion ?? preset.azureApiVersion ?? AZURE_OPENAI_API_VERSION+ const azureModelFamily = ov.azureModelFamily ?? preset.azureModelFamily ?? "auto"const context = ov.maxContextSize ?? preset.suggestedContextSize ?? 131072const reasoning = ov.reasoning ?? { mode: "auto" as const }const [testState, setTestState] = useState<ProviderTestState>({ kind: "idle" })- const hasConfig = !!apiKey || !!ov.baseUrl || !!ov.model || !!ov.azureApiVersion+ const hasConfig = !!apiKey || !!ov.baseUrl || !!ov.model || !!ov.azureApiVersion || !!ov.azureModelFamily// Local CLI providers authenticate via their own existing login state// (inherited by the spawned subprocess), so no API key field is shown.// Ollama ditto for its local-only model.@@ -139,7 +140,7 @@ function PresetRow({const resolvedConfig = useMemo(() => resolveConfig(preset, ov, useWikiStore.getState().llmConfig),- [apiKey, apiMode, azureApiVersion, baseUrl, context, model, preset, reasoning, ov],+ [apiKey, apiMode, azureApiVersion, azureModelFamily, baseUrl, context, model, preset, reasoning, ov],)async function runProviderTest(kind: "connection" | "function") {@@ -277,16 +278,32 @@ function PresetRow({)}{preset.provider === "azure" && (- <div className="space-y-2">- <Label>Azure API version</Label>- <Input- value={azureApiVersion}- onChange={(e) => onChange({ azureApiVersion: e.target.value })}- placeholder="2024-10-21"- />- <p className="text-xs text-muted-foreground">- Sent as the Azure OpenAI <code className="font-mono">api-version</code> query parameter.- </p>+ <div className="grid gap-4 md:grid-cols-2">+ <div className="space-y-2">+ <Label>{t("settings.sections.llm.azureApiVersion")}</Label>+ <Input+ value={azureApiVersion}+ onChange={(e) => onChange({ azureApiVersion: e.target.value })}+ placeholder="2024-10-21"+ />+ <p className="text-xs text-muted-foreground">+ {t("settings.sections.llm.azureApiVersionHint")}+ </p>+ </div>+ <div className="space-y-2">+ <Label>{t("settings.sections.llm.azureModelFamily")}</Label>+ <select+ className="w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"+ value={azureModelFamily}+ onChange={(e) => onChange({ azureModelFamily: e.target.value as typeof azureModelFamily })}+ >+ <option value="auto">{t("settings.sections.llm.azureModelFamilyAuto")}</option>+ <option value="gpt5">{t("settings.sections.llm.azureModelFamilyGpt5")}</option>+ </select>+ <p className="text-xs text-muted-foreground">+ {t("settings.sections.llm.azureModelFamilyHint")}+ </p>+ </div></div>)}diff --git a/src/components/settings/sections/multimodal-section.tsx b/src/components/settings/sections/multimodal-section.tsxindex 271384e2..308f2d4f 100644--- a/src/components/settings/sections/multimodal-section.tsx+++ b/src/components/settings/sections/multimodal-section.tsx@@ -206,19 +206,32 @@ export function MultimodalSection({ draft, setDraft }: Props) {)}{draft.multimodalProvider === "azure" && (- <div className="space-y-2">- <Label>{t("settings.sections.multimodal.azureApiVersion", "Azure API version")}</Label>- <Input- value={draft.multimodalAzureApiVersion}- onChange={(e) => setDraft("multimodalAzureApiVersion", e.target.value)}- placeholder="2024-10-21"- />- <p className="text-xs text-muted-foreground">- {t(- "settings.sections.multimodal.azureApiVersionHint",- "Sent as the Azure OpenAI api-version query parameter.",- )}- </p>+ <div className="grid gap-4 md:grid-cols-2">+ <div className="space-y-2">+ <Label>{t("settings.sections.multimodal.azureApiVersion")}</Label>+ <Input+ value={draft.multimodalAzureApiVersion}+ onChange={(e) => setDraft("multimodalAzureApiVersion", e.target.value)}+ placeholder="2024-10-21"+ />+ <p className="text-xs text-muted-foreground">+ {t("settings.sections.multimodal.azureApiVersionHint")}+ </p>+ </div>+ <div className="space-y-2">+ <Label>{t("settings.sections.multimodal.azureModelFamily")}</Label>+ <select+ className="w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"+ value={draft.multimodalAzureModelFamily}+ onChange={(e) => setDraft("multimodalAzureModelFamily", e.target.value as typeof draft.multimodalAzureModelFamily)}+ >+ <option value="auto">{t("settings.sections.multimodal.azureModelFamilyAuto")}</option>+ <option value="gpt5">{t("settings.sections.multimodal.azureModelFamilyGpt5")}</option>+ </select>+ <p className="text-xs text-muted-foreground">+ {t("settings.sections.multimodal.azureModelFamilyHint")}+ </p>+ </div></div>)}diff --git a/src/components/settings/settings-types.ts b/src/components/settings/settings-types.tsindex 5478d959..01397218 100644--- a/src/components/settings/settings-types.ts+++ b/src/components/settings/settings-types.ts@@ -1,5 +1,5 @@import type { CustomApiMode } from "./llm-presets"-import type { ReasoningConfig, SourceWatchConfig } from "@/stores/wiki-store"+import type { AzureModelFamily, ReasoningConfig, SourceWatchConfig } from "@/stores/wiki-store"/*** Shape of the draft state each section reads from and writes into.@@ -15,6 +15,7 @@ export interface SettingsDraft {ollamaUrl: stringcustomEndpoint: stringazureApiVersion: string+ azureModelFamily: AzureModelFamilymaxContextSize: numberapiMode: CustomApiMode | undefinedreasoning: ReasoningConfig | undefined@@ -40,6 +41,7 @@ export interface SettingsDraft {multimodalOllamaUrl: stringmultimodalCustomEndpoint: stringmultimodalAzureApiVersion: string+ multimodalAzureModelFamily: AzureModelFamilymultimodalApiMode: CustomApiMode | undefinedmultimodalConcurrency: numberdiff --git a/src/components/settings/settings-view.tsx b/src/components/settings/settings-view.tsxindex 4f7c104a..5a8f13c0 100644--- a/src/components/settings/settings-view.tsx+++ b/src/components/settings/settings-view.tsx@@ -109,6 +109,7 @@ function initialDraft(ollamaUrl: llm.ollamaUrl,customEndpoint: llm.customEndpoint,azureApiVersion: llm.azureApiVersion ?? "2024-10-21",+ azureModelFamily: llm.azureModelFamily ?? "auto",maxContextSize: llm.maxContextSize ?? 204800,apiMode: llm.apiMode,reasoning: llm.reasoning,@@ -127,6 +128,7 @@ function initialDraft(multimodalOllamaUrl: multimodal.ollamaUrl,multimodalCustomEndpoint: multimodal.customEndpoint,multimodalAzureApiVersion: multimodal.azureApiVersion ?? "2024-10-21",+ multimodalAzureModelFamily: multimodal.azureModelFamily ?? "auto",multimodalApiMode: multimodal.apiMode,multimodalConcurrency: multimodal.concurrency,outputLanguage,@@ -272,6 +274,7 @@ export function SettingsView() {ollamaUrl: draft.ollamaUrl,customEndpoint: draft.customEndpoint,azureApiVersion: draft.provider === "azure" ? draft.azureApiVersion.trim() : undefined,+ azureModelFamily: draft.provider === "azure" ? draft.azureModelFamily : undefined,maxContextSize: draft.maxContextSize,apiMode: draft.provider === "custom" ? draft.apiMode : undefined,reasoning: draft.reasoning,@@ -294,6 +297,7 @@ export function SettingsView() {ollamaUrl: draft.multimodalOllamaUrl,customEndpoint: draft.multimodalCustomEndpoint,azureApiVersion: draft.multimodalProvider === "azure" ? draft.multimodalAzureApiVersion.trim() : undefined,+ azureModelFamily: draft.multimodalProvider === "azure" ? draft.multimodalAzureModelFamily : undefined,apiMode: draft.multimodalProvider === "custom" ? draft.multimodalApiMode : undefined,// Clamp at save time so a hand-edited persisted store with a// ridiculous concurrency value (e.g. someone setting 1000 indiff --git a/src/i18n/en.json b/src/i18n/en.jsonindex 8ea36a08..a61ca6e5 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -223,6 +223,13 @@"testFunction": "Test function","testingConnection": "Testing connection…","testingFunction": "Testing function…",+ "deploymentName": "Deployment name",+ "azureApiVersion": "Azure API version",+ "azureApiVersionHint": "Sent as the Azure OpenAI api-version query parameter.",+ "azureModelFamily": "Azure model family",+ "azureModelFamilyAuto": "Auto-detect from deployment name",+ "azureModelFamilyGpt5": "GPT-5 / o-series strict parameters",+ "azureModelFamilyHint": "Azure deployment names are arbitrary. Choose GPT-5 / o-series if this deployment rejects max_tokens or non-default temperature.","reasoning": {"title": "Reasoning / thinking","auto": "Auto",@@ -284,6 +291,15 @@"ollamaUrl": "Ollama URL","customEndpoint": "Endpoint URL","customEndpointHint": "OpenAI-compatible /v1 base. LM Studio, llama.cpp server, vLLM, LocalAI all work.",+ "azureEndpoint": "Azure endpoint",+ "azureEndpointHint": "Use your Azure OpenAI resource endpoint. The model field is the deployment name.",+ "azureApiVersion": "Azure API version",+ "azureApiVersionHint": "Sent as the Azure OpenAI api-version query parameter.",+ "azureModelFamily": "Azure model family",+ "azureModelFamilyAuto": "Auto-detect from deployment name",+ "azureModelFamilyGpt5": "GPT-5 / o-series strict parameters",+ "azureModelFamilyHint": "Choose GPT-5 / o-series if this deployment rejects max_tokens or non-default temperature.",+ "azureDeployment": "Deployment name","apiKey": "API key","apiKeyPlaceholder": "Leave blank for local / no-auth endpoints","model": "Model",diff --git a/src/i18n/zh.json b/src/i18n/zh.jsonindex b78cadcf..1e4d09e1 100644--- a/src/i18n/zh.json+++ b/src/i18n/zh.json@@ -223,6 +223,13 @@"testFunction": "测试功能","testingConnection": "正在测试连接…","testingFunction": "正在测试功能…",+ "deploymentName": "部署名称",+ "azureApiVersion": "Azure API 版本",+ "azureApiVersionHint": "会作为 Azure OpenAI 的 api-version 查询参数发送。",+ "azureModelFamily": "Azure 模型族",+ "azureModelFamilyAuto": "根据部署名称自动判断",+ "azureModelFamilyGpt5": "GPT-5 / o-series 严格参数",+ "azureModelFamilyHint": "Azure 的 deployment 名称可以任意命名。如果该部署拒绝 max_tokens 或非默认 temperature,请选择 GPT-5 / o-series。","reasoning": {"title": "Reasoning / thinking","auto": "自动",@@ -284,6 +291,15 @@"ollamaUrl": "Ollama URL","customEndpoint": "端点 URL","customEndpointHint": "OpenAI 兼容的 /v1 根地址。LM Studio、llama.cpp server、vLLM、LocalAI 都可以。",+ "azureEndpoint": "Azure 端点",+ "azureEndpointHint": "填写 Azure OpenAI resource endpoint。模型字段填写 deployment name。",+ "azureApiVersion": "Azure API 版本",+ "azureApiVersionHint": "会作为 Azure OpenAI 的 api-version 查询参数发送。",+ "azureModelFamily": "Azure 模型族",+ "azureModelFamilyAuto": "根据部署名称自动判断",+ "azureModelFamilyGpt5": "GPT-5 / o-series 严格参数",+ "azureModelFamilyHint": "如果该部署拒绝 max_tokens 或非默认 temperature,请选择 GPT-5 / o-series。",+ "azureDeployment": "部署名称","apiKey": "API Key","apiKeyPlaceholder": "本地 / 无鉴权端点留空","model": "模型",diff --git a/src/lib/azure-openai.test.ts b/src/lib/azure-openai.test.tsindex 0d470ab7..144db4e6 100644--- a/src/lib/azure-openai.test.ts+++ b/src/lib/azure-openai.test.ts@@ -1,5 +1,5 @@import { describe, it, expect } from "vitest"-import { buildAzureOpenAiUrl } from "./azure-openai"+import { buildAzureOpenAiUrl, isAzureOpenAiEndpoint } from "./azure-openai"describe("buildAzureOpenAiUrl", () => {it("builds deployment chat URL with api-version", () => {@@ -25,4 +25,11 @@ describe("buildAzureOpenAiUrl", () => {"https://my-resource.openai.azure.com/openai/deployments/my-gpt5/chat/completions?api-version=2024-10-21",)})++ it("detects only real Azure OpenAI hostnames", () => {+ expect(isAzureOpenAiEndpoint("https://my-resource.openai.azure.com")).toBe(true)+ expect(isAzureOpenAiEndpoint("my-resource.openai.azure.com/openai/deployments/wiki")).toBe(true)+ expect(isAzureOpenAiEndpoint("https://my-resource.openai.azure.com.evil.com")).toBe(false)+ expect(isAzureOpenAiEndpoint("https://example.com/path/openai.azure.com")).toBe(false)+ })})diff --git a/src/lib/azure-openai.ts b/src/lib/azure-openai.tsindex 881b0ffd..983d2647 100644--- a/src/lib/azure-openai.ts+++ b/src/lib/azure-openai.ts@@ -1,7 +1,14 @@export const AZURE_OPENAI_API_VERSION = "2024-10-21"export function isAzureOpenAiEndpoint(endpoint: string): boolean {- return /\.openai\.azure\.com/i.test(endpoint)+ const trimmed = endpoint.trim()+ if (!trimmed) return false+ try {+ const url = new URL(/^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`)+ return url.hostname.toLowerCase().endsWith(".openai.azure.com")+ } catch {+ return /(^|\/\/)[^/?#]+\.openai\.azure\.com(?::\d+)?(?:[/?#]|$)/i.test(trimmed)+ }}export interface AzureParsedEndpoint {diff --git a/src/lib/ingest.ts b/src/lib/ingest.tsindex 47a6c815..a64616a6 100644--- a/src/lib/ingest.ts+++ b/src/lib/ingest.ts@@ -42,6 +42,8 @@ function resolveCaptionConfig(model: mm.model,ollamaUrl: mm.ollamaUrl,customEndpoint: mm.customEndpoint,+ azureApiVersion: mm.azureApiVersion,+ azureModelFamily: mm.azureModelFamily,apiMode: mm.apiMode,// The caption helper hits `streamChat` directly, which doesn't// care about `maxContextSize` (that field is for the analysisdiff --git a/src/lib/llm-providers.test.ts b/src/lib/llm-providers.test.tsindex de7375c6..9b25a73c 100644--- a/src/lib/llm-providers.test.ts+++ b/src/lib/llm-providers.test.ts@@ -193,6 +193,40 @@ describe("Azure OpenAI provider", () => {expect(body.temperature).toBeUndefined()})++ it("uses explicit Azure model family when deployment name does not reveal GPT-5", () => {+ const cfg = getProviderConfig(mkConfig({+ provider: "azure",+ model: "production-chat-deployment",+ customEndpoint: "https://example-resource.openai.azure.com",+ azureModelFamily: "gpt5",+ }))+ const body = cfg.buildBody(+ [{ role: "user", content: "hi" }],+ { max_tokens: 1024, temperature: 0.1 },+ ) as Record<string, unknown>++ expect(body.max_tokens).toBeUndefined()+ expect(body.max_completion_tokens).toBe(1024)+ expect(body.temperature).toBeUndefined()+ })++ it("applies explicit Azure model family to custom Azure endpoints", () => {+ const cfg = getProviderConfig(mkConfig({+ provider: "custom",+ model: "wiki-main",+ customEndpoint: "https://example-resource.openai.azure.com",+ azureModelFamily: "gpt5",+ }))+ const body = cfg.buildBody(+ [{ role: "user", content: "hi" }],+ { max_tokens: 512, temperature: 0.1 },+ ) as Record<string, unknown>++ expect(body.model).toBeUndefined()+ expect(body.max_completion_tokens).toBe(512)+ expect(body.temperature).toBeUndefined()+ })})describe("Ollama / custom (chat_completions) — vision content", () => {diff --git a/src/lib/llm-providers.ts b/src/lib/llm-providers.tsindex 1ea9455a..1478bf18 100644--- a/src/lib/llm-providers.ts+++ b/src/lib/llm-providers.ts@@ -251,6 +251,11 @@ function isKimiEndpoint(config: LlmConfig): boolean {}function isOpenAiStrictCompletionModel(config: LlmConfig): boolean {+ if ((config.provider === "azure" || (config.provider === "custom" && isAzureOpenAiEndpoint(config.customEndpoint)))+ && config.azureModelFamily === "gpt5") {+ return true+ }+const model = config.model.trim().toLowerCase()const strictModel =/^gpt-5(?:[.\-_]|$)/.test(model) || /^o\d+(?:[.\-_]|$)/.test(model)diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.tsindex d6775147..4303a18c 100644--- a/src/stores/wiki-store.ts+++ b/src/stores/wiki-store.ts@@ -9,6 +9,7 @@ import { DEFAULT_SOURCE_WATCH_CONFIG } from "@/lib/source-watch-config"* `chat_completions` for backward compatibility with pre-0.3.7 configs.*/export type CustomApiMode = "chat_completions" | "anthropic_messages"+export type AzureModelFamily = "auto" | "gpt5"export type ReasoningMode = "auto" | "off" | "low" | "medium" | "high" | "max" | "custom"export interface ReasoningConfig {@@ -23,6 +24,7 @@ interface LlmConfig {ollamaUrl: stringcustomEndpoint: stringazureApiVersion?: string+ azureModelFamily?: AzureModelFamilymaxContextSize: number // max context window in charactersapiMode?: CustomApiModereasoning?: ReasoningConfig@@ -186,6 +188,7 @@ interface MultimodalConfig {ollamaUrl: stringcustomEndpoint: stringazureApiVersion?: string+ azureModelFamily?: AzureModelFamilyapiMode?: CustomApiMode/** Max parallel caption requests during ingest. >=1. */concurrency: number@@ -231,6 +234,7 @@ export interface ProviderOverride {model?: stringbaseUrl?: string // customEndpoint for custom presets, ollamaUrl for ollamaazureApiVersion?: string+ azureModelFamily?: AzureModelFamilyapiMode?: CustomApiModemaxContextSize?: numberreasoning?: ReasoningConfig