When implementing AI model integrations, maintain consistent interfaces and proper type definitions across different providers. This ensures compatibility, prevents runtime errors, and simplifies maintenance.
When implementing AI model integrations, maintain consistent interfaces and proper type definitions across different providers. This ensures compatibility, prevents runtime errors, and simplifies maintenance.
Key guidelines:
Example of proper implementation:
// Define shared interface
interface ModelProvider {
embed(chunks: string[], task: EmbeddingTasks): Promise<number[][]>;
chat(messages: ChatMessage[], options: ChatOptions): AsyncGenerator<string>;
}
// Implement provider-specific class
class DeepSeekProvider implements ModelProvider {
// Extend base types for provider-specific features
interface DeepSeekMessage extends ChatMessage {
reasoning_content?: string;
}
// Implement shared interface with provider-specific logic
async embed(chunks: string[], task: EmbeddingTasks): Promise<number[][]> {
// Provider-specific implementation
}
}
This approach:
Enter the URL of a public GitHub repository