ai 4.0.28 → 4.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +39 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -810,7 +810,7 @@ import {
|
|
810
810
|
async function generateImage({
|
811
811
|
model,
|
812
812
|
prompt,
|
813
|
-
n,
|
813
|
+
n = 1,
|
814
814
|
size,
|
815
815
|
aspectRatio,
|
816
816
|
seed,
|
@@ -819,27 +819,46 @@ async function generateImage({
|
|
819
819
|
abortSignal,
|
820
820
|
headers
|
821
821
|
}) {
|
822
|
+
var _a14;
|
822
823
|
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
824
|
+
const maxImagesPerCall = (_a14 = model.maxImagesPerCall) != null ? _a14 : 1;
|
825
|
+
const callCount = Math.ceil(n / maxImagesPerCall);
|
826
|
+
const callImageCounts = Array.from({ length: callCount }, (_, i) => {
|
827
|
+
if (i < callCount - 1) {
|
828
|
+
return maxImagesPerCall;
|
829
|
+
}
|
830
|
+
const remainder = n % maxImagesPerCall;
|
831
|
+
return remainder === 0 ? maxImagesPerCall : remainder;
|
832
|
+
});
|
833
|
+
const results = await Promise.all(
|
834
|
+
callImageCounts.map(
|
835
|
+
async (callImageCount) => retry(
|
836
|
+
() => model.doGenerate({
|
837
|
+
prompt,
|
838
|
+
n: callImageCount,
|
839
|
+
abortSignal,
|
840
|
+
headers,
|
841
|
+
size,
|
842
|
+
aspectRatio,
|
843
|
+
seed,
|
844
|
+
providerOptions: providerOptions != null ? providerOptions : {}
|
845
|
+
})
|
846
|
+
)
|
835
847
|
)
|
836
848
|
);
|
849
|
+
const images = [];
|
850
|
+
const warnings = [];
|
851
|
+
for (const result of results) {
|
852
|
+
images.push(
|
853
|
+
...result.images.map((image) => new DefaultGeneratedImage({ image }))
|
854
|
+
);
|
855
|
+
warnings.push(...result.warnings);
|
856
|
+
}
|
857
|
+
return new DefaultGenerateImageResult({ images, warnings });
|
837
858
|
}
|
838
859
|
var DefaultGenerateImageResult = class {
|
839
860
|
constructor(options) {
|
840
|
-
this.images = options.images
|
841
|
-
(image) => new DefaultGeneratedImage({ imageData: image })
|
842
|
-
);
|
861
|
+
this.images = options.images;
|
843
862
|
this.warnings = options.warnings;
|
844
863
|
}
|
845
864
|
get image() {
|
@@ -847,10 +866,10 @@ var DefaultGenerateImageResult = class {
|
|
847
866
|
}
|
848
867
|
};
|
849
868
|
var DefaultGeneratedImage = class {
|
850
|
-
constructor({
|
851
|
-
const isUint8Array =
|
852
|
-
this.base64Data = isUint8Array ? void 0 :
|
853
|
-
this.uint8ArrayData = isUint8Array ?
|
869
|
+
constructor({ image }) {
|
870
|
+
const isUint8Array = image instanceof Uint8Array;
|
871
|
+
this.base64Data = isUint8Array ? void 0 : image;
|
872
|
+
this.uint8ArrayData = isUint8Array ? image : void 0;
|
854
873
|
}
|
855
874
|
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
856
875
|
get base64() {
|