@umituz/react-native-ai-pruna-provider 1.0.15 → 1.0.16
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-ai-pruna-provider",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "Pruna AI provider for React Native - implements IAIProvider interface for unified AI generation",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -37,11 +37,11 @@ export async function buildModelInput(
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (model === 'p-image-edit') {
|
|
40
|
-
return buildImageEditInput(prompt, aspectRatio, input, sessionId);
|
|
40
|
+
return await buildImageEditInput(prompt, aspectRatio, input, apiKey, sessionId);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (model === 'p-video') {
|
|
44
|
-
return buildVideoInput(prompt, aspectRatio, input, apiKey, sessionId);
|
|
44
|
+
return await buildVideoInput(prompt, aspectRatio, input, apiKey, sessionId);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
throw new Error(`Unknown Pruna model: ${model}`);
|
|
@@ -62,42 +62,52 @@ function buildImageInput(
|
|
|
62
62
|
return payload;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function buildImageEditInput(
|
|
65
|
+
async function buildImageEditInput(
|
|
66
66
|
prompt: string,
|
|
67
67
|
aspectRatio: PrunaAspectRatio,
|
|
68
68
|
input: Record<string, unknown>,
|
|
69
|
+
apiKey: string,
|
|
69
70
|
sessionId: string,
|
|
70
|
-
): Record<string, unknown
|
|
71
|
-
// p-image-edit
|
|
72
|
-
//
|
|
73
|
-
let
|
|
74
|
-
|
|
75
|
-
const ensureDataUriPrefix = (img: string): string => {
|
|
76
|
-
if (img.startsWith('http')) return img; // Already a URL
|
|
77
|
-
if (img.startsWith('data:')) return img; // Already has data URI prefix
|
|
78
|
-
// Add data URI prefix for raw base64
|
|
79
|
-
return `data:image/jpeg;base64,${img}`;
|
|
80
|
-
};
|
|
71
|
+
): Promise<Record<string, unknown>> {
|
|
72
|
+
// p-image-edit requires uploaded file URLs, not base64
|
|
73
|
+
// First upload all images to Pruna storage, then use the URLs
|
|
74
|
+
let rawImages: string[];
|
|
81
75
|
|
|
82
76
|
if (Array.isArray(input.images)) {
|
|
83
77
|
const validImages = (input.images as unknown[]).filter((img): img is string => typeof img === 'string');
|
|
84
78
|
if (validImages.length === 0) {
|
|
85
79
|
throw new Error("Image array is empty or contains no valid strings for p-image-edit.");
|
|
86
80
|
}
|
|
87
|
-
|
|
81
|
+
rawImages = validImages;
|
|
88
82
|
} else if (typeof input.image === 'string') {
|
|
89
|
-
|
|
83
|
+
rawImages = [input.image as string];
|
|
90
84
|
} else if (typeof input.image_url === 'string') {
|
|
91
|
-
|
|
85
|
+
rawImages = [input.image_url as string];
|
|
92
86
|
} else if (Array.isArray(input.image_urls)) {
|
|
93
|
-
|
|
87
|
+
rawImages = input.image_urls as string[];
|
|
94
88
|
} else {
|
|
95
89
|
throw new Error("Image is required for p-image-edit. Provide 'image', 'images', 'image_url', or 'image_urls'.");
|
|
96
90
|
}
|
|
97
91
|
|
|
98
|
-
generationLogCollector.log(sessionId, TAG, `p-image-edit: ${
|
|
92
|
+
generationLogCollector.log(sessionId, TAG, `p-image-edit: uploading ${rawImages.length} image(s) to Pruna storage...`);
|
|
93
|
+
|
|
94
|
+
// Upload all images and get URLs
|
|
95
|
+
const imageUrls: string[] = [];
|
|
96
|
+
for (let i = 0; i < rawImages.length; i++) {
|
|
97
|
+
const rawImage = rawImages[i];
|
|
98
|
+
generationLogCollector.log(sessionId, TAG, `p-image-edit: uploading image ${i + 1}/${rawImages.length}...`);
|
|
99
|
+
const url = await uploadFileToStorage(rawImage, apiKey, sessionId);
|
|
100
|
+
imageUrls.push(url);
|
|
101
|
+
}
|
|
99
102
|
|
|
100
|
-
|
|
103
|
+
generationLogCollector.log(sessionId, TAG, `p-image-edit: all ${imageUrls.length} image(s) uploaded successfully`);
|
|
104
|
+
|
|
105
|
+
const payload: Record<string, unknown> = {
|
|
106
|
+
images: imageUrls,
|
|
107
|
+
prompt,
|
|
108
|
+
aspect_ratio: aspectRatio,
|
|
109
|
+
reference_image: "1", // Required by Pruna API for p-image-edit
|
|
110
|
+
};
|
|
101
111
|
|
|
102
112
|
if (input.seed !== undefined) payload.seed = input.seed;
|
|
103
113
|
if (input.disable_safety_checker !== undefined) payload.disable_safety_checker = input.disable_safety_checker;
|