jpglens
Version:
🔍 Universal AI-Powered UI Testing - See your interfaces through the lens of intelligence
153 lines • 3.49 kB
TypeScript
/**
* 🔍 jpglens - API Compatibility Layer
* Handles differences between OpenAI and Anthropic API formats
*
* @author Taha Bahrami (Kaito)
* @license MIT
*/
import { AIProviderConfig } from './types.js';
/**
* API message formats
*/
export interface OpenAIMessage {
role: 'system' | 'user' | 'assistant';
content: string | Array<{
type: 'text' | 'image_url';
text?: string;
image_url?: {
url: string;
};
}>;
}
export interface AnthropicMessage {
role: 'user' | 'assistant';
content: string | Array<{
type: 'text' | 'image';
text?: string;
source?: {
type: 'base64';
media_type: string;
data: string;
};
}>;
}
/**
* API request formats
*/
export interface OpenAIRequest {
model: string;
messages: OpenAIMessage[];
max_tokens?: number;
temperature?: number;
stream?: boolean;
}
export interface AnthropicRequest {
model: string;
max_tokens: number;
messages: AnthropicMessage[];
temperature?: number;
system?: string;
}
/**
* API response formats
*/
export interface OpenAIResponse {
id: string;
object: string;
created: number;
model: string;
choices: Array<{
index: number;
message: {
role: string;
content: string;
};
finish_reason: string;
}>;
usage: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
}
export interface AnthropicResponse {
id: string;
type: string;
role: string;
content: Array<{
type: string;
text: string;
}>;
model: string;
stop_reason: string;
stop_sequence: null;
usage: {
input_tokens: number;
output_tokens: number;
};
}
/**
* API Compatibility Handler
*/
export declare class APICompatibilityHandler {
private config;
constructor(config: AIProviderConfig);
/**
* Detect API format based on provider and model
*/
detectAPIFormat(): 'openai' | 'anthropic';
/**
* Convert prompt and image to appropriate API format
*/
formatRequest(prompt: string, imageBase64?: string, systemPrompt?: string): OpenAIRequest | AnthropicRequest;
/**
* Format request for OpenAI API
*/
private formatOpenAIRequest;
/**
* Format request for Anthropic API
*/
private formatAnthropicRequest;
/**
* Parse response from either API format
*/
parseResponse(response: any): {
content: string;
tokensUsed: number;
model: string;
};
/**
* Parse OpenAI API response
*/
private parseOpenAIResponse;
/**
* Parse Anthropic API response
*/
private parseAnthropicResponse;
/**
* Get appropriate headers for the API
*/
getHeaders(): Record<string, string>;
/**
* Get appropriate API endpoint
*/
getEndpoint(): string;
/**
* Validate configuration for the detected API format
*/
validateConfig(): void;
/**
* Get configuration summary
*/
getConfigSummary(): {
provider: string;
model: string;
apiFormat: string;
endpoint: string;
};
}
/**
* Create API compatibility handler
*/
export declare function createAPICompatibilityHandler(config: AIProviderConfig): APICompatibilityHandler;
//# sourceMappingURL=api-compatibility.d.ts.map