import { BaseLLMProvider, GenerateOptions, GenerateResponse } from '@agenite/llm';
class CustomProvider extends BaseLLMProvider {
name = 'custom-provider';
version = '1.0.0';
constructor(private apiKey: string) {
super();
}
async generate(
input: string | BaseMessage[],
options?: Partial<GenerateOptions>
): Promise<GenerateResponse> {
// Convert input to standard messages format
const messages = convertStringToMessages(input);
// Make API call to your custom LLM service
// ...
// Return standardized response
return {
content: [{ type: 'text', text: 'Response from custom LLM' }],
tokenUsage: { model: 'custom-model', inputTokens: 10, outputTokens: 20, inputCost: 0, outputCost: 0 },
duration: 500,
};
}
async *stream(
input: string | BaseMessage[],
options?: Partial<GenerateOptions>
): AsyncGenerator<PartialReturn, GenerateResponse, unknown> {
// Stream implementation
// ...
yield { type: 'text', text: 'Partial response...' };
return {
content: [{ type: 'text', text: 'Complete response' }],
tokenUsage: { model: 'custom-model', inputTokens: 10, outputTokens: 20, inputCost: 0, outputCost: 0 },
duration: 500,
};
}
}