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(sampling): Top K faellt aus dem Popup, der Ausloeser bekommt einen Namen

purple510e40bf9264
diff --git a/src/api/__tests__/sampling-reaches-the-cloud-body.test.ts b/src/api/__tests__/sampling-reaches-the-cloud-body.test.ts
index de9ac2dd..98a1942f 100644
--- a/src/api/__tests__/sampling-reaches-the-cloud-body.test.ts
+++ b/src/api/__tests__/sampling-reaches-the-cloud-body.test.ts
@@ -7,17 +7,18 @@
* interface in types/settings.ts:49-52, not in DEFAULT_SETTINGS in
* lib/constants.ts:12-15, and `OpenAIChatRequest` in openai-provider.ts:86-100
* has no member it could be assigned to), and temperature goes on the wire.
- * SamplingControls writes exactly four keys, all through one setter
- * (SamplingControls.tsx:77 for the three sliders, :96 for Max tokens), and
- * useChat.ts:825-828 hands the same four to the provider.
+ * SamplingControls writes three keys, all through one setter (the FIELDS table
+ * for the two sliders, the Max tokens box for the third), and useChat.ts hands
+ * four to the provider: those three plus Top K from the settings page.
*
- * The value that really has no effect in the cloud is TOP K, and that is not a
- * bug to fix here: the OpenAI-compatible body has no field for it. It is read
- * by ollama-provider.ts:150 and anthropic-provider.ts:320 and dropped by
- * openai-provider, which never looks at `options.topK` at all, so the slider
- * works on Ollama and Anthropic and is inert on every OpenAI-protocol backend,
- * LU Cloud and this app's own engine included. Documented on the wire here
- * rather than argued about again.
+ * The value that really has no effect in the cloud is TOP K. The OpenAI
+ * compatible body has no field for it: it is read by ollama-provider.ts:150 and
+ * anthropic-provider.ts:320 and dropped by openai-provider, which never looks at
+ * `options.topK` at all, so it works on Ollama and Anthropic and is inert on
+ * every OpenAI-protocol backend, LU Cloud and this app's own engine included.
+ * Since R5-13 it is therefore no longer a slider in the per-chat popup, only a
+ * control on the settings page. Documented on the wire here rather than argued
+ * about again.
*
* Asserted on the JSON body of a real request, because a note about a slider
* is exactly the kind of claim that source-reading gets wrong twice.
@@ -148,17 +149,37 @@ describe('what the sliders put on the wire', () => {
})
describe('the panel writes the keys the send reads', () => {
- it('the three sliders and the number field write those four settings', () => {
+ it('the two sliders and the number field write those three settings', () => {
const panel = src('../../components/chat/SamplingControls.tsx')
expect(panel).toMatch(/key: 'temperature'/)
expect(panel).toMatch(/key: 'topP'/)
- expect(panel).toMatch(/key: 'topK'/)
expect(panel).toMatch(/update\(\{ maxTokens:/)
// The slider setter is keyed off the FIELDS table, so it cannot write a
// name that is not in it.
expect(panel).toMatch(/update\(\{ \[f\.key\]: Number\(e\.target\.value\) \}\)/)
})
+ /**
+ * R5-13. The dead control is gone from the popup, and this is the guard that
+ * keeps it from coming back: the popup writes nothing the OpenAI-compatible
+ * body has no field for. Mirrors the web guard in
+ * apps/web/components/chat/__tests__/sampling-popup-parity.test.ts.
+ */
+ it('R5-13: the popup offers no Top K, and names itself the way the web app does', () => {
+ const panel = src('../../components/chat/SamplingControls.tsx')
+ expect(panel).not.toContain("key: 'topK'")
+ expect(panel).not.toContain('topK: DEFAULT_SETTINGS.topK')
+ expect(panel).toContain('title="Sampling for this chat"')
+ })
+
+ it('R5-13 NEGATIVKONTROLLE: Top K is still offered on the settings page', () => {
+ // Removed from the popup, not from the app. Ollama and Anthropic read it,
+ // and that is where it is set.
+ const page = src('../../components/settings/SettingsPage.tsx')
+ expect(page).toContain('topK')
+ expect(src('../providers/ollama-provider.ts')).toContain('top_k')
+ })
+
it('and the send reads exactly those four', () => {
const chat = src('../../hooks/useChat.ts')
expect(chat).toMatch(/temperature: settings\.temperature/)
diff --git a/src/components/chat/SamplingControls.tsx b/src/components/chat/SamplingControls.tsx
index d4aded6d..22e3933b 100644
--- a/src/components/chat/SamplingControls.tsx
+++ b/src/components/chat/SamplingControls.tsx
@@ -41,10 +41,23 @@ import { useDismissOnEscape } from '../../hooks/useDismissOnEscape'
* - the keyboard goes into the popup when it opens and back to the trigger
* when it closes.
*/
+/**
+ * ## Why Top K is not in this list
+ *
+ * It used to be, and it moved nothing on the paid default path: the
+ * OpenAI-compatible body has no field for it, and `openai-provider.ts` never
+ * reads `options.topK` at all, so on LU Cloud and on this app's own engine the
+ * slider was a dead control with no feedback. The same value also had two
+ * scales, `0..200` here against `1..100` on the settings page, so this popup
+ * could write a 150 that the other control cannot even display.
+ *
+ * Top K stays on the settings page, where Ollama and Anthropic read it
+ * (`ollama-provider.ts:150`, `anthropic-provider.ts:320`). That is the same
+ * arrangement the web app describes in `apps/web/lib/sampling.ts:22-26`.
+ */
const FIELDS = [
{ key: 'temperature', label: 'Temperature', min: 0, max: 2, step: 0.05 },
{ key: 'topP', label: 'Top P', min: 0, max: 1, step: 0.01 },
- { key: 'topK', label: 'Top K', min: 0, max: 200, step: 1 },
] as const
/**
@@ -149,6 +162,11 @@ export function SamplingControls() {
aria-expanded={open}
aria-controls={panelId}
data-testid="sampling-trigger"
+ // Word for word the web app's trigger (apps/web/components/chat/
+ // SamplingControls.tsx:82-83), so the button has one name on Windows,
+ // Mac and the web app instead of being read out as a bare number.
+ title="Sampling for this chat"
+ aria-label={`Sampling: temperature ${settings.temperature}`}
// Opens, never closes. A trigger that also closed made the panel
// disappear under the pointer on the second click.
onClick={() => setOpen(true)}
@@ -236,10 +254,11 @@ export function SamplingControls() {
disabled={!changed}
onClick={() => {
setDraft(null)
+ // Resets what this popup shows. Top K is not on it, so this
+ // button does not silently reach over to the settings page.
update({
temperature: DEFAULT_SETTINGS.temperature,
topP: DEFAULT_SETTINGS.topP,
- topK: DEFAULT_SETTINGS.topK,
maxTokens: DEFAULT_SETTINGS.maxTokens,
})
}}
diff --git a/src/components/chat/__tests__/sampling-controls.test.tsx b/src/components/chat/__tests__/sampling-controls.test.tsx
index 8c39bb51..462289e0 100644
--- a/src/components/chat/__tests__/sampling-controls.test.tsx
+++ b/src/components/chat/__tests__/sampling-controls.test.tsx
@@ -38,10 +38,45 @@ describe('SamplingControls', () => {
open()
fireEvent.change(screen.getByLabelText('Temperature'), { target: { value: '1.3' } })
fireEvent.change(screen.getByLabelText('Top P'), { target: { value: '0.5' } })
- fireEvent.change(screen.getByLabelText('Top K'), { target: { value: '20' } })
expect(settings().temperature).toBe(1.3)
expect(settings().topP).toBe(0.5)
- expect(settings().topK).toBe(20)
+ })
+
+ /**
+ * R5-13. Top K moved nothing on the paid default path: the OpenAI-compatible
+ * body has no field for it and `openai-provider.ts` never reads it, so on LU
+ * Cloud and on this app's own engine the slider was a dead control. It also
+ * carried a second scale, 0..200 here against 1..100 on the settings page.
+ * It belongs on the settings page, where Ollama and Anthropic read it.
+ */
+ it('R5-13: carries no Top K, because it moves nothing on the cloud path', () => {
+ render(<SamplingControls />)
+ open()
+ expect(screen.queryByLabelText('Top K')).toBeNull()
+ expect(screen.queryByText('Top K')).toBeNull()
+ })
+
+ it('R5-13 NEGATIVKONTROLLE: Top K keeps its stored value, this popup only stops showing it', () => {
+ // The value is not deleted and the settings page keeps offering it. What
+ // falls away is a control that wrote a number nobody could see again.
+ useSettingsStore.getState().updateSettings({ topK: 55 })
+ render(<SamplingControls />)
+ open()
+ expect(settings().topK).toBe(55)
+ expect(screen.getByLabelText('Temperature')).toBeTruthy()
+ })
+
+ /**
+ * R5-14. The trigger was bare text, so a screen reader announced a number
+ * and nothing else. Both strings are word for word the web app's
+ * (apps/web/components/chat/SamplingControls.tsx:82-83).
+ */
+ it('R5-14: the trigger has the same name and title as the web app', () => {
+ useSettingsStore.getState().updateSettings({ temperature: 0.7 })
+ render(<SamplingControls />)
+ expect(trigger().getAttribute('title')).toBe('Sampling for this chat')
+ expect(trigger().getAttribute('aria-label')).toBe('Sampling: temperature 0.7')
+ expect(screen.getByRole('button', { name: 'Sampling: temperature 0.7' })).toBeTruthy()
})
it('never lets max tokens go negative', () => {
@@ -96,16 +131,28 @@ describe('SamplingControls', () => {
})
it('marks a changed setup and resets every field at once', () => {
- useSettingsStore.getState().updateSettings({ temperature: 1.9, topK: 5 })
+ useSettingsStore.getState().updateSettings({ temperature: 1.9, topP: 0.3, maxTokens: 512 })
render(<SamplingControls />)
expect(screen.getByTitle(/Changed from the defaults/)).toBeTruthy()
open()
fireEvent.click(screen.getByRole('button', { name: 'Reset' }))
expect(settings().temperature).toBe(DEFAULT_SETTINGS.temperature)
- expect(settings().topK).toBe(DEFAULT_SETTINGS.topK)
+ expect(settings().topP).toBe(DEFAULT_SETTINGS.topP)
+ expect(settings().maxTokens).toBe(DEFAULT_SETTINGS.maxTokens)
expect(screen.queryByTitle(/Changed from the defaults/)).toBeNull()
})
+ it('R5-13: Reset stays inside this popup and leaves Top K alone', () => {
+ // Top K is not on this panel any more, so a Reset here must not reach over
+ // to the settings page and undo a value the user set there.
+ useSettingsStore.getState().updateSettings({ temperature: 1.9, topK: 55 })
+ render(<SamplingControls />)
+ open()
+ fireEvent.click(screen.getByRole('button', { name: 'Reset' }))
+ expect(settings().temperature).toBe(DEFAULT_SETTINGS.temperature)
+ expect(settings().topK).toBe(55)
+ })
+
it('offers no reset while everything is at its default', () => {
render(<SamplingControls />)
open()