@elizaos/plugin-ollama 2.0.0-beta.1 → 2.0.3-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -27
- package/dist/browser/index.browser.js +78 -61
- package/dist/browser/index.browser.js.map +7 -7
- package/dist/cjs/index.node.cjs +78 -61
- package/dist/cjs/index.node.cjs.map +7 -7
- package/dist/node/index.node.js +78 -61
- package/dist/node/index.node.js.map +7 -7
- package/dist/node/models/embedding.d.ts.map +1 -1
- package/dist/node/models/text.d.ts.map +1 -1
- package/dist/node/plugin.d.ts.map +1 -1
- package/dist/node/utils/ai-sdk-wire.d.ts +1 -1
- package/dist/node/utils/config.d.ts +1 -1
- package/dist/node/utils/config.d.ts.map +1 -1
- package/package.json +16 -10
- package/registry-entry.json +96 -0
package/dist/cjs/index.node.cjs
CHANGED
|
@@ -71,7 +71,7 @@ var import_ollama_ai_provider_v2 = require("ollama-ai-provider-v2");
|
|
|
71
71
|
// utils/config.ts
|
|
72
72
|
var DEFAULT_OLLAMA_URL = "http://localhost:11434";
|
|
73
73
|
var DEFAULT_SMALL_MODEL = "eliza-1-2b";
|
|
74
|
-
var DEFAULT_LARGE_MODEL = "eliza-1-
|
|
74
|
+
var DEFAULT_LARGE_MODEL = "eliza-1-4b";
|
|
75
75
|
var DEFAULT_EMBEDDING_MODEL = "eliza-1-2b";
|
|
76
76
|
function getEnvValue(key) {
|
|
77
77
|
if (typeof process === "undefined" || !process.env) {
|
|
@@ -83,12 +83,12 @@ function getEnvValue(key) {
|
|
|
83
83
|
function getSetting(runtime, key, defaultValue) {
|
|
84
84
|
const value = runtime.getSetting(key);
|
|
85
85
|
if (value !== undefined && value !== null) {
|
|
86
|
-
return String(value);
|
|
86
|
+
return String(value).trim();
|
|
87
87
|
}
|
|
88
|
-
return getEnvValue(key) ?? defaultValue;
|
|
88
|
+
return getEnvValue(key)?.trim() ?? defaultValue;
|
|
89
89
|
}
|
|
90
90
|
function getBaseURL(runtime) {
|
|
91
|
-
const apiEndpoint = getSetting(runtime, "OLLAMA_API_ENDPOINT") || getSetting(runtime, "OLLAMA_API_URL") || DEFAULT_OLLAMA_URL;
|
|
91
|
+
const apiEndpoint = getSetting(runtime, "OLLAMA_API_ENDPOINT") || getSetting(runtime, "OLLAMA_API_URL") || getSetting(runtime, "OLLAMA_BASE_URL") || DEFAULT_OLLAMA_URL;
|
|
92
92
|
if (!apiEndpoint.endsWith("/api")) {
|
|
93
93
|
return apiEndpoint.endsWith("/") ? `${apiEndpoint}api` : `${apiEndpoint}/api`;
|
|
94
94
|
}
|
|
@@ -236,39 +236,53 @@ async function ensureModelAvailable(model, providedBaseURL, customFetch) {
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
// models/embedding.ts
|
|
239
|
+
var INIT_PROBE_TEXT = "dimension probe";
|
|
240
|
+
function extractText(params) {
|
|
241
|
+
if (params === null) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
if (typeof params === "string") {
|
|
245
|
+
return params;
|
|
246
|
+
}
|
|
247
|
+
if (typeof params === "object" && typeof params.text === "string") {
|
|
248
|
+
return params.text;
|
|
249
|
+
}
|
|
250
|
+
throw new Error("Invalid input format for embedding: expected string or { text: string }");
|
|
251
|
+
}
|
|
239
252
|
async function handleTextEmbedding(runtime, params) {
|
|
253
|
+
const text = extractText(params);
|
|
254
|
+
const isInitProbe = text === null;
|
|
255
|
+
if (!isInitProbe && !text.trim()) {
|
|
256
|
+
throw new Error("Cannot generate embedding for empty text");
|
|
257
|
+
}
|
|
240
258
|
try {
|
|
241
259
|
const baseURL = getBaseURL(runtime);
|
|
242
260
|
const customFetch = runtime.fetch ?? undefined;
|
|
243
261
|
const ollama = import_ollama_ai_provider_v2.createOllama({
|
|
244
|
-
fetch: customFetch,
|
|
262
|
+
...customFetch ? { fetch: customFetch } : {},
|
|
245
263
|
baseURL
|
|
246
264
|
});
|
|
247
265
|
const modelName = getEmbeddingModel(runtime);
|
|
248
266
|
import_core3.logger.log(`[Ollama] Using TEXT_EMBEDDING model: ${modelName}`);
|
|
249
267
|
await ensureModelAvailable(modelName, baseURL, customFetch);
|
|
250
|
-
let text = typeof params === "string" ? params : params ? params.text || "" : "";
|
|
251
268
|
const maxChars = 8000 * 4;
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
269
|
+
let embeddingText = isInitProbe ? INIT_PROBE_TEXT : text;
|
|
270
|
+
if (embeddingText.length > maxChars) {
|
|
271
|
+
import_core3.logger.warn(`[Ollama] Embedding input too long (~${Math.ceil(embeddingText.length / 4)} tokens), truncating to ~8000 tokens`);
|
|
272
|
+
embeddingText = embeddingText.slice(0, maxChars);
|
|
255
273
|
}
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const { embedding, usage } = await import_ai.embed(embedParams);
|
|
274
|
+
const embedParams = {
|
|
275
|
+
model: ollama.embedding(modelName),
|
|
276
|
+
value: embeddingText
|
|
277
|
+
};
|
|
278
|
+
const { embedding, usage } = await import_ai.embed(embedParams);
|
|
279
|
+
if (!isInitProbe) {
|
|
263
280
|
emitModelUsed(runtime, import_core3.ModelType.TEXT_EMBEDDING, modelName, normalizeTokenUsage(usage) ?? estimateEmbeddingUsage(embeddingText));
|
|
264
|
-
return embedding;
|
|
265
|
-
} catch (embeddingError) {
|
|
266
|
-
import_core3.logger.error({ error: embeddingError }, "Error generating embedding");
|
|
267
|
-
return Array(1536).fill(0);
|
|
268
281
|
}
|
|
282
|
+
return embedding;
|
|
269
283
|
} catch (error) {
|
|
270
284
|
import_core3.logger.error({ error }, "Error in TEXT_EMBEDDING model");
|
|
271
|
-
|
|
285
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
272
286
|
}
|
|
273
287
|
}
|
|
274
288
|
|
|
@@ -548,11 +562,11 @@ function firstString(...values) {
|
|
|
548
562
|
}
|
|
549
563
|
|
|
550
564
|
// models/text.ts
|
|
551
|
-
var TEXT_NANO_MODEL_TYPE = import_core4.ModelType.TEXT_NANO
|
|
552
|
-
var TEXT_MEDIUM_MODEL_TYPE = import_core4.ModelType.TEXT_MEDIUM
|
|
553
|
-
var TEXT_MEGA_MODEL_TYPE = import_core4.ModelType.TEXT_MEGA
|
|
554
|
-
var RESPONSE_HANDLER_MODEL_TYPE = import_core4.ModelType.RESPONSE_HANDLER
|
|
555
|
-
var ACTION_PLANNER_MODEL_TYPE = import_core4.ModelType.ACTION_PLANNER
|
|
565
|
+
var TEXT_NANO_MODEL_TYPE = import_core4.ModelType.TEXT_NANO;
|
|
566
|
+
var TEXT_MEDIUM_MODEL_TYPE = import_core4.ModelType.TEXT_MEDIUM;
|
|
567
|
+
var TEXT_MEGA_MODEL_TYPE = import_core4.ModelType.TEXT_MEGA;
|
|
568
|
+
var RESPONSE_HANDLER_MODEL_TYPE = import_core4.ModelType.RESPONSE_HANDLER;
|
|
569
|
+
var ACTION_PLANNER_MODEL_TYPE = import_core4.ModelType.ACTION_PLANNER;
|
|
556
570
|
function summarizeAiSdkErrorForLogs(error, depth = 0) {
|
|
557
571
|
if (depth > 4) {
|
|
558
572
|
return { note: "max depth summarizing nested error" };
|
|
@@ -613,7 +627,7 @@ function serializeStructuredGenerateTextResult(result) {
|
|
|
613
627
|
if (result.output !== undefined && result.output !== null) {
|
|
614
628
|
return typeof result.output === "string" ? result.output : JSON.stringify(result.output);
|
|
615
629
|
}
|
|
616
|
-
const trimmed = result.text
|
|
630
|
+
const trimmed = result.text.trim();
|
|
617
631
|
if (trimmed)
|
|
618
632
|
return trimmed;
|
|
619
633
|
throw new Error("[Ollama] Structured generation returned no text or output.");
|
|
@@ -622,7 +636,7 @@ function buildNativeResultCast(result, modelName, usage) {
|
|
|
622
636
|
const payload = {
|
|
623
637
|
text: result.text,
|
|
624
638
|
toolCalls: mapAiSdkToolCallsToCore(result.toolCalls),
|
|
625
|
-
finishReason: String(result.finishReason
|
|
639
|
+
finishReason: String(result.finishReason),
|
|
626
640
|
usage,
|
|
627
641
|
providerMetadata: { modelName }
|
|
628
642
|
};
|
|
@@ -636,9 +650,7 @@ function buildOllamaStreamTextResult(args) {
|
|
|
636
650
|
});
|
|
637
651
|
const usagePromise = Promise.resolve(streamResult.usage).then(async (usage) => {
|
|
638
652
|
const fullText = await textPromise;
|
|
639
|
-
|
|
640
|
-
emitModelUsed(args.runtime, args.modelType, args.model, normalized);
|
|
641
|
-
return normalized;
|
|
653
|
+
return normalizeTokenUsage(usage) ?? estimateUsage(args.promptForEstimate, fullText);
|
|
642
654
|
}).catch(() => {
|
|
643
655
|
return;
|
|
644
656
|
});
|
|
@@ -654,9 +666,12 @@ function buildOllamaStreamTextResult(args) {
|
|
|
654
666
|
throw streamErr;
|
|
655
667
|
} finally {
|
|
656
668
|
if (completed) {
|
|
657
|
-
await usagePromise.catch(() => {
|
|
669
|
+
const usage = await usagePromise.catch(() => {
|
|
658
670
|
return;
|
|
659
671
|
});
|
|
672
|
+
if (usage) {
|
|
673
|
+
emitModelUsed(args.runtime, args.modelType, args.model, usage);
|
|
674
|
+
}
|
|
660
675
|
}
|
|
661
676
|
}
|
|
662
677
|
}
|
|
@@ -682,9 +697,7 @@ function buildOllamaStreamWithToolsResult(args) {
|
|
|
682
697
|
const toolCallsPromise = Promise.resolve(streamResult.toolCalls).then((calls) => mapAiSdkToolCallsToCore(calls)).catch(() => []);
|
|
683
698
|
const usagePromise = Promise.resolve(streamResult.usage).then(async (usage) => {
|
|
684
699
|
const fullText = await sdkTextPromise;
|
|
685
|
-
|
|
686
|
-
emitModelUsed(args.runtime, args.modelType, args.model, normalized);
|
|
687
|
-
return normalized;
|
|
700
|
+
return normalizeTokenUsage(usage) ?? estimateUsage(args.promptForEstimate, fullText);
|
|
688
701
|
}).catch(() => {
|
|
689
702
|
return;
|
|
690
703
|
});
|
|
@@ -705,6 +718,11 @@ function buildOllamaStreamWithToolsResult(args) {
|
|
|
705
718
|
const first = mapped[0];
|
|
706
719
|
if (first) {
|
|
707
720
|
yield stringifyPlannerToolArgs(first.arguments);
|
|
721
|
+
} else {
|
|
722
|
+
const fallbackText = await sdkTextPromise;
|
|
723
|
+
if (fallbackText) {
|
|
724
|
+
yield fallbackText;
|
|
725
|
+
}
|
|
708
726
|
}
|
|
709
727
|
} else {
|
|
710
728
|
for await (const chunk of streamResult.textStream) {
|
|
@@ -717,9 +735,12 @@ function buildOllamaStreamWithToolsResult(args) {
|
|
|
717
735
|
throw streamErr;
|
|
718
736
|
} finally {
|
|
719
737
|
if (completed) {
|
|
720
|
-
await usagePromise.catch(() => {
|
|
738
|
+
const usage = await usagePromise.catch(() => {
|
|
721
739
|
return;
|
|
722
740
|
});
|
|
741
|
+
if (usage) {
|
|
742
|
+
emitModelUsed(args.runtime, args.modelType, args.model, usage);
|
|
743
|
+
}
|
|
723
744
|
}
|
|
724
745
|
}
|
|
725
746
|
}
|
|
@@ -753,26 +774,21 @@ function getModelNameForType(runtime, modelType) {
|
|
|
753
774
|
}
|
|
754
775
|
async function handleTextWithModelType(runtime, modelType, params) {
|
|
755
776
|
const extended = params;
|
|
756
|
-
const
|
|
757
|
-
|
|
758
|
-
if (structuredDisabled && extended.responseSchema) {
|
|
759
|
-
import_core4.logger.debug("[Ollama] OLLAMA_DISABLE_STRUCTURED_OUTPUT is set — ignoring responseSchema for this call.");
|
|
760
|
-
responseSchema = undefined;
|
|
761
|
-
}
|
|
762
|
-
const tools = normalizeNativeTools(extended.tools);
|
|
763
|
-
const {
|
|
764
|
-
prompt,
|
|
765
|
-
maxTokens = 8192,
|
|
766
|
-
temperature = 0.7,
|
|
767
|
-
frequencyPenalty = 0.7,
|
|
768
|
-
presencePenalty = 0.7
|
|
769
|
-
} = params;
|
|
777
|
+
const { prompt, temperature = 0.7, frequencyPenalty = 0.7, presencePenalty = 0.7 } = params;
|
|
778
|
+
const maxTokens = params.omitMaxTokens ? undefined : params.maxTokens ?? 8192;
|
|
770
779
|
let modelIdForLog = "";
|
|
771
780
|
try {
|
|
781
|
+
const structuredDisabled = isOllamaStructuredOutputDisabled(runtime);
|
|
782
|
+
let responseSchema = extended.responseSchema;
|
|
783
|
+
if (structuredDisabled && extended.responseSchema) {
|
|
784
|
+
import_core4.logger.debug("[Ollama] OLLAMA_DISABLE_STRUCTURED_OUTPUT is set — ignoring responseSchema for this call.");
|
|
785
|
+
responseSchema = undefined;
|
|
786
|
+
}
|
|
787
|
+
const tools = normalizeNativeTools(extended.tools);
|
|
772
788
|
const baseURL = getBaseURL(runtime);
|
|
773
789
|
const customFetch = runtime.fetch ?? undefined;
|
|
774
790
|
const ollama = import_ollama_ai_provider_v22.createOllama({
|
|
775
|
-
fetch: customFetch,
|
|
791
|
+
...customFetch ? { fetch: customFetch } : {},
|
|
776
792
|
baseURL
|
|
777
793
|
});
|
|
778
794
|
const model = getModelNameForType(runtime, modelType);
|
|
@@ -794,7 +810,7 @@ async function handleTextWithModelType(runtime, modelType, params) {
|
|
|
794
810
|
const toolChoice = tools ? normalizeToolChoice(extended.toolChoice) : undefined;
|
|
795
811
|
const shouldReturnNative = Boolean(hasChatMessages || tools || extended.toolChoice || outputSpec !== undefined);
|
|
796
812
|
const renderedPrompt = hasChatMessages ? "" : import_core4.renderChatMessagesForPrompt(params.messages, {
|
|
797
|
-
omitDuplicateSystem: system
|
|
813
|
+
...system ? { omitDuplicateSystem: system } : {}
|
|
798
814
|
}) ?? prompt ?? "";
|
|
799
815
|
const promptOrMessages = hasChatMessages ? { messages: normalizedMessages } : { prompt: renderedPrompt };
|
|
800
816
|
const resolvedStopSequences = Array.isArray(params.stopSequences) && params.stopSequences.length > 0 ? params.stopSequences : undefined;
|
|
@@ -804,9 +820,9 @@ async function handleTextWithModelType(runtime, modelType, params) {
|
|
|
804
820
|
...promptOrMessages,
|
|
805
821
|
system,
|
|
806
822
|
temperature,
|
|
807
|
-
maxOutputTokens: maxTokens,
|
|
808
823
|
frequencyPenalty,
|
|
809
824
|
presencePenalty,
|
|
825
|
+
...typeof maxTokens === "number" ? { maxOutputTokens: maxTokens } : {},
|
|
810
826
|
...resolvedStopSequences ? { stopSequences: resolvedStopSequences } : {},
|
|
811
827
|
...tools ? { tools, ...toolChoice ? { toolChoice } : {} } : {},
|
|
812
828
|
...outputSpec ? { output: outputSpec } : {}
|
|
@@ -854,7 +870,7 @@ async function handleTextWithModelType(runtime, modelType, params) {
|
|
|
854
870
|
endpoint = getBaseURL(runtime);
|
|
855
871
|
} catch {}
|
|
856
872
|
logOllamaTextFailure("generateText", String(modelType), modelIdForLog || "(unknown)", endpoint, error);
|
|
857
|
-
|
|
873
|
+
throw error;
|
|
858
874
|
}
|
|
859
875
|
}
|
|
860
876
|
async function handleTextSmall(runtime, params) {
|
|
@@ -889,11 +905,11 @@ function getProcessEnv() {
|
|
|
889
905
|
return process.env;
|
|
890
906
|
}
|
|
891
907
|
var env = getProcessEnv();
|
|
892
|
-
var TEXT_NANO_MODEL_TYPE2 = import_core5.ModelType.TEXT_NANO
|
|
893
|
-
var TEXT_MEDIUM_MODEL_TYPE2 = import_core5.ModelType.TEXT_MEDIUM
|
|
894
|
-
var TEXT_MEGA_MODEL_TYPE2 = import_core5.ModelType.TEXT_MEGA
|
|
895
|
-
var RESPONSE_HANDLER_MODEL_TYPE2 = import_core5.ModelType.RESPONSE_HANDLER
|
|
896
|
-
var ACTION_PLANNER_MODEL_TYPE2 = import_core5.ModelType.ACTION_PLANNER
|
|
908
|
+
var TEXT_NANO_MODEL_TYPE2 = import_core5.ModelType.TEXT_NANO;
|
|
909
|
+
var TEXT_MEDIUM_MODEL_TYPE2 = import_core5.ModelType.TEXT_MEDIUM;
|
|
910
|
+
var TEXT_MEGA_MODEL_TYPE2 = import_core5.ModelType.TEXT_MEGA;
|
|
911
|
+
var RESPONSE_HANDLER_MODEL_TYPE2 = import_core5.ModelType.RESPONSE_HANDLER;
|
|
912
|
+
var ACTION_PLANNER_MODEL_TYPE2 = import_core5.ModelType.ACTION_PLANNER;
|
|
897
913
|
var ollamaPlugin = {
|
|
898
914
|
name: "ollama",
|
|
899
915
|
description: "Ollama plugin for local LLM inference",
|
|
@@ -933,7 +949,8 @@ var ollamaPlugin = {
|
|
|
933
949
|
}
|
|
934
950
|
}
|
|
935
951
|
try {
|
|
936
|
-
const
|
|
952
|
+
const fetchImpl = runtime.fetch ?? fetch;
|
|
953
|
+
const response = await fetchImpl(`${apiBase}/api/tags`, {
|
|
937
954
|
method: "GET",
|
|
938
955
|
headers: { "Content-Type": "application/json" }
|
|
939
956
|
});
|
|
@@ -1087,5 +1104,5 @@ var ollamaPlugin = {
|
|
|
1087
1104
|
var defaultOllamaPlugin = ollamaPlugin;
|
|
1088
1105
|
var index_node_default = defaultOllamaPlugin;
|
|
1089
1106
|
|
|
1090
|
-
//# debugId=
|
|
1107
|
+
//# debugId=88040C7A9C8949A364756E2164756E21
|
|
1091
1108
|
//# sourceMappingURL=index.node.cjs.map
|