modelfusion 0.101.0 → 0.103.0
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 +41 -0
- package/model-function/generate-image/ImageGenerationModel.d.ts +12 -2
- package/model-function/generate-image/PromptTemplateImageGenerationModel.cjs +3 -3
- package/model-function/generate-image/PromptTemplateImageGenerationModel.d.ts +2 -2
- package/model-function/generate-image/PromptTemplateImageGenerationModel.js +3 -3
- package/model-function/generate-image/generateImage.cjs +9 -7
- package/model-function/generate-image/generateImage.d.ts +2 -0
- package/model-function/generate-image/generateImage.js +9 -7
- package/model-function/generate-text/PromptTemplateTextGenerationModel.d.ts +1 -1
- package/model-function/generate-text/TextGenerationModel.cjs +7 -0
- package/model-function/generate-text/TextGenerationModel.d.ts +3 -1
- package/model-function/generate-text/TextGenerationModel.js +6 -1
- package/model-function/generate-text/TextGenerationResult.cjs +2 -0
- package/model-function/generate-text/TextGenerationResult.d.ts +11 -0
- package/model-function/generate-text/TextGenerationResult.js +1 -0
- package/model-function/generate-text/generateText.cjs +14 -9
- package/model-function/generate-text/generateText.d.ts +3 -0
- package/model-function/generate-text/generateText.js +14 -9
- package/model-function/generate-text/index.cjs +1 -0
- package/model-function/generate-text/index.d.ts +1 -0
- package/model-function/generate-text/index.js +1 -0
- package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +23 -8
- package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +6 -1
- package/model-provider/anthropic/AnthropicTextGenerationModel.js +24 -9
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +7 -5
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +16 -2
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +7 -5
- package/model-provider/automatic1111/Automatic1111ImageGenerationPrompt.d.ts +0 -1
- package/model-provider/cohere/CohereTextGenerationModel.cjs +22 -6
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +6 -1
- package/model-provider/cohere/CohereTextGenerationModel.js +22 -6
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.cjs +2 -2
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.js +2 -2
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +9 -8
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +4 -5
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +9 -8
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +51 -51
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +20 -17
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +51 -51
- package/model-provider/mistral/MistralChatModel.cjs +19 -2
- package/model-provider/mistral/MistralChatModel.d.ts +6 -1
- package/model-provider/mistral/MistralChatModel.js +19 -2
- package/model-provider/ollama/OllamaChatModel.cjs +8 -3
- package/model-provider/ollama/OllamaChatModel.d.ts +4 -1
- package/model-provider/ollama/OllamaChatModel.js +8 -3
- package/model-provider/ollama/OllamaCompletionModel.cjs +8 -3
- package/model-provider/ollama/OllamaCompletionModel.d.ts +4 -1
- package/model-provider/ollama/OllamaCompletionModel.js +8 -3
- package/model-provider/openai/OpenAICompletionModel.cjs +20 -4
- package/model-provider/openai/OpenAICompletionModel.d.ts +6 -1
- package/model-provider/openai/OpenAICompletionModel.js +20 -4
- package/model-provider/openai/OpenAIImageGenerationModel.cjs +25 -31
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +2 -3
- package/model-provider/openai/OpenAIImageGenerationModel.js +25 -31
- package/model-provider/openai/chat/AbstractOpenAIChatModel.cjs +19 -1
- package/model-provider/openai/chat/AbstractOpenAIChatModel.d.ts +6 -1
- package/model-provider/openai/chat/AbstractOpenAIChatModel.js +19 -1
- package/model-provider/openai/chat/OpenAIChatModel.cjs +2 -3
- package/model-provider/openai/chat/OpenAIChatModel.js +2 -3
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.cjs +2 -3
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.js +2 -3
- package/model-provider/stability/StabilityApiConfiguration.cjs +12 -5
- package/model-provider/stability/StabilityApiConfiguration.d.ts +7 -8
- package/model-provider/stability/StabilityApiConfiguration.js +12 -5
- package/model-provider/stability/StabilityError.cjs +7 -31
- package/model-provider/stability/StabilityError.d.ts +2 -11
- package/model-provider/stability/StabilityError.js +6 -28
- package/model-provider/stability/StabilityFacade.cjs +11 -3
- package/model-provider/stability/StabilityFacade.d.ts +10 -2
- package/model-provider/stability/StabilityFacade.js +9 -2
- package/model-provider/stability/StabilityImageGenerationModel.cjs +39 -50
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +42 -27
- package/model-provider/stability/StabilityImageGenerationModel.js +39 -50
- package/model-provider/stability/index.cjs +1 -3
- package/model-provider/stability/index.d.ts +1 -1
- package/model-provider/stability/index.js +0 -1
- package/package.json +2 -2
@@ -9,6 +9,10 @@ const PromptTemplateImageGenerationModel_js_1 = require("../../model-function/ge
|
|
9
9
|
const StabilityApiConfiguration_js_1 = require("./StabilityApiConfiguration.cjs");
|
10
10
|
const StabilityError_js_1 = require("./StabilityError.cjs");
|
11
11
|
const StabilityImageGenerationPrompt_js_1 = require("./StabilityImageGenerationPrompt.cjs");
|
12
|
+
const stabilityImageGenerationModels = [
|
13
|
+
"stable-diffusion-v1-6",
|
14
|
+
"stable-diffusion-xl-1024-v1-0",
|
15
|
+
];
|
12
16
|
/**
|
13
17
|
* Create an image generation model that calls the Stability AI image generation API.
|
14
18
|
*
|
@@ -16,13 +20,12 @@ const StabilityImageGenerationPrompt_js_1 = require("./StabilityImageGenerationP
|
|
16
20
|
*
|
17
21
|
* @example
|
18
22
|
* const image = await generateImage(
|
19
|
-
*
|
20
|
-
* model: "stable-diffusion-
|
23
|
+
* stability.ImageGenerator({
|
24
|
+
* model: "stable-diffusion-v1-6",
|
21
25
|
* cfgScale: 7,
|
22
26
|
* clipGuidancePreset: "FAST_BLUE",
|
23
27
|
* height: 512,
|
24
28
|
* width: 512,
|
25
|
-
* samples: 1,
|
26
29
|
* steps: 30,
|
27
30
|
* })
|
28
31
|
* [
|
@@ -45,37 +48,50 @@ class StabilityImageGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
45
48
|
return this.settings.model;
|
46
49
|
}
|
47
50
|
async callAPI(input, options) {
|
51
|
+
const api = this.settings.api ?? new StabilityApiConfiguration_js_1.StabilityApiConfiguration();
|
52
|
+
const abortSignal = options?.run?.abortSignal;
|
48
53
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
49
54
|
retry: this.settings.api?.retry,
|
50
55
|
throttle: this.settings.api?.throttle,
|
51
|
-
call: async () =>
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
call: async () => (0, postToApi_js_1.postJsonToApi)({
|
57
|
+
url: api.assembleUrl(`/generation/${this.settings.model}/text-to-image`),
|
58
|
+
headers: api.headers,
|
59
|
+
body: {
|
60
|
+
height: this.settings.height,
|
61
|
+
width: this.settings.width,
|
62
|
+
text_prompts: input,
|
63
|
+
cfg_scale: this.settings.cfgScale,
|
64
|
+
clip_guidance_preset: this.settings.clipGuidancePreset,
|
65
|
+
sampler: this.settings.sampler,
|
66
|
+
samples: this.settings.numberOfGenerations,
|
67
|
+
seed: this.settings.seed,
|
68
|
+
steps: this.settings.steps,
|
69
|
+
style_preset: this.settings.stylePreset,
|
70
|
+
},
|
71
|
+
failedResponseHandler: StabilityError_js_1.failedStabilityCallResponseHandler,
|
72
|
+
successfulResponseHandler: (0, postToApi_js_1.createJsonResponseHandler)(stabilityImageGenerationResponseSchema),
|
73
|
+
abortSignal,
|
56
74
|
}),
|
57
75
|
});
|
58
76
|
}
|
59
77
|
get settingsForEvent() {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
];
|
72
|
-
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
78
|
+
return {
|
79
|
+
numberOfGenerations: this.settings.numberOfGenerations,
|
80
|
+
height: this.settings.height,
|
81
|
+
width: this.settings.width,
|
82
|
+
cfgScale: this.settings.cfgScale,
|
83
|
+
clipGuidancePreset: this.settings.clipGuidancePreset,
|
84
|
+
sampler: this.settings.sampler,
|
85
|
+
seed: this.settings.seed,
|
86
|
+
steps: this.settings.steps,
|
87
|
+
stylePreset: this.settings.stylePreset,
|
88
|
+
};
|
73
89
|
}
|
74
|
-
async
|
90
|
+
async doGenerateImages(prompt, options) {
|
75
91
|
const response = await this.callAPI(prompt, options);
|
76
92
|
return {
|
77
93
|
response,
|
78
|
-
|
94
|
+
base64Images: response.artifacts.map((artifact) => artifact.base64),
|
79
95
|
};
|
80
96
|
}
|
81
97
|
withTextPrompt() {
|
@@ -92,12 +108,6 @@ class StabilityImageGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
92
108
|
}
|
93
109
|
}
|
94
110
|
exports.StabilityImageGenerationModel = StabilityImageGenerationModel;
|
95
|
-
const stabilityImageGenerationModels = [
|
96
|
-
"stable-diffusion-v1-5",
|
97
|
-
"stable-diffusion-512-v2-1",
|
98
|
-
"stable-diffusion-xl-1024-v0-9",
|
99
|
-
"stable-diffusion-xl-1024-v1-0",
|
100
|
-
];
|
101
111
|
const stabilityImageGenerationResponseSchema = zod_1.z.object({
|
102
112
|
artifacts: zod_1.z.array(zod_1.z.object({
|
103
113
|
base64: zod_1.z.string(),
|
@@ -105,24 +115,3 @@ const stabilityImageGenerationResponseSchema = zod_1.z.object({
|
|
105
115
|
finishReason: zod_1.z.enum(["SUCCESS", "ERROR", "CONTENT_FILTERED"]),
|
106
116
|
})),
|
107
117
|
});
|
108
|
-
async function callStabilityImageGenerationAPI({ api = new StabilityApiConfiguration_js_1.StabilityApiConfiguration(), abortSignal, engineId, height, width, textPrompts, cfgScale, clipGuidancePreset, sampler, samples, seed, steps, stylePreset, }) {
|
109
|
-
return (0, postToApi_js_1.postJsonToApi)({
|
110
|
-
url: api.assembleUrl(`/generation/${engineId}/text-to-image`),
|
111
|
-
headers: api.headers,
|
112
|
-
body: {
|
113
|
-
height,
|
114
|
-
width,
|
115
|
-
text_prompts: textPrompts,
|
116
|
-
cfg_scale: cfgScale,
|
117
|
-
clip_guidance_preset: clipGuidancePreset,
|
118
|
-
sampler,
|
119
|
-
samples,
|
120
|
-
seed,
|
121
|
-
steps,
|
122
|
-
style_preset: stylePreset,
|
123
|
-
},
|
124
|
-
failedResponseHandler: StabilityError_js_1.failedStabilityCallResponseHandler,
|
125
|
-
successfulResponseHandler: (0, postToApi_js_1.createJsonResponseHandler)(stabilityImageGenerationResponseSchema),
|
126
|
-
abortSignal,
|
127
|
-
});
|
128
|
-
}
|
@@ -6,6 +6,39 @@ import { PromptTemplate } from "../../model-function/PromptTemplate.js";
|
|
6
6
|
import { ImageGenerationModel, ImageGenerationModelSettings } from "../../model-function/generate-image/ImageGenerationModel.js";
|
7
7
|
import { PromptTemplateImageGenerationModel } from "../../model-function/generate-image/PromptTemplateImageGenerationModel.js";
|
8
8
|
import { StabilityImageGenerationPrompt } from "./StabilityImageGenerationPrompt.js";
|
9
|
+
declare const stabilityImageGenerationModels: readonly ["stable-diffusion-v1-6", "stable-diffusion-xl-1024-v1-0"];
|
10
|
+
export type StabilityImageGenerationModelType = (typeof stabilityImageGenerationModels)[number] | (string & {});
|
11
|
+
export type StabilityImageGenerationStylePreset = "3d-model" | "analog-film" | "anime" | "cinematic" | "comic-book" | "digital-art" | "enhance" | "fantasy-art" | "isometric" | "line-art" | "low-poly" | "modeling-compound" | "neon-punk" | "origami" | "photographic" | "pixel-art" | "tile-texture";
|
12
|
+
export type StabilityImageGenerationSampler = "DDIM" | "DDPM" | "K_DPMPP_2M" | "K_DPMPP_2S_ANCESTRAL" | "K_DPM_2" | "K_DPM_2_ANCESTRAL" | "K_EULER" | "K_EULER_ANCESTRAL" | "K_HEUN" | "K_LMS";
|
13
|
+
export type StabilityClipGuidancePreset = "FAST_BLUE" | "FAST_GREEN" | "NONE" | "SIMPLE" | "SLOW" | "SLOWER" | "SLOWEST";
|
14
|
+
export interface StabilityImageGenerationSettings extends ImageGenerationModelSettings {
|
15
|
+
api?: ApiConfiguration;
|
16
|
+
model: StabilityImageGenerationModelType;
|
17
|
+
height?: number;
|
18
|
+
width?: number;
|
19
|
+
/**
|
20
|
+
* How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt)
|
21
|
+
*/
|
22
|
+
cfgScale?: number;
|
23
|
+
clipGuidancePreset?: StabilityClipGuidancePreset;
|
24
|
+
/**
|
25
|
+
* Which sampler to use for the diffusion process.
|
26
|
+
* If this value is omitted we'll automatically select an appropriate sampler for you.
|
27
|
+
*/
|
28
|
+
sampler?: StabilityImageGenerationSampler;
|
29
|
+
/**
|
30
|
+
* Random noise seed (omit this option or use 0 for a random seed).
|
31
|
+
*/
|
32
|
+
seed?: number;
|
33
|
+
/**
|
34
|
+
* Number of diffusion steps to run.
|
35
|
+
*/
|
36
|
+
steps?: number;
|
37
|
+
/**
|
38
|
+
* Pass in a style preset to guide the image model towards a particular style.
|
39
|
+
*/
|
40
|
+
stylePreset?: StabilityImageGenerationStylePreset;
|
41
|
+
}
|
9
42
|
/**
|
10
43
|
* Create an image generation model that calls the Stability AI image generation API.
|
11
44
|
*
|
@@ -13,13 +46,12 @@ import { StabilityImageGenerationPrompt } from "./StabilityImageGenerationPrompt
|
|
13
46
|
*
|
14
47
|
* @example
|
15
48
|
* const image = await generateImage(
|
16
|
-
*
|
17
|
-
* model: "stable-diffusion-
|
49
|
+
* stability.ImageGenerator({
|
50
|
+
* model: "stable-diffusion-v1-6",
|
18
51
|
* cfgScale: 7,
|
19
52
|
* clipGuidancePreset: "FAST_BLUE",
|
20
53
|
* height: 512,
|
21
54
|
* width: 512,
|
22
|
-
* samples: 1,
|
23
55
|
* steps: 30,
|
24
56
|
* })
|
25
57
|
* [
|
@@ -34,63 +66,46 @@ export declare class StabilityImageGenerationModel extends AbstractModel<Stabili
|
|
34
66
|
get modelName(): StabilityImageGenerationModelType;
|
35
67
|
callAPI(input: StabilityImageGenerationPrompt, options?: FunctionOptions): Promise<StabilityImageGenerationResponse>;
|
36
68
|
get settingsForEvent(): Partial<StabilityImageGenerationSettings>;
|
37
|
-
|
69
|
+
doGenerateImages(prompt: StabilityImageGenerationPrompt, options?: FunctionOptions): Promise<{
|
38
70
|
response: {
|
39
71
|
artifacts: {
|
72
|
+
finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
|
40
73
|
base64: string;
|
41
74
|
seed: number;
|
42
|
-
finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED";
|
43
75
|
}[];
|
44
76
|
};
|
45
|
-
|
77
|
+
base64Images: string[];
|
46
78
|
}>;
|
47
79
|
withTextPrompt(): PromptTemplateImageGenerationModel<string, StabilityImageGenerationPrompt, StabilityImageGenerationSettings, this>;
|
48
80
|
withPromptTemplate<INPUT_PROMPT>(promptTemplate: PromptTemplate<INPUT_PROMPT, StabilityImageGenerationPrompt>): PromptTemplateImageGenerationModel<INPUT_PROMPT, StabilityImageGenerationPrompt, StabilityImageGenerationSettings, this>;
|
49
81
|
withSettings(additionalSettings: StabilityImageGenerationSettings): this;
|
50
82
|
}
|
51
|
-
declare const stabilityImageGenerationModels: readonly ["stable-diffusion-v1-5", "stable-diffusion-512-v2-1", "stable-diffusion-xl-1024-v0-9", "stable-diffusion-xl-1024-v1-0"];
|
52
|
-
export type StabilityImageGenerationModelType = (typeof stabilityImageGenerationModels)[number] | (string & {});
|
53
|
-
export interface StabilityImageGenerationSettings extends ImageGenerationModelSettings {
|
54
|
-
api?: ApiConfiguration;
|
55
|
-
model: StabilityImageGenerationModelType;
|
56
|
-
height?: number;
|
57
|
-
width?: number;
|
58
|
-
cfgScale?: number;
|
59
|
-
clipGuidancePreset?: string;
|
60
|
-
sampler?: StabilityImageGenerationSampler;
|
61
|
-
samples?: number;
|
62
|
-
seed?: number;
|
63
|
-
steps?: number;
|
64
|
-
stylePreset?: StabilityImageGenerationStylePreset;
|
65
|
-
}
|
66
83
|
declare const stabilityImageGenerationResponseSchema: z.ZodObject<{
|
67
84
|
artifacts: z.ZodArray<z.ZodObject<{
|
68
85
|
base64: z.ZodString;
|
69
86
|
seed: z.ZodNumber;
|
70
87
|
finishReason: z.ZodEnum<["SUCCESS", "ERROR", "CONTENT_FILTERED"]>;
|
71
88
|
}, "strip", z.ZodTypeAny, {
|
89
|
+
finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
|
72
90
|
base64: string;
|
73
91
|
seed: number;
|
74
|
-
finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED";
|
75
92
|
}, {
|
93
|
+
finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
|
76
94
|
base64: string;
|
77
95
|
seed: number;
|
78
|
-
finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED";
|
79
96
|
}>, "many">;
|
80
97
|
}, "strip", z.ZodTypeAny, {
|
81
98
|
artifacts: {
|
99
|
+
finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
|
82
100
|
base64: string;
|
83
101
|
seed: number;
|
84
|
-
finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED";
|
85
102
|
}[];
|
86
103
|
}, {
|
87
104
|
artifacts: {
|
105
|
+
finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
|
88
106
|
base64: string;
|
89
107
|
seed: number;
|
90
|
-
finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED";
|
91
108
|
}[];
|
92
109
|
}>;
|
93
110
|
export type StabilityImageGenerationResponse = z.infer<typeof stabilityImageGenerationResponseSchema>;
|
94
|
-
export type StabilityImageGenerationStylePreset = "enhance" | "anime" | "photographic" | "digital-art" | "comic-book" | "fantasy-art" | "line-art" | "analog-film" | "neon-punk" | "isometric" | "low-poly" | "origami" | "modeling-compound" | "cinematic" | "3d-model" | "pixel-art" | "tile-texture";
|
95
|
-
export type StabilityImageGenerationSampler = "DDIM" | "DDPM" | "K_DPMPP_2M" | "K_DPMPP_2S_ANCESTRAL" | "K_DPM_2" | "K_DPM_2_ANCESTRAL" | "K_EULER" | "K_EULER_ANCESTRAL" | "K_HEUN" | "K_LMS";
|
96
111
|
export {};
|
@@ -6,6 +6,10 @@ import { PromptTemplateImageGenerationModel } from "../../model-function/generat
|
|
6
6
|
import { StabilityApiConfiguration } from "./StabilityApiConfiguration.js";
|
7
7
|
import { failedStabilityCallResponseHandler } from "./StabilityError.js";
|
8
8
|
import { mapBasicPromptToStabilityFormat, } from "./StabilityImageGenerationPrompt.js";
|
9
|
+
const stabilityImageGenerationModels = [
|
10
|
+
"stable-diffusion-v1-6",
|
11
|
+
"stable-diffusion-xl-1024-v1-0",
|
12
|
+
];
|
9
13
|
/**
|
10
14
|
* Create an image generation model that calls the Stability AI image generation API.
|
11
15
|
*
|
@@ -13,13 +17,12 @@ import { mapBasicPromptToStabilityFormat, } from "./StabilityImageGenerationProm
|
|
13
17
|
*
|
14
18
|
* @example
|
15
19
|
* const image = await generateImage(
|
16
|
-
*
|
17
|
-
* model: "stable-diffusion-
|
20
|
+
* stability.ImageGenerator({
|
21
|
+
* model: "stable-diffusion-v1-6",
|
18
22
|
* cfgScale: 7,
|
19
23
|
* clipGuidancePreset: "FAST_BLUE",
|
20
24
|
* height: 512,
|
21
25
|
* width: 512,
|
22
|
-
* samples: 1,
|
23
26
|
* steps: 30,
|
24
27
|
* })
|
25
28
|
* [
|
@@ -42,37 +45,50 @@ export class StabilityImageGenerationModel extends AbstractModel {
|
|
42
45
|
return this.settings.model;
|
43
46
|
}
|
44
47
|
async callAPI(input, options) {
|
48
|
+
const api = this.settings.api ?? new StabilityApiConfiguration();
|
49
|
+
const abortSignal = options?.run?.abortSignal;
|
45
50
|
return callWithRetryAndThrottle({
|
46
51
|
retry: this.settings.api?.retry,
|
47
52
|
throttle: this.settings.api?.throttle,
|
48
|
-
call: async () =>
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
call: async () => postJsonToApi({
|
54
|
+
url: api.assembleUrl(`/generation/${this.settings.model}/text-to-image`),
|
55
|
+
headers: api.headers,
|
56
|
+
body: {
|
57
|
+
height: this.settings.height,
|
58
|
+
width: this.settings.width,
|
59
|
+
text_prompts: input,
|
60
|
+
cfg_scale: this.settings.cfgScale,
|
61
|
+
clip_guidance_preset: this.settings.clipGuidancePreset,
|
62
|
+
sampler: this.settings.sampler,
|
63
|
+
samples: this.settings.numberOfGenerations,
|
64
|
+
seed: this.settings.seed,
|
65
|
+
steps: this.settings.steps,
|
66
|
+
style_preset: this.settings.stylePreset,
|
67
|
+
},
|
68
|
+
failedResponseHandler: failedStabilityCallResponseHandler,
|
69
|
+
successfulResponseHandler: createJsonResponseHandler(stabilityImageGenerationResponseSchema),
|
70
|
+
abortSignal,
|
53
71
|
}),
|
54
72
|
});
|
55
73
|
}
|
56
74
|
get settingsForEvent() {
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
];
|
69
|
-
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
75
|
+
return {
|
76
|
+
numberOfGenerations: this.settings.numberOfGenerations,
|
77
|
+
height: this.settings.height,
|
78
|
+
width: this.settings.width,
|
79
|
+
cfgScale: this.settings.cfgScale,
|
80
|
+
clipGuidancePreset: this.settings.clipGuidancePreset,
|
81
|
+
sampler: this.settings.sampler,
|
82
|
+
seed: this.settings.seed,
|
83
|
+
steps: this.settings.steps,
|
84
|
+
stylePreset: this.settings.stylePreset,
|
85
|
+
};
|
70
86
|
}
|
71
|
-
async
|
87
|
+
async doGenerateImages(prompt, options) {
|
72
88
|
const response = await this.callAPI(prompt, options);
|
73
89
|
return {
|
74
90
|
response,
|
75
|
-
|
91
|
+
base64Images: response.artifacts.map((artifact) => artifact.base64),
|
76
92
|
};
|
77
93
|
}
|
78
94
|
withTextPrompt() {
|
@@ -88,12 +104,6 @@ export class StabilityImageGenerationModel extends AbstractModel {
|
|
88
104
|
return new StabilityImageGenerationModel(Object.assign({}, this.settings, additionalSettings));
|
89
105
|
}
|
90
106
|
}
|
91
|
-
const stabilityImageGenerationModels = [
|
92
|
-
"stable-diffusion-v1-5",
|
93
|
-
"stable-diffusion-512-v2-1",
|
94
|
-
"stable-diffusion-xl-1024-v0-9",
|
95
|
-
"stable-diffusion-xl-1024-v1-0",
|
96
|
-
];
|
97
107
|
const stabilityImageGenerationResponseSchema = z.object({
|
98
108
|
artifacts: z.array(z.object({
|
99
109
|
base64: z.string(),
|
@@ -101,24 +111,3 @@ const stabilityImageGenerationResponseSchema = z.object({
|
|
101
111
|
finishReason: z.enum(["SUCCESS", "ERROR", "CONTENT_FILTERED"]),
|
102
112
|
})),
|
103
113
|
});
|
104
|
-
async function callStabilityImageGenerationAPI({ api = new StabilityApiConfiguration(), abortSignal, engineId, height, width, textPrompts, cfgScale, clipGuidancePreset, sampler, samples, seed, steps, stylePreset, }) {
|
105
|
-
return postJsonToApi({
|
106
|
-
url: api.assembleUrl(`/generation/${engineId}/text-to-image`),
|
107
|
-
headers: api.headers,
|
108
|
-
body: {
|
109
|
-
height,
|
110
|
-
width,
|
111
|
-
text_prompts: textPrompts,
|
112
|
-
cfg_scale: cfgScale,
|
113
|
-
clip_guidance_preset: clipGuidancePreset,
|
114
|
-
sampler,
|
115
|
-
samples,
|
116
|
-
seed,
|
117
|
-
steps,
|
118
|
-
style_preset: stylePreset,
|
119
|
-
},
|
120
|
-
failedResponseHandler: failedStabilityCallResponseHandler,
|
121
|
-
successfulResponseHandler: createJsonResponseHandler(stabilityImageGenerationResponseSchema),
|
122
|
-
abortSignal,
|
123
|
-
});
|
124
|
-
}
|
@@ -26,10 +26,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
26
|
return result;
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.stability =
|
29
|
+
exports.stability = void 0;
|
30
30
|
__exportStar(require("./StabilityApiConfiguration.cjs"), exports);
|
31
|
-
var StabilityError_js_1 = require("./StabilityError.cjs");
|
32
|
-
Object.defineProperty(exports, "StabilityError", { enumerable: true, get: function () { return StabilityError_js_1.StabilityError; } });
|
33
31
|
exports.stability = __importStar(require("./StabilityFacade.cjs"));
|
34
32
|
__exportStar(require("./StabilityImageGenerationModel.cjs"), exports);
|
35
33
|
__exportStar(require("./StabilityImageGenerationPrompt.cjs"), exports);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export * from "./StabilityApiConfiguration.js";
|
2
|
-
export {
|
2
|
+
export { StabilityErrorData } from "./StabilityError.js";
|
3
3
|
export * as stability from "./StabilityFacade.js";
|
4
4
|
export * from "./StabilityImageGenerationModel.js";
|
5
5
|
export * from "./StabilityImageGenerationPrompt.js";
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "modelfusion",
|
3
3
|
"description": "The TypeScript library for building multi-modal AI applications.",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.103.0",
|
5
5
|
"author": "Lars Grammel",
|
6
6
|
"license": "MIT",
|
7
7
|
"keywords": [
|
@@ -89,7 +89,7 @@
|
|
89
89
|
"@vitest/coverage-v8": "^1.1.0",
|
90
90
|
"@vitest/ui": "1.1.0",
|
91
91
|
"eslint": "^8.45.0",
|
92
|
-
"eslint-config-prettier": "9.
|
92
|
+
"eslint-config-prettier": "9.1.0",
|
93
93
|
"fastify": "^4.0.0",
|
94
94
|
"msw": "2.0.10"
|
95
95
|
}
|