Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(models): F3 - top_k, abgeschnittener Modellname, vererbter API-Key

purple38598c4b6a95
diff --git a/src/api/providers/__tests__/openai-top-k.test.ts b/src/api/providers/__tests__/openai-top-k.test.ts
new file mode 100644
index 00000000..e96d9350
--- /dev/null
+++ b/src/api/providers/__tests__/openai-top-k.test.ts
@@ -0,0 +1,96 @@
+/**
+ * F3 (3.0.1, T4 Nebenfund): the sampling popup's top_k slider reached the
+ * request body for local/self-hosted OpenAI-compatible endpoints for
+ * temperature and top_p, but never for top_k — the field simply was not on
+ * OpenAIChatRequest and nothing ever assigned it. The slider promised an
+ * effect the server never saw.
+ *
+ * Run: npx vitest run src/api/providers/__tests__/openai-top-k.test.ts
+ */
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
+import type { ProviderConfig, ChatStreamChunk } from '../types'
+import type { OpenAIChatRequest } from '../openai-provider'
+import type { FetchArgs } from '../../__tests__/provider-test-support'
+
+const streamBody = 'data: {"choices":[{"delta":{"content":"hi"}}]}\n\ndata: [DONE]\n\n'
+
+type CapturedInit = { method?: string; headers?: Record<string, string>; body?: string }
+
+let sent: { url: string; body: OpenAIChatRequest }[]
+
+function answer(url: string, init: CapturedInit) {
+ if (typeof init.body !== 'string') throw new Error('request had no JSON body')
+ const body = JSON.parse(init.body) as OpenAIChatRequest
+ sent.push({ url, body })
+ if (body.stream) return new Response(streamBody, { status: 200 })
+ return new Response(JSON.stringify({ choices: [{ message: { content: 'ok' } }] }), { status: 200 })
+}
+
+async function makeProvider(config: ProviderConfig) {
+ vi.resetModules()
+ sent = []
+ vi.doMock('../../backend', () => ({
+ localFetch: vi.fn(async (url: string, init: CapturedInit) => answer(url, init)),
+ localFetchStream: vi.fn(async (url: string, init: CapturedInit) => answer(url, init)),
+ backendCall: vi.fn(),
+ isPrivateOrLanHost: (host: string) => host === 'localhost' || host === '127.0.0.1',
+ isDirectFetchAllowed: () => true,
+ hostnameOf: (url: string) => new URL(url).hostname,
+ ensureProxyAllowsHost: vi.fn(),
+ isTauri: () => false,
+ }))
+ vi.doMock('../../builtin-ensure', () => ({
+ ensureBuiltinEngineAlive: vi.fn(),
+ explainDeadEngine: (e: unknown) => e,
+ explainEngineTransportMessage: (m: string) => m,
+ isManagedBuiltinSlot: () => false,
+ }))
+ const mod = await import('../openai-provider')
+ return new mod.OpenAIProvider(config)
+}
+
+const OWN_ENDPOINT: ProviderConfig = {
+ id: 'openai', name: 'My Server', apiKey: '', enabled: true,
+ baseUrl: 'http://127.0.0.1:5001/v1', isLocal: true,
+}
+
+async function drain(gen: AsyncGenerator<ChatStreamChunk>) {
+ for await (const _ of gen) { /* the fetch only fires on the first next() */ }
+}
+
+beforeEach(() => {
+ vi.spyOn(globalThis, 'fetch').mockImplementation(
+ async (url: FetchArgs[0], init: FetchArgs[1]) =>
+ answer(String(url), { body: typeof init?.body === 'string' ? init.body : undefined }),
+ )
+})
+afterEach(() => {
+ vi.doUnmock('../../backend')
+ vi.doUnmock('../../builtin-ensure')
+ vi.restoreAllMocks()
+ vi.resetModules()
+})
+
+describe('F3 — top_k reaches an own OpenAI-compatible endpoint', () => {
+ it('chatStream sends top_k alongside temperature and top_p', async () => {
+ const p = await makeProvider(OWN_ENDPOINT)
+ await drain(p.chatStream('m', [{ role: 'user', content: 'hi' }], {
+ temperature: 0.7, topP: 0.9, topK: 40,
+ }))
+ expect(sent[0].body.temperature).toBe(0.7)
+ expect(sent[0].body.top_p).toBe(0.9)
+ expect(sent[0].body.top_k).toBe(40)
+ })
+
+ it('chatWithTools sends top_k too, not just the streaming path', async () => {
+ const p = await makeProvider(OWN_ENDPOINT)
+ await p.chatWithTools('m', [{ role: 'user', content: 'hi' }], [], { topK: 20 })
+ expect(sent[0].body.top_k).toBe(20)
+ })
+
+ it('omits top_k entirely when the caller did not set it, same as top_p', async () => {
+ const p = await makeProvider(OWN_ENDPOINT)
+ await drain(p.chatStream('m', [{ role: 'user', content: 'hi' }], {}))
+ expect('top_k' in sent[0].body).toBe(false)
+ })
+})
diff --git a/src/api/providers/openai-provider.ts b/src/api/providers/openai-provider.ts
index d71da2d2..8203bdd2 100644
--- a/src/api/providers/openai-provider.ts
+++ b/src/api/providers/openai-provider.ts
@@ -90,6 +90,12 @@ export interface OpenAIChatRequest {
stream: boolean
temperature?: number
top_p?: number
+ /** F3 (3.0.1): not part of the official OpenAI spec, but every self-hosted
+ * OpenAI-compatible server this app talks to (llama.cpp, vLLM, KoboldCpp,
+ * LM Studio, the built-in engine) accepts it as an extension the same way
+ * it accepts top_p. Omitted when unset, same as top_p, so a real OpenAI
+ * endpoint that 400s on unknown fields never sees it. */
+ top_k?: number
max_tokens?: number
tools?: ToolDefinition[]
tool_choice?: 'auto' | 'none' | 'required'
@@ -774,6 +780,9 @@ export class OpenAIProvider implements ProviderClient {
if (options?.temperature !== undefined) body.temperature = options.temperature
if (options?.topP !== undefined) body.top_p = options.topP
+ // F3: temperature and top_p reached the request, top_k never did —
+ // the sampling popup's slider promised an effect that never happened.
+ if (options?.topK !== undefined) body.top_k = options.topK
// Streaming tool turn: same wire shape as chatWithTools, but the calls
// come back as deltas which the accumulator below already merges.
if (options?.tools?.length) {
@@ -984,6 +993,9 @@ export class OpenAIProvider implements ProviderClient {
if (options?.temperature !== undefined) body.temperature = options.temperature
if (options?.topP !== undefined) body.top_p = options.topP
+ // F3: temperature and top_p reached the request, top_k never did —
+ // the sampling popup's slider promised an effect that never happened.
+ if (options?.topK !== undefined) body.top_k = options.topK
await this.applyMaxTokens(model, body, options)
// Same reasoning_effort gate as chatStream.
const effort = this.thinkingEffort(model, options?.thinking, options)
diff --git a/src/api/providers/types.ts b/src/api/providers/types.ts
index feda02f2..9fe113e1 100644
--- a/src/api/providers/types.ts
+++ b/src/api/providers/types.ts
@@ -156,7 +156,11 @@ export interface ToolCall {
export interface ChatOptions {
temperature?: number
topP?: number
- topK?: number // Ollama/Anthropic support this, OpenAI doesn't
+ // Ollama/Anthropic support this. The real OpenAI API does not, but F3
+ // (3.0.1): the OpenAI-COMPATIBLE provider (self-hosted endpoints —
+ // llama.cpp, vLLM, KoboldCpp, LM Studio, the built-in engine) sends it as
+ // an extension field, the same way it already sends top_p.
+ topK?: number
maxTokens?: number
thinking?: boolean // Enable model thinking/reasoning mode
/**
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsx
index e0fd721b..263e2b92 100644
--- a/src/components/models/ModelSelector.tsx
+++ b/src/components/models/ModelSelector.tsx
@@ -1097,7 +1097,14 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
const gezeigtesObj = models.find((m) => m.name === gezeigtesModell)
const activeDisplayName = gezeigtesModell
? (gezeigtesObj && 'displayName' in gezeigtesObj && gezeigtesObj.displayName) ||
- shortModelLabel(displayModelName(gezeigtesModell).split(':')[0])
+ // F3 (3.0.1): `.split(':')[0]` here truncated at the FIRST colon in the
+ // model id, not just the `provider::model` prefix `displayModelName`
+ // already stripped. An Ollama tag ("llama3.1:8b-instruct-q4_K_M") uses
+ // a single colon as its OWN separator, so the header showed only
+ // "llama3.1" while the dropdown row below it — which never split on
+ // ':' — showed the real, full name. Dropped the split entirely so the
+ // header matches the row (both go through shortModelLabel only).
+ shortModelLabel(displayModelName(gezeigtesModell))
: 'Select Model'
// Der Punkt folgt demselben Modell wie der Name daneben, sonst haette der
// Knopf waehrend eines Wechsels zwei Aussagen in sich.
diff --git a/src/components/settings/ProviderConfig.tsx b/src/components/settings/ProviderConfig.tsx
index f00821d0..b1293baa 100644
--- a/src/components/settings/ProviderConfig.tsx
+++ b/src/components/settings/ProviderConfig.tsx
@@ -11,6 +11,7 @@ import {
standbyIsRemovable,
slotRemoveOccupantUpdate,
slotForgetStandbyUpdate,
+ takeoverClearsApiKey,
} from '../../lib/openai-slot-handover'
import { getProvider } from '../../api/providers'
import { PROVIDER_PRESETS } from '../../api/providers/types'
@@ -298,12 +299,14 @@ export function ProviderSettings() {
// for it. `managed` is still set explicitly in both directions, so
// switching to LM Studio/vLLM clears the built-in flag and re-selecting
// Built-in restores it.
- setProviderConfig('openai', slotTakeoverUpdate(providers.openai, {
- name: preset.name,
- baseUrl: preset.baseUrl,
- isLocal: preset.isLocal,
- managed: preset.managed,
- }))
+ const incoming = { name: preset.name, baseUrl: preset.baseUrl, isLocal: preset.isLocal, managed: preset.managed }
+ // F3 (3.0.1, T4 Nebenfund): a real takeover must not leave the
+ // displaced backend's API key sitting in the shared slot's field —
+ // see takeoverClearsApiKey in lib/openai-slot-handover.ts.
+ if (takeoverClearsApiKey(providers.openai, incoming)) {
+ setProviderApiKey('openai', '')
+ }
+ setProviderConfig('openai', slotTakeoverUpdate(providers.openai, incoming))
}
setDropdownOpen(false)
diff --git a/src/lib/__tests__/model-label-colon.test.ts b/src/lib/__tests__/model-label-colon.test.ts
new file mode 100644
index 00000000..d66b4c5b
--- /dev/null
+++ b/src/lib/__tests__/model-label-colon.test.ts
@@ -0,0 +1,41 @@
+/**
+ * F3 (3.0.1, T4 Nebenfund): the chat model button showed only "Model: C" for
+ * a name that continues past a colon — ModelSelector.tsx applied
+ * `.split(':')[0]` on TOP of `displayModelName` (which already strips only
+ * the `provider::model` prefix), so an Ollama tag like
+ * "llama3.1:8b-instruct-q4_K_M" lost everything from its own colon onward.
+ * The dropdown row right below it never did that split and showed the real
+ * name, so the header and the list disagreed about the same model.
+ *
+ * This is the exact expression the button now uses:
+ * `shortModelLabel(displayModelName(name))`, no `.split(':')` in between.
+ *
+ * Run: npx vitest run src/lib/__tests__/model-label-colon.test.ts
+ */
+import { describe, it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import { shortModelLabel } from '../model-label'
+import { displayModelName } from '../../api/providers/model-name'
+
+describe('F3 — the model header keeps everything after a colon', () => {
+ it('a plain Ollama tag survives whole', () => {
+ const name = 'llama3.1:8b-instruct-q4_K_M'
+ expect(shortModelLabel(displayModelName(name))).toBe('llama3.1:8b-instruct-q4_K_M')
+ })
+
+ it('the provider:: prefix is still the only thing stripped', () => {
+ const name = 'anthropic::claude-opus-4:20260501'
+ expect(shortModelLabel(displayModelName(name))).toBe('claude-opus-4:20260501')
+ })
+
+ it('a name with no colon at all is unaffected', () => {
+ expect(shortModelLabel(displayModelName('qwen2.5-0.5b-instruct'))).toBe('qwen2.5-0.5b-instruct')
+ })
+
+ it('ModelSelector.tsx no longer truncates the header at the first colon', () => {
+ const src = readFileSync(resolve(__dirname, '../../components/models/ModelSelector.tsx'), 'utf8')
+ expect(src).not.toContain("displayModelName(gezeigtesModell).split(':')[0]")
+ expect(src).toContain('shortModelLabel(displayModelName(gezeigtesModell))')
+ })
+})
diff --git a/src/lib/__tests__/openai-slot-handover-api-key.test.ts b/src/lib/__tests__/openai-slot-handover-api-key.test.ts
new file mode 100644
index 00000000..738c9d41
--- /dev/null
+++ b/src/lib/__tests__/openai-slot-handover-api-key.test.ts
@@ -0,0 +1,41 @@
+/**
+ * F3 (3.0.1, T4 Nebenfund): "a freshly added provider comes with a prefilled
+ * value". Add Provider pushes a new backend into the shared `openai` slot via
+ * `slotTakeoverUpdate`, whose patch never mentions `apiKey` — the plain store
+ * merge in ProviderConfig.tsx's setProviderConfig therefore left whatever key
+ * the DISPLACED backend had sitting in the field, so a brand new custom
+ * OpenAI-compatible provider showed (and would have submitted) a secret that
+ * belongs to a completely different endpoint.
+ *
+ * Run: npx vitest run src/lib/__tests__/openai-slot-handover-api-key.test.ts
+ */
+import { describe, it, expect } from 'vitest'
+import { takeoverClearsApiKey, type HandoverSlot } from '../openai-slot-handover'
+
+const jan: HandoverSlot = {
+ enabled: true, name: 'Jan', baseUrl: 'http://localhost:1337/v1', isLocal: true, managed: false,
+}
+
+describe('F3 — a slot takeover clears the inherited API key', () => {
+ it('a genuinely different backend clears it — the old key belongs elsewhere', () => {
+ const incoming = { name: 'My Server', baseUrl: 'http://localhost:5001/v1', isLocal: true, managed: false }
+ expect(takeoverClearsApiKey(jan, incoming)).toBe(true)
+ })
+
+ it('re-selecting the SAME backend that already holds the slot keeps the key', () => {
+ const incoming = { name: jan.name, baseUrl: jan.baseUrl, isLocal: jan.isLocal, managed: jan.managed }
+ expect(takeoverClearsApiKey(jan, incoming)).toBe(false)
+ })
+
+ it('an empty/disabled slot has nothing to leak, so nothing is cleared', () => {
+ const empty: HandoverSlot = { enabled: false, name: '', baseUrl: '', isLocal: true, managed: false }
+ const incoming = { name: 'My Server', baseUrl: 'http://localhost:5001/v1', isLocal: true, managed: false }
+ expect(takeoverClearsApiKey(empty, incoming)).toBe(false)
+ })
+
+ it('switching only the managed flag (Built-in Engine <-> foreign backend) still counts as different', () => {
+ const builtin: HandoverSlot = { enabled: true, name: 'Built-in Engine', baseUrl: 'http://127.0.0.1:8127/v1', isLocal: true, managed: true }
+ const incoming = { name: 'Built-in Engine', baseUrl: 'http://127.0.0.1:8127/v1', isLocal: true, managed: false }
+ expect(takeoverClearsApiKey(builtin, incoming)).toBe(true)
+ })
+})
diff --git a/src/lib/openai-slot-handover.ts b/src/lib/openai-slot-handover.ts
index eb5ae63f..93fa0a19 100644
--- a/src/lib/openai-slot-handover.ts
+++ b/src/lib/openai-slot-handover.ts
@@ -83,6 +83,23 @@ export function isDifferentBackend(slot: SlotOccupant, incoming: SlotOccupant):
return !!slot.managed !== !!incoming.managed
}
+/**
+ * F3 (3.0.1, T4 Nebenfund): "a freshly added provider comes with a prefilled
+ * value". `slotTakeoverUpdate`'s patch never mentions `apiKey` — it only
+ * decides `name`/`baseUrl`/`isLocal`/`managed`/`displaced` — so the plain
+ * store merge in `setProviderConfig` left whatever key the DISPLACED backend
+ * had sitting in the shared `openai` slot's `apiKey` field. The new
+ * provider's key box then showed, and would have submitted, a secret that
+ * belongs to a completely different endpoint.
+ *
+ * Same condition `slotTakeoverUpdate` itself uses to decide anything changed
+ * at all: re-selecting the SAME backend that is already in the slot must not
+ * wipe a key the user already entered for it, only a REAL takeover should.
+ */
+export function takeoverClearsApiKey(slot: HandoverSlot, incoming: SlotOccupant): boolean {
+ return slot.enabled && isDifferentBackend(slot, incoming)
+}
+
/**
* The patch Add Provider writes into the `openai` slot, including the memory
* of who was pushed out.