@llmbridge/core
Version:
Core package for unified LLM interface
132 lines • 4.78 kB
TypeScript
export type ResponseFormat = {
type: "json_object";
} | {
type: "json_schema";
json_schema: any;
};
export type Model = `${string}/${string}`;
export interface Provider {
run(providerName: string, model: string, systemPrompt: string | null, messages: Message[], checkAbort: () => void, plugins: Plugins, options: Options): Promise<Response>;
getEmbeddings(model: string, plugins: Plugins, text: string): Promise<number[]>;
}
export interface Options {
maxTokens: number;
temperature: number;
tools?: Tools;
/**
* The effort of the reasoning process. OpenAI uses enum values, Anthropic uses a budget of tokens.
* Estimates for conversion:
* - Numbers to OpenAI: < 100 -> 'minimal', < 1000 -> 'low', 1000-2500 -> 'medium', 2500+ -> 'high'
* - Anthropic: 'minimal' -> 100, 'low' -> 500, 'medium' -> 1500, 'high' -> 5000
*/
reasoningEffort?: 'minimal' | 'low' | 'medium' | 'high' | number;
responseFormat?: ResponseFormat;
}
export interface MessageGeneric {
model?: string;
timestamp?: number;
}
export interface TextMessage extends MessageGeneric {
role: 'user' | 'assistant' | 'model' | 'function' | 'system';
content: string;
}
export interface ImageContent {
type: 'image';
media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
data: string;
}
export interface TextContent {
type: 'text';
text: string;
}
export type MediaMessageContent = ImageContent | TextContent;
export interface MediaMessage extends MessageGeneric {
role: 'user' | 'assistant';
content: MediaMessageContent[];
}
export interface ToolRequest extends MessageGeneric {
id: string;
name: string;
comment?: string;
input: any;
}
export interface ToolResponse extends MessageGeneric {
id: string;
name?: string;
output: any;
}
export type Message = TextMessage | MediaMessage | ToolRequest | ToolResponse;
export declare function isToolRequest(message: Message): message is ToolRequest;
export declare function isToolResponse(message: Message): message is ToolResponse;
export declare function isTextMessage(message: Message): message is TextMessage;
export declare function isMediaMessage(message: Message): message is MediaMessage;
export interface ToolImageTextResult {
type: 'text';
text: string;
}
export interface ToolImageContentResult {
type: 'image';
source: {
"type": "base64";
"media_type": string;
"data": string;
};
}
export type ToolImageResult = [ToolImageTextResult, ToolImageContentResult];
export type ToolTextResult = string;
export interface Tools {
tool_choice: {
type: 'auto';
} | {
type: 'any';
} | {
type: 'tool';
name: string;
};
tools: Array<Tool>;
usesLimit: number;
}
export interface Tool {
name: string;
description: string;
input_schema: any;
callback(input: any, context: Message[]): Promise<void | ToolTextResult | ToolImageResult>;
instructions: string;
}
export interface Response {
messages: Message[];
tokenUsage: TokenUsage;
}
export interface TokenUsage {
inputTokens: number;
outputTokens: number;
totalTokens: number;
cachedTokens: number;
}
export type TokenUsageRecord = Partial<Record<Model, TokenUsage>>;
export interface PluginCompletionContext {
model: string;
systemPrompt: string | null;
messages: Message[];
options: Options;
provider: Provider;
providerName: string;
tokenUsage?: TokenUsage;
}
export interface PluginEmbeddingsContext {
model: string;
provider: Provider;
}
export interface Plugin<T1, T2, T3, T4> {
wrapRun?: (next: () => Promise<Response>, context: PluginCompletionContext) => Promise<Response>;
wrapExec?: (next: (params: any) => Promise<any>, params: any, context: PluginCompletionContext) => Promise<any>;
wrapToolExec?: (next: (tool: Tool, counter: number, input: any) => Promise<any>, tool: Tool, counter: number, input: any, context: PluginCompletionContext) => Promise<any>;
wrapGetEmbeddings?: (next: (params: any) => Promise<number[]>, params: any, context: PluginEmbeddingsContext) => Promise<number[]>;
}
export interface Plugins {
wrapRun(next: () => Promise<Response>, context: PluginCompletionContext): Promise<Response>;
wrapExec(next: (params: any) => Promise<any>, params: any, context: PluginCompletionContext): Promise<any>;
wrapToolExec(next: (tool: Tool, counter: number, input: any) => Promise<any>, tool: Tool, counter: number, input: any, context: PluginCompletionContext): Promise<any>;
wrapGetEmbeddings(next: (params: any) => Promise<number[]>, params: any, context: PluginEmbeddingsContext): Promise<number[]>;
}
//# sourceMappingURL=types.d.ts.map