Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat(chat): expose sampler order, backend sampling, repeat_last_n, and thinking budget
Akarshan Biswas3f5d24824a79
diff --git a/extensions/llamacpp-extension/settings.json b/extensions/llamacpp-extension/settings.jsonindex e5e501c1e..ca65e2049 100644--- a/extensions/llamacpp-extension/settings.json+++ b/extensions/llamacpp-extension/settings.json@@ -102,7 +102,7 @@{"key": "fit_ctx","title": "Fit Minimum Context Size",- "description": "Minimum context size (tokens) that can be set by --fit option. (env: LLAMA_ARG_FIT_CTX)",+ "description": "Minimum context size (tokens) that can be set by the auto-fit option.","controllerType": "input","controllerProps": {"value": 4096,@@ -356,7 +356,7 @@{"key": "cache_ram","title": "Prompt Cache RAM (MiB)",- "description": "Maximum prompt cache size in MiB (--cache-ram). -1 = unlimited, 0 = disabled.",+ "description": "Maximum prompt cache size in MiB. -1 = unlimited, 0 = disabled.","controllerType": "input","controllerProps": {"value": -1,@@ -368,7 +368,7 @@{"key": "cache_reuse","title": "Cache Reuse",- "description": "Min chunk size of matching prefix tokens to reuse from cache (--cache-reuse). 0 = disabled.",+ "description": "Min chunk size of matching prefix tokens to reuse from cache. 0 = disabled.","controllerType": "input","controllerProps": {"value": 0,@@ -381,7 +381,7 @@{"key": "swa_full","title": "Full SWA Cache",- "description": "Use full-size SWA cache (--swa-full). May improve quality at the cost of memory.",+ "description": "Use full-size SWA cache. May improve quality at the cost of memory.","controllerType": "checkbox","controllerProps": {"value": false@@ -399,7 +399,7 @@{"key": "keep","title": "Keep First N Tokens",- "description": "Number of tokens from the initial prompt to keep when context is shifted (--keep). -1 = keep all.",+ "description": "Number of tokens from the initial prompt to keep when context is shifted. -1 = keep all.","controllerType": "input","controllerProps": {"value": 0,diff --git a/web-app/src/lib/__tests__/model-factory.test.ts b/web-app/src/lib/__tests__/model-factory.test.tsindex 93aa034e8..cad604250 100644--- a/web-app/src/lib/__tests__/model-factory.test.ts+++ b/web-app/src/lib/__tests__/model-factory.test.ts@@ -367,6 +367,45 @@ describe('createCustomFetch — max_tokens coercion', () => {})expect(sent.max_tokens).toBe('')})++ it('remaps dynatemp_exp to the llama-server wire name dynatemp_exponent', async () => {+ const sent = await captureSentBody({ dynatemp_exp: 1.5 }, true, {+ messages: [],+ })+ expect(sent.dynatemp_exponent).toBe(1.5)+ expect(sent.dynatemp_exp).toBeUndefined()+ })++ it('splits the samplers string param into an array on the wire', async () => {+ const sent = await captureSentBody(+ { samplers: 'top_k, typ_p ;top_p' },+ true,+ { messages: [] }+ )+ expect(sent.samplers).toEqual(['top_k', 'typ_p', 'top_p'])+ })++ it('omits samplers entirely when the string is empty', async () => {+ const sent = await captureSentBody({ samplers: '' }, true, {+ messages: [],+ })+ expect(sent.samplers).toBeUndefined()+ })++ it('forwards repeat_last_n, backend_sampling, and thinking_budget_tokens as-is', async () => {+ const sent = await captureSentBody(+ {+ repeat_last_n: 128,+ backend_sampling: true,+ thinking_budget_tokens: 4096,+ },+ true,+ { messages: [] }+ )+ expect(sent.repeat_last_n).toBe(128)+ expect(sent.backend_sampling).toBe(true)+ expect(sent.thinking_budget_tokens).toBe(4096)+ })})describe('createCustomFetch — llamacpp 500 handling', () => {diff --git a/web-app/src/lib/model-factory.ts b/web-app/src/lib/model-factory.tsindex 6aa15f7c7..f47db4811 100644--- a/web-app/src/lib/model-factory.ts+++ b/web-app/src/lib/model-factory.ts@@ -376,6 +376,23 @@ export function createCustomFetch(return Number.isNaN(n) ? value : n}+ // Internal param keys that don't match the llama-server wire field name.+ const WIRE_KEY_REMAP: Record<string, string> = {+ max_output_tokens: 'max_tokens',+ dynatemp_exp: 'dynatemp_exponent',+ }++ // Server expects an array of sampler names; the UI stores a comma/+ // semicolon-separated string for easy editing.+ const coerceSamplers = (value: unknown): unknown => {+ if (typeof value !== 'string') return value+ const names = value+ .split(/[,;]/)+ .map((s) => s.trim())+ .filter(Boolean)+ return names.length > 0 ? names : undefined+ }+const buildBody = (rawBody: Record<string, unknown>,includeOurParams: boolean@@ -389,8 +406,13 @@ export function createCustomFetch(for (const [key, value] of Object.entries(parameters)) {if (CLIENT_SIDE_PARAM_KEYS.has(key)) continueif (!keepLlamacppOnly && LLAMACPP_ONLY_PARAM_KEYS.has(key)) continue- const targetKey = key === 'max_output_tokens' ? 'max_tokens' : key- normalised[targetKey] = coerceNumericParam(key, value)+ const targetKey = WIRE_KEY_REMAP[key] ?? key+ const coerced =+ key === 'samplers'+ ? coerceSamplers(value)+ : coerceNumericParam(key, value)+ if (coerced === undefined) continue+ normalised[targetKey] = coerced}const merged = { ...rawBody, ...normalised }if (keepLlamacppOnly && merged.stream === true) {diff --git a/web-app/src/lib/predefinedParams.ts b/web-app/src/lib/predefinedParams.tsindex 15993a329..41f732747 100644--- a/web-app/src/lib/predefinedParams.ts+++ b/web-app/src/lib/predefinedParams.ts@@ -30,6 +30,9 @@ export type SamplerCap =| 'grammar'| 'json_schema'| 'ignore_eos'+ | 'sampler_order'+ | 'backend_sampling'+ | 'thinking_budget'| 'client_only'export interface ParamControllerProps {@@ -348,13 +351,50 @@ export const paramsSettings: Record<string, ParamDef> = {controllerType: 'checkbox',capability: 'ignore_eos',},+ repeat_last_n: {+ key: 'repeat_last_n',+ title: 'Repeat Last N',+ description:+ 'Number of recent tokens considered for the repeat penalty. -1 = full context, 0 = disabled.',+ value: 64,+ controllerType: 'input',+ controllerProps: { min: -1, step: 1 },+ capability: 'repetition',+ },+ samplers: {+ key: 'samplers',+ title: 'Sampler Order',+ description:+ 'Order in which samplers are applied, comma-separated (e.g. "top_k,typ_p,top_p,min_p,xtc,temperature"). Empty = server default order.',+ value: '',+ controllerType: 'input',+ controllerProps: { placeholder: 'top_k,typ_p,top_p,min_p,xtc,temperature' },+ capability: 'sampler_order',+ },+ backend_sampling: {+ key: 'backend_sampling',+ title: 'Backend Sampling',+ description: 'Use the model backend\'s own sampler instead of llama.cpp\'s.',+ value: false,+ controllerType: 'checkbox',+ capability: 'backend_sampling',+ },+ thinking_budget_tokens: {+ key: 'thinking_budget_tokens',+ title: 'Thinking Budget',+ description:+ 'Maximum tokens the model may spend on reasoning before being forced to answer. -1 = unlimited.',+ value: -1,+ controllerType: 'input',+ controllerProps: { min: -1, step: 1 },+ capability: 'thinking_budget',+ },}/*** Sampler keys exposed as per-model defaults in the model edit dialog. Persist* to the model (model.yml → router preset for llamacpp) and act as defaults the* local API server uses; per-assistant and per-request values override them.- * `repeat_last_n` is intentionally omitted — it has no paramsSettings entry.*/export const SAMPLER_DEFAULT_KEYS = ['temperature',@@ -362,6 +402,7 @@ export const SAMPLER_DEFAULT_KEYS = ['top_k','min_p','repeat_penalty',+ 'repeat_last_n','presence_penalty','frequency_penalty',] as const@@ -417,6 +458,10 @@ export const LLAMACPP_ONLY_PARAM_KEYS: ReadonlySet<string> = new Set(['ignore_eos','min_p','repeat_penalty',+ 'repeat_last_n',+ 'samplers',+ 'backend_sampling',+ 'thinking_budget_tokens',])export function evaluateDisabled(@@ -519,7 +564,12 @@ export const paramCategories: CategoryDef[] = [{id: 'penalties',title: 'Penalties',- paramKeys: ['frequency_penalty', 'presence_penalty', 'repeat_penalty'],+ paramKeys: [+ 'frequency_penalty',+ 'presence_penalty',+ 'repeat_penalty',+ 'repeat_last_n',+ ],groupIds: [],},{@@ -532,13 +582,14 @@ export const paramCategories: CategoryDef[] = ['auto_compact','max_context_tokens','ignore_eos',+ 'thinking_budget_tokens',],groupIds: [],},{id: 'advanced',title: 'Advanced samplers',- paramKeys: ['typical_p', 'top_n_sigma'],+ paramKeys: ['typical_p', 'top_n_sigma', 'samplers', 'backend_sampling'],groupIds: ['mirostat', 'dry', 'xtc', 'dynatemp'],},]diff --git a/web-app/src/lib/providerCaps.ts b/web-app/src/lib/providerCaps.tsindex afb46f259..8c55f0f80 100644--- a/web-app/src/lib/providerCaps.ts+++ b/web-app/src/lib/providerCaps.ts@@ -105,7 +105,10 @@ const LLAMACPP: ProviderCaps = {'top_n_sigma','grammar','json_schema',- 'ignore_eos'+ 'ignore_eos',+ 'sampler_order',+ 'backend_sampling',+ 'thinking_budget'),maybe: new Set(),}@@ -136,6 +139,9 @@ const CUSTOM_PERMISSIVE: ProviderCaps = {'grammar','json_schema','ignore_eos',+ 'sampler_order',+ 'backend_sampling',+ 'thinking_budget',]),}