@elizaos/plugin-ollama 1.2.3 → 2.0.0-alpha.1
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/dist/browser/index.browser.js +424 -0
- package/dist/browser/index.browser.js.map +15 -0
- package/dist/browser/index.d.ts +2 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.node.cjs +456 -0
- package/dist/cjs/index.node.cjs.map +15 -0
- package/dist/node/build.d.ts +2 -0
- package/dist/node/build.d.ts.map +1 -0
- package/dist/node/generated/specs/specs.d.ts +55 -0
- package/dist/node/generated/specs/specs.d.ts.map +1 -0
- package/dist/node/index.browser.d.ts +3 -0
- package/dist/node/index.browser.d.ts.map +1 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.node.js +424 -0
- package/dist/node/index.node.js.map +15 -0
- package/dist/node/models/availability.d.ts +2 -0
- package/dist/node/models/availability.d.ts.map +1 -0
- package/dist/node/models/embedding.d.ts +3 -0
- package/dist/node/models/embedding.d.ts.map +1 -0
- package/dist/node/models/index.d.ts +5 -0
- package/dist/node/models/index.d.ts.map +1 -0
- package/dist/node/models/object.d.ts +4 -0
- package/dist/node/models/object.d.ts.map +1 -0
- package/dist/node/models/text.d.ts +4 -0
- package/dist/node/models/text.d.ts.map +1 -0
- package/dist/node/plugin.d.ts +3 -0
- package/dist/node/plugin.d.ts.map +1 -0
- package/dist/node/types/index.d.ts +47 -0
- package/dist/node/types/index.d.ts.map +1 -0
- package/dist/node/utils/config.d.ts +15 -0
- package/dist/node/utils/config.d.ts.map +1 -0
- package/dist/node/utils/index.d.ts +2 -0
- package/dist/node/utils/index.d.ts.map +1 -0
- package/package.json +41 -24
- package/LICENSE +0 -21
- package/README.md +0 -160
- package/dist/index.js +0 -367
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-ollama",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "dist/node/index.node.js",
|
|
6
|
+
"module": "dist/node/index.node.js",
|
|
7
|
+
"types": "dist/node/index.d.ts",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/elizaos-plugins/plugin-ollama.git"
|
|
@@ -12,32 +12,54 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
"./package.json": "./package.json",
|
|
14
14
|
".": {
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
15
|
+
"types": "./dist/node/index.d.ts",
|
|
16
|
+
"browser": {
|
|
17
|
+
"types": "./dist/browser/index.d.ts",
|
|
18
|
+
"import": "./dist/browser/index.browser.js",
|
|
19
|
+
"default": "./dist/browser/index.browser.js"
|
|
20
|
+
},
|
|
21
|
+
"node": {
|
|
22
|
+
"types": "./dist/node/index.d.ts",
|
|
23
|
+
"import": "./dist/node/index.node.js",
|
|
24
|
+
"default": "./dist/node/index.node.js"
|
|
25
|
+
},
|
|
26
|
+
"bun": {
|
|
27
|
+
"types": "./dist/node/index.d.ts",
|
|
28
|
+
"default": "./dist/node/index.node.js"
|
|
29
|
+
},
|
|
30
|
+
"require": "./dist/cjs/index.node.cjs",
|
|
31
|
+
"default": "./dist/node/index.node.js"
|
|
19
32
|
}
|
|
20
33
|
},
|
|
21
34
|
"files": [
|
|
22
35
|
"dist"
|
|
23
36
|
],
|
|
37
|
+
"sideEffects": false,
|
|
24
38
|
"dependencies": {
|
|
25
39
|
"@ai-sdk/ui-utils": "^1.2.8",
|
|
26
|
-
"@elizaos/core": "
|
|
40
|
+
"@elizaos/core": "workspace:*",
|
|
27
41
|
"ai": "^4.3.9",
|
|
28
42
|
"js-tiktoken": "^1.0.18",
|
|
29
|
-
"ollama-ai-provider": "^1.2.0"
|
|
30
|
-
|
|
43
|
+
"ollama-ai-provider": "^1.2.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^25.0.3",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"@biomejs/biome": "^2.3.11"
|
|
31
49
|
},
|
|
32
50
|
"scripts": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"lint": "prettier --write ./src",
|
|
51
|
+
"dev": "bun run build.ts --watch",
|
|
52
|
+
"lint": "bunx @biomejs/biome check --write --unsafe .",
|
|
36
53
|
"clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo",
|
|
37
|
-
"format": "
|
|
38
|
-
"format:check": "
|
|
39
|
-
"
|
|
40
|
-
"
|
|
54
|
+
"format": "bunx @biomejs/biome format --write .",
|
|
55
|
+
"format:check": "bunx @biomejs/biome format .",
|
|
56
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:unit": "vitest run __tests__/",
|
|
59
|
+
"postinstall": "bun scripts/install-ollama.js",
|
|
60
|
+
"lint:check": "bunx @biomejs/biome check .",
|
|
61
|
+
"build": "bun run build.ts",
|
|
62
|
+
"build:ts": "bun run build.ts"
|
|
41
63
|
},
|
|
42
64
|
"publishConfig": {
|
|
43
65
|
"access": "public"
|
|
@@ -95,10 +117,5 @@
|
|
|
95
117
|
}
|
|
96
118
|
}
|
|
97
119
|
},
|
|
98
|
-
"gitHead": "646c632924826e2b75c2304a75ee56959fe4a460"
|
|
99
|
-
"devDependencies": {
|
|
100
|
-
"@types/node": "^24.0.4",
|
|
101
|
-
"prettier": "3.5.3",
|
|
102
|
-
"typescript": "^5.8.2"
|
|
103
|
-
}
|
|
120
|
+
"gitHead": "646c632924826e2b75c2304a75ee56959fe4a460"
|
|
104
121
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Shaw Walters and elizaOS Contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# Ollama Plugin
|
|
2
|
-
|
|
3
|
-
This plugin provides integration with [Ollama](https://ollama.com/)'s local models through the ElizaOS platform. It allows you to leverage locally running LLMs for text generation, embeddings, and object generation.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
Ollama enables running large language models locally on your machine. This plugin connects ElizaOS with your local Ollama installation, giving your characters access to powerful language models running on your own hardware.
|
|
8
|
-
|
|
9
|
-
## Requirements
|
|
10
|
-
|
|
11
|
-
- [Ollama](https://ollama.com/) installed and running on your system
|
|
12
|
-
- ElizaOS platform
|
|
13
|
-
- At least one Ollama model pulled and available (e.g., `llama3`, `gemma3:latest`)
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
1. Install this plugin in your ElizaOS project:
|
|
18
|
-
```bash
|
|
19
|
-
bun add @elizaos-plugins/plugin-ollama
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
2. Make sure Ollama is running:
|
|
23
|
-
```bash
|
|
24
|
-
ollama serve
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
Add the plugin to your character configuration:
|
|
30
|
-
|
|
31
|
-
```json
|
|
32
|
-
"plugins": ["@elizaos-plugins/plugin-ollama"]
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Configuration
|
|
36
|
-
|
|
37
|
-
The plugin requires these environment variables (can be set in .env file or character settings):
|
|
38
|
-
|
|
39
|
-
```json
|
|
40
|
-
"settings": {
|
|
41
|
-
"OLLAMA_API_ENDPOINT": "http://localhost:11434/api",
|
|
42
|
-
"OLLAMA_SMALL_MODEL": "gemma3:latest",
|
|
43
|
-
"OLLAMA_MEDIUM_MODEL": "gemma3:latest",
|
|
44
|
-
"OLLAMA_LARGE_MODEL": "gemma3:latest",
|
|
45
|
-
"OLLAMA_EMBEDDING_MODEL": "nomic-embed-text:latest"
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Or in `.env` file:
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
OLLAMA_API_ENDPOINT=http://localhost:11434/api
|
|
53
|
-
OLLAMA_SMALL_MODEL=gemma3:latest
|
|
54
|
-
OLLAMA_MEDIUM_MODEL=gemma3:latest
|
|
55
|
-
OLLAMA_LARGE_MODEL=gemma3:latest
|
|
56
|
-
OLLAMA_EMBEDDING_MODEL=nomic-embed-text:latest
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Configuration Options
|
|
60
|
-
|
|
61
|
-
- `OLLAMA_API_ENDPOINT`: Ollama API endpoint (default: http://localhost:11434/api)
|
|
62
|
-
- `OLLAMA_SMALL_MODEL`: Model for simpler tasks (default: gemma3:latest)
|
|
63
|
-
- `OLLAMA_MEDIUM_MODEL`: Medium-complexity model (default: gemma3:latest)
|
|
64
|
-
- `OLLAMA_LARGE_MODEL`: Model for complex tasks (default: gemma3:latest)
|
|
65
|
-
- `OLLAMA_EMBEDDING_MODEL`: Model for text embeddings (default: nomic-embed-text:latest)
|
|
66
|
-
|
|
67
|
-
The plugin provides these model classes:
|
|
68
|
-
|
|
69
|
-
- `TEXT_SMALL`: Optimized for fast responses with simpler prompts
|
|
70
|
-
- `TEXT_LARGE`: For complex tasks requiring deeper reasoning
|
|
71
|
-
- `TEXT_EMBEDDING`: Text embedding model
|
|
72
|
-
- `OBJECT_SMALL`: JSON object generation with simpler models
|
|
73
|
-
- `OBJECT_LARGE`: JSON object generation with more complex models
|
|
74
|
-
|
|
75
|
-
## API Reference
|
|
76
|
-
|
|
77
|
-
For detailed information about the Ollama API used by this plugin, refer to the [official Ollama API documentation](https://github.com/ollama/ollama/blob/main/docs/api.md).
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
## Features
|
|
82
|
-
|
|
83
|
-
### Text Generation (Small Model)
|
|
84
|
-
|
|
85
|
-
Generate text using smaller, faster models optimized for quick responses:
|
|
86
|
-
|
|
87
|
-
```js
|
|
88
|
-
const text = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
89
|
-
prompt: 'What is the nature of reality?',
|
|
90
|
-
stopSequences: [], // optional
|
|
91
|
-
});
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Text Generation (Large Model)
|
|
95
|
-
|
|
96
|
-
Generate comprehensive text responses using more powerful models for complex tasks:
|
|
97
|
-
|
|
98
|
-
```js
|
|
99
|
-
const text = await runtime.useModel(ModelType.TEXT_LARGE, {
|
|
100
|
-
prompt: 'Write a detailed explanation of quantum physics',
|
|
101
|
-
stopSequences: [], // optional
|
|
102
|
-
maxTokens: 8192, // optional (default: 8192)
|
|
103
|
-
temperature: 0.7, // optional (default: 0.7)
|
|
104
|
-
frequencyPenalty: 0.7, // optional (default: 0.7)
|
|
105
|
-
presencePenalty: 0.7, // optional (default: 0.7)
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Text Embeddings
|
|
110
|
-
|
|
111
|
-
Generate vector embeddings for text, which can be used for semantic search or other vector operations:
|
|
112
|
-
|
|
113
|
-
```js
|
|
114
|
-
const embedding = await runtime.useModel(ModelType.TEXT_EMBEDDING, {
|
|
115
|
-
text: 'Text to embed',
|
|
116
|
-
});
|
|
117
|
-
// or
|
|
118
|
-
const embedding = await runtime.useModel(ModelType.TEXT_EMBEDDING, 'Text to embed');
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Object Generation (Small Model)
|
|
122
|
-
|
|
123
|
-
Generate structured JSON objects using faster models:
|
|
124
|
-
|
|
125
|
-
```js
|
|
126
|
-
const object = await runtime.useModel(ModelType.OBJECT_SMALL, {
|
|
127
|
-
prompt: 'Generate a JSON object representing a user profile',
|
|
128
|
-
temperature: 0.7, // optional
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Object Generation (Large Model)
|
|
133
|
-
|
|
134
|
-
Generate complex, detailed JSON objects using more powerful models:
|
|
135
|
-
|
|
136
|
-
```js
|
|
137
|
-
const object = await runtime.useModel(ModelType.OBJECT_LARGE, {
|
|
138
|
-
prompt: 'Generate a detailed JSON object representing a restaurant',
|
|
139
|
-
temperature: 0.7, // optional
|
|
140
|
-
});
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Troubleshooting
|
|
144
|
-
|
|
145
|
-
### Connection Issues
|
|
146
|
-
|
|
147
|
-
- Ensure Ollama is running by testing the `OLLAMA_API_ENDPOINT`
|
|
148
|
-
- Verify the `OLLAMA_API_ENDPOINT` points to the correct host and port
|
|
149
|
-
- Check firewall settings if connecting to a remote Ollama instance
|
|
150
|
-
|
|
151
|
-
### Model Availability
|
|
152
|
-
|
|
153
|
-
- The plugin will attempt to download models automatically if they're not found
|
|
154
|
-
- You can pre-download models using `ollama pull modelname`
|
|
155
|
-
- Check model availability with `ollama list`
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
## License
|
|
159
|
-
|
|
160
|
-
See LICENSE file for details.
|
package/dist/index.js
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { ModelType, logger } from "@elizaos/core";
|
|
3
|
-
import { generateObject, generateText, embed } from "ai";
|
|
4
|
-
import { createOllama } from "ollama-ai-provider";
|
|
5
|
-
var OLLAMA_API_URL = "http://localhost:11434/api";
|
|
6
|
-
function getBaseURL(runtime) {
|
|
7
|
-
const apiEndpoint = runtime.getSetting("OLLAMA_API_ENDPOINT") || runtime.getSetting("OLLAMA_API_URL") || OLLAMA_API_URL;
|
|
8
|
-
if (!apiEndpoint.endsWith("/api")) {
|
|
9
|
-
return apiEndpoint.endsWith("/") ? `${apiEndpoint}api` : `${apiEndpoint}/api`;
|
|
10
|
-
}
|
|
11
|
-
return apiEndpoint;
|
|
12
|
-
}
|
|
13
|
-
async function ensureModelAvailable(runtime, model, providedBaseURL) {
|
|
14
|
-
const baseURL = providedBaseURL || getBaseURL(runtime);
|
|
15
|
-
const apiBase = baseURL.endsWith("/api") ? baseURL.slice(0, -4) : baseURL;
|
|
16
|
-
try {
|
|
17
|
-
const showRes = await fetch(`${apiBase}/api/show`, {
|
|
18
|
-
method: "POST",
|
|
19
|
-
headers: { "Content-Type": "application/json" },
|
|
20
|
-
body: JSON.stringify({ model })
|
|
21
|
-
});
|
|
22
|
-
if (showRes.ok) return;
|
|
23
|
-
logger.info(`[Ollama] Model ${model} not found locally. Downloading...`);
|
|
24
|
-
const pullRes = await fetch(`${apiBase}/api/pull`, {
|
|
25
|
-
method: "POST",
|
|
26
|
-
headers: { "Content-Type": "application/json" },
|
|
27
|
-
body: JSON.stringify({ model, stream: false })
|
|
28
|
-
});
|
|
29
|
-
if (!pullRes.ok) {
|
|
30
|
-
logger.error(`Failed to pull model ${model}: ${pullRes.statusText}`);
|
|
31
|
-
} else {
|
|
32
|
-
logger.info(`[Ollama] Downloaded model ${model}`);
|
|
33
|
-
}
|
|
34
|
-
} catch (err) {
|
|
35
|
-
logger.error("Error ensuring model availability:", err);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async function generateOllamaText(ollama, model, params) {
|
|
39
|
-
try {
|
|
40
|
-
const { text: ollamaResponse } = await generateText({
|
|
41
|
-
model: ollama(model),
|
|
42
|
-
prompt: params.prompt,
|
|
43
|
-
system: params.system,
|
|
44
|
-
temperature: params.temperature,
|
|
45
|
-
maxTokens: params.maxTokens,
|
|
46
|
-
frequencyPenalty: params.frequencyPenalty,
|
|
47
|
-
presencePenalty: params.presencePenalty,
|
|
48
|
-
stopSequences: params.stopSequences
|
|
49
|
-
});
|
|
50
|
-
return ollamaResponse;
|
|
51
|
-
} catch (error) {
|
|
52
|
-
logger.error("Error in generateOllamaText:", error);
|
|
53
|
-
return "Error generating text. Please try again later.";
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function generateOllamaObject(ollama, model, params) {
|
|
57
|
-
try {
|
|
58
|
-
const { object } = await generateObject({
|
|
59
|
-
model: ollama(model),
|
|
60
|
-
output: "no-schema",
|
|
61
|
-
prompt: params.prompt,
|
|
62
|
-
temperature: params.temperature
|
|
63
|
-
});
|
|
64
|
-
return object;
|
|
65
|
-
} catch (error) {
|
|
66
|
-
logger.error("Error generating object:", error);
|
|
67
|
-
return {};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
var ollamaPlugin = {
|
|
71
|
-
name: "ollama",
|
|
72
|
-
description: "Ollama plugin",
|
|
73
|
-
config: {
|
|
74
|
-
OLLAMA_API_ENDPOINT: process.env.OLLAMA_API_ENDPOINT,
|
|
75
|
-
OLLAMA_SMALL_MODEL: process.env.OLLAMA_SMALL_MODEL,
|
|
76
|
-
OLLAMA_MEDIUM_MODEL: process.env.OLLAMA_MEDIUM_MODEL,
|
|
77
|
-
OLLAMA_LARGE_MODEL: process.env.OLLAMA_LARGE_MODEL,
|
|
78
|
-
OLLAMA_EMBEDDING_MODEL: process.env.OLLAMA_EMBEDDING_MODEL
|
|
79
|
-
},
|
|
80
|
-
async init(_config, runtime) {
|
|
81
|
-
const baseURL = getBaseURL(runtime);
|
|
82
|
-
if (!baseURL || baseURL === "http://localhost:11434/api") {
|
|
83
|
-
const endpoint = runtime.getSetting("OLLAMA_API_ENDPOINT");
|
|
84
|
-
if (!endpoint) {
|
|
85
|
-
logger.warn(
|
|
86
|
-
"OLLAMA_API_ENDPOINT is not set in environment - Ollama functionality will use default localhost:11434"
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
const apiBase = baseURL.endsWith("/api") ? baseURL.slice(0, -4) : baseURL;
|
|
92
|
-
const response = await fetch(`${apiBase}/api/tags`, {
|
|
93
|
-
method: "GET",
|
|
94
|
-
headers: { "Content-Type": "application/json" }
|
|
95
|
-
});
|
|
96
|
-
if (!response.ok) {
|
|
97
|
-
logger.warn(
|
|
98
|
-
`Ollama API endpoint validation failed: ${response.statusText}`
|
|
99
|
-
);
|
|
100
|
-
logger.warn(
|
|
101
|
-
"Ollama functionality will be limited until a valid endpoint is provided"
|
|
102
|
-
);
|
|
103
|
-
} else {
|
|
104
|
-
const data = await response.json();
|
|
105
|
-
const modelCount = data?.models?.length || 0;
|
|
106
|
-
logger.log(
|
|
107
|
-
`Ollama API endpoint validated successfully. Found ${modelCount} models available.`
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
} catch (fetchError) {
|
|
111
|
-
const message = fetchError instanceof Error ? fetchError.message : String(fetchError);
|
|
112
|
-
logger.warn(`Error validating Ollama API endpoint: ${message}`);
|
|
113
|
-
logger.warn(
|
|
114
|
-
"Ollama functionality will be limited until a valid endpoint is provided - Make sure Ollama is running at ${baseURL}"
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
models: {
|
|
119
|
-
[ModelType.TEXT_EMBEDDING]: async (runtime, params) => {
|
|
120
|
-
try {
|
|
121
|
-
const baseURL = getBaseURL(runtime);
|
|
122
|
-
const ollama = createOllama({
|
|
123
|
-
fetch: runtime.fetch,
|
|
124
|
-
baseURL
|
|
125
|
-
});
|
|
126
|
-
const modelName = runtime.getSetting("OLLAMA_EMBEDDING_MODEL") || "nomic-embed-text:latest";
|
|
127
|
-
logger.log(`[Ollama] Using TEXT_EMBEDDING model: ${modelName}`);
|
|
128
|
-
await ensureModelAvailable(runtime, modelName, baseURL);
|
|
129
|
-
const text = typeof params === "string" ? params : params ? params.text || "" : "";
|
|
130
|
-
const embeddingText = text || "test";
|
|
131
|
-
if (!text) {
|
|
132
|
-
logger.debug(
|
|
133
|
-
"No text provided for embedding, using default text for dimension detection"
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
const { embedding } = await embed({
|
|
138
|
-
model: ollama.embedding(modelName),
|
|
139
|
-
value: embeddingText
|
|
140
|
-
});
|
|
141
|
-
return embedding;
|
|
142
|
-
} catch (embeddingError) {
|
|
143
|
-
logger.error("Error generating embedding:", embeddingError);
|
|
144
|
-
return Array(1536).fill(0);
|
|
145
|
-
}
|
|
146
|
-
} catch (error) {
|
|
147
|
-
logger.error("Error in TEXT_EMBEDDING model:", error);
|
|
148
|
-
return Array(1536).fill(0);
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
[ModelType.TEXT_SMALL]: async (runtime, { prompt, stopSequences = [] }) => {
|
|
152
|
-
try {
|
|
153
|
-
const temperature = 0.7;
|
|
154
|
-
const frequency_penalty = 0.7;
|
|
155
|
-
const presence_penalty = 0.7;
|
|
156
|
-
const max_response_length = 8e3;
|
|
157
|
-
const baseURL = getBaseURL(runtime);
|
|
158
|
-
const ollama = createOllama({
|
|
159
|
-
fetch: runtime.fetch,
|
|
160
|
-
baseURL
|
|
161
|
-
});
|
|
162
|
-
const model = runtime.getSetting("OLLAMA_SMALL_MODEL") || runtime.getSetting("SMALL_MODEL") || "gemma3:latest";
|
|
163
|
-
logger.log(`[Ollama] Using TEXT_SMALL model: ${model}`);
|
|
164
|
-
await ensureModelAvailable(runtime, model, baseURL);
|
|
165
|
-
logger.log("generating text");
|
|
166
|
-
logger.log(prompt);
|
|
167
|
-
return await generateOllamaText(ollama, model, {
|
|
168
|
-
prompt,
|
|
169
|
-
system: runtime.character?.system || void 0,
|
|
170
|
-
temperature,
|
|
171
|
-
maxTokens: max_response_length,
|
|
172
|
-
frequencyPenalty: frequency_penalty,
|
|
173
|
-
presencePenalty: presence_penalty,
|
|
174
|
-
stopSequences
|
|
175
|
-
});
|
|
176
|
-
} catch (error) {
|
|
177
|
-
logger.error("Error in TEXT_SMALL model:", error);
|
|
178
|
-
return "Error generating text. Please try again later.";
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
[ModelType.TEXT_LARGE]: async (runtime, {
|
|
182
|
-
prompt,
|
|
183
|
-
stopSequences = [],
|
|
184
|
-
maxTokens = 8192,
|
|
185
|
-
temperature = 0.7,
|
|
186
|
-
frequencyPenalty = 0.7,
|
|
187
|
-
presencePenalty = 0.7
|
|
188
|
-
}) => {
|
|
189
|
-
try {
|
|
190
|
-
const model = runtime.getSetting("OLLAMA_LARGE_MODEL") || runtime.getSetting("LARGE_MODEL") || "gemma3:latest";
|
|
191
|
-
const baseURL = getBaseURL(runtime);
|
|
192
|
-
const ollama = createOllama({
|
|
193
|
-
fetch: runtime.fetch,
|
|
194
|
-
baseURL
|
|
195
|
-
});
|
|
196
|
-
logger.log(`[Ollama] Using TEXT_LARGE model: ${model}`);
|
|
197
|
-
await ensureModelAvailable(runtime, model, baseURL);
|
|
198
|
-
return await generateOllamaText(ollama, model, {
|
|
199
|
-
prompt,
|
|
200
|
-
system: runtime.character?.system || void 0,
|
|
201
|
-
temperature,
|
|
202
|
-
maxTokens,
|
|
203
|
-
frequencyPenalty,
|
|
204
|
-
presencePenalty,
|
|
205
|
-
stopSequences
|
|
206
|
-
});
|
|
207
|
-
} catch (error) {
|
|
208
|
-
logger.error("Error in TEXT_LARGE model:", error);
|
|
209
|
-
return "Error generating text. Please try again later.";
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
[ModelType.OBJECT_SMALL]: async (runtime, params) => {
|
|
213
|
-
try {
|
|
214
|
-
const baseURL = getBaseURL(runtime);
|
|
215
|
-
const ollama = createOllama({
|
|
216
|
-
fetch: runtime.fetch,
|
|
217
|
-
baseURL
|
|
218
|
-
});
|
|
219
|
-
const model = runtime.getSetting("OLLAMA_SMALL_MODEL") || runtime.getSetting("SMALL_MODEL") || "gemma3:latest";
|
|
220
|
-
logger.log(`[Ollama] Using OBJECT_SMALL model: ${model}`);
|
|
221
|
-
await ensureModelAvailable(runtime, model, baseURL);
|
|
222
|
-
if (params.schema) {
|
|
223
|
-
logger.info("Using OBJECT_SMALL without schema validation");
|
|
224
|
-
}
|
|
225
|
-
return await generateOllamaObject(ollama, model, params);
|
|
226
|
-
} catch (error) {
|
|
227
|
-
logger.error("Error in OBJECT_SMALL model:", error);
|
|
228
|
-
return {};
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
[ModelType.OBJECT_LARGE]: async (runtime, params) => {
|
|
232
|
-
try {
|
|
233
|
-
const baseURL = getBaseURL(runtime);
|
|
234
|
-
const ollama = createOllama({
|
|
235
|
-
fetch: runtime.fetch,
|
|
236
|
-
baseURL
|
|
237
|
-
});
|
|
238
|
-
const model = runtime.getSetting("OLLAMA_LARGE_MODEL") || runtime.getSetting("LARGE_MODEL") || "gemma3:latest";
|
|
239
|
-
logger.log(`[Ollama] Using OBJECT_LARGE model: ${model}`);
|
|
240
|
-
await ensureModelAvailable(runtime, model, baseURL);
|
|
241
|
-
if (params.schema) {
|
|
242
|
-
logger.info("Using OBJECT_LARGE without schema validation");
|
|
243
|
-
}
|
|
244
|
-
return await generateOllamaObject(ollama, model, params);
|
|
245
|
-
} catch (error) {
|
|
246
|
-
logger.error("Error in OBJECT_LARGE model:", error);
|
|
247
|
-
return {};
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
tests: [
|
|
252
|
-
{
|
|
253
|
-
name: "ollama_plugin_tests",
|
|
254
|
-
tests: [
|
|
255
|
-
{
|
|
256
|
-
name: "ollama_test_url_validation",
|
|
257
|
-
fn: async (runtime) => {
|
|
258
|
-
try {
|
|
259
|
-
const baseURL = getBaseURL(runtime);
|
|
260
|
-
const apiBase = baseURL.endsWith("/api") ? baseURL.slice(0, -4) : baseURL;
|
|
261
|
-
const response = await fetch(`${apiBase}/api/tags`);
|
|
262
|
-
const data = await response.json();
|
|
263
|
-
logger.log(
|
|
264
|
-
"Models Available:",
|
|
265
|
-
data && typeof data === "object" && "models" in data && Array.isArray(data.models) ? data.models.length : 0
|
|
266
|
-
);
|
|
267
|
-
if (!response.ok) {
|
|
268
|
-
logger.error(
|
|
269
|
-
`Failed to validate Ollama API: ${response.statusText}`
|
|
270
|
-
);
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
} catch (error) {
|
|
274
|
-
logger.error("Error in ollama_test_url_validation:", error);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
name: "ollama_test_text_embedding",
|
|
280
|
-
fn: async (runtime) => {
|
|
281
|
-
try {
|
|
282
|
-
const embedding = await runtime.useModel(
|
|
283
|
-
ModelType.TEXT_EMBEDDING,
|
|
284
|
-
{
|
|
285
|
-
text: "Hello, world!"
|
|
286
|
-
}
|
|
287
|
-
);
|
|
288
|
-
logger.log("embedding", embedding);
|
|
289
|
-
} catch (error) {
|
|
290
|
-
logger.error("Error in test_text_embedding:", error);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
name: "ollama_test_text_large",
|
|
296
|
-
fn: async (runtime) => {
|
|
297
|
-
try {
|
|
298
|
-
const text = await runtime.useModel(ModelType.TEXT_LARGE, {
|
|
299
|
-
prompt: "What is the nature of reality in 10 words?"
|
|
300
|
-
});
|
|
301
|
-
if (text.length === 0) {
|
|
302
|
-
logger.error("Failed to generate text");
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
logger.log("generated with test_text_large:", text);
|
|
306
|
-
} catch (error) {
|
|
307
|
-
logger.error("Error in test_text_large:", error);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
name: "ollama_test_text_small",
|
|
313
|
-
fn: async (runtime) => {
|
|
314
|
-
try {
|
|
315
|
-
const text = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
316
|
-
prompt: "What is the nature of reality in 10 words?"
|
|
317
|
-
});
|
|
318
|
-
if (text.length === 0) {
|
|
319
|
-
logger.error("Failed to generate text");
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
logger.log("generated with test_text_small:", text);
|
|
323
|
-
} catch (error) {
|
|
324
|
-
logger.error("Error in test_text_small:", error);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
name: "ollama_test_object_small",
|
|
330
|
-
fn: async (runtime) => {
|
|
331
|
-
try {
|
|
332
|
-
const object = await runtime.useModel(ModelType.OBJECT_SMALL, {
|
|
333
|
-
prompt: "Generate a JSON object representing a user profile with name, age, and hobbies",
|
|
334
|
-
temperature: 0.7,
|
|
335
|
-
schema: void 0
|
|
336
|
-
});
|
|
337
|
-
logger.log("Generated object:", object);
|
|
338
|
-
} catch (error) {
|
|
339
|
-
logger.error("Error in test_object_small:", error);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
name: "ollama_test_object_large",
|
|
345
|
-
fn: async (runtime) => {
|
|
346
|
-
try {
|
|
347
|
-
const object = await runtime.useModel(ModelType.OBJECT_LARGE, {
|
|
348
|
-
prompt: "Generate a detailed JSON object representing a restaurant with name, cuisine type, menu items with prices, and customer reviews",
|
|
349
|
-
temperature: 0.7,
|
|
350
|
-
schema: void 0
|
|
351
|
-
});
|
|
352
|
-
logger.log("Generated object:", object);
|
|
353
|
-
} catch (error) {
|
|
354
|
-
logger.error("Error in test_object_large:", error);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
]
|
|
359
|
-
}
|
|
360
|
-
]
|
|
361
|
-
};
|
|
362
|
-
var index_default = ollamaPlugin;
|
|
363
|
-
export {
|
|
364
|
-
index_default as default,
|
|
365
|
-
ollamaPlugin
|
|
366
|
-
};
|
|
367
|
-
//# sourceMappingURL=index.js.map
|