Skip to content

Build your personal knowledge base with Trilium Notes

fix(ollama): use chat completions API for older Ollama compatibility

Tomáš Adámek880c719599d4
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
index 17cd17eb52..0303f90851 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
@@ -11,6 +11,16 @@ export interface ModelOption extends LlmModelInfo {
costDescription?: string;
}
+function getCostDescription(model: LlmModelInfo): string | undefined {
+ if (model.costMultiplier) {
+ return `${model.costMultiplier}x`;
+ }
+ if (model.pricing.input === 0 && model.pricing.output === 0) {
+ return t("llm_chat.free");
+ }
+ return undefined;
+}
+
export interface LlmChatOptions {
/** Default value for enableNoteTools */
defaultEnableNoteTools?: boolean;
@@ -123,11 +133,7 @@ export function useLlmChat(
getAvailableModels().then(models => {
const modelsWithDescription = models.map(m => ({
...m,
- costDescription: m.costMultiplier
- ? `${m.costMultiplier}x`
- : m.pricing.input === 0 && m.pricing.output === 0
- ? t("llm_chat.free")
- : undefined
+ costDescription: getCostDescription(m)
}));
setAvailableModels(modelsWithDescription);
setHasProvider(models.length > 0);
diff --git a/apps/server/src/services/llm/providers/ollama.ts b/apps/server/src/services/llm/providers/ollama.ts
index 87d750ec05..c47caabd3c 100644
--- a/apps/server/src/services/llm/providers/ollama.ts
+++ b/apps/server/src/services/llm/providers/ollama.ts
@@ -96,7 +96,10 @@ export class OllamaProvider extends BaseProvider {
}
protected createModel(modelId: string) {
- return this.openai(modelId);
+ // Use the Chat Completions API explicitly — calling `this.openai(modelId)`
+ // defaults to the OpenAI Responses API, which Ollama only supports
+ // since 0.13.3. Chat Completions works on all Ollama versions.
+ return this.openai.chat(modelId);
}
override getAvailableModels(): ModelInfo[] {