Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat: cap at model's max context when auto increase ctx_len
Vanalite75997d5f91bc
diff --git a/extensions/llamacpp-extension/src/index.ts b/extensions/llamacpp-extension/src/index.tsindex 624191f82..184bd84aa 100644--- a/extensions/llamacpp-extension/src/index.ts+++ b/extensions/llamacpp-extension/src/index.ts@@ -64,7 +64,6 @@ import {import { getSystemUsage, getSystemInfo } from '@janhq/tauri-plugin-hardware-api'// Error message constant - matches web-app/src/utils/error.ts-const OUT_OF_CONTEXT_SIZE = 'the request exceeds the available context size.'/*** Override the default app.log function to use Jan's logging system.@@ -1830,12 +1829,6 @@ export default class llamacpp_extension extends AIEngine {const data = JSON.parse(jsonStr)const chunk = data as chatCompletionChunk- // Check for out-of-context error conditions- if (chunk.choices?.[0]?.finish_reason === 'length') {- // finish_reason 'length' indicates context limit was hit- throw new Error(OUT_OF_CONTEXT_SIZE)- }-yield chunk} catch (e) {logger.error('Error parsing JSON from stream or server error:', e)@@ -1923,12 +1916,6 @@ export default class llamacpp_extension extends AIEngine {const completionResponse = (await response.json()) as chatCompletion- // Check for out-of-context error conditions- if (completionResponse.choices?.[0]?.finish_reason === 'length') {- // finish_reason 'length' indicates context limit was hit- throw new Error(OUT_OF_CONTEXT_SIZE)- }-return completionResponse}diff --git a/web-app/src/routes/threads/$threadId.tsx b/web-app/src/routes/threads/$threadId.tsxindex 7733f6e56..2b5dd5a6c 100644--- a/web-app/src/routes/threads/$threadId.tsx+++ b/web-app/src/routes/threads/$threadId.tsx@@ -148,7 +148,9 @@ function ThreadDetail() {// context-limit hit, so the user sees it instead of a blank gap.const [pendingContinueMessage, setPendingContinueMessage] =useState<UIMessage | null>(null)- const [isAutoIncreasingContext, setIsAutoIncreasingContext] = useState(false)+ const [autoIncreaseAttempts, setAutoIncreaseAttempts] = useState(0)+ const MAX_AUTO_INCREASE_ATTEMPTS = 3+ const isAutoIncreasingContext = autoIncreaseAttempts > 0 && autoIncreaseAttempts < MAX_AUTO_INCREASE_ATTEMPTSconst [contextLimitError, setContextLimitError] = useState<Error | null>(null)// Refs so onFinish (captured in closure) always calls the latest callbacks@@ -772,6 +774,9 @@ function ThreadDetail() {// Increase context length in steps: <8192 -> 8192 -> 32768 -> x1.5const currentCtxLen =(model.settings?.ctx_len?.controller_props?.value as number) ?? 8192+ const maxCtxLen =+ (model.settings?.ctx_len?.controller_props?.max as number) || 131072+let newCtxLen: numberif (currentCtxLen < 8192) {newCtxLen = 8192@@ -781,6 +786,12 @@ function ThreadDetail() {newCtxLen = Math.round(currentCtxLen * 1.5)}+ newCtxLen = Math.min(newCtxLen, maxCtxLen)+ if (newCtxLen <= currentCtxLen) {+ setContextLimitError(new Error(OUT_OF_CONTEXT_SIZE))+ return+ }+const updatedModel = {...model,settings: {@@ -825,6 +836,7 @@ function ThreadDetail() {)useEffect(() => {if (!error || agentModeActive) return+ if (autoIncreaseAttempts >= MAX_AUTO_INCREASE_ATTEMPTS) returnconst autoIncrease =selectedModel?.settings?.auto_increase_ctx_len?.controller_props?.value ??true@@ -836,7 +848,7 @@ function ThreadDetail() {error.message?.toLowerCase().includes('limit'))) ||error.message === OUT_OF_CONTEXT_SIZEif (isContextError) {- setIsAutoIncreasingContext(true)+ setAutoIncreaseAttempts((prev) => prev + 1)handleContextSizeIncrease()}}, [error]) // eslint-disable-line react-hooks/exhaustive-deps@@ -845,8 +857,8 @@ function ThreadDetail() {if (status === 'streaming' || status === 'submitted') {setContextLimitError(null)}- if (isAutoIncreasingContext && (status === 'streaming' || status === 'error')) {- setIsAutoIncreasingContext(false)+ if (status === 'streaming' && autoIncreaseAttempts > 0) {+ setAutoIncreaseAttempts(0)}if (status === 'error' && pendingContinueMessage) {setPendingContinueMessage(null)diff --git a/web-app/src/types/modelProviders.d.ts b/web-app/src/types/modelProviders.d.tsindex cb1f7714a..5252b873c 100644--- a/web-app/src/types/modelProviders.d.ts+++ b/web-app/src/types/modelProviders.d.ts@@ -8,6 +8,9 @@ type ControllerProps = {options?: Array<{ value: number | string; name: string }>input_actions?: string[]recommended?: string+ min?: number+ max?: number+ step?: number}/**