@agentic-kit/ollama 1.0.0 → 1.0.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/LICENSE +22 -0
- package/README.md +36 -0
- package/package.json +4 -2
- package/CHANGELOG.md +0 -28
- package/__tests__/first.test.ts +0 -188
- package/dist/README.md +0 -123
- package/dist/package.json +0 -34
- package/jest.config.js +0 -19
- package/jest.setup.js +0 -4
- package/src/index.ts +0 -224
- package/tsconfig.esm.json +0 -9
- package/tsconfig.json +0 -9
- /package/{dist/esm → esm}/index.js +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2025 Constructive <developers@constructive.io>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ A JavaScript/TypeScript client for the Ollama LLM server, supporting model listi
|
|
|
20
20
|
npm install @agentic-kit/ollama
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
|
|
23
24
|
## Usage
|
|
24
25
|
|
|
25
26
|
```typescript
|
|
@@ -86,3 +87,38 @@ interface GenerateInput {
|
|
|
86
87
|
## Contributing
|
|
87
88
|
|
|
88
89
|
Please open issues or pull requests on [GitHub](https://github.com/constructive-io/agentic-kit).
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Related Constructive Tooling
|
|
94
|
+
|
|
95
|
+
### 🤖 AI & Agent Development
|
|
96
|
+
|
|
97
|
+
* [agentic-kit](https://github.com/constructive-io/agentic-kit): **🧰 Provider-agnostic LLM adapter** with streaming and multi-turn support. Swap between Anthropic, OpenAI, Ollama, and any OpenAI-compatible endpoint.
|
|
98
|
+
|
|
99
|
+
### 📦 Package Management
|
|
100
|
+
|
|
101
|
+
* [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
|
|
102
|
+
|
|
103
|
+
### 🧪 Testing
|
|
104
|
+
|
|
105
|
+
* [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
|
|
106
|
+
* [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **🌱 PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
|
|
107
|
+
* [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
|
|
108
|
+
|
|
109
|
+
### 🧠 Parsing & AST
|
|
110
|
+
|
|
111
|
+
* [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
112
|
+
* [libpg-query-node](https://www.npmjs.com/package/libpg-query): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
113
|
+
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
|
|
114
|
+
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
|
|
115
|
+
|
|
116
|
+
## Credits
|
|
117
|
+
|
|
118
|
+
**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
|
|
119
|
+
|
|
120
|
+
## Disclaimer
|
|
121
|
+
|
|
122
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
123
|
+
|
|
124
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentic-kit/ollama",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "Ollama",
|
|
6
6
|
"main": "index.js",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"clean": "makage clean",
|
|
24
|
+
"prepack": "npm run build",
|
|
24
25
|
"build": "makage build",
|
|
25
26
|
"build:dev": "makage build --dev",
|
|
26
27
|
"lint": "eslint . --fix",
|
|
@@ -30,5 +31,6 @@
|
|
|
30
31
|
"keywords": [],
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"cross-fetch": "^4.1.0"
|
|
33
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "cbd1f7833d4a107f6fcc897ac7d0df9041cabbdd"
|
|
34
36
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [1.0.0](https://github.com/constructive-io/agentic-kit/compare/@agentic-kit/ollama@0.1.2...@agentic-kit/ollama@1.0.0) (2026-02-28)
|
|
7
|
-
|
|
8
|
-
### Features
|
|
9
|
-
|
|
10
|
-
- add @agentic-kit/anthropic and @agentic-kit/openai packages ([3281fd3](https://github.com/constructive-io/agentic-kit/commit/3281fd39949a2094ee89e0da5ba639b61ff7abc5))
|
|
11
|
-
|
|
12
|
-
## [0.1.2](https://github.com/hyperweb-io/agentic-kit/compare/@agentic-kit/ollama@0.1.1...@agentic-kit/ollama@0.1.2) (2025-06-09)
|
|
13
|
-
|
|
14
|
-
**Note:** Version bump only for package @agentic-kit/ollama
|
|
15
|
-
|
|
16
|
-
## [0.1.1](https://github.com/hyperweb-io/agentic-kit/compare/@agentic-kit/ollama@0.1.0...@agentic-kit/ollama@0.1.1) (2025-06-09)
|
|
17
|
-
|
|
18
|
-
**Note:** Version bump only for package @agentic-kit/ollama
|
|
19
|
-
|
|
20
|
-
# [0.1.0](https://github.com/hyperweb-io/agentic-kit/compare/@agentic-kit/ollama@0.0.2...@agentic-kit/ollama@0.1.0) (2025-06-09)
|
|
21
|
-
|
|
22
|
-
### Features
|
|
23
|
-
|
|
24
|
-
- add streaming support to generate method and implement adapter pattern ([f363a07](https://github.com/hyperweb-io/agentic-kit/commit/f363a071b790ef8f032ad8bb23209cafe3a3cdb1))
|
|
25
|
-
|
|
26
|
-
## 0.0.2 (2025-06-09)
|
|
27
|
-
|
|
28
|
-
**Note:** Version bump only for package @agentic-kit/ollama
|
package/__tests__/first.test.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import fetch from 'cross-fetch';
|
|
2
|
-
import { TextEncoder } from 'util';
|
|
3
|
-
|
|
4
|
-
import OllamaClient, { GenerateInput } from '../src';
|
|
5
|
-
|
|
6
|
-
describe('OllamaClient', () => {
|
|
7
|
-
let client: OllamaClient;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
client = new OllamaClient('http://localhost:11434');
|
|
11
|
-
jest.clearAllMocks();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
jest.resetAllMocks();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// ── listModels ──────────────────────────────────────────────────────────────
|
|
19
|
-
|
|
20
|
-
it('listModels returns names from models array', async () => {
|
|
21
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
22
|
-
ok: true,
|
|
23
|
-
json: async () => ({
|
|
24
|
-
models: [{ name: 'model1' }, { name: 'model2' }],
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
27
|
-
const models = await client.listModels();
|
|
28
|
-
expect(models).toEqual(['model1', 'model2']);
|
|
29
|
-
expect(fetch).toHaveBeenCalledWith('http://localhost:11434/api/tags');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('listModels falls back to tags array', async () => {
|
|
33
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
34
|
-
ok: true,
|
|
35
|
-
json: async () => ({ tags: ['model1', 'model2'] }),
|
|
36
|
-
});
|
|
37
|
-
const models = await client.listModels();
|
|
38
|
-
expect(models).toEqual(['model1', 'model2']);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// ── generate (single-shot, /api/generate) ───────────────────────────────────
|
|
42
|
-
|
|
43
|
-
it('generate returns response text', async () => {
|
|
44
|
-
const input: GenerateInput = { model: 'llama3', prompt: 'hello' };
|
|
45
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
46
|
-
ok: true,
|
|
47
|
-
json: async () => ({ response: 'hi there', done: true }),
|
|
48
|
-
});
|
|
49
|
-
const text = await client.generate(input);
|
|
50
|
-
expect(text).toBe('hi there');
|
|
51
|
-
expect(fetch).toHaveBeenCalledWith('http://localhost:11434/api/generate', {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers: { 'Content-Type': 'application/json' },
|
|
54
|
-
body: JSON.stringify({ model: 'llama3', prompt: 'hello', stream: false }),
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('generate passes system prompt to /api/generate', async () => {
|
|
59
|
-
const input: GenerateInput = { model: 'llama3', prompt: 'hello', system: 'Be concise.' };
|
|
60
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
61
|
-
ok: true,
|
|
62
|
-
json: async () => ({ response: 'ok', done: true }),
|
|
63
|
-
});
|
|
64
|
-
await client.generate(input);
|
|
65
|
-
const body = JSON.parse((fetch as jest.Mock).mock.calls[0][1].body);
|
|
66
|
-
expect(body.system).toBe('Be concise.');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('generate streams via /api/generate', async () => {
|
|
70
|
-
const chunkData = JSON.stringify({ response: 'chunk1', done: false }) + '\n';
|
|
71
|
-
const encoded = new TextEncoder().encode(chunkData);
|
|
72
|
-
const mockReader = {
|
|
73
|
-
read: jest.fn()
|
|
74
|
-
.mockResolvedValueOnce({ done: false, value: encoded })
|
|
75
|
-
.mockResolvedValueOnce({ done: true, value: undefined }),
|
|
76
|
-
};
|
|
77
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
78
|
-
ok: true,
|
|
79
|
-
body: { getReader: () => mockReader },
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const chunks: string[] = [];
|
|
83
|
-
await client.generate({ model: 'llama3', prompt: 'hello', stream: true }, (c) => chunks.push(c));
|
|
84
|
-
expect(chunks).toEqual(['chunk1']);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// ── generate (multi-turn, /api/chat) ────────────────────────────────────────
|
|
88
|
-
|
|
89
|
-
it('generate routes to /api/chat when messages provided', async () => {
|
|
90
|
-
const input: GenerateInput = {
|
|
91
|
-
model: 'llama3',
|
|
92
|
-
messages: [{ role: 'user', content: 'hello' }],
|
|
93
|
-
};
|
|
94
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
95
|
-
ok: true,
|
|
96
|
-
json: async () => ({
|
|
97
|
-
message: { role: 'assistant', content: 'hi!' },
|
|
98
|
-
done: true,
|
|
99
|
-
}),
|
|
100
|
-
});
|
|
101
|
-
const text = await client.generate(input);
|
|
102
|
-
expect(text).toBe('hi!');
|
|
103
|
-
expect(fetch).toHaveBeenCalledWith('http://localhost:11434/api/chat', expect.any(Object));
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('generate prepends system message in /api/chat', async () => {
|
|
107
|
-
const input: GenerateInput = {
|
|
108
|
-
model: 'llama3',
|
|
109
|
-
messages: [{ role: 'user', content: 'hello' }],
|
|
110
|
-
system: 'You are helpful.',
|
|
111
|
-
};
|
|
112
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
113
|
-
ok: true,
|
|
114
|
-
json: async () => ({ message: { role: 'assistant', content: 'sure' }, done: true }),
|
|
115
|
-
});
|
|
116
|
-
await client.generate(input);
|
|
117
|
-
const body = JSON.parse((fetch as jest.Mock).mock.calls[0][1].body);
|
|
118
|
-
expect(body.messages[0]).toEqual({ role: 'system', content: 'You are helpful.' });
|
|
119
|
-
expect(body.messages[1]).toEqual({ role: 'user', content: 'hello' });
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('generate streams via /api/chat', async () => {
|
|
123
|
-
const chunkData = JSON.stringify({ message: { content: 'chunk1' }, done: false }) + '\n';
|
|
124
|
-
const encoded = new TextEncoder().encode(chunkData);
|
|
125
|
-
const mockReader = {
|
|
126
|
-
read: jest.fn()
|
|
127
|
-
.mockResolvedValueOnce({ done: false, value: encoded })
|
|
128
|
-
.mockResolvedValueOnce({ done: true, value: undefined }),
|
|
129
|
-
};
|
|
130
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
131
|
-
ok: true,
|
|
132
|
-
body: { getReader: () => mockReader },
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const chunks: string[] = [];
|
|
136
|
-
await client.generate(
|
|
137
|
-
{ model: 'llama3', messages: [{ role: 'user', content: 'hi' }] },
|
|
138
|
-
(c) => chunks.push(c)
|
|
139
|
-
);
|
|
140
|
-
expect(chunks).toEqual(['chunk1']);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// ── pullModel / deleteModel ──────────────────────────────────────────────────
|
|
144
|
-
|
|
145
|
-
it('pullModel resolves', async () => {
|
|
146
|
-
(fetch as jest.Mock).mockResolvedValueOnce({ ok: true });
|
|
147
|
-
await expect(client.pullModel('llama3')).resolves.toBeUndefined();
|
|
148
|
-
expect(fetch).toHaveBeenCalledWith('http://localhost:11434/api/pull', {
|
|
149
|
-
method: 'POST',
|
|
150
|
-
headers: { 'Content-Type': 'application/json' },
|
|
151
|
-
body: JSON.stringify({ name: 'llama3' }),
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('deleteModel resolves', async () => {
|
|
156
|
-
(fetch as jest.Mock).mockResolvedValueOnce({ ok: true });
|
|
157
|
-
await expect(client.deleteModel('llama3')).resolves.toBeUndefined();
|
|
158
|
-
expect(fetch).toHaveBeenCalledWith('http://localhost:11434/api/delete', {
|
|
159
|
-
method: 'DELETE',
|
|
160
|
-
headers: { 'Content-Type': 'application/json' },
|
|
161
|
-
body: JSON.stringify({ name: 'llama3' }),
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// ── generateEmbedding ───────────────────────────────────────────────────────
|
|
166
|
-
|
|
167
|
-
it('generateEmbedding returns embedding with default model', async () => {
|
|
168
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
169
|
-
ok: true,
|
|
170
|
-
json: async () => ({ embedding: [0.1, 0.2, 0.3] }),
|
|
171
|
-
});
|
|
172
|
-
const embedding = await client.generateEmbedding('test text');
|
|
173
|
-
expect(embedding).toEqual([0.1, 0.2, 0.3]);
|
|
174
|
-
const body = JSON.parse((fetch as jest.Mock).mock.calls[0][1].body);
|
|
175
|
-
expect(body.model).toBe('nomic-embed-text');
|
|
176
|
-
expect(body.prompt).toBe('test text');
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('generateEmbedding accepts custom model', async () => {
|
|
180
|
-
(fetch as jest.Mock).mockResolvedValueOnce({
|
|
181
|
-
ok: true,
|
|
182
|
-
json: async () => ({ embedding: [1, 2, 3] }),
|
|
183
|
-
});
|
|
184
|
-
await client.generateEmbedding('text', 'mxbai-embed-large');
|
|
185
|
-
const body = JSON.parse((fetch as jest.Mock).mock.calls[0][1].body);
|
|
186
|
-
expect(body.model).toBe('mxbai-embed-large');
|
|
187
|
-
});
|
|
188
|
-
});
|
package/dist/README.md
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
# @agentic-kit/ollama
|
|
2
|
-
|
|
3
|
-
<p align="center" width="100%">
|
|
4
|
-
<img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
<p align="center" width="100%">
|
|
8
|
-
<a href="https://github.com/constructive-io/agentic-kit/actions/workflows/run-tests.yaml">
|
|
9
|
-
<img height="20" src="https://github.com/constructive-io/agentic-kit/actions/workflows/run-tests.yaml/badge.svg" />
|
|
10
|
-
</a>
|
|
11
|
-
<a href="https://github.com/constructive-io/agentic-kit/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
-
<a href="https://www.npmjs.com/package/@agentic-kit/ollama"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/agentic-kit?filename=packages%2Follama%2Fpackage.json"/></a>
|
|
13
|
-
</p>
|
|
14
|
-
|
|
15
|
-
A JavaScript/TypeScript client for the Ollama LLM server, supporting model listing, text generation, streaming responses, embeddings, and model management.
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install @agentic-kit/ollama
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Usage
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
import OllamaClient, { GenerateInput } from '@agentic-kit/ollama';
|
|
27
|
-
|
|
28
|
-
// Create a client (default port 11434)
|
|
29
|
-
const client = new OllamaClient('http://localhost:11434');
|
|
30
|
-
|
|
31
|
-
// List available models
|
|
32
|
-
const models = await client.listModels();
|
|
33
|
-
console.log('Available models:', models);
|
|
34
|
-
|
|
35
|
-
// Non-streaming text generation
|
|
36
|
-
const output = await client.generate({ model: 'mistral', prompt: 'Hello, Ollama!' });
|
|
37
|
-
console.log(output);
|
|
38
|
-
|
|
39
|
-
// Streaming generation
|
|
40
|
-
await client.generate(
|
|
41
|
-
{ model: 'mistral', prompt: 'Hello, streaming!', stream: true },
|
|
42
|
-
(chunk) => {
|
|
43
|
-
console.log('Received chunk:', chunk);
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
// Pull a model to local cache
|
|
48
|
-
await client.pullModel('mistral');
|
|
49
|
-
|
|
50
|
-
// Generate embeddings
|
|
51
|
-
const embedding = await client.generateEmbedding('Compute embeddings');
|
|
52
|
-
console.log('Embedding vector length:', embedding.length);
|
|
53
|
-
|
|
54
|
-
// Generate a conversational response with context
|
|
55
|
-
const response = await client.generateResponse(
|
|
56
|
-
'What is the capital of France?',
|
|
57
|
-
'Geography trivia'
|
|
58
|
-
);
|
|
59
|
-
console.log(response);
|
|
60
|
-
|
|
61
|
-
// Delete a pulled model when done
|
|
62
|
-
await client.deleteModel('mistral');
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## API Reference
|
|
66
|
-
|
|
67
|
-
- `new OllamaClient(baseUrl?: string)` – defaults to `http://localhost:11434`
|
|
68
|
-
- `.listModels(): Promise<string[]>`
|
|
69
|
-
- `.generate(input: GenerateInput, onChunk?: (chunk: string) => void): Promise<string | void>`
|
|
70
|
-
- `.generateStreamingResponse(prompt: string, onChunk: (chunk: string) => void, context?: string): Promise<void>`
|
|
71
|
-
- `.generateEmbedding(text: string): Promise<number[]>`
|
|
72
|
-
- `.generateResponse(prompt: string, context?: string): Promise<string>`
|
|
73
|
-
- `.pullModel(model: string): Promise<void>`
|
|
74
|
-
- `.deleteModel(model: string): Promise<void>`
|
|
75
|
-
|
|
76
|
-
## GenerateInput type
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
interface GenerateInput {
|
|
80
|
-
model: string;
|
|
81
|
-
prompt: string;
|
|
82
|
-
stream?: boolean;
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Contributing
|
|
87
|
-
|
|
88
|
-
Please open issues or pull requests on [GitHub](https://github.com/constructive-io/agentic-kit).
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
## Related Constructive Tooling
|
|
93
|
-
|
|
94
|
-
### 🤖 AI & Agent Development
|
|
95
|
-
|
|
96
|
-
* [agentic-kit](https://github.com/constructive-io/agentic-kit): **🧰 Provider-agnostic LLM adapter** with streaming and multi-turn support. Swap between Anthropic, OpenAI, Ollama, and any OpenAI-compatible endpoint.
|
|
97
|
-
|
|
98
|
-
### 📦 Package Management
|
|
99
|
-
|
|
100
|
-
* [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
|
|
101
|
-
|
|
102
|
-
### 🧪 Testing
|
|
103
|
-
|
|
104
|
-
* [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
|
|
105
|
-
* [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **🌱 PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
|
|
106
|
-
* [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
|
|
107
|
-
|
|
108
|
-
### 🧠 Parsing & AST
|
|
109
|
-
|
|
110
|
-
* [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
111
|
-
* [libpg-query-node](https://www.npmjs.com/package/libpg-query): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
112
|
-
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
|
|
113
|
-
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
|
|
114
|
-
|
|
115
|
-
## Credits
|
|
116
|
-
|
|
117
|
-
**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
|
|
118
|
-
|
|
119
|
-
## Disclaimer
|
|
120
|
-
|
|
121
|
-
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
122
|
-
|
|
123
|
-
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
package/dist/package.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@agentic-kit/ollama",
|
|
3
|
-
"version": "0.1.2",
|
|
4
|
-
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
|
-
"description": "Ollama",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"module": "esm/index.js",
|
|
8
|
-
"types": "index.d.ts",
|
|
9
|
-
"homepage": "https://github.com/constructive-io/agentic-kit",
|
|
10
|
-
"license": "SEE LICENSE IN LICENSE",
|
|
11
|
-
"publishConfig": {
|
|
12
|
-
"access": "public",
|
|
13
|
-
"directory": "dist"
|
|
14
|
-
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "https://github.com/constructive-io/agentic-kit"
|
|
18
|
-
},
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/constructive-io/agentic-kit/issues"
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"clean": "makage clean",
|
|
24
|
-
"build": "makage build",
|
|
25
|
-
"build:dev": "makage build --dev",
|
|
26
|
-
"lint": "eslint . --fix",
|
|
27
|
-
"test": "jest",
|
|
28
|
-
"test:watch": "jest --watch"
|
|
29
|
-
},
|
|
30
|
-
"keywords": [],
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"cross-fetch": "^4.1.0"
|
|
33
|
-
}
|
|
34
|
-
}
|
package/jest.config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
transform: {
|
|
6
|
-
'^.+\\.tsx?$': [
|
|
7
|
-
'ts-jest',
|
|
8
|
-
{
|
|
9
|
-
babelConfig: false,
|
|
10
|
-
tsconfig: 'tsconfig.json',
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
},
|
|
14
|
-
transformIgnorePatterns: [`/node_modules/*`],
|
|
15
|
-
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
|
|
16
|
-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
17
|
-
modulePathIgnorePatterns: ['dist/*'],
|
|
18
|
-
setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
|
|
19
|
-
};
|
package/jest.setup.js
DELETED
package/src/index.ts
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import fetch from 'cross-fetch';
|
|
2
|
-
|
|
3
|
-
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
4
|
-
|
|
5
|
-
export interface ChatMessage {
|
|
6
|
-
role: 'system' | 'user' | 'assistant';
|
|
7
|
-
content: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface GenerateInput {
|
|
11
|
-
model: string;
|
|
12
|
-
/** Single-shot prompt — routes to /api/generate */
|
|
13
|
-
prompt?: string;
|
|
14
|
-
/** Multi-turn messages — routes to /api/chat (takes precedence over prompt) */
|
|
15
|
-
messages?: ChatMessage[];
|
|
16
|
-
/** System prompt — injected into /api/generate or prepended to /api/chat messages */
|
|
17
|
-
system?: string;
|
|
18
|
-
stream?: boolean;
|
|
19
|
-
temperature?: number;
|
|
20
|
-
maxTokens?: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface OllamaGenerateResponse {
|
|
24
|
-
model: string;
|
|
25
|
-
created_at: string;
|
|
26
|
-
response: string;
|
|
27
|
-
done: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface OllamaChatResponse {
|
|
31
|
-
model: string;
|
|
32
|
-
created_at: string;
|
|
33
|
-
message: { role: string; content: string };
|
|
34
|
-
done: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface OllamaEmbeddingResponse {
|
|
38
|
-
embedding: number[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface OllamaTagsResponse {
|
|
42
|
-
models?: Array<{
|
|
43
|
-
name: string;
|
|
44
|
-
model: string;
|
|
45
|
-
modified_at: string;
|
|
46
|
-
size: number;
|
|
47
|
-
digest: string;
|
|
48
|
-
}>;
|
|
49
|
-
tags?: string[];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// ─── Client ───────────────────────────────────────────────────────────────────
|
|
53
|
-
|
|
54
|
-
export default class OllamaClient {
|
|
55
|
-
private baseUrl: string;
|
|
56
|
-
|
|
57
|
-
constructor(baseUrl: string = 'http://localhost:11434') {
|
|
58
|
-
this.baseUrl = baseUrl;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ── Models ──────────────────────────────────────────────────────────────────
|
|
62
|
-
|
|
63
|
-
async listModels(): Promise<string[]> {
|
|
64
|
-
const res = await fetch(`${this.baseUrl}/api/tags`);
|
|
65
|
-
if (!res.ok) {
|
|
66
|
-
throw new Error(`listModels failed: ${res.status} ${res.statusText}`);
|
|
67
|
-
}
|
|
68
|
-
const data: OllamaTagsResponse = await res.json();
|
|
69
|
-
if (data.models?.length) return data.models.map((m) => m.name);
|
|
70
|
-
if (data.tags?.length) return data.tags;
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async pullModel(model: string): Promise<void> {
|
|
75
|
-
const res = await fetch(`${this.baseUrl}/api/pull`, {
|
|
76
|
-
method: 'POST',
|
|
77
|
-
headers: { 'Content-Type': 'application/json' },
|
|
78
|
-
body: JSON.stringify({ name: model }),
|
|
79
|
-
});
|
|
80
|
-
if (!res.ok) {
|
|
81
|
-
throw new Error(`pullModel failed: ${res.status} ${res.statusText}`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async deleteModel(model: string): Promise<void> {
|
|
86
|
-
const res = await fetch(`${this.baseUrl}/api/delete`, {
|
|
87
|
-
method: 'DELETE',
|
|
88
|
-
headers: { 'Content-Type': 'application/json' },
|
|
89
|
-
body: JSON.stringify({ name: model }),
|
|
90
|
-
});
|
|
91
|
-
if (!res.ok) {
|
|
92
|
-
throw new Error(`deleteModel failed: ${res.status} ${res.statusText}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// ── Generate (single-shot or multi-turn) ────────────────────────────────────
|
|
97
|
-
|
|
98
|
-
async generate(input: GenerateInput): Promise<string>;
|
|
99
|
-
async generate(input: GenerateInput, onChunk: (chunk: string) => void): Promise<void>;
|
|
100
|
-
async generate(
|
|
101
|
-
input: GenerateInput,
|
|
102
|
-
onChunk?: (chunk: string) => void
|
|
103
|
-
): Promise<string | void> {
|
|
104
|
-
if (input.messages) {
|
|
105
|
-
return this._chat(input, onChunk);
|
|
106
|
-
}
|
|
107
|
-
return this._generate(input, onChunk);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// ── Embeddings ──────────────────────────────────────────────────────────────
|
|
111
|
-
|
|
112
|
-
async generateEmbedding(text: string, model = 'nomic-embed-text'): Promise<number[]> {
|
|
113
|
-
const res = await fetch(`${this.baseUrl}/api/embeddings`, {
|
|
114
|
-
method: 'POST',
|
|
115
|
-
headers: { 'Content-Type': 'application/json' },
|
|
116
|
-
body: JSON.stringify({ model, prompt: text }),
|
|
117
|
-
});
|
|
118
|
-
if (!res.ok) {
|
|
119
|
-
throw new Error(`generateEmbedding failed: ${res.status} ${res.statusText}`);
|
|
120
|
-
}
|
|
121
|
-
const data: OllamaEmbeddingResponse = await res.json();
|
|
122
|
-
return data.embedding;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// ── Private: /api/generate ──────────────────────────────────────────────────
|
|
126
|
-
|
|
127
|
-
private async _generate(
|
|
128
|
-
input: GenerateInput,
|
|
129
|
-
onChunk?: (chunk: string) => void
|
|
130
|
-
): Promise<string | void> {
|
|
131
|
-
const body: Record<string, unknown> = {
|
|
132
|
-
model: input.model,
|
|
133
|
-
prompt: input.prompt ?? '',
|
|
134
|
-
stream: !!onChunk,
|
|
135
|
-
};
|
|
136
|
-
if (input.system) body.system = input.system;
|
|
137
|
-
if (input.temperature !== undefined) body.temperature = input.temperature;
|
|
138
|
-
|
|
139
|
-
const res = await fetch(`${this.baseUrl}/api/generate`, {
|
|
140
|
-
method: 'POST',
|
|
141
|
-
headers: { 'Content-Type': 'application/json' },
|
|
142
|
-
body: JSON.stringify(body),
|
|
143
|
-
});
|
|
144
|
-
if (!res.ok) {
|
|
145
|
-
const text = await res.text().catch(() => '');
|
|
146
|
-
throw new Error(`generate failed: ${res.status} ${res.statusText} — ${text}`);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (onChunk) {
|
|
150
|
-
return this._streamResponse(res, (data: OllamaGenerateResponse) => data.response, onChunk);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const data: OllamaGenerateResponse = await res.json();
|
|
154
|
-
return data.response;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// ── Private: /api/chat ──────────────────────────────────────────────────────
|
|
158
|
-
|
|
159
|
-
private async _chat(
|
|
160
|
-
input: GenerateInput,
|
|
161
|
-
onChunk?: (chunk: string) => void
|
|
162
|
-
): Promise<string | void> {
|
|
163
|
-
const messages: ChatMessage[] = [];
|
|
164
|
-
if (input.system) {
|
|
165
|
-
messages.push({ role: 'system', content: input.system });
|
|
166
|
-
}
|
|
167
|
-
messages.push(...(input.messages ?? []));
|
|
168
|
-
|
|
169
|
-
const body: Record<string, unknown> = {
|
|
170
|
-
model: input.model,
|
|
171
|
-
messages,
|
|
172
|
-
stream: !!onChunk,
|
|
173
|
-
};
|
|
174
|
-
if (input.temperature !== undefined) body.temperature = input.temperature;
|
|
175
|
-
|
|
176
|
-
const res = await fetch(`${this.baseUrl}/api/chat`, {
|
|
177
|
-
method: 'POST',
|
|
178
|
-
headers: { 'Content-Type': 'application/json' },
|
|
179
|
-
body: JSON.stringify(body),
|
|
180
|
-
});
|
|
181
|
-
if (!res.ok) {
|
|
182
|
-
const text = await res.text().catch(() => '');
|
|
183
|
-
throw new Error(`chat failed: ${res.status} ${res.statusText} — ${text}`);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (onChunk) {
|
|
187
|
-
return this._streamResponse(
|
|
188
|
-
res,
|
|
189
|
-
(data: OllamaChatResponse) => data.message?.content ?? '',
|
|
190
|
-
onChunk
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const data: OllamaChatResponse = await res.json();
|
|
195
|
-
return data.message?.content ?? '';
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// ── Private: streaming reader ───────────────────────────────────────────────
|
|
199
|
-
|
|
200
|
-
private async _streamResponse<T>(
|
|
201
|
-
res: Response,
|
|
202
|
-
extract: (data: T) => string,
|
|
203
|
-
onChunk: (chunk: string) => void
|
|
204
|
-
): Promise<void> {
|
|
205
|
-
const reader = res.body?.getReader();
|
|
206
|
-
if (!reader) throw new Error('No response body reader');
|
|
207
|
-
|
|
208
|
-
const decoder = new TextDecoder();
|
|
209
|
-
while (true) {
|
|
210
|
-
const { done, value } = await reader.read();
|
|
211
|
-
if (done) break;
|
|
212
|
-
const lines = decoder.decode(value).split('\n').filter(Boolean);
|
|
213
|
-
for (const line of lines) {
|
|
214
|
-
try {
|
|
215
|
-
const data: T = JSON.parse(line);
|
|
216
|
-
const chunk = extract(data);
|
|
217
|
-
if (chunk) onChunk(chunk);
|
|
218
|
-
} catch {
|
|
219
|
-
// partial line — skip
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
package/tsconfig.esm.json
DELETED
package/tsconfig.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|