@agentic-kit/ollama 0.1.0 → 0.1.2
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 +110 -6
- package/esm/index.js +9 -1
- package/index.js +9 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,12 +1,116 @@
|
|
|
1
|
-
# Ollama
|
|
1
|
+
# Ollama Client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A JavaScript/TypeScript client for the Ollama LLM server, supporting model listing, text generation, streaming responses, embeddings, and model management.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
+
```bash
|
|
8
|
+
npm install @agentic-kit/ollama
|
|
9
|
+
# or
|
|
10
|
+
yarn add @agentic-kit/ollama
|
|
11
|
+
```
|
|
7
12
|
|
|
8
|
-
##
|
|
13
|
+
## Usage
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
```typescript
|
|
16
|
+
import OllamaClient, { GenerateInput } from '@agentic-kit/ollama';
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
// Create a client (default port 11434)
|
|
19
|
+
const client = new OllamaClient('http://localhost:11434');
|
|
20
|
+
|
|
21
|
+
// List available models
|
|
22
|
+
const models = await client.listModels();
|
|
23
|
+
console.log('Available models:', models);
|
|
24
|
+
|
|
25
|
+
// Non-streaming text generation
|
|
26
|
+
const output = await client.generate({ model: 'mistral', prompt: 'Hello, Ollama!' });
|
|
27
|
+
console.log(output);
|
|
28
|
+
|
|
29
|
+
// Streaming generation
|
|
30
|
+
await client.generate(
|
|
31
|
+
{ model: 'mistral', prompt: 'Hello, streaming!', stream: true },
|
|
32
|
+
(chunk) => {
|
|
33
|
+
console.log('Received chunk:', chunk);
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// Pull a model to local cache
|
|
38
|
+
await client.pullModel('mistral');
|
|
39
|
+
|
|
40
|
+
// Generate embeddings
|
|
41
|
+
const embedding = await client.generateEmbedding('Compute embeddings');
|
|
42
|
+
console.log('Embedding vector length:', embedding.length);
|
|
43
|
+
|
|
44
|
+
// Generate a conversational response with context
|
|
45
|
+
const response = await client.generateResponse(
|
|
46
|
+
'What is the capital of France?',
|
|
47
|
+
'Geography trivia'
|
|
48
|
+
);
|
|
49
|
+
console.log(response);
|
|
50
|
+
|
|
51
|
+
// Delete a pulled model when done
|
|
52
|
+
await client.deleteModel('mistral');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API Reference
|
|
56
|
+
|
|
57
|
+
- `new OllamaClient(baseUrl?: string)` – defaults to `http://localhost:11434`
|
|
58
|
+
- `.listModels(): Promise<string[]>`
|
|
59
|
+
- `.generate(input: GenerateInput, onChunk?: (chunk: string) => void): Promise<string | void>`
|
|
60
|
+
- `.generateStreamingResponse(prompt: string, onChunk: (chunk: string) => void, context?: string): Promise<void>`
|
|
61
|
+
- `.generateEmbedding(text: string): Promise<number[]>`
|
|
62
|
+
- `.generateResponse(prompt: string, context?: string): Promise<string>`
|
|
63
|
+
- `.pullModel(model: string): Promise<void>`
|
|
64
|
+
- `.deleteModel(model: string): Promise<void>`
|
|
65
|
+
|
|
66
|
+
## GenerateInput type
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
interface GenerateInput {
|
|
70
|
+
model: string;
|
|
71
|
+
prompt: string;
|
|
72
|
+
stream?: boolean;
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Contributing
|
|
77
|
+
|
|
78
|
+
Please open issues or pull requests on [GitHub](https://github.com/hyperweb-io/agentic-kit).
|
|
79
|
+
|
|
80
|
+
## API Response Format
|
|
81
|
+
|
|
82
|
+
The Ollama `/api/tags` endpoint returns the following JSON structure:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"models": [
|
|
87
|
+
{
|
|
88
|
+
"name": "mistral:latest",
|
|
89
|
+
"model": "mistral:latest",
|
|
90
|
+
"modified_at": "2025-06-09T04:48:21.588888008Z",
|
|
91
|
+
"size": 4113301824,
|
|
92
|
+
"digest": "...",
|
|
93
|
+
"details": {
|
|
94
|
+
"parent_model": "",
|
|
95
|
+
"format": "gguf",
|
|
96
|
+
"family": "llama",
|
|
97
|
+
"families": ["llama"],
|
|
98
|
+
"parameter_size": "7.2B",
|
|
99
|
+
"quantization_level": "Q4_0"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The `listModels()` method extracts and returns just the model names:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const client = new OllamaClient('http://localhost:11434');
|
|
110
|
+
const models = await client.listModels();
|
|
111
|
+
console.log(models); // ["mistral:latest", "llama2:latest", ...]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
© Hyperweb (formerly Cosmology). See LICENSE for full licensing and disclaimer.
|
package/esm/index.js
CHANGED
|
@@ -10,7 +10,15 @@ export default class OllamaClient {
|
|
|
10
10
|
throw new Error(`Failed to list models: ${response.status} ${response.statusText}`);
|
|
11
11
|
}
|
|
12
12
|
const data = await response.json();
|
|
13
|
-
|
|
13
|
+
// Handle actual API response format (models array)
|
|
14
|
+
if (data.models && Array.isArray(data.models)) {
|
|
15
|
+
return data.models.map(model => model.name);
|
|
16
|
+
}
|
|
17
|
+
// Fallback to documented format (tags array) for backwards compatibility
|
|
18
|
+
if (data.tags && Array.isArray(data.tags)) {
|
|
19
|
+
return data.tags;
|
|
20
|
+
}
|
|
21
|
+
return [];
|
|
14
22
|
}
|
|
15
23
|
async generate(input, onChunk) {
|
|
16
24
|
if (input.stream && onChunk) {
|
package/index.js
CHANGED
|
@@ -15,7 +15,15 @@ class OllamaClient {
|
|
|
15
15
|
throw new Error(`Failed to list models: ${response.status} ${response.statusText}`);
|
|
16
16
|
}
|
|
17
17
|
const data = await response.json();
|
|
18
|
-
|
|
18
|
+
// Handle actual API response format (models array)
|
|
19
|
+
if (data.models && Array.isArray(data.models)) {
|
|
20
|
+
return data.models.map(model => model.name);
|
|
21
|
+
}
|
|
22
|
+
// Fallback to documented format (tags array) for backwards compatibility
|
|
23
|
+
if (data.tags && Array.isArray(data.tags)) {
|
|
24
|
+
return data.tags;
|
|
25
|
+
}
|
|
26
|
+
return [];
|
|
19
27
|
}
|
|
20
28
|
async generate(input, onChunk) {
|
|
21
29
|
if (input.stream && onChunk) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentic-kit/ollama",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "Ollama",
|
|
6
6
|
"main": "index.js",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"cross-fetch": "^4.1.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "957a378bb3b08f3be63cce7b72d741f1f044ae95"
|
|
37
37
|
}
|