@triplef/ollama-api
v0.1.0
Published
A lean NestJS module for the Ollama API — merged local + Ollama Cloud model catalog, capability and origin resolution, and provider-client factory.
Readme
@triplef/ollama-api
A lean NestJS module for the Ollama API — merged local + Ollama Cloud model catalog, capability and origin resolution, and a per-connection provider-client factory.
This library is **ESM-only** and does not support CommonJS.Your project must use ES modules.
StatusBadges
DevDependencies
PeerDependencies
Features
- NestJS-native — a dynamic module (
registerAsync) wiring a lean Ollama API client to a caller-suppliedresolveConnectionresolver. - Merged model catalog — local Ollama tags plus the Ollama Cloud catalog (when an API key is set), with per-model origin routing and capability detection.
- Provider-client factory — cached
ollama-ai-provider-v2clients per host/API-key pair, ready for@triplef/ai-sdk.
Installation
pnpm add @triplef/ollama-apiUsage
Module setup
The library ships no env-driven config — supply the OllamaApiConfig through a
factory, and validate your own env config with the exported OllamaApiConfigSchema.
resolveConnection is called per request, so live connection overrides take
effect immediately.
import { OllamaApiModule } from '@triplef/ollama-api';
@Module({
imports: [
OllamaApiModule.registerAsync({
global: true,
inject: [OllamaOverridesService],
useFactory: (overrides: OllamaOverridesService) => ({
resolveConnection: () => overrides.getConfig(),
refreshIntervalMs: 60_000, // optional: warm + refresh the catalog in the background
}),
}),
],
})
export class AppModule {}Catalog, capabilities, and provider clients
import { OllamaApiService } from '@triplef/ollama-api';
@Injectable()
export class ChatService {
constructor(private readonly ollama: OllamaApiService) {}
async models() {
return this.ollama.getModels(); // merged local + cloud catalog
}
async canSee(model: string) {
return this.ollama.supportsCapability(model, 'vision');
}
model(name: string) {
return this.ollama.createModel(name); // routed to its local or cloud origin
}
}