File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -2139,6 +2139,33 @@ export const generateImage = async (
2139
2139
console . error ( error ) ;
2140
2140
return { success : false , error : error } ;
2141
2141
}
2142
+ } else if ( runtime . imageModelProvider === ModelProviderName . NEARAI ) {
2143
+ let targetSize = `${ data . width } x${ data . height } ` ;
2144
+ if (
2145
+ targetSize !== "1024x1024" &&
2146
+ targetSize !== "1792x1024" &&
2147
+ targetSize !== "1024x1792" &&
2148
+ targetSize !== "512x512" &&
2149
+ targetSize !== "256x256"
2150
+ ) {
2151
+ targetSize = "1024x1024" ;
2152
+ }
2153
+ // NEAR AI uses OpenAI compatible API
2154
+ const openai = new OpenAI ( {
2155
+ baseURL : getEndpoint ( ModelProviderName . NEARAI ) ,
2156
+ apiKey,
2157
+ } ) ;
2158
+ const response = await openai . images . generate ( {
2159
+ model,
2160
+ prompt : data . prompt ,
2161
+ size : targetSize as "1024x1024" | "1792x1024" | "1024x1792" | "512x512" | "256x256" ,
2162
+ n : data . count ,
2163
+ response_format : "b64_json" ,
2164
+ } ) ;
2165
+ const base64s = response . data . map (
2166
+ ( image ) => `data:image/png;base64,${ image . b64_json } `
2167
+ ) ;
2168
+ return { success : true , data : base64s } ;
2142
2169
} else {
2143
2170
let targetSize = `${ data . width } x${ data . height } ` ;
2144
2171
if (
You can’t perform that action at this time.
0 commit comments