UNPKG

@convo-lang/convo-lang

Version:
28 lines 1.28 kB
import { httpClient, joinPaths } from "@iyio/common"; import { defaultOpenAiImageModel } from "./openai-models.js"; import { openAiApiKeyParam, openAiBaseUrlParam, openAiImageModelParam } from "./openai-params.js"; export const createOpenAiConvoImageGenerator = ({ apiBaseUrl = openAiBaseUrlParam.get() || 'https://api.openai.com', model = openAiImageModelParam.get() ?? defaultOpenAiImageModel.name, defaultSize = '1024x1024', apiKey = globalThis.process?.env['OPENAI_API_KEY'] || openAiApiKeyParam() } = {}) => { return async (request) => { const images = await httpClient().postAsync(joinPaths(apiBaseUrl, '/v1/images/generations'), { model: request.model ?? model, prompt: request.prompt, n: 1, size: request.size ?? defaultSize }, { noAuth: true, headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}`, }, }); if (!images?.data.length) { return undefined; } return images.data.map(i => ({ created: Date.now(), url: i.url, revisedPrompt: i.revised_prompt, })); }; }; //# sourceMappingURL=openai-convo-image-generator.js.map