@agenite/ollama
Version:
Ollama provider for Agenite
99 lines (95 loc) • 2.79 kB
TypeScript
import { BaseLLMConfig, ToolDefinition, BaseLLMProvider, BaseMessage, GenerateOptions, GenerateResponse, PartialReturn } from '@agenite/llm';
/**
* Available Ollama model types
*/
type OllamaModel = 'llama3.2' | 'llama2' | 'codellama' | 'mistral' | 'mixtral' | 'phi' | 'neural-chat' | 'starling-lm' | 'openchat' | 'dolphin-phi' | 'stable-beluga' | (string & {});
/**
* Ollama-specific configuration options
*/
interface OllamaConfig extends BaseLLMConfig {
model: OllamaModel;
/**
* Host URL for Ollama server
*/
host?: string;
/**
* System prompt to be prepended to all messages
*/
systemPrompt?: string;
/**
* Tool definitions in Ollama format
*/
tools?: ToolDefinition[];
/**
* Default temperature for generation
*/
temperature?: number;
/**
* Default maximum tokens for generation
*/
maxTokens?: number;
/**
* Additional model parameters
* @see https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values
*/
parameters?: {
mirostat?: number;
mirostat_eta?: number;
mirostat_tau?: number;
num_ctx?: number;
num_gqa?: number;
num_gpu?: number;
num_thread?: number;
repeat_last_n?: number;
repeat_penalty?: number;
temperature?: number;
tfs_z?: number;
top_k?: number;
top_p?: number;
};
}
interface OllamaMessage {
role: string;
content: string;
images?: string[];
tool_calls?: Array<{
function: {
name: string;
arguments: Record<string, unknown>;
};
}>;
name?: string;
}
interface ToolParameterValue {
type: string;
description?: string;
enum?: string[];
}
interface OllamaToolCall {
function: {
name: string;
arguments: string | Record<string, unknown>;
};
}
declare class OllamaProvider extends BaseLLMProvider {
private client;
private config;
readonly name = "Ollama";
readonly version = "1.0";
constructor(config: OllamaConfig);
/**
* Creates base chat request parameters
*/
private createBaseRequest;
/**
* Prepares messages for chat request
*/
private prepareMessages;
/**
* Combines text and tool calls into a single response content
*/
private combineResponseContent;
generate(input: string | BaseMessage[], options?: Partial<GenerateOptions>): Promise<GenerateResponse>;
stream(input: string | BaseMessage[], options?: Partial<GenerateOptions>): AsyncGenerator<PartialReturn, GenerateResponse, unknown>;
}
export { type OllamaConfig, type OllamaMessage, type OllamaModel, OllamaProvider, type OllamaToolCall, type ToolParameterValue };