OllamaClient

class OllamaClient @JvmOverloads constructor(httpClient: KoogHttpClient, clock: KoogClock = KoogClock.System, contextWindowStrategy: ContextWindowStrategy = ContextWindowStrategy.Companion.None, toolDescriptorConverter: ToolDescriptorSchemaGenerator = OllamaToolDescriptorSchemaGenerator()) : LLMClient(source)

Client for interacting with the Ollama API with comprehensive model support.

Implements:

Parameters

httpClient

A preconfigured Koog HTTP client used for API calls. Must have the Ollama base URL and timeouts already embedded. To create a client with standard defaults, use the secondary constructor that accepts a base URL and a KoogHttpClient.Factory.

clock

Clock instance used for tracking response metadata timestamps.

contextWindowStrategy

The ContextWindowStrategy to use for computing context window lengths. Defaults to ContextWindowStrategy.None.

toolDescriptorConverter

Generates JSON schemas for tool descriptors sent to the model.

Constructors

Link copied to clipboard
constructor(httpClient: KoogHttpClient, clock: KoogClock = KoogClock.System, contextWindowStrategy: ContextWindowStrategy = ContextWindowStrategy.Companion.None, toolDescriptorConverter: ToolDescriptorSchemaGenerator = OllamaToolDescriptorSchemaGenerator())
constructor(httpClientFactory: KoogHttpClient.Factory, baseUrl: String = DEFAULT_BASE_URL, headers: Map<String, String> = emptyMap(), queryParameters: Map<String, String> = emptyMap(), timeoutConfig: ConnectionTimeoutConfig = ConnectionTimeoutConfig(), clock: KoogClock = KoogClock.System, contextWindowStrategy: ContextWindowStrategy = ContextWindowStrategy.Companion.None, toolDescriptorConverter: ToolDescriptorSchemaGenerator = OllamaToolDescriptorSchemaGenerator())

Secondary constructor that builds the underlying KoogHttpClient from a KoogHttpClient.Factory.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open val clientName: String

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open suspend override fun embed(text: String, model: LLModel): List<Double>

Embeds the given text using the Ollama model.

open suspend override fun embed(inputs: List<String>, model: LLModel): List<List<Double>>

Embeds the given inputs using the Ollama embeddings API.

Link copied to clipboard
open suspend override fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): Message.Assistant
Link copied to clipboard
open suspend fun executeMultipleChoices(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): LLMChoice
Link copied to clipboard
open fun executeStreaming(prompt: Prompt, model: LLModel): Flow<StreamFrame>
open override fun executeStreaming(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): Flow<StreamFrame>
Link copied to clipboard
suspend fun getModelOrNull(name: String, pullIfMissing: Boolean = false): OllamaModelCard?

Returns a model card by its model name, on null if no such model exists on the server.

Link copied to clipboard

Returns the model cards for all the available models on the server.

Link copied to clipboard
open override fun llmProvider(): LLMProvider

Provides the type of Language Learning Model (LLM) provider used by the client.

Link copied to clipboard
open suspend fun models(): List<LLModel>
Link copied to clipboard
open suspend override fun moderate(prompt: Prompt, model: LLModel): ModerationResult