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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(chat): Sampling-Regler neben dem Eingabefeld
David1b9ec1826d48
diff --git a/src/components/chat/ChatInput.tsx b/src/components/chat/ChatInput.tsxindex 17b62ba4..8c3e37a3 100644--- a/src/components/chat/ChatInput.tsx+++ b/src/components/chat/ChatInput.tsx@@ -1,4 +1,5 @@import { useState, useRef, useEffect, useCallback, type ReactNode } from 'react'+import { SamplingControls } from './SamplingControls'import { Send, Square, Paperclip, X, Brain, Gauge, Terminal } from 'lucide-react'import { matchAgentCommands, type AgentCommand, type CommandScope } from '../../lib/agent-commands'import { VoiceButton } from './VoiceButton'@@ -639,6 +640,9 @@ export function ChatInput({ onSend, onStop, isGenerating, pendingApproval, onApp<div className="flex-1 min-w-0" />+ {/* Sampling controls sit next to the picker: same row, collapsed. */}+ <div className="shrink-0"><SamplingControls /></div>+{/* Model picker, opens upward from the composer */}<div className="shrink-0">{composerModel}</div>diff --git a/src/components/chat/SamplingControls.tsx b/src/components/chat/SamplingControls.tsxnew file mode 100644index 00000000..b67a79c1--- /dev/null+++ b/src/components/chat/SamplingControls.tsx@@ -0,0 +1,97 @@+import { useState } from 'react'+import { useSettingsStore } from '../../stores/settingsStore'+import { DEFAULT_SETTINGS } from '../../lib/constants'+import { HINWEIS_TEXT } from '../../lib/hinweis'++/**+ * Sampling controls next to the composer.+ *+ * The values already existed in settings and already reached the request; they+ * were just buried in the settings page, where nobody adjusts them per+ * conversation. Collapsed by default so the composer stays quiet.+ *+ * Every catalogue model accepts these parameters (measured 2026-09-10, no+ * request was rejected for one). Reasoning models accept them and react less,+ * which the help line says instead of hiding the control.+ */+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++export function SamplingControls() {+ const [open, setOpen] = useState(false)+ const settings = useSettingsStore((s) => s.settings)+ const update = useSettingsStore((s) => s.updateSettings)+ const changed = FIELDS.some((f) => settings[f.key] !== DEFAULT_SETTINGS[f.key])+ || settings.maxTokens !== DEFAULT_SETTINGS.maxTokens++ return (+ <div className="text-xs" data-testid="sampling-controls">+ <button+ type="button"+ className="text-gray-500 hover:text-gray-300"+ aria-expanded={open}+ onClick={() => setOpen((v) => !v)}+ >+ Sampling: {settings.temperature.toFixed(2)}+ {/* Ein geaenderter Regler ist kein Zwischenfall, also traegt der+ Stern den ruhigen Ton und keine eigene Warnfarbe. */}+ {changed && <span className={`ml-1 ${HINWEIS_TEXT.ruhig}`} title="Changed from the defaults">*</span>}+ </button>++ {open && (+ <div className="mt-2 space-y-2 rounded border border-gray-700 p-2" data-testid="sampling-panel">+ {FIELDS.map((f) => (+ <label key={f.key} className="flex items-center gap-2">+ <span className="w-20 text-gray-400">{f.label}</span>+ <input+ type="range"+ className="flex-1"+ min={f.min}+ max={f.max}+ step={f.step}+ value={settings[f.key]}+ aria-label={f.label}+ onChange={(e) => update({ [f.key]: Number(e.target.value) })}+ />+ <span className="w-10 text-right tabular-nums text-gray-300">{settings[f.key]}</span>+ </label>+ ))}++ <label className="flex items-center gap-2">+ <span className="w-20 text-gray-400">Max tokens</span>+ <input+ type="number"+ className="flex-1 rounded border border-gray-700 bg-transparent px-1 py-0.5"+ min={0}+ step={128}+ value={settings.maxTokens}+ aria-label="Max tokens"+ onChange={(e) => update({ maxTokens: Math.max(0, Number(e.target.value) || 0) })}+ />+ <span className="w-10 text-right text-gray-500">{settings.maxTokens === 0 ? 'auto' : ''}</span>+ </label>++ <div className="flex items-center justify-between pt-1">+ <span className="text-gray-500">Reasoning models accept these and react less to them.</span>+ <button+ type="button"+ className="text-gray-400 underline disabled:opacity-40"+ disabled={!changed}+ onClick={() => update({+ temperature: DEFAULT_SETTINGS.temperature,+ topP: DEFAULT_SETTINGS.topP,+ topK: DEFAULT_SETTINGS.topK,+ maxTokens: DEFAULT_SETTINGS.maxTokens,+ })}+ >+ Reset+ </button>+ </div>+ </div>+ )}+ </div>+ )+}diff --git a/src/components/chat/__tests__/sampling-controls.test.tsx b/src/components/chat/__tests__/sampling-controls.test.tsxnew file mode 100644index 00000000..97cd9f0a--- /dev/null+++ b/src/components/chat/__tests__/sampling-controls.test.tsx@@ -0,0 +1,75 @@+// @vitest-environment jsdom+import { beforeEach, describe, expect, it } from 'vitest'+import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { useSettingsStore } from '../../../stores/settingsStore'+import { DEFAULT_SETTINGS } from '../../../lib/constants'+import { SamplingControls } from '../SamplingControls'++const settings = () => useSettingsStore.getState().settings+const open = () => fireEvent.click(screen.getByRole('button', { name: /Sampling/ }))++beforeEach(() => {+ cleanup()+ useSettingsStore.getState().updateSettings({+ temperature: DEFAULT_SETTINGS.temperature,+ topP: DEFAULT_SETTINGS.topP,+ topK: DEFAULT_SETTINGS.topK,+ maxTokens: DEFAULT_SETTINGS.maxTokens,+ })+})++describe('SamplingControls', () => {+ it('stays collapsed until asked, so the composer stays quiet', () => {+ render(<SamplingControls />)+ expect(screen.queryByTestId('sampling-panel')).toBeNull()+ open()+ expect(screen.getByTestId('sampling-panel')).toBeTruthy()+ })++ it('shows the live temperature on the closed control', () => {+ useSettingsStore.getState().updateSettings({ temperature: 1.15 })+ render(<SamplingControls />)+ expect(screen.getByRole('button', { name: /1\.15/ })).toBeTruthy()+ })++ it('writes each value into the settings the request already reads', () => {+ render(<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)+ })++ it('never lets max tokens go negative', () => {+ render(<SamplingControls />)+ open()+ fireEvent.change(screen.getByLabelText('Max tokens'), { target: { value: '-500' } })+ expect(settings().maxTokens).toBe(0)+ })++ it('marks a changed setup and resets every field at once', () => {+ useSettingsStore.getState().updateSettings({ temperature: 1.9, topK: 5 })+ 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(screen.queryByTitle(/Changed from the defaults/)).toBeNull()+ })++ it('offers no reset while everything is at its default', () => {+ render(<SamplingControls />)+ open()+ expect((screen.getByRole('button', { name: 'Reset' }) as HTMLButtonElement).disabled).toBe(true)+ })++ it('says plainly that reasoning models react less, instead of hiding the control', () => {+ render(<SamplingControls />)+ open()+ expect(screen.getByText(/Reasoning models accept these/)).toBeTruthy()+ })+})diff --git a/vitest.config.ts b/vitest.config.tsindex cfeb398b..66f8c765 100644--- a/vitest.config.ts+++ b/vitest.config.ts@@ -10,6 +10,12 @@ export default defineConfig({// dev-server/ kam mit ZB-7 dazu: der Dev-Server lag bis dahin in// vite.config.ts und war damit fuer vitest unsichtbar. Die Tests dort// haengen die ECHTEN Handler an einen echten node:http-Server.- include: ['src/**/__tests__/**/*.test.ts', 'dev-server/**/__tests__/**/*.test.ts'],+ // .tsx kam mit den Sampling-Reglern dazu: Komponententests brauchen JSX,+ // und ohne die Endung war die Datei fuer vitest unsichtbar.+ include: [+ 'src/**/__tests__/**/*.test.ts',+ 'src/**/__tests__/**/*.test.tsx',+ 'dev-server/**/__tests__/**/*.test.ts',+ ],},})