call-ai 0.7.2 → 0.8.1
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/dist/image.d.ts +12 -0
- package/dist/image.js +89 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -1
- package/dist/types.d.ts +51 -0
- package/package.json +1 -1
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image generation API implementation for call-ai
|
|
3
|
+
* Integration with custom image generation API
|
|
4
|
+
*/
|
|
5
|
+
import { ImageGenOptions, ImageResponse } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Generate images using a custom API that mimics OpenAI's image generation capabilities
|
|
8
|
+
* @param prompt Text prompt describing the image to generate
|
|
9
|
+
* @param options Configuration options for the image generation request
|
|
10
|
+
* @returns A Promise that resolves to the image response containing base64 encoded image data
|
|
11
|
+
*/
|
|
12
|
+
export declare function imageGen(prompt: string, options?: ImageGenOptions): Promise<ImageResponse>;
|
package/dist/image.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageGen = imageGen;
|
|
4
|
+
// Import package version for debugging (same as main API)
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6
|
+
const PACKAGE_VERSION = require("../package.json").version;
|
|
7
|
+
/**
|
|
8
|
+
* Generate images using a custom API that mimics OpenAI's image generation capabilities
|
|
9
|
+
* @param prompt Text prompt describing the image to generate
|
|
10
|
+
* @param options Configuration options for the image generation request
|
|
11
|
+
* @returns A Promise that resolves to the image response containing base64 encoded image data
|
|
12
|
+
*/
|
|
13
|
+
async function imageGen(prompt, options = {}) {
|
|
14
|
+
const { model = "gpt-image-1", apiKey = "VIBES_DIY", debug = false, } = options;
|
|
15
|
+
if (debug) {
|
|
16
|
+
console.log(`[imageGen:${PACKAGE_VERSION}] Generating image with prompt: ${prompt.substring(0, 50)}...`);
|
|
17
|
+
console.log(`[imageGen:${PACKAGE_VERSION}] Using model: ${model}`);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
// Handle image generation
|
|
21
|
+
if (!options.images || options.images.length === 0) {
|
|
22
|
+
// Simple image generation with text prompt
|
|
23
|
+
// Ensure we have a fully qualified URL by prepending document.location.origin
|
|
24
|
+
const baseUrl = typeof document !== 'undefined' ? document.location.origin : '';
|
|
25
|
+
const generateEndpoint = `${baseUrl}/api/openai-image/generate`;
|
|
26
|
+
const response = await fetch(generateEndpoint, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
model,
|
|
34
|
+
prompt,
|
|
35
|
+
...(options.size && { size: options.size }),
|
|
36
|
+
...(options.quality && { quality: options.quality }),
|
|
37
|
+
...(options.style && { style: options.style }),
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const errorData = await response.text();
|
|
42
|
+
throw new Error(`Image generation failed: ${response.status} ${response.statusText} - ${errorData}`);
|
|
43
|
+
}
|
|
44
|
+
const result = await response.json();
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Image editing with multiple input images
|
|
49
|
+
const formData = new FormData();
|
|
50
|
+
formData.append("prompt", prompt);
|
|
51
|
+
formData.append("model", model);
|
|
52
|
+
// Add image files to the form data
|
|
53
|
+
if (Array.isArray(options.images)) {
|
|
54
|
+
options.images.forEach(image => {
|
|
55
|
+
formData.append("image[]", image);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Add optional parameters if provided
|
|
59
|
+
if (options.size)
|
|
60
|
+
formData.append("size", options.size);
|
|
61
|
+
if (options.quality)
|
|
62
|
+
formData.append("quality", options.quality);
|
|
63
|
+
if (options.style)
|
|
64
|
+
formData.append("style", options.style);
|
|
65
|
+
// Ensure we have a fully qualified URL by prepending document.location.origin
|
|
66
|
+
const baseUrl = typeof document !== 'undefined' ? document.location.origin : '';
|
|
67
|
+
const editEndpoint = `${baseUrl}/api/openai-image/edit`;
|
|
68
|
+
const response = await fetch(editEndpoint, {
|
|
69
|
+
method: "POST",
|
|
70
|
+
headers: {
|
|
71
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
72
|
+
},
|
|
73
|
+
body: formData,
|
|
74
|
+
});
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
const errorData = await response.text();
|
|
77
|
+
throw new Error(`Image editing failed: ${response.status} ${response.statusText} - ${errorData}`);
|
|
78
|
+
}
|
|
79
|
+
const result = await response.json();
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (debug) {
|
|
85
|
+
console.error(`[imageGen:${PACKAGE_VERSION}] Error:`, error);
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,12 +17,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.callAI = void 0;
|
|
20
|
+
exports.imageGen = exports.callAI = void 0;
|
|
21
21
|
// Export public types
|
|
22
22
|
__exportStar(require("./types"), exports);
|
|
23
23
|
// Export API function
|
|
24
24
|
var api_1 = require("./api");
|
|
25
25
|
Object.defineProperty(exports, "callAI", { enumerable: true, get: function () { return api_1.callAI; } });
|
|
26
|
+
// Export image generation function
|
|
27
|
+
var image_1 = require("./image");
|
|
28
|
+
Object.defineProperty(exports, "imageGen", { enumerable: true, get: function () { return image_1.imageGen; } });
|
|
26
29
|
// Export strategies and utilities for advanced use cases
|
|
27
30
|
__exportStar(require("./strategies"), exports);
|
|
28
31
|
__exportStar(require("./utils"), exports);
|
package/dist/types.d.ts
CHANGED
|
@@ -123,3 +123,54 @@ export interface AIResponse {
|
|
|
123
123
|
};
|
|
124
124
|
model: string;
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Response from image generation API
|
|
128
|
+
*/
|
|
129
|
+
export interface ImageResponse {
|
|
130
|
+
created: number;
|
|
131
|
+
data: {
|
|
132
|
+
b64_json: string;
|
|
133
|
+
url?: string;
|
|
134
|
+
revised_prompt?: string;
|
|
135
|
+
}[];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Options for image generation
|
|
139
|
+
*/
|
|
140
|
+
export interface ImageGenOptions {
|
|
141
|
+
/**
|
|
142
|
+
* API key for authentication
|
|
143
|
+
* Defaults to "VIBES_DIY"
|
|
144
|
+
*/
|
|
145
|
+
apiKey?: string;
|
|
146
|
+
/**
|
|
147
|
+
* Model to use for image generation
|
|
148
|
+
* Defaults to "gpt-image-1"
|
|
149
|
+
*/
|
|
150
|
+
model?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Size of the generated image
|
|
153
|
+
*/
|
|
154
|
+
size?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Quality of the generated image
|
|
157
|
+
*/
|
|
158
|
+
quality?: string;
|
|
159
|
+
/**
|
|
160
|
+
* Style of the generated image
|
|
161
|
+
*/
|
|
162
|
+
style?: string;
|
|
163
|
+
/**
|
|
164
|
+
* For image editing: array of File objects to be edited
|
|
165
|
+
*/
|
|
166
|
+
images?: File[];
|
|
167
|
+
/**
|
|
168
|
+
* Enable debug logging
|
|
169
|
+
*/
|
|
170
|
+
debug?: boolean;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* @deprecated Use ImageGenOptions instead
|
|
174
|
+
*/
|
|
175
|
+
export interface ImageEditOptions extends ImageGenOptions {
|
|
176
|
+
}
|