smartai/ts/abstract.classes.multimodal.ts

87 lines
2.6 KiB
TypeScript
Raw Permalink Normal View History

/**
* Message format for chat interactions
*/
export interface ChatMessage {
role: 'assistant' | 'user' | 'system';
content: string;
}
/**
* Options for chat interactions
*/
export interface ChatOptions {
systemMessage: string;
userMessage: string;
messageHistory: ChatMessage[];
}
/**
* Response format for chat interactions
*/
export interface ChatResponse {
role: 'assistant';
message: string;
}
/**
* Abstract base class for multi-modal AI models.
* Provides a common interface for different AI providers (OpenAI, Anthropic, Perplexity, Ollama)
*/
2024-04-04 02:47:44 +02:00
export abstract class MultiModalModel {
/**
* Initializes the model and any necessary resources
* Should be called before using any other methods
2024-04-04 02:47:44 +02:00
*/
2024-03-31 01:32:37 +01:00
abstract start(): Promise<void>;
2024-04-04 02:47:44 +02:00
/**
* Cleans up any resources used by the model
* Should be called when the model is no longer needed
2024-04-04 02:47:44 +02:00
*/
2024-03-31 01:32:37 +01:00
abstract stop(): Promise<void>;
2024-04-25 10:49:07 +02:00
/**
* Synchronous chat interaction with the model
* @param optionsArg Options containing system message, user message, and message history
* @returns Promise resolving to the assistant's response
*/
public abstract chat(optionsArg: ChatOptions): Promise<ChatResponse>;
2024-03-31 01:32:37 +01:00
2024-04-25 10:49:07 +02:00
/**
* Streaming interface for chat interactions
* Allows for real-time responses from the model
* @param input Stream of user messages
* @returns Stream of model responses
2024-04-25 10:49:07 +02:00
*/
public abstract chatStream(input: ReadableStream<Uint8Array>): Promise<ReadableStream<string>>;
2024-04-25 10:49:07 +02:00
/**
* Text-to-speech conversion
* @param optionsArg Options containing the message to convert to speech
* @returns Promise resolving to a readable stream of audio data
* @throws Error if the provider doesn't support audio generation
*/
public abstract audio(optionsArg: { message: string }): Promise<NodeJS.ReadableStream>;
/**
* Vision-language processing
* @param optionsArg Options containing the image and prompt for analysis
* @returns Promise resolving to the model's description or analysis of the image
* @throws Error if the provider doesn't support vision tasks
*/
public abstract vision(optionsArg: { image: Buffer; prompt: string }): Promise<string>;
/**
* Document analysis and processing
* @param optionsArg Options containing system message, user message, PDF documents, and message history
* @returns Promise resolving to the model's analysis of the documents
* @throws Error if the provider doesn't support document processing
*/
public abstract document(optionsArg: {
systemMessage: string;
userMessage: string;
pdfDocuments: Uint8Array[];
messageHistory: ChatMessage[];
}): Promise<{ message: any }>;
2024-03-31 01:32:37 +01:00
}