MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / generateImageWithOpenAIRest

Method generateImageWithOpenAIRest

ai/ai.ts:3032–3145  ·  view source on GitHub ↗
(
    providerConfig: ProviderConfig,
    model: string,
    prompt: string,
    image: AIImage | undefined,
    modeConfig: ProviderModeConfig,
    token?: AbortToken,
  )

Source from the content-addressed store, hash-verified

3030
3031 private async generateImageWithOpenAIRest(
3032 providerConfig: ProviderConfig,
3033 model: string,
3034 prompt: string,
3035 image: AIImage | undefined,
3036 modeConfig: ProviderModeConfig,
3037 token?: AbortToken,
3038 ): Promise<AIImage[]> {
3039 const baseUrl = resolveBaseUrl(providerConfig, modeConfig);
3040 let endpoint = modeConfig.endpoint || "images/generations";
3041 const authMode = resolveAuthMode(
3042 getProviderProfile(providerConfig),
3043 modeConfig,
3044 providerConfig,
3045 );
3046
3047 const requestModel = model;
3048
3049 let data: any;
3050 let headers: Record<string, string> = {};
3051
3052 if (image && image.data) {
3053 const dataUri = `data:${image.mimeType};base64,${image.data.toString("base64")}`;
3054
3055 if (
3056 model.includes("gpt-image") ||
3057 model.includes("chatgpt-image") ||
3058 model.includes("dall-e")
3059 ) {
3060 endpoint = modeConfig.endpoint || "images/edits";
3061 data = {
3062 model: requestModel,
3063 prompt,
3064 images: [
3065 {
3066 image_url: dataUri,
3067 },
3068 ],
3069 };
3070 this.applyImageDefaults(data, providerConfig, requestModel, modeConfig);
3071 headers["Content-Type"] = "application/json";
3072 } else {
3073 endpoint = modeConfig.endpoint || "images/edits";
3074 const fields: Record<string, any> = {
3075 model: requestModel,
3076 prompt,
3077 };
3078 this.applyImageDefaults(
3079 fields,
3080 providerConfig,
3081 requestModel,
3082 modeConfig,
3083 );
3084
3085 const boundary =
3086 "----WebKitFormBoundary" + Math.random().toString(36).substring(2);
3087 const chunks: Buffer[] = [];
3088
3089 for (const [key, value] of Object.entries(fields)) {

Callers 1

Calls 8

applyImageDefaultsMethod · 0.95
resolveBaseUrlFunction · 0.85
resolveAuthModeFunction · 0.85
getProviderProfileFunction · 0.85
applyAuthConfigFunction · 0.85
resolveEndpointUrlFunction · 0.85
requestMethod · 0.45

Tested by

no test coverage detected