@aigne/ideogram 0.4.17-beta → 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 -1316
- 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
package/README.md
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
<picture>
|
|
5
|
-
<source srcset="https://raw.githubusercontent.com/
|
|
6
|
-
<source srcset="https://raw.githubusercontent.com/
|
|
7
|
-
<img src="https://raw.githubusercontent.com/
|
|
5
|
+
<source srcset="https://raw.githubusercontent.com/ArcBlock/aigne-framework/main/logo-dark.svg" media="(prefers-color-scheme: dark)">
|
|
6
|
+
<source srcset="https://raw.githubusercontent.com/ArcBlock/aigne-framework/main/logo.svg" media="(prefers-color-scheme: light)">
|
|
7
|
+
<img src="https://raw.githubusercontent.com/ArcBlock/aigne-framework/main/logo.svg" alt="AIGNE Logo" width="400" />
|
|
8
8
|
</picture>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
|
-
[](https://star-history.com/#ArcBlock/aigne-framework)
|
|
12
|
+
[](https://github.com/ArcBlock/aigne-framework/issues)
|
|
13
|
+
[](https://codecov.io/gh/ArcBlock/aigne-framework)
|
|
14
14
|
[](https://www.npmjs.com/package/@aigne/ideogram)
|
|
15
|
-
[](https://github.com/
|
|
15
|
+
[](https://github.com/ArcBlock/aigne-framework/blob/main/LICENSE.md)
|
|
16
16
|
|
|
17
|
-
AIGNE Ideogram SDK for integrating with Ideogram's image generation models and API services within the [AIGNE Framework](https://github.com/
|
|
17
|
+
AIGNE Ideogram SDK for integrating with Ideogram's image generation models and API services within the [AIGNE Framework](https://github.com/ArcBlock/aigne-framework).
|
|
18
18
|
|
|
19
19
|
## Introduction
|
|
20
20
|
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
let _aigne_core = require("@aigne/core");
|
|
2
|
+
let _aigne_core_utils_camelize = require("@aigne/core/utils/camelize");
|
|
3
|
+
let _aigne_core_utils_fetch = require("@aigne/core/utils/fetch");
|
|
4
|
+
let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
|
|
5
|
+
let ufo = require("ufo");
|
|
6
|
+
let zod = require("zod");
|
|
7
|
+
|
|
8
|
+
//#region src/ideogram-image-model.ts
|
|
9
|
+
const IDEOGRAM_BASE_URL = "https://api.ideogram.ai";
|
|
10
|
+
const IDEOGRAM_DEFAULT_IMAGE_MODEL = "ideogram-v3";
|
|
11
|
+
const ideogramImageModelInputSchema = _aigne_core.imageModelInputSchema.extend({});
|
|
12
|
+
const ideogramImageModelOptionsSchema = zod.z.object({
|
|
13
|
+
apiKey: zod.z.string().optional(),
|
|
14
|
+
baseURL: zod.z.string().optional(),
|
|
15
|
+
model: zod.z.string().optional(),
|
|
16
|
+
modelOptions: zod.z.object({}).optional(),
|
|
17
|
+
clientOptions: zod.z.object({}).optional()
|
|
18
|
+
});
|
|
19
|
+
var IdeogramImageModel = class extends _aigne_core.ImageModel {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
super({
|
|
22
|
+
...options,
|
|
23
|
+
inputSchema: ideogramImageModelInputSchema,
|
|
24
|
+
description: options?.description ?? "Draw or edit image by Ideogram image models"
|
|
25
|
+
});
|
|
26
|
+
this.options = options;
|
|
27
|
+
if (options) (0, _aigne_core_utils_type_utils.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") throw new Error(`${this.name} only support ideogram-v3`);
|
|
49
|
+
const inputKeys = [
|
|
50
|
+
"prompt",
|
|
51
|
+
"seed",
|
|
52
|
+
"resolution",
|
|
53
|
+
"aspectRatio",
|
|
54
|
+
"renderingSpeed",
|
|
55
|
+
"magicPrompt",
|
|
56
|
+
"negativePrompt",
|
|
57
|
+
"colorPalette",
|
|
58
|
+
"styleCodes",
|
|
59
|
+
"styleType"
|
|
60
|
+
];
|
|
61
|
+
const mergedInput = (0, _aigne_core_utils_camelize.snakelize)((0, _aigne_core_utils_type_utils.pick)({
|
|
62
|
+
...this.modelOptions,
|
|
63
|
+
...input.modelOptions,
|
|
64
|
+
...input
|
|
65
|
+
}, inputKeys));
|
|
66
|
+
Object.keys(mergedInput).forEach((key) => {
|
|
67
|
+
if (mergedInput[key]) formData.append(key, mergedInput[key]);
|
|
68
|
+
});
|
|
69
|
+
if (input.n) formData.append("num_images", input.n.toString());
|
|
70
|
+
const inputImages = (0, _aigne_core_utils_type_utils.flat)(input.image);
|
|
71
|
+
const image = inputImages.at(0);
|
|
72
|
+
if (image) {
|
|
73
|
+
if (inputImages.length > 1) throw new Error(`${this.name} only support one image for editing`);
|
|
74
|
+
const { data } = await this.transformFileType("file", image);
|
|
75
|
+
formData.append("image", new Blob([Buffer.from(data, "base64")]));
|
|
76
|
+
}
|
|
77
|
+
const { url, apiKey } = this.credential;
|
|
78
|
+
if (!apiKey) throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
|
|
79
|
+
return {
|
|
80
|
+
images: (await (await (0, _aigne_core_utils_fetch.fetch)((0, ufo.joinURL)(new URL(url).origin, "v1", model, image ? "remix" : "generate"), {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: { "api-key": apiKey },
|
|
83
|
+
body: formData,
|
|
84
|
+
timeout: this.options?.clientOptions?.timeout ?? 60 * 1e3
|
|
85
|
+
})).json()).data.map((item) => ({
|
|
86
|
+
type: "url",
|
|
87
|
+
url: item.url,
|
|
88
|
+
mimeType: "image/png"
|
|
89
|
+
})),
|
|
90
|
+
usage: {
|
|
91
|
+
inputTokens: 0,
|
|
92
|
+
outputTokens: 0
|
|
93
|
+
},
|
|
94
|
+
model
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
exports.IdeogramImageModel = IdeogramImageModel;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AgentInvokeOptions, ImageModel, ImageModelInput, ImageModelOptions, ImageModelOutput } from "@aigne/core";
|
|
2
|
+
|
|
3
|
+
//#region src/ideogram-image-model.d.ts
|
|
4
|
+
interface IdeogramImageModelInput extends ImageModelInput {
|
|
5
|
+
seed?: number;
|
|
6
|
+
resolution?: string;
|
|
7
|
+
aspectRatio?: string;
|
|
8
|
+
renderingSpeed?: string;
|
|
9
|
+
magicPrompt?: string;
|
|
10
|
+
negativePrompt?: string;
|
|
11
|
+
numImages?: number;
|
|
12
|
+
colorPalette?: any;
|
|
13
|
+
styleCodes?: string[];
|
|
14
|
+
styleType?: string;
|
|
15
|
+
}
|
|
16
|
+
interface IdeogramImageModelOutput extends ImageModelOutput {}
|
|
17
|
+
interface IdeogramImageModelOptions extends ImageModelOptions<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
baseURL?: string;
|
|
20
|
+
model?: string;
|
|
21
|
+
modelOptions?: Omit<Partial<IdeogramImageModelInput>, "model">;
|
|
22
|
+
clientOptions?: Record<string, any>;
|
|
23
|
+
}
|
|
24
|
+
declare class IdeogramImageModel extends ImageModel<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
25
|
+
options?: IdeogramImageModelOptions | undefined;
|
|
26
|
+
constructor(options?: IdeogramImageModelOptions | undefined);
|
|
27
|
+
protected apiKeyEnvName: string;
|
|
28
|
+
get credential(): {
|
|
29
|
+
url: string;
|
|
30
|
+
apiKey: string | undefined;
|
|
31
|
+
model: string;
|
|
32
|
+
};
|
|
33
|
+
get modelOptions(): Omit<Partial<IdeogramImageModelInput>, "model"> | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Process the input and generate a response
|
|
36
|
+
* @param input The input to process
|
|
37
|
+
* @returns The generated response
|
|
38
|
+
*/
|
|
39
|
+
process(input: IdeogramImageModelInput, _options: AgentInvokeOptions): Promise<ImageModelOutput>;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { IdeogramImageModel, IdeogramImageModelInput, IdeogramImageModelOptions, IdeogramImageModelOutput };
|
|
43
|
+
//# sourceMappingURL=ideogram-image-model.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ideogram-image-model.d.cts","names":[],"sources":["../src/ideogram-image-model.ts"],"mappings":";;;UAiBiB,uBAAA,SAAgC,eAAA;EAAA,IAAA;EAAA,UAAA;EAAA,WAAA;EAAA,cAAA;EAAA,WAAA;EAAA,cAAA;EAAA,SAAA;EAAA,YAAA;EAAA,UAAA;EAAA,SAAA;AAAA;AAAA,UAahC,wBAAA,SAAiC,gBAAA;AAAA,UAEjC,yBAAA,SACP,iBAAA,CAAkB,uBAAA,EAAyB,wBAAA;EAAA,MAAA;EAAA,OAAA;EAAA,KAAA;EAAA,YAAA,GAIpC,IAAA,CAAK,OAAA,CAAQ,uBAAA;EAAA,aAAA,GACZ,MAAA;AAAA;AAAA,cAaL,kBAAA,SAA2B,UAAA,CACtC,uBAAA,EACA,wBAAA;EAAA,OAAA,GAEsC,yBAAA;EAAA,YAAA,OAAA,GAAA,yBAAA;EAAA,UAAA,aAAA;EAAA,IAAA,WAAA;IAAA,GAAA;IAAA,MAAA;IAAA,KAAA;EAAA;EAAA,IAAA,aAAA,GAmBtB,IAAA,CAAA,OAAA,CAAA,uBAAA;EAAA;;;;;EAAA,QAAA,KAAA,EAUP,uBAAA,EAAA,QAAA,EACG,kBAAA,GACT,OAAA,CAAQ,gBAAA;AAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AgentInvokeOptions, ImageModel, ImageModelInput, ImageModelOptions, ImageModelOutput } from "@aigne/core";
|
|
2
|
+
|
|
3
|
+
//#region src/ideogram-image-model.d.ts
|
|
4
|
+
interface IdeogramImageModelInput extends ImageModelInput {
|
|
5
|
+
seed?: number;
|
|
6
|
+
resolution?: string;
|
|
7
|
+
aspectRatio?: string;
|
|
8
|
+
renderingSpeed?: string;
|
|
9
|
+
magicPrompt?: string;
|
|
10
|
+
negativePrompt?: string;
|
|
11
|
+
numImages?: number;
|
|
12
|
+
colorPalette?: any;
|
|
13
|
+
styleCodes?: string[];
|
|
14
|
+
styleType?: string;
|
|
15
|
+
}
|
|
16
|
+
interface IdeogramImageModelOutput extends ImageModelOutput {}
|
|
17
|
+
interface IdeogramImageModelOptions extends ImageModelOptions<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
baseURL?: string;
|
|
20
|
+
model?: string;
|
|
21
|
+
modelOptions?: Omit<Partial<IdeogramImageModelInput>, "model">;
|
|
22
|
+
clientOptions?: Record<string, any>;
|
|
23
|
+
}
|
|
24
|
+
declare class IdeogramImageModel extends ImageModel<IdeogramImageModelInput, IdeogramImageModelOutput> {
|
|
25
|
+
options?: IdeogramImageModelOptions | undefined;
|
|
26
|
+
constructor(options?: IdeogramImageModelOptions | undefined);
|
|
27
|
+
protected apiKeyEnvName: string;
|
|
28
|
+
get credential(): {
|
|
29
|
+
url: string;
|
|
30
|
+
apiKey: string | undefined;
|
|
31
|
+
model: string;
|
|
32
|
+
};
|
|
33
|
+
get modelOptions(): Omit<Partial<IdeogramImageModelInput>, "model"> | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Process the input and generate a response
|
|
36
|
+
* @param input The input to process
|
|
37
|
+
* @returns The generated response
|
|
38
|
+
*/
|
|
39
|
+
process(input: IdeogramImageModelInput, _options: AgentInvokeOptions): Promise<ImageModelOutput>;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { IdeogramImageModel, IdeogramImageModelInput, IdeogramImageModelOptions, IdeogramImageModelOutput };
|
|
43
|
+
//# sourceMappingURL=ideogram-image-model.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ideogram-image-model.d.mts","names":[],"sources":["../src/ideogram-image-model.ts"],"mappings":";;;UAiBiB,uBAAA,SAAgC,eAAA;EAAA,IAAA;EAAA,UAAA;EAAA,WAAA;EAAA,cAAA;EAAA,WAAA;EAAA,cAAA;EAAA,SAAA;EAAA,YAAA;EAAA,UAAA;EAAA,SAAA;AAAA;AAAA,UAahC,wBAAA,SAAiC,gBAAA;AAAA,UAEjC,yBAAA,SACP,iBAAA,CAAkB,uBAAA,EAAyB,wBAAA;EAAA,MAAA;EAAA,OAAA;EAAA,KAAA;EAAA,YAAA,GAIpC,IAAA,CAAK,OAAA,CAAQ,uBAAA;EAAA,aAAA,GACZ,MAAA;AAAA;AAAA,cAaL,kBAAA,SAA2B,UAAA,CACtC,uBAAA,EACA,wBAAA;EAAA,OAAA,GAEsC,yBAAA;EAAA,YAAA,OAAA,GAAA,yBAAA;EAAA,UAAA,aAAA;EAAA,IAAA,WAAA;IAAA,GAAA;IAAA,MAAA;IAAA,KAAA;EAAA;EAAA,IAAA,aAAA,GAmBtB,IAAA,CAAA,OAAA,CAAA,uBAAA;EAAA;;;;;EAAA,QAAA,KAAA,EAUP,uBAAA,EAAA,QAAA,EACG,kBAAA,GACT,OAAA,CAAQ,gBAAA;AAAA"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ImageModel, imageModelInputSchema } from "@aigne/core";
|
|
2
|
+
import { snakelize } from "@aigne/core/utils/camelize";
|
|
3
|
+
import { fetch } from "@aigne/core/utils/fetch";
|
|
4
|
+
import { checkArguments, flat, pick } from "@aigne/core/utils/type-utils";
|
|
5
|
+
import { joinURL } from "ufo";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
|
|
8
|
+
//#region src/ideogram-image-model.ts
|
|
9
|
+
const IDEOGRAM_BASE_URL = "https://api.ideogram.ai";
|
|
10
|
+
const IDEOGRAM_DEFAULT_IMAGE_MODEL = "ideogram-v3";
|
|
11
|
+
const ideogramImageModelInputSchema = imageModelInputSchema.extend({});
|
|
12
|
+
const ideogramImageModelOptionsSchema = z.object({
|
|
13
|
+
apiKey: z.string().optional(),
|
|
14
|
+
baseURL: z.string().optional(),
|
|
15
|
+
model: z.string().optional(),
|
|
16
|
+
modelOptions: z.object({}).optional(),
|
|
17
|
+
clientOptions: z.object({}).optional()
|
|
18
|
+
});
|
|
19
|
+
var IdeogramImageModel = class extends ImageModel {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
super({
|
|
22
|
+
...options,
|
|
23
|
+
inputSchema: ideogramImageModelInputSchema,
|
|
24
|
+
description: options?.description ?? "Draw or edit image by Ideogram image models"
|
|
25
|
+
});
|
|
26
|
+
this.options = options;
|
|
27
|
+
if (options) 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") throw new Error(`${this.name} only support ideogram-v3`);
|
|
49
|
+
const inputKeys = [
|
|
50
|
+
"prompt",
|
|
51
|
+
"seed",
|
|
52
|
+
"resolution",
|
|
53
|
+
"aspectRatio",
|
|
54
|
+
"renderingSpeed",
|
|
55
|
+
"magicPrompt",
|
|
56
|
+
"negativePrompt",
|
|
57
|
+
"colorPalette",
|
|
58
|
+
"styleCodes",
|
|
59
|
+
"styleType"
|
|
60
|
+
];
|
|
61
|
+
const mergedInput = snakelize(pick({
|
|
62
|
+
...this.modelOptions,
|
|
63
|
+
...input.modelOptions,
|
|
64
|
+
...input
|
|
65
|
+
}, inputKeys));
|
|
66
|
+
Object.keys(mergedInput).forEach((key) => {
|
|
67
|
+
if (mergedInput[key]) formData.append(key, mergedInput[key]);
|
|
68
|
+
});
|
|
69
|
+
if (input.n) formData.append("num_images", input.n.toString());
|
|
70
|
+
const inputImages = flat(input.image);
|
|
71
|
+
const image = inputImages.at(0);
|
|
72
|
+
if (image) {
|
|
73
|
+
if (inputImages.length > 1) throw new Error(`${this.name} only support one image for editing`);
|
|
74
|
+
const { data } = await this.transformFileType("file", image);
|
|
75
|
+
formData.append("image", new Blob([Buffer.from(data, "base64")]));
|
|
76
|
+
}
|
|
77
|
+
const { url, apiKey } = this.credential;
|
|
78
|
+
if (!apiKey) throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
|
|
79
|
+
return {
|
|
80
|
+
images: (await (await fetch(joinURL(new URL(url).origin, "v1", model, image ? "remix" : "generate"), {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: { "api-key": apiKey },
|
|
83
|
+
body: formData,
|
|
84
|
+
timeout: this.options?.clientOptions?.timeout ?? 60 * 1e3
|
|
85
|
+
})).json()).data.map((item) => ({
|
|
86
|
+
type: "url",
|
|
87
|
+
url: item.url,
|
|
88
|
+
mimeType: "image/png"
|
|
89
|
+
})),
|
|
90
|
+
usage: {
|
|
91
|
+
inputTokens: 0,
|
|
92
|
+
outputTokens: 0
|
|
93
|
+
},
|
|
94
|
+
model
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
export { IdeogramImageModel };
|
|
101
|
+
//# sourceMappingURL=ideogram-image-model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ideogram-image-model.mjs","names":[],"sources":["../src/ideogram-image-model.ts"],"sourcesContent":["import {\n type AgentInvokeOptions,\n ImageModel,\n type ImageModelInput,\n type ImageModelOptions,\n type ImageModelOutput,\n imageModelInputSchema,\n} from \"@aigne/core\";\nimport { snakelize } from \"@aigne/core/utils/camelize\";\nimport { fetch } from \"@aigne/core/utils/fetch\";\nimport { checkArguments, flat, pick } from \"@aigne/core/utils/type-utils\";\nimport { joinURL } from \"ufo\";\nimport { z } from \"zod\";\n\nconst IDEOGRAM_BASE_URL = \"https://api.ideogram.ai\";\nconst IDEOGRAM_DEFAULT_IMAGE_MODEL = \"ideogram-v3\";\n\nexport interface IdeogramImageModelInput extends ImageModelInput {\n seed?: number;\n resolution?: string;\n aspectRatio?: string;\n renderingSpeed?: string;\n magicPrompt?: string;\n negativePrompt?: string;\n numImages?: number;\n colorPalette?: any;\n styleCodes?: string[];\n styleType?: string;\n}\n\nexport interface IdeogramImageModelOutput extends ImageModelOutput {}\n\nexport interface IdeogramImageModelOptions\n extends ImageModelOptions<IdeogramImageModelInput, IdeogramImageModelOutput> {\n apiKey?: string;\n baseURL?: string;\n model?: string;\n modelOptions?: Omit<Partial<IdeogramImageModelInput>, \"model\">;\n clientOptions?: Record<string, any>;\n}\n\nconst ideogramImageModelInputSchema = imageModelInputSchema.extend({});\n\nconst ideogramImageModelOptionsSchema = z.object({\n apiKey: z.string().optional(),\n baseURL: z.string().optional(),\n model: z.string().optional(),\n modelOptions: z.object({}).optional(),\n clientOptions: z.object({}).optional(),\n});\n\nexport class IdeogramImageModel extends ImageModel<\n IdeogramImageModelInput,\n IdeogramImageModelOutput\n> {\n constructor(public override options?: IdeogramImageModelOptions) {\n super({\n ...options,\n inputSchema: ideogramImageModelInputSchema,\n description: options?.description ?? \"Draw or edit image by Ideogram image models\",\n });\n if (options) checkArguments(this.name, ideogramImageModelOptionsSchema, options);\n }\n\n protected apiKeyEnvName = \"IDEOGRAM_API_KEY\";\n\n override get credential() {\n return {\n url: this.options?.baseURL || process.env.IDEOGRAM_BASE_URL || IDEOGRAM_BASE_URL,\n apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],\n model: this.options?.model || IDEOGRAM_DEFAULT_IMAGE_MODEL,\n };\n }\n\n get modelOptions() {\n return this.options?.modelOptions;\n }\n\n /**\n * Process the input and generate a response\n * @param input The input to process\n * @returns The generated response\n */\n override async process(\n input: IdeogramImageModelInput,\n _options: AgentInvokeOptions,\n ): Promise<ImageModelOutput> {\n const model = input.model || this.credential.model;\n const formData = new FormData();\n\n if (model !== \"ideogram-v3\") {\n throw new Error(`${this.name} only support ideogram-v3`);\n }\n\n const inputKeys = [\n \"prompt\",\n \"seed\",\n \"resolution\",\n \"aspectRatio\",\n \"renderingSpeed\",\n \"magicPrompt\",\n \"negativePrompt\",\n \"colorPalette\",\n \"styleCodes\",\n \"styleType\",\n ];\n\n const mergedInput = snakelize(\n pick({ ...this.modelOptions, ...input.modelOptions, ...input }, inputKeys),\n );\n\n Object.keys(mergedInput).forEach((key) => {\n if (mergedInput[key]) {\n formData.append(key, mergedInput[key] as string);\n }\n });\n\n if (input.n) {\n formData.append(\"num_images\", input.n.toString());\n }\n\n const inputImages = flat(input.image);\n const image = inputImages.at(0);\n if (image) {\n if (inputImages.length > 1) {\n throw new Error(`${this.name} only support one image for editing`);\n }\n const { data } = await this.transformFileType(\"file\", image);\n formData.append(\"image\", new Blob([Buffer.from(data, \"base64\")]));\n }\n\n const { url, apiKey } = this.credential;\n if (!apiKey)\n throw new Error(\n `${this.name} requires an API key. Please provide it via \\`options.apiKey\\`, or set the \\`${this.apiKeyEnvName}\\` environment variable`,\n );\n\n const apiURL = joinURL(new URL(url).origin, \"v1\", model, image ? \"remix\" : \"generate\");\n\n const response = await fetch(apiURL, {\n method: \"POST\",\n headers: { \"api-key\": apiKey },\n body: formData,\n timeout: this.options?.clientOptions?.timeout ?? 60 * 1000,\n });\n\n const data: { data: { url: string }[] } = await response.json();\n\n return {\n images: data.data.map((item) => ({ type: \"url\", url: item.url, mimeType: \"image/png\" })),\n usage: {\n inputTokens: 0,\n outputTokens: 0,\n },\n model,\n };\n }\n}\n"],"mappings":";;;;;;;;AAcA,MAAM,oBAAoB;AAC1B,MAAM,+BAA+B;AA0BrC,MAAM,gCAAgC,sBAAsB,OAAO,EAAE,CAAC;AAEtE,MAAM,kCAAkC,EAAE,OAAO;CAC/C,QAAQ,EAAE,QAAQ,CAAC,UAAU;CAC7B,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU;CAC5B,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU;CACrC,eAAe,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU;CACvC,CAAC;AAEF,IAAa,qBAAb,cAAwC,WAGtC;CACA,YAAY,AAAgB,SAAqC;AAC/D,QAAM;GACJ,GAAG;GACH,aAAa;GACb,aAAa,SAAS,eAAe;GACtC,CAAC;EALwB;AAM1B,MAAI,QAAS,gBAAe,KAAK,MAAM,iCAAiC,QAAQ;;CAGlF,AAAU,gBAAgB;CAE1B,IAAa,aAAa;AACxB,SAAO;GACL,KAAK,KAAK,SAAS,WAAW,QAAQ,IAAI,qBAAqB;GAC/D,QAAQ,KAAK,SAAS,UAAU,QAAQ,IAAI,KAAK;GACjD,OAAO,KAAK,SAAS,SAAS;GAC/B;;CAGH,IAAI,eAAe;AACjB,SAAO,KAAK,SAAS;;;;;;;CAQvB,MAAe,QACb,OACA,UAC2B;EAC3B,MAAM,QAAQ,MAAM,SAAS,KAAK,WAAW;EAC7C,MAAM,WAAW,IAAI,UAAU;AAE/B,MAAI,UAAU,cACZ,OAAM,IAAI,MAAM,GAAG,KAAK,KAAK,2BAA2B;EAG1D,MAAM,YAAY;GAChB;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EAED,MAAM,cAAc,UAClB,KAAK;GAAE,GAAG,KAAK;GAAc,GAAG,MAAM;GAAc,GAAG;GAAO,EAAE,UAAU,CAC3E;AAED,SAAO,KAAK,YAAY,CAAC,SAAS,QAAQ;AACxC,OAAI,YAAY,KACd,UAAS,OAAO,KAAK,YAAY,KAAe;IAElD;AAEF,MAAI,MAAM,EACR,UAAS,OAAO,cAAc,MAAM,EAAE,UAAU,CAAC;EAGnD,MAAM,cAAc,KAAK,MAAM,MAAM;EACrC,MAAM,QAAQ,YAAY,GAAG,EAAE;AAC/B,MAAI,OAAO;AACT,OAAI,YAAY,SAAS,EACvB,OAAM,IAAI,MAAM,GAAG,KAAK,KAAK,qCAAqC;GAEpE,MAAM,EAAE,SAAS,MAAM,KAAK,kBAAkB,QAAQ,MAAM;AAC5D,YAAS,OAAO,SAAS,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,CAAC;;EAGnE,MAAM,EAAE,KAAK,WAAW,KAAK;AAC7B,MAAI,CAAC,OACH,OAAM,IAAI,MACR,GAAG,KAAK,KAAK,+EAA+E,KAAK,cAAc,yBAChH;AAaH,SAAO;GACL,SAHwC,OAPzB,MAAM,MAFR,QAAQ,IAAI,IAAI,IAAI,CAAC,QAAQ,MAAM,OAAO,QAAQ,UAAU,WAAW,EAEjD;IACnC,QAAQ;IACR,SAAS,EAAE,WAAW,QAAQ;IAC9B,MAAM;IACN,SAAS,KAAK,SAAS,eAAe,WAAW,KAAK;IACvD,CAAC,EAEuD,MAAM,EAGhD,KAAK,KAAK,UAAU;IAAE,MAAM;IAAO,KAAK,KAAK;IAAK,UAAU;IAAa,EAAE;GACxF,OAAO;IACL,aAAa;IACb,cAAc;IACf;GACD;GACD"}
|
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,60 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/ideogram",
|
|
3
|
+
"version": "1.74.0-beta",
|
|
3
4
|
"description": "AIGNE Ideogram SDK for integrating with Ideogram's image models and API services",
|
|
5
|
+
"license": "Elastic-2.0",
|
|
4
6
|
"publishConfig": {
|
|
5
7
|
"access": "public"
|
|
6
8
|
},
|
|
7
9
|
"author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
|
|
8
10
|
"homepage": "https://www.aigne.io/framework",
|
|
9
|
-
"license": "Elastic-2.0",
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/
|
|
13
|
+
"url": "git+https://github.com/ArcBlock/aigne-framework"
|
|
13
14
|
},
|
|
14
15
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/ArcBlock/aigne-framework/issues"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./dist/index.cjs",
|
|
20
|
+
"module": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.cts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"require": "./dist/index.cjs",
|
|
25
|
+
"import": "./dist/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./*": "./*"
|
|
16
28
|
},
|
|
17
29
|
"files": [
|
|
18
|
-
"
|
|
19
|
-
"lib/dts",
|
|
20
|
-
"lib/esm",
|
|
30
|
+
"dist",
|
|
21
31
|
"LICENSE",
|
|
22
32
|
"README.md",
|
|
23
33
|
"CHANGELOG.md"
|
|
24
34
|
],
|
|
25
|
-
"type": "module",
|
|
26
|
-
"main": "./lib/cjs/index.js",
|
|
27
|
-
"module": "./lib/esm/index.js",
|
|
28
|
-
"types": "./lib/dts/index.d.ts",
|
|
29
|
-
"exports": {
|
|
30
|
-
".": {
|
|
31
|
-
"import": "./lib/esm/index.js",
|
|
32
|
-
"require": "./lib/cjs/index.js",
|
|
33
|
-
"types": "./lib/dts/index.d.ts"
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
35
|
"dependencies": {
|
|
37
36
|
"ufo": "^1.6.1",
|
|
38
37
|
"zod": "3.25.67",
|
|
39
|
-
"@aigne/core": "1.
|
|
38
|
+
"@aigne/core": "1.74.0-beta"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
|
-
"@types/bun": "^1.
|
|
43
|
-
"@types/node": "^24.5.1",
|
|
41
|
+
"@types/bun": "^1.3.6",
|
|
44
42
|
"detect-port": "^2.1.0",
|
|
45
43
|
"hono": "^4.9.7",
|
|
46
44
|
"npm-run-all": "^4.1.5",
|
|
47
|
-
"rimraf": "^6.
|
|
48
|
-
"
|
|
49
|
-
"
|
|
45
|
+
"rimraf": "^6.1.2",
|
|
46
|
+
"tsdown": "0.20.0-beta.3",
|
|
47
|
+
"typescript": "5.9.2",
|
|
48
|
+
"@aigne/utils": "1.74.0-beta",
|
|
49
|
+
"@aigne/typescript-config": "0.0.0",
|
|
50
|
+
"@aigne/scripts": "0.0.0"
|
|
50
51
|
},
|
|
51
|
-
"version": "0.4.17-beta",
|
|
52
52
|
"scripts": {
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"clean": "rimraf
|
|
53
|
+
"build": "tsdown",
|
|
54
|
+
"check-types": "tsc --noEmit",
|
|
55
|
+
"clean": "rimraf dist coverage",
|
|
56
56
|
"test": "bun test",
|
|
57
|
-
"test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text"
|
|
58
|
-
"postbuild": "node ../../scripts/post-build-lib.mjs"
|
|
57
|
+
"test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text"
|
|
59
58
|
}
|
|
60
59
|
}
|