@aigne/ideogram 0.4.16 → 1.74.0-beta
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/README.md +8 -8
- package/dist/ideogram-image-model.cjs +100 -0
- package/dist/ideogram-image-model.d.cts +43 -0
- package/dist/ideogram-image-model.d.cts.map +1 -0
- package/dist/ideogram-image-model.d.mts +43 -0
- package/dist/ideogram-image-model.d.mts.map +1 -0
- package/dist/ideogram-image-model.mjs +101 -0
- package/dist/ideogram-image-model.mjs.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/package.json +28 -29
- package/CHANGELOG.md +0 -1305
- package/lib/cjs/ideogram-image-model.d.ts +0 -39
- package/lib/cjs/ideogram-image-model.js +0 -105
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -17
- package/lib/cjs/package.json +0 -3
- package/lib/dts/ideogram-image-model.d.ts +0 -39
- package/lib/dts/index.d.ts +0 -1
- package/lib/esm/ideogram-image-model.d.ts +0 -39
- package/lib/esm/ideogram-image-model.js +0 -101
- package/lib/esm/index.d.ts +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/package.json +0 -3
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type AgentInvokeOptions, ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
|
|
2
|
-
export interface IdeogramImageModelInput extends ImageModelInput {
|
|
3
|
-
seed?: number;
|
|
4
|
-
resolution?: string;
|
|
5
|
-
aspectRatio?: string;
|
|
6
|
-
renderingSpeed?: string;
|
|
7
|
-
magicPrompt?: string;
|
|
8
|
-
negativePrompt?: string;
|
|
9
|
-
numImages?: number;
|
|
10
|
-
colorPalette?: any;
|
|
11
|
-
styleCodes?: string[];
|
|
12
|
-
styleType?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface IdeogramImageModelOutput extends ImageModelOutput {
|
|
15
|
-
}
|
|
16
|
-
export interface IdeogramImageModelOptions extends ImageModelOptions<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
17
|
-
apiKey?: string;
|
|
18
|
-
baseURL?: string;
|
|
19
|
-
model?: string;
|
|
20
|
-
modelOptions?: Omit<Partial<IdeogramImageModelInput>, "model">;
|
|
21
|
-
clientOptions?: Record<string, any>;
|
|
22
|
-
}
|
|
23
|
-
export declare class IdeogramImageModel extends ImageModel<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
24
|
-
options?: IdeogramImageModelOptions | undefined;
|
|
25
|
-
constructor(options?: IdeogramImageModelOptions | undefined);
|
|
26
|
-
protected apiKeyEnvName: string;
|
|
27
|
-
get credential(): {
|
|
28
|
-
url: string;
|
|
29
|
-
apiKey: string | undefined;
|
|
30
|
-
model: string;
|
|
31
|
-
};
|
|
32
|
-
get modelOptions(): Omit<Partial<IdeogramImageModelInput>, "model"> | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Process the input and generate a response
|
|
35
|
-
* @param input The input to process
|
|
36
|
-
* @returns The generated response
|
|
37
|
-
*/
|
|
38
|
-
process(input: IdeogramImageModelInput, _options: AgentInvokeOptions): Promise<ImageModelOutput>;
|
|
39
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IdeogramImageModel = void 0;
|
|
4
|
-
const core_1 = require("@aigne/core");
|
|
5
|
-
const camelize_js_1 = require("@aigne/core/utils/camelize.js");
|
|
6
|
-
const fetch_js_1 = require("@aigne/core/utils/fetch.js");
|
|
7
|
-
const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
|
|
8
|
-
const ufo_1 = require("ufo");
|
|
9
|
-
const zod_1 = require("zod");
|
|
10
|
-
const IDEOGRAM_BASE_URL = "https://api.ideogram.ai";
|
|
11
|
-
const IDEOGRAM_DEFAULT_IMAGE_MODEL = "ideogram-v3";
|
|
12
|
-
const ideogramImageModelInputSchema = core_1.imageModelInputSchema.extend({});
|
|
13
|
-
const ideogramImageModelOptionsSchema = zod_1.z.object({
|
|
14
|
-
apiKey: zod_1.z.string().optional(),
|
|
15
|
-
baseURL: zod_1.z.string().optional(),
|
|
16
|
-
model: zod_1.z.string().optional(),
|
|
17
|
-
modelOptions: zod_1.z.object({}).optional(),
|
|
18
|
-
clientOptions: zod_1.z.object({}).optional(),
|
|
19
|
-
});
|
|
20
|
-
class IdeogramImageModel extends core_1.ImageModel {
|
|
21
|
-
options;
|
|
22
|
-
constructor(options) {
|
|
23
|
-
super({
|
|
24
|
-
...options,
|
|
25
|
-
inputSchema: ideogramImageModelInputSchema,
|
|
26
|
-
description: options?.description ?? "Draw or edit image by Ideogram image models",
|
|
27
|
-
});
|
|
28
|
-
this.options = options;
|
|
29
|
-
if (options)
|
|
30
|
-
(0, type_utils_js_1.checkArguments)(this.name, ideogramImageModelOptionsSchema, options);
|
|
31
|
-
}
|
|
32
|
-
apiKeyEnvName = "IDEOGRAM_API_KEY";
|
|
33
|
-
get credential() {
|
|
34
|
-
return {
|
|
35
|
-
url: this.options?.baseURL || process.env.IDEOGRAM_BASE_URL || IDEOGRAM_BASE_URL,
|
|
36
|
-
apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],
|
|
37
|
-
model: this.options?.model || IDEOGRAM_DEFAULT_IMAGE_MODEL,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
get modelOptions() {
|
|
41
|
-
return this.options?.modelOptions;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Process the input and generate a response
|
|
45
|
-
* @param input The input to process
|
|
46
|
-
* @returns The generated response
|
|
47
|
-
*/
|
|
48
|
-
async process(input, _options) {
|
|
49
|
-
const model = input.model || this.credential.model;
|
|
50
|
-
const formData = new FormData();
|
|
51
|
-
if (model !== "ideogram-v3") {
|
|
52
|
-
throw new Error(`${this.name} only support ideogram-v3`);
|
|
53
|
-
}
|
|
54
|
-
const inputKeys = [
|
|
55
|
-
"prompt",
|
|
56
|
-
"seed",
|
|
57
|
-
"resolution",
|
|
58
|
-
"aspectRatio",
|
|
59
|
-
"renderingSpeed",
|
|
60
|
-
"magicPrompt",
|
|
61
|
-
"negativePrompt",
|
|
62
|
-
"colorPalette",
|
|
63
|
-
"styleCodes",
|
|
64
|
-
"styleType",
|
|
65
|
-
];
|
|
66
|
-
const mergedInput = (0, camelize_js_1.snakelize)((0, type_utils_js_1.pick)({ ...this.modelOptions, ...input.modelOptions, ...input }, inputKeys));
|
|
67
|
-
Object.keys(mergedInput).forEach((key) => {
|
|
68
|
-
if (mergedInput[key]) {
|
|
69
|
-
formData.append(key, mergedInput[key]);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
if (input.n) {
|
|
73
|
-
formData.append("num_images", input.n.toString());
|
|
74
|
-
}
|
|
75
|
-
const inputImages = (0, type_utils_js_1.flat)(input.image);
|
|
76
|
-
const image = inputImages.at(0);
|
|
77
|
-
if (image) {
|
|
78
|
-
if (inputImages.length > 1) {
|
|
79
|
-
throw new Error(`${this.name} only support one image for editing`);
|
|
80
|
-
}
|
|
81
|
-
const { data } = await this.transformFileType("file", image);
|
|
82
|
-
formData.append("image", new Blob([Buffer.from(data, "base64")]));
|
|
83
|
-
}
|
|
84
|
-
const { url, apiKey } = this.credential;
|
|
85
|
-
if (!apiKey)
|
|
86
|
-
throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
|
|
87
|
-
const apiURL = (0, ufo_1.joinURL)(new URL(url).origin, "v1", model, image ? "remix" : "generate");
|
|
88
|
-
const response = await (0, fetch_js_1.fetch)(apiURL, {
|
|
89
|
-
method: "POST",
|
|
90
|
-
headers: { "api-key": apiKey },
|
|
91
|
-
body: formData,
|
|
92
|
-
timeout: this.options?.clientOptions?.timeout ?? 60 * 1000,
|
|
93
|
-
});
|
|
94
|
-
const data = await response.json();
|
|
95
|
-
return {
|
|
96
|
-
images: data.data.map((item) => ({ type: "url", url: item.url, mimeType: "image/png" })),
|
|
97
|
-
usage: {
|
|
98
|
-
inputTokens: 0,
|
|
99
|
-
outputTokens: 0,
|
|
100
|
-
},
|
|
101
|
-
model,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.IdeogramImageModel = IdeogramImageModel;
|
package/lib/cjs/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./ideogram-image-model.js";
|
package/lib/cjs/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./ideogram-image-model.js"), exports);
|
package/lib/cjs/package.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type AgentInvokeOptions, ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
|
|
2
|
-
export interface IdeogramImageModelInput extends ImageModelInput {
|
|
3
|
-
seed?: number;
|
|
4
|
-
resolution?: string;
|
|
5
|
-
aspectRatio?: string;
|
|
6
|
-
renderingSpeed?: string;
|
|
7
|
-
magicPrompt?: string;
|
|
8
|
-
negativePrompt?: string;
|
|
9
|
-
numImages?: number;
|
|
10
|
-
colorPalette?: any;
|
|
11
|
-
styleCodes?: string[];
|
|
12
|
-
styleType?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface IdeogramImageModelOutput extends ImageModelOutput {
|
|
15
|
-
}
|
|
16
|
-
export interface IdeogramImageModelOptions extends ImageModelOptions<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
17
|
-
apiKey?: string;
|
|
18
|
-
baseURL?: string;
|
|
19
|
-
model?: string;
|
|
20
|
-
modelOptions?: Omit<Partial<IdeogramImageModelInput>, "model">;
|
|
21
|
-
clientOptions?: Record<string, any>;
|
|
22
|
-
}
|
|
23
|
-
export declare class IdeogramImageModel extends ImageModel<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
24
|
-
options?: IdeogramImageModelOptions | undefined;
|
|
25
|
-
constructor(options?: IdeogramImageModelOptions | undefined);
|
|
26
|
-
protected apiKeyEnvName: string;
|
|
27
|
-
get credential(): {
|
|
28
|
-
url: string;
|
|
29
|
-
apiKey: string | undefined;
|
|
30
|
-
model: string;
|
|
31
|
-
};
|
|
32
|
-
get modelOptions(): Omit<Partial<IdeogramImageModelInput>, "model"> | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Process the input and generate a response
|
|
35
|
-
* @param input The input to process
|
|
36
|
-
* @returns The generated response
|
|
37
|
-
*/
|
|
38
|
-
process(input: IdeogramImageModelInput, _options: AgentInvokeOptions): Promise<ImageModelOutput>;
|
|
39
|
-
}
|
package/lib/dts/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./ideogram-image-model.js";
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type AgentInvokeOptions, ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
|
|
2
|
-
export interface IdeogramImageModelInput extends ImageModelInput {
|
|
3
|
-
seed?: number;
|
|
4
|
-
resolution?: string;
|
|
5
|
-
aspectRatio?: string;
|
|
6
|
-
renderingSpeed?: string;
|
|
7
|
-
magicPrompt?: string;
|
|
8
|
-
negativePrompt?: string;
|
|
9
|
-
numImages?: number;
|
|
10
|
-
colorPalette?: any;
|
|
11
|
-
styleCodes?: string[];
|
|
12
|
-
styleType?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface IdeogramImageModelOutput extends ImageModelOutput {
|
|
15
|
-
}
|
|
16
|
-
export interface IdeogramImageModelOptions extends ImageModelOptions<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
17
|
-
apiKey?: string;
|
|
18
|
-
baseURL?: string;
|
|
19
|
-
model?: string;
|
|
20
|
-
modelOptions?: Omit<Partial<IdeogramImageModelInput>, "model">;
|
|
21
|
-
clientOptions?: Record<string, any>;
|
|
22
|
-
}
|
|
23
|
-
export declare class IdeogramImageModel extends ImageModel<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
24
|
-
options?: IdeogramImageModelOptions | undefined;
|
|
25
|
-
constructor(options?: IdeogramImageModelOptions | undefined);
|
|
26
|
-
protected apiKeyEnvName: string;
|
|
27
|
-
get credential(): {
|
|
28
|
-
url: string;
|
|
29
|
-
apiKey: string | undefined;
|
|
30
|
-
model: string;
|
|
31
|
-
};
|
|
32
|
-
get modelOptions(): Omit<Partial<IdeogramImageModelInput>, "model"> | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Process the input and generate a response
|
|
35
|
-
* @param input The input to process
|
|
36
|
-
* @returns The generated response
|
|
37
|
-
*/
|
|
38
|
-
process(input: IdeogramImageModelInput, _options: AgentInvokeOptions): Promise<ImageModelOutput>;
|
|
39
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { ImageModel, imageModelInputSchema, } from "@aigne/core";
|
|
2
|
-
import { snakelize } from "@aigne/core/utils/camelize.js";
|
|
3
|
-
import { fetch } from "@aigne/core/utils/fetch.js";
|
|
4
|
-
import { checkArguments, flat, pick } from "@aigne/core/utils/type-utils.js";
|
|
5
|
-
import { joinURL } from "ufo";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
const IDEOGRAM_BASE_URL = "https://api.ideogram.ai";
|
|
8
|
-
const IDEOGRAM_DEFAULT_IMAGE_MODEL = "ideogram-v3";
|
|
9
|
-
const ideogramImageModelInputSchema = imageModelInputSchema.extend({});
|
|
10
|
-
const ideogramImageModelOptionsSchema = z.object({
|
|
11
|
-
apiKey: z.string().optional(),
|
|
12
|
-
baseURL: z.string().optional(),
|
|
13
|
-
model: z.string().optional(),
|
|
14
|
-
modelOptions: z.object({}).optional(),
|
|
15
|
-
clientOptions: z.object({}).optional(),
|
|
16
|
-
});
|
|
17
|
-
export class IdeogramImageModel extends ImageModel {
|
|
18
|
-
options;
|
|
19
|
-
constructor(options) {
|
|
20
|
-
super({
|
|
21
|
-
...options,
|
|
22
|
-
inputSchema: ideogramImageModelInputSchema,
|
|
23
|
-
description: options?.description ?? "Draw or edit image by Ideogram image models",
|
|
24
|
-
});
|
|
25
|
-
this.options = options;
|
|
26
|
-
if (options)
|
|
27
|
-
checkArguments(this.name, ideogramImageModelOptionsSchema, options);
|
|
28
|
-
}
|
|
29
|
-
apiKeyEnvName = "IDEOGRAM_API_KEY";
|
|
30
|
-
get credential() {
|
|
31
|
-
return {
|
|
32
|
-
url: this.options?.baseURL || process.env.IDEOGRAM_BASE_URL || IDEOGRAM_BASE_URL,
|
|
33
|
-
apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],
|
|
34
|
-
model: this.options?.model || IDEOGRAM_DEFAULT_IMAGE_MODEL,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
get modelOptions() {
|
|
38
|
-
return this.options?.modelOptions;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Process the input and generate a response
|
|
42
|
-
* @param input The input to process
|
|
43
|
-
* @returns The generated response
|
|
44
|
-
*/
|
|
45
|
-
async process(input, _options) {
|
|
46
|
-
const model = input.model || this.credential.model;
|
|
47
|
-
const formData = new FormData();
|
|
48
|
-
if (model !== "ideogram-v3") {
|
|
49
|
-
throw new Error(`${this.name} only support ideogram-v3`);
|
|
50
|
-
}
|
|
51
|
-
const inputKeys = [
|
|
52
|
-
"prompt",
|
|
53
|
-
"seed",
|
|
54
|
-
"resolution",
|
|
55
|
-
"aspectRatio",
|
|
56
|
-
"renderingSpeed",
|
|
57
|
-
"magicPrompt",
|
|
58
|
-
"negativePrompt",
|
|
59
|
-
"colorPalette",
|
|
60
|
-
"styleCodes",
|
|
61
|
-
"styleType",
|
|
62
|
-
];
|
|
63
|
-
const mergedInput = snakelize(pick({ ...this.modelOptions, ...input.modelOptions, ...input }, inputKeys));
|
|
64
|
-
Object.keys(mergedInput).forEach((key) => {
|
|
65
|
-
if (mergedInput[key]) {
|
|
66
|
-
formData.append(key, mergedInput[key]);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
if (input.n) {
|
|
70
|
-
formData.append("num_images", input.n.toString());
|
|
71
|
-
}
|
|
72
|
-
const inputImages = flat(input.image);
|
|
73
|
-
const image = inputImages.at(0);
|
|
74
|
-
if (image) {
|
|
75
|
-
if (inputImages.length > 1) {
|
|
76
|
-
throw new Error(`${this.name} only support one image for editing`);
|
|
77
|
-
}
|
|
78
|
-
const { data } = await this.transformFileType("file", image);
|
|
79
|
-
formData.append("image", new Blob([Buffer.from(data, "base64")]));
|
|
80
|
-
}
|
|
81
|
-
const { url, apiKey } = this.credential;
|
|
82
|
-
if (!apiKey)
|
|
83
|
-
throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
|
|
84
|
-
const apiURL = joinURL(new URL(url).origin, "v1", model, image ? "remix" : "generate");
|
|
85
|
-
const response = await fetch(apiURL, {
|
|
86
|
-
method: "POST",
|
|
87
|
-
headers: { "api-key": apiKey },
|
|
88
|
-
body: formData,
|
|
89
|
-
timeout: this.options?.clientOptions?.timeout ?? 60 * 1000,
|
|
90
|
-
});
|
|
91
|
-
const data = await response.json();
|
|
92
|
-
return {
|
|
93
|
-
images: data.data.map((item) => ({ type: "url", url: item.url, mimeType: "image/png" })),
|
|
94
|
-
usage: {
|
|
95
|
-
inputTokens: 0,
|
|
96
|
-
outputTokens: 0,
|
|
97
|
-
},
|
|
98
|
-
model,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
package/lib/esm/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./ideogram-image-model.js";
|
package/lib/esm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./ideogram-image-model.js";
|
package/lib/esm/package.json
DELETED