Package Exports
- @agentic-kit/ollama
Readme
@agentic-kit/ollama
A JavaScript/TypeScript client and provider adapter for the Ollama API, supporting model listing, structured streaming text generation, embeddings, and model management.
Installation
npm install @agentic-kit/ollamaUsage
import OllamaClient, { GenerateInput } from '@agentic-kit/ollama';
// Create a client (default port 11434)
const client = new OllamaClient('http://localhost:11434');
// List available models
const models = await client.listModels();
console.log('Available models:', models);
// Non-streaming text generation
const output = await client.generate({ model: 'mistral', prompt: 'Hello, Ollama!' });
console.log(output);
// Streaming generation
await client.generate(
{ model: 'mistral', prompt: 'Hello, streaming!', stream: true },
(chunk) => {
console.log('Received chunk:', chunk);
}
);
// Pull a model to local cache
await client.pullModel('mistral');
// Generate embeddings (with token count from /api/embed)
const result = await client.generateEmbedding('Compute embeddings');
console.log('Embedding vector length:', result.embedding.length);
console.log('Prompt tokens:', result.promptTokens);
// Delete a pulled model when done
await client.deleteModel('mistral');API Reference
new OllamaClient(baseUrl?: string)โ defaults tohttp://localhost:11434.listModels(): Promise<string[]>.showModel(model: string): Promise<{ capabilities?: string[] } | null>.generate(input: GenerateInput, onChunk?: (chunk: string) => void): Promise<string | void>.generateEmbedding(text: string, model?: string): Promise<EmbeddingResult>โ returns{ embedding: number[], promptTokens: number }, defaults tonomic-embed-text.pullModel(model: string): Promise<void>.deleteModel(model: string): Promise<void>
Provider Adapter
import { OllamaAdapter } from '@agentic-kit/ollama';
const provider = new OllamaAdapter('http://localhost:11434');
const model = provider.createModel('llama3');
// Embeddings with real token counts
const result = await provider.embed('Compute embeddings', 'nomic-embed-text');
console.log(result.embedding.length, result.promptTokens);Local Live Tests
The package includes a local-only live lane that never talks to hosted providers.
OLLAMA_LIVE_MODEL=qwen3.5:4b pnpm --filter @agentic-kit/ollama test:liveThat default command runs the fast smoke tier. Run the broader suite explicitly when you want slower behavioral coverage:
OLLAMA_LIVE_MODEL=qwen3.5:4b pnpm --filter @agentic-kit/ollama test:live:extendedNotes:
- The preflight checks
OLLAMA_BASE_URLfirst and defaults tohttp://127.0.0.1:11434. - The default live model is
qwen3.5:4b; overrideOLLAMA_LIVE_MODELonly if you want a different local model. - If
nomic-embed-text:latestis installed, the live lane also covers local embeddings. Override it withOLLAMA_LIVE_EMBED_MODELif needed. smokecovers fast adapter invariants;extendedruns the smoke tier plus slower behavioral checks such as reasoning metadata, legacy generate, short multi-turn context, and embeddings.- If Ollama is not running, or the configured model is not installed, the live script exits cleanly with a skip message.
- Normal
pnpm testruns do not include the live lane.
GenerateInput type
interface GenerateInput {
model: string;
prompt?: string;
messages?: ChatMessage[];
system?: string;
stream?: boolean;
temperature?: number;
maxTokens?: number;
}Either prompt (single-turn) or messages (multi-turn) must be set.
Contributing
Please open issues or pull requests on GitHub.
Related Constructive Tooling
๐ค AI & Agent Development
- agentic-kit: ๐งฐ Provider-agnostic LLM adapter with streaming and multi-turn support. Swap between Anthropic, OpenAI, Ollama, and any OpenAI-compatible endpoint.
๐ฆ Package Management
- pgpm: ๐ฅ๏ธ PostgreSQL Package Manager for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
๐งช Testing
- pgsql-test: ๐ Isolated testing environments with per-test transaction rollbacksโideal for integration tests, complex migrations, and RLS simulation.
- pgsql-seed: ๐ฑ PostgreSQL seeding utilities for CSV, JSON, SQL data loading, and pgpm deployment.
- supabase-test: ๐งช Supabase-native test harness preconfigured for the local Supabase stackโper-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
๐ง Parsing & AST
- pgsql-parser: ๐ SQL conversion engine that interprets and converts PostgreSQL syntax.
- libpg-query-node: ๐ Node.js bindings for
libpg_query, converting SQL into parse trees. - @pgsql/types: ๐ Type definitions for PostgreSQL AST nodes in TypeScript.
- @pgsql/utils: ๐ ๏ธ AST utilities for constructing and transforming PostgreSQL syntax trees.
Credits
๐ Built by the Constructive team โ creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on GitHub.
Disclaimer
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
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.