Skip to content

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

feat: add configurable AI output language for all generated content

nash_su3444050a8196
diff --git a/src/App.tsx b/src/App.tsx
index 0ea0fcfb..8ef93edb 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -5,7 +5,7 @@ import { useWikiStore } from "@/stores/wiki-store"
import { useReviewStore } from "@/stores/review-store"
import { useChatStore } from "@/stores/chat-store"
import { listDirectory, openProject } from "@/commands/fs"
-import { getLastProject, getRecentProjects, saveLastProject, loadLlmConfig, loadLanguage, loadSearchApiConfig, loadEmbeddingConfig } from "@/lib/project-store"
+import { getLastProject, getRecentProjects, saveLastProject, loadLlmConfig, loadLanguage, loadSearchApiConfig, loadEmbeddingConfig, loadOutputLanguage } from "@/lib/project-store"
import { loadReviewItems, loadChatHistory } from "@/lib/persist"
import { setupAutoSave } from "@/lib/auto-save"
import { startClipWatcher } from "@/lib/clip-watcher"
@@ -45,6 +45,10 @@ function App() {
if (savedEmbeddingConfig) {
useWikiStore.getState().setEmbeddingConfig(savedEmbeddingConfig)
}
+ const savedOutputLang = await loadOutputLanguage()
+ if (savedOutputLang) {
+ useWikiStore.getState().setOutputLanguage(savedOutputLang)
+ }
const savedLang = await loadLanguage()
if (savedLang) {
await i18n.changeLanguage(savedLang)
diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsx
index 67d487b1..2604cf80 100644
--- a/src/components/chat/chat-panel.tsx
+++ b/src/components/chat/chat-panel.tsx
@@ -13,7 +13,7 @@ import { buildRetrievalGraph, getRelatedNodes } from "@/lib/graph-relevance"
import { useReviewStore } from "@/stores/review-store"
import type { FileNode } from "@/types/wiki"
import { normalizePath, getFileName, getRelativePath } from "@/lib/path-utils"
-import { detectLanguage } from "@/lib/detect-language"
+import { getOutputLanguage, buildLanguageReminder } from "@/lib/output-language"
// Store the page mapping from the last query so SourceFilesBar can show which pages were cited
export let lastQueryPages: { title: string; path: string }[] = []
@@ -283,7 +283,7 @@ export function ChatPanel() {
`[${i + 1}] ${p.title} (${p.path})`
).join("\n")
- const userLanguage = detectLanguage(text)
+ const outLang = getOutputLanguage(text)
systemMessages.push({
role: "system",
@@ -307,19 +307,18 @@ export function ChatPanel() {
"",
"---",
"",
- `## ⚠️ MANDATORY OUTPUT LANGUAGE: ${userLanguage}`,
+ `## ⚠️ MANDATORY OUTPUT LANGUAGE: ${outLang}`,
"",
- `You MUST write your entire response in **${userLanguage}**.`,
+ `You MUST write your entire response in **${outLang}**.`,
`The wiki content above may be in a different language, but this is IRRELEVANT to your output language.`,
- `Ignore the language of the wiki content. Write in ${userLanguage} only.`,
- `Even proper nouns should use standard ${userLanguage} transliteration when appropriate.`,
+ `Ignore the language of the wiki content. Write in ${outLang} only.`,
+ `Even proper nouns should use standard ${outLang} transliteration when appropriate.`,
`DO NOT use any other language. This overrides all other instructions.`,
].filter(Boolean).join("\n"),
})
// Stash language reminder to inject right before the user's current message
- // (placed after history so it's the last system instruction LLM sees)
- const langReminder = `REMINDER: Respond in ${userLanguage}. The user's message is in ${userLanguage}; your response must also be in ${userLanguage}.`
+ const langReminder = buildLanguageReminder(text)
;(systemMessages as unknown as { __langReminder?: string }).__langReminder = langReminder
lastQueryPages = relevantPages.map((p) => ({ title: p.title, path: p.path }))
diff --git a/src/components/settings/settings-view.tsx b/src/components/settings/settings-view.tsx
index 156d375e..bd167193 100644
--- a/src/components/settings/settings-view.tsx
+++ b/src/components/settings/settings-view.tsx
@@ -32,6 +32,8 @@ export function SettingsView() {
const setSearchApiConfig = useWikiStore((s) => s.setSearchApiConfig)
const embeddingConfig = useWikiStore((s) => s.embeddingConfig)
const setEmbeddingConfig = useWikiStore((s) => s.setEmbeddingConfig)
+ const outputLanguage = useWikiStore((s) => s.outputLanguage)
+ const setOutputLanguage = useWikiStore((s) => s.setOutputLanguage)
const maxHistoryMessages = useChatStore((s) => s.maxHistoryMessages)
const setMaxHistoryMessages = useChatStore((s) => s.setMaxHistoryMessages)
@@ -47,6 +49,7 @@ export function SettingsView() {
const [embeddingEndpoint, setEmbeddingEndpoint] = useState(embeddingConfig.endpoint)
const [embeddingApiKey, setEmbeddingApiKey] = useState(embeddingConfig.apiKey)
const [embeddingModel, setEmbeddingModel] = useState(embeddingConfig.model)
+ const [localOutputLang, setLocalOutputLang] = useState(outputLanguage)
const [saved, setSaved] = useState(false)
const [currentLang, setCurrentLang] = useState(i18n.language)
@@ -63,10 +66,14 @@ export function SettingsView() {
setSearchApiKey(searchApiConfig.apiKey)
}, [searchApiConfig])
+ useEffect(() => {
+ setLocalOutputLang(outputLanguage)
+ }, [outputLanguage])
+
const currentProvider = PROVIDERS.find((p) => p.value === provider)
async function handleSave() {
- const { saveLlmConfig, saveSearchApiConfig, saveEmbeddingConfig } = await import("@/lib/project-store")
+ const { saveLlmConfig, saveSearchApiConfig, saveEmbeddingConfig, saveOutputLanguage } = await import("@/lib/project-store")
const newConfig = { provider, apiKey, model, ollamaUrl, customEndpoint, maxContextSize }
const newSearchConfig = { provider: searchProvider, apiKey: searchApiKey }
const newEmbeddingConfig = { enabled: embeddingEnabled, endpoint: embeddingEndpoint, apiKey: embeddingApiKey, model: embeddingModel }
@@ -74,6 +81,8 @@ export function SettingsView() {
await saveSearchApiConfig(newSearchConfig)
setEmbeddingConfig(newEmbeddingConfig)
await saveEmbeddingConfig(newEmbeddingConfig)
+ setOutputLanguage(localOutputLang)
+ await saveOutputLanguage(localOutputLang)
setLlmConfig(newConfig)
await saveLlmConfig(newConfig)
setSaved(true)
@@ -274,6 +283,45 @@ export function SettingsView() {
)}
</div>
+ {/* Output Language section */}
+ <div className="space-y-4 rounded-lg border p-4">
+ <h3 className="font-semibold">AI Output Language</h3>
+ <p className="text-xs text-muted-foreground">
+ Force all AI-generated content (chat responses, wiki pages, research results, lint reports) to use the selected language.
+ Choose "Auto" to match the user's input or source document language.
+ </p>
+ <div className="space-y-2">
+ <Label>Language</Label>
+ <select
+ value={localOutputLang}
+ onChange={(e) => setLocalOutputLang(e.target.value as typeof localOutputLang)}
+ className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"
+ >
+ <option value="auto">Auto (detect from input/source)</option>
+ <option value="English">English</option>
+ <option value="Chinese">简体中文 (Simplified Chinese)</option>
+ <option value="Traditional Chinese">繁體中文 (Traditional Chinese)</option>
+ <option value="Japanese">日本語 (Japanese)</option>
+ <option value="Korean">한국어 (Korean)</option>
+ <option value="Vietnamese">Tiếng Việt (Vietnamese)</option>
+ <option value="French">Français (French)</option>
+ <option value="German">Deutsch (German)</option>
+ <option value="Spanish">Español (Spanish)</option>
+ <option value="Portuguese">Português (Portuguese)</option>
+ <option value="Italian">Italiano (Italian)</option>
+ <option value="Russian">Русский (Russian)</option>
+ <option value="Arabic">العربية (Arabic)</option>
+ <option value="Hindi">हिन्दी (Hindi)</option>
+ <option value="Turkish">Türkçe (Turkish)</option>
+ <option value="Dutch">Nederlands (Dutch)</option>
+ <option value="Polish">Polski (Polish)</option>
+ <option value="Swedish">Svenska (Swedish)</option>
+ <option value="Indonesian">Bahasa Indonesia (Indonesian)</option>
+ <option value="Thai">ไทย (Thai)</option>
+ </select>
+ </div>
+ </div>
+
{/* Embedding Search section */}
<div className="space-y-4 rounded-lg border p-4">
<div className="flex items-center justify-between">
diff --git a/src/lib/deep-research.ts b/src/lib/deep-research.ts
index 237ceb9e..fdc3fb7e 100644
--- a/src/lib/deep-research.ts
+++ b/src/lib/deep-research.ts
@@ -5,6 +5,7 @@ import { writeFile, readFile, listDirectory } from "@/commands/fs"
import { useWikiStore, type LlmConfig, type SearchApiConfig } from "@/stores/wiki-store"
import { useResearchStore } from "@/stores/research-store"
import { normalizePath } from "@/lib/path-utils"
+import { buildLanguageDirective } from "@/lib/output-language"
let processing = false
@@ -115,8 +116,7 @@ async function executeResearch(
const systemPrompt = [
"You are a research assistant. Synthesize the web search results into a comprehensive wiki page.",
"",
- "## Language Rule",
- "- ALWAYS match the language of the research topic. If the topic is in Chinese, write in Chinese. If in English, write in English.",
+ buildLanguageDirective(topic),
"",
"## Cross-referencing (IMPORTANT)",
"- The wiki already has existing pages listed in the Wiki Index below.",
diff --git a/src/lib/ingest.ts b/src/lib/ingest.ts
index 4d5a08f7..d8cbc0aa 100644
--- a/src/lib/ingest.ts
+++ b/src/lib/ingest.ts
@@ -7,10 +7,20 @@ import { useActivityStore } from "@/stores/activity-store"
import { useReviewStore, type ReviewItem } from "@/stores/review-store"
import { getFileName, normalizePath } from "@/lib/path-utils"
import { checkIngestCache, saveIngestCache } from "@/lib/ingest-cache"
+import { buildLanguageDirective, getOutputLanguage } from "@/lib/output-language"
const FILE_BLOCK_REGEX = /---FILE:\s*([^\n-]+?)\s*---\n([\s\S]*?)---END FILE---/g
-export const LANGUAGE_RULE = "## Language Rule\n- ALWAYS match the language of the source document. If the source is in Chinese, write in Chinese. If in English, write in English. Wiki page titles, content, and descriptions should all be in the same language as the source material."
+/**
+ * Build the language rule for ingest prompts.
+ * Uses the user's configured output language, falling back to source content detection.
+ */
+export function languageRule(sourceContent: string = ""): string {
+ return buildLanguageDirective(sourceContent)
+}
+
+/** @deprecated Use languageRule() instead — kept for backwards compat with enrich-wikilinks */
+export const LANGUAGE_RULE = buildLanguageDirective("")
/**
* Auto-ingest: reads source → LLM analyzes → LLM writes wiki pages, all in one go.
@@ -68,7 +78,7 @@ export async function autoIngest(
await streamChat(
llmConfig,
[
- { role: "system", content: buildAnalysisPrompt(purpose, index) },
+ { role: "system", content: buildAnalysisPrompt(purpose, index, truncatedContent) },
{ role: "user", content: `Analyze this source document:\n\n**File:** ${fileName}${folderContext ? `\n**Folder context:** ${folderContext}` : ""}\n\n---\n\n${truncatedContent}` },
],
{
@@ -94,7 +104,7 @@ export async function autoIngest(
await streamChat(
llmConfig,
[
- { role: "system", content: buildGenerationPrompt(schema, purpose, index, fileName, overview) },
+ { role: "system", content: buildGenerationPrompt(schema, purpose, index, fileName, overview, truncatedContent) },
{
role: "user",
content: [
@@ -312,11 +322,11 @@ function parseReviewBlocks(
* Step 1 prompt: AI reads the source and produces a structured analysis.
* This is the "discussion" step — the AI reasons about the source before writing wiki pages.
*/
-function buildAnalysisPrompt(purpose: string, index: string): string {
+function buildAnalysisPrompt(purpose: string, index: string, sourceContent: string = ""): string {
return [
"You are an expert research analyst. Read the source document and produce a structured analysis.",
"",
- LANGUAGE_RULE,
+ languageRule(sourceContent),
"",
"Your analysis should cover:",
"",
@@ -362,14 +372,14 @@ function buildAnalysisPrompt(purpose: string, index: string): string {
/**
* Step 2 prompt: AI takes its own analysis and generates wiki files + review items.
*/
-function buildGenerationPrompt(schema: string, purpose: string, index: string, sourceFileName: string, overview?: string): string {
+function buildGenerationPrompt(schema: string, purpose: string, index: string, sourceFileName: string, overview?: string, sourceContent: string = ""): string {
// Use original filename (without extension) as the source summary page name
const sourceBaseName = sourceFileName.replace(/\.[^.]+$/, "")
return [
"You are a wiki maintainer. Based on the analysis provided, generate wiki files.",
"",
- LANGUAGE_RULE,
+ languageRule(sourceContent),
"",
`## IMPORTANT: Source File`,
`The original source file is: **${sourceFileName}**`,
@@ -496,7 +506,7 @@ export async function startIngest(
const systemPrompt = [
"You are a knowledgeable assistant helping to build a wiki from source documents.",
"",
- LANGUAGE_RULE,
+ languageRule(sourceContent),
"",
purpose ? `## Wiki Purpose\n${purpose}` : "",
schema ? `## Wiki Schema\n${schema}` : "",
@@ -594,7 +604,7 @@ export async function executeIngestWrites(
const systemPrompt = [
"You are a wiki generation assistant. Your task is to produce structured wiki file contents.",
"",
- LANGUAGE_RULE,
+ languageRule(""),
schema ? `## Wiki Schema\n${schema}` : "",
]
.filter(Boolean)
diff --git a/src/lib/lint.ts b/src/lib/lint.ts
index 845cadc6..eb90b6fe 100644
--- a/src/lib/lint.ts
+++ b/src/lib/lint.ts
@@ -4,6 +4,7 @@ import type { LlmConfig } from "@/stores/wiki-store"
import type { FileNode } from "@/types/wiki"
import { useActivityStore } from "@/stores/activity-store"
import { getFileName, getRelativePath, normalizePath } from "@/lib/path-utils"
+import { buildLanguageDirective } from "@/lib/output-language"
export interface LintResult {
type: "orphan" | "broken-link" | "no-outlinks" | "semantic"
@@ -201,8 +202,7 @@ export async function runSemanticLint(
const prompt = [
"You are a wiki quality analyst. Review the following wiki page summaries and identify issues.",
"",
- "## Language Rule",
- "- Match the language of the wiki content. If pages are in Chinese, write issues in Chinese. If in English, use English.",
+ buildLanguageDirective(""),
"",
"For each issue, output exactly this format:",
"",
diff --git a/src/lib/output-language.ts b/src/lib/output-language.ts
new file mode 100644
index 00000000..ce829565
--- /dev/null
+++ b/src/lib/output-language.ts
@@ -0,0 +1,40 @@
+import { useWikiStore } from "@/stores/wiki-store"
+import { detectLanguage } from "./detect-language"
+
+/**
+ * Get the effective output language for LLM content generation.
+ *
+ * If user has explicitly set an outputLanguage, use it.
+ * Otherwise (auto), fall back to detecting the language from the given text.
+ */
+export function getOutputLanguage(fallbackText: string = ""): string {
+ const configured = useWikiStore.getState().outputLanguage
+ if (configured && configured !== "auto") {
+ return configured
+ }
+ return detectLanguage(fallbackText || "English")
+}
+
+/**
+ * Build a strong language directive to inject into system prompts.
+ */
+export function buildLanguageDirective(fallbackText: string = ""): string {
+ const lang = getOutputLanguage(fallbackText)
+ return [
+ `## ⚠️ MANDATORY OUTPUT LANGUAGE: ${lang}`,
+ "",
+ `You MUST write your entire response (including wiki page titles, content, descriptions, summaries, and any generated text) in **${lang}**.`,
+ `The source material or wiki content may be in a different language, but this is IRRELEVANT to your output language.`,
+ `Ignore the language of any source content. Generate everything in ${lang} only.`,
+ `Proper nouns should use standard ${lang} transliteration when appropriate.`,
+ `DO NOT use any other language. This overrides all other instructions.`,
+ ].join("\n")
+}
+
+/**
+ * Short reminder version — for placing right before user's current message.
+ */
+export function buildLanguageReminder(fallbackText: string = ""): string {
+ const lang = getOutputLanguage(fallbackText)
+ return `REMINDER: All output must be in ${lang}. Do not use any other language.`
+}
diff --git a/src/lib/project-store.ts b/src/lib/project-store.ts
index 596f79ea..42dabe21 100644
--- a/src/lib/project-store.ts
+++ b/src/lib/project-store.ts
@@ -1,6 +1,6 @@
import { load } from "@tauri-apps/plugin-store"
import type { WikiProject } from "@/types/wiki"
-import type { LlmConfig, SearchApiConfig, EmbeddingConfig } from "@/stores/wiki-store"
+import type { LlmConfig, SearchApiConfig, EmbeddingConfig, OutputLanguage } from "@/stores/wiki-store"
const STORE_NAME = "app-state.json"
const RECENT_PROJECTS_KEY = "recentProjects"
@@ -94,3 +94,15 @@ export async function loadLanguage(): Promise<string | null> {
const store = await getStore()
return (await store.get<string>(LANGUAGE_KEY)) ?? null
}
+
+const OUTPUT_LANGUAGE_KEY = "outputLanguage"
+
+export async function saveOutputLanguage(lang: OutputLanguage): Promise<void> {
+ const store = await getStore()
+ await store.set(OUTPUT_LANGUAGE_KEY, lang)
+}
+
+export async function loadOutputLanguage(): Promise<OutputLanguage | null> {
+ const store = await getStore()
+ return (await store.get<OutputLanguage>(OUTPUT_LANGUAGE_KEY)) ?? null
+}
diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.ts
index 788cb9d4..a2762d6e 100644
--- a/src/stores/wiki-store.ts
+++ b/src/stores/wiki-store.ts
@@ -22,6 +22,34 @@ interface EmbeddingConfig {
model: string // e.g. "text-embedding-qwen3-embedding-0.6b"
}
+/**
+ * Output language for LLM-generated content (wiki pages, chat responses, research).
+ * "auto" = detect from user input / source document language.
+ * Otherwise = force all LLM output to use the specified language.
+ */
+type OutputLanguage =
+ | "auto"
+ | "English"
+ | "Chinese"
+ | "Traditional Chinese"
+ | "Japanese"
+ | "Korean"
+ | "Vietnamese"
+ | "French"
+ | "German"
+ | "Spanish"
+ | "Portuguese"
+ | "Italian"
+ | "Russian"
+ | "Arabic"
+ | "Hindi"
+ | "Turkish"
+ | "Dutch"
+ | "Polish"
+ | "Swedish"
+ | "Indonesian"
+ | "Thai"
+
interface WikiState {
project: WikiProject | null
fileTree: FileNode[]
@@ -32,6 +60,7 @@ interface WikiState {
llmConfig: LlmConfig
searchApiConfig: SearchApiConfig
embeddingConfig: EmbeddingConfig
+ outputLanguage: OutputLanguage
dataVersion: number
setProject: (project: WikiProject | null) => void
@@ -43,6 +72,7 @@ interface WikiState {
setLlmConfig: (config: LlmConfig) => void
setSearchApiConfig: (config: SearchApiConfig) => void
setEmbeddingConfig: (config: EmbeddingConfig) => void
+ setOutputLanguage: (lang: OutputLanguage) => void
bumpDataVersion: () => void
}
@@ -82,10 +112,13 @@ export const useWikiStore = create<WikiState>((set) => ({
model: "",
},
+ outputLanguage: "auto",
+
setLlmConfig: (llmConfig) => set({ llmConfig }),
setSearchApiConfig: (searchApiConfig) => set({ searchApiConfig }),
setEmbeddingConfig: (embeddingConfig) => set({ embeddingConfig }),
+ setOutputLanguage: (outputLanguage) => set({ outputLanguage }),
bumpDataVersion: () => set((state) => ({ dataVersion: state.dataVersion + 1 })),
}))
-export type { WikiState, LlmConfig, SearchApiConfig, EmbeddingConfig }
+export type { WikiState, LlmConfig, SearchApiConfig, EmbeddingConfig, OutputLanguage }