@llumiverse/drivers
Version:
LLM driver implementations. Currently supported are: openai, huggingface, bedrock, replicate.
82 lines • 4.42 kB
TypeScript
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
import { PredictionServiceClient, v1beta1 } from "@google-cloud/aiplatform";
import { type Content, GoogleGenAI, type Model } from "@google/genai";
import { type AIModel, AbstractDriver, type Completion, type CompletionChunkObject, type DriverOptions, type EmbeddingsOptions, type EmbeddingsResult, type ExecutionOptions, type LlumiverseError, type LlumiverseErrorContext, type ModelSearchPayload, type PromptSegment } from "@llumiverse/core";
import { FetchClient } from "@vertesia/api-fetch-client";
import { GoogleAuth, type GoogleAuthOptions } from "google-auth-library";
import { type ImagenPrompt } from "./models/imagen.js";
export interface VertexAIDriverOptions extends DriverOptions {
project: string;
region: string;
googleAuthOptions?: GoogleAuthOptions;
}
export interface GenerateContentPrompt {
contents: Content[];
system?: Content;
}
export type VertexAIPrompt = ImagenPrompt | GenerateContentPrompt;
export declare function trimModelName(model: string): string;
export declare class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, VertexAIPrompt> {
static PROVIDER: string;
provider: string;
aiplatform: v1beta1.ModelServiceClient | undefined;
anthropicClient: AnthropicVertex | undefined;
fetchClient: FetchClient | undefined;
googleGenAI: GoogleGenAI | undefined;
googleGenAIRegion: string | undefined;
googleGenAIFlex: boolean | undefined;
llamaClient: FetchClient & {
region?: string;
} | undefined;
modelGarden: v1beta1.ModelGardenServiceClient | undefined;
imagenClient: PredictionServiceClient | undefined;
googleAuth: GoogleAuth<any>;
private authClientPromise;
constructor(options: VertexAIDriverOptions);
private getAuthClient;
getGoogleGenAIClient(region?: string, flex?: boolean): GoogleGenAI;
private buildGoogleGenAIClient;
getFetchClient(): FetchClient;
getLLamaClient(region?: string): FetchClient;
getAnthropicClient(region?: string): Promise<AnthropicVertex>;
getAIPlatformClient(): Promise<v1beta1.ModelServiceClient>;
getModelGardenClient(): Promise<v1beta1.ModelGardenServiceClient>;
getImagenClient(): Promise<PredictionServiceClient>;
validateResult(result: Completion, options: ExecutionOptions): void;
protected canStream(options: ExecutionOptions): Promise<boolean>;
protected isImageModel(model: string): boolean;
createPrompt(segments: PromptSegment[], options: ExecutionOptions): Promise<VertexAIPrompt>;
requestTextCompletion(prompt: VertexAIPrompt, options: ExecutionOptions): Promise<Completion>;
requestTextCompletionStream(prompt: VertexAIPrompt, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>>;
/**
* Build conversation context after streaming completion.
* Reconstructs the assistant message from accumulated results and applies stripping.
* Handles both Gemini (Content[]) and Claude (ClaudePrompt) formats.
*/
buildStreamingConversation(prompt: VertexAIPrompt, result: unknown[], toolUse: unknown[] | undefined, options: ExecutionOptions): Content[] | unknown | undefined;
/**
* Build conversation for Claude streaming.
* Creates assistant message with tool_use blocks in Claude's ContentBlock format.
*/
private buildClaudeStreamingConversation;
requestImageGeneration(_prompt: ImagenPrompt, _options: ExecutionOptions): Promise<Completion>;
getGenAIModelsArray(client: GoogleGenAI): Promise<Model[]>;
listModels(_params?: ModelSearchPayload): Promise<AIModel<string>[]>;
validateConnection(): Promise<boolean>;
generateEmbeddings(options: EmbeddingsOptions): Promise<EmbeddingsResult>;
/**
* Cleanup Google Cloud clients when the driver is evicted from the cache.
*/
destroy(): void;
/**
* Format VertexAI errors by routing to model-specific error handlers.
* Each model definition (Gemini, Claude, Llama) can provide custom error parsing
* based on their specific SDK error structures.
*
* @param error - The error from the VertexAI/model SDK
* @param context - Context about where the error occurred
* @returns A standardized LlumiverseError
*/
formatLlumiverseError(error: unknown, context: LlumiverseErrorContext): LlumiverseError;
}
//# sourceMappingURL=index.d.ts.map