@sconedev/ai_toolkit
Version:
Simplify AI integration in web apps with local and offline model support
22 lines (21 loc) • 807 B
JavaScript
import { retry } from '../utils/retry'; // Import custom retry function
import { getProvider } from './providers';
import { getConfig } from './config';
import { getCached, setCached } from './cache';
export async function generateImage(description, options) {
const config = getConfig();
const cacheKey = `generateImage:${description}`;
const cached = getCached(cacheKey);
if (cached) {
return cached;
}
if (config.onRequest) {
config.onRequest({ provider: config.provider, function: 'generateImage', input: description });
}
const provider = getProvider();
const response = await retry(async () => {
return provider.generateImage(description, options);
}, 3); // Retry up to 3 times
setCached(cacheKey, response);
return response;
}