Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions extensions/llamacpp-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,14 @@ export default class llamacpp_extension extends AIEngine {
)
// Clear the invalid stored preference
this.clearStoredBackendType()
bestAvailableBackendString =
await this.determineBestBackend(version_backends)
bestAvailableBackendString = await this.determineBestBackend(
version_backends
)
}
} else {
bestAvailableBackendString =
await this.determineBestBackend(version_backends)
bestAvailableBackendString = await this.determineBestBackend(
version_backends
)
}

let settings = structuredClone(SETTINGS)
Expand Down Expand Up @@ -2151,7 +2153,12 @@ export default class llamacpp_extension extends AIEngine {
if (mmprojPath && !this.isAbsolutePath(mmprojPath))
mmprojPath = await joinPath([await getJanDataFolderPath(), path])
try {
const result = await planModelLoadInternal(path, this.memoryMode, mmprojPath, requestedCtx)
const result = await planModelLoadInternal(
path,
this.memoryMode,
mmprojPath,
requestedCtx
)
return result
} catch (e) {
throw new Error(String(e))
Expand Down Expand Up @@ -2279,12 +2286,18 @@ export default class llamacpp_extension extends AIEngine {
}

// Calculate text tokens
const messages = JSON.stringify({ messages: opts.messages })
// Use chat_template_kwargs from opts if provided, otherwise default to disable enable_thinking
const tokenizeRequest = {
messages: opts.messages,
chat_template_kwargs: opts.chat_template_kwargs || {
enable_thinking: false,
},
}

let parseResponse = await fetch(`${baseUrl}/apply-template`, {
method: 'POST',
headers: headers,
body: messages,
body: JSON.stringify(tokenizeRequest),
})

if (!parseResponse.ok) {
Expand Down
7 changes: 5 additions & 2 deletions web-app/src/containers/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
const servers = await serviceHub.mcp().getConnectedServers()
setConnectedServers(servers)
} catch (error) {
console.error('Failed to get connected servers:', error)
setConnectedServers([])
}

Check warning on line 114 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

112-114 lines are not covered with tests
}

checkConnectedServers()
Expand All @@ -129,7 +129,10 @@
const activeModels = await serviceHub
.models()
.getActiveModels('llamacpp')
setHasActiveModels(activeModels.length > 0)
const hasMatchingActiveModel = activeModels.some(
(model) => String(model) === selectedModel?.id
)

Check warning on line 134 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

132-134 lines are not covered with tests
setHasActiveModels(activeModels.length > 0 && hasMatchingActiveModel)
} catch (error) {
console.error('Failed to get active models:', error)
setHasActiveModels(false)
Expand All @@ -142,7 +145,7 @@
const intervalId = setInterval(checkActiveModels, 3000)

return () => clearInterval(intervalId)
}, [serviceHub])
}, [serviceHub, selectedModel?.id])

// Check for mmproj existence or vision capability when model changes
useEffect(() => {
Expand All @@ -153,12 +156,12 @@
if (selectedModel?.capabilities?.includes('vision')) {
setHasMmproj(true)
} else {
setHasMmproj(false)
}

Check warning on line 160 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

159-160 lines are not covered with tests
} catch (error) {
console.error('Error checking mmproj:', error)
setHasMmproj(false)
}

Check warning on line 164 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

162-164 lines are not covered with tests
}
}

Expand All @@ -170,12 +173,12 @@

const handleSendMesage = (prompt: string) => {
if (!selectedModel) {
setMessage('Please select a model to start chatting.')
return
}

Check warning on line 178 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

176-178 lines are not covered with tests
if (!prompt.trim() && uploadedFiles.length === 0) {
return
}

Check warning on line 181 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

180-181 lines are not covered with tests
setMessage('')
sendMessage(
prompt,
Expand All @@ -189,8 +192,8 @@
useEffect(() => {
const handleFocusIn = () => {
if (document.activeElement === textareaRef.current) {
setIsFocused(true)
}

Check warning on line 196 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

195-196 lines are not covered with tests
}

const handleFocusOut = () => {
Expand All @@ -217,8 +220,8 @@

useEffect(() => {
if (tooltipToolsAvailable && dropdownToolsAvailable) {
setTooltipToolsAvailable(false)
}

Check warning on line 224 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

223-224 lines are not covered with tests
}, [dropdownToolsAvailable, tooltipToolsAvailable])

// Focus when thread changes
Expand All @@ -240,17 +243,17 @@

const stopStreaming = useCallback(
(threadId: string) => {
abortControllers[threadId]?.abort()
cancelToolCall?.()
},

Check warning on line 248 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

246-248 lines are not covered with tests
[abortControllers, cancelToolCall]
)

const fileInputRef = useRef<HTMLInputElement>(null)

const handleAttachmentClick = () => {
fileInputRef.current?.click()
}

Check warning on line 256 in web-app/src/containers/ChatInput.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

255-256 lines are not covered with tests

const handleRemoveFile = (indexToRemove: number) => {
setUploadedFiles((prev) =>
Expand Down
6 changes: 6 additions & 0 deletions web-app/src/services/models/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ export class DefaultModelsService implements ModelsService {
}
}>
}>
chat_template_kwargs?: {
enable_thinking: boolean
}
}) => Promise<number>
}

Expand Down Expand Up @@ -654,6 +657,9 @@ export class DefaultModelsService implements ModelsService {
return await engine.getTokensCount({
model: modelId,
messages: transformedMessages,
chat_template_kwargs: {
enable_thinking: false,
},
})
}

Expand Down
Loading