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
@@ -57,7 +57,7 @@ export const calculateOpenAIImageGenerationCostInMillicents = ({ model, settings
|
|
57
57
|
if (cost == null) {
|
58
58
|
return null;
|
59
59
|
}
|
60
|
-
return (settings.
|
60
|
+
return (settings.numberOfGenerations ?? 1) * cost;
|
61
61
|
};
|
62
62
|
/**
|
63
63
|
* Create an image generation model that calls the OpenAI AI image creation API.
|
@@ -84,38 +84,48 @@ export class OpenAIImageGenerationModel extends AbstractModel {
|
|
84
84
|
return this.settings.model;
|
85
85
|
}
|
86
86
|
async callAPI(prompt, options) {
|
87
|
-
const
|
87
|
+
const api = this.settings.api ?? new OpenAIApiConfiguration();
|
88
|
+
const abortSignal = options?.run?.abortSignal;
|
89
|
+
const userId = options?.run?.userId;
|
88
90
|
const responseFormat = options?.responseFormat;
|
89
|
-
const callSettings = {
|
90
|
-
...this.settings,
|
91
|
-
user: this.settings.isUserIdForwardingEnabled ? run?.userId : undefined,
|
92
|
-
abortSignal: run?.abortSignal,
|
93
|
-
responseFormat,
|
94
|
-
prompt,
|
95
|
-
};
|
96
91
|
return callWithRetryAndThrottle({
|
97
|
-
retry:
|
98
|
-
throttle:
|
99
|
-
call: async () =>
|
92
|
+
retry: api.retry,
|
93
|
+
throttle: api.throttle,
|
94
|
+
call: async () => {
|
95
|
+
return postJsonToApi({
|
96
|
+
url: api.assembleUrl("/images/generations"),
|
97
|
+
headers: api.headers,
|
98
|
+
body: {
|
99
|
+
prompt,
|
100
|
+
n: this.settings.numberOfGenerations,
|
101
|
+
size: this.settings.size,
|
102
|
+
response_format: responseFormat.type,
|
103
|
+
user: this.settings.isUserIdForwardingEnabled ? userId : undefined,
|
104
|
+
},
|
105
|
+
failedResponseHandler: failedOpenAICallResponseHandler,
|
106
|
+
successfulResponseHandler: responseFormat?.handler,
|
107
|
+
abortSignal,
|
108
|
+
});
|
109
|
+
},
|
100
110
|
});
|
101
111
|
}
|
102
112
|
get settingsForEvent() {
|
103
113
|
const eventSettingProperties = [
|
104
|
-
"
|
114
|
+
"numberOfGenerations",
|
105
115
|
"size",
|
106
116
|
"quality",
|
107
117
|
"style",
|
108
118
|
];
|
109
119
|
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
110
120
|
}
|
111
|
-
async
|
121
|
+
async doGenerateImages(prompt, options) {
|
112
122
|
const response = await this.callAPI(prompt, {
|
113
123
|
responseFormat: OpenAIImageGenerationResponseFormat.base64Json,
|
114
124
|
...options,
|
115
125
|
});
|
116
126
|
return {
|
117
127
|
response,
|
118
|
-
|
128
|
+
base64Images: response.data.map((item) => item.b64_json),
|
119
129
|
};
|
120
130
|
}
|
121
131
|
withPromptTemplate(promptTemplate) {
|
@@ -150,19 +160,3 @@ export const OpenAIImageGenerationResponseFormat = {
|
|
150
160
|
handler: createJsonResponseHandler(openAIImageGenerationBase64JsonSchema),
|
151
161
|
},
|
152
162
|
};
|
153
|
-
async function callOpenAIImageGenerationAPI({ api = new OpenAIApiConfiguration(), abortSignal, prompt, n, size, responseFormat, user, }) {
|
154
|
-
return postJsonToApi({
|
155
|
-
url: api.assembleUrl("/images/generations"),
|
156
|
-
headers: api.headers,
|
157
|
-
body: {
|
158
|
-
prompt,
|
159
|
-
n,
|
160
|
-
size,
|
161
|
-
response_format: responseFormat.type,
|
162
|
-
user,
|
163
|
-
},
|
164
|
-
failedResponseHandler: failedOpenAICallResponseHandler,
|
165
|
-
successfulResponseHandler: responseFormat?.handler,
|
166
|
-
abortSignal,
|
167
|
-
});
|
168
|
-
}
|
@@ -80,10 +80,28 @@ class AbstractOpenAIChatModel extends AbstractModel_js_1.AbstractModel {
|
|
80
80
|
});
|
81
81
|
return {
|
82
82
|
response,
|
83
|
-
|
83
|
+
textGenerationResults: response.choices.map((choice) => ({
|
84
|
+
text: choice.message.content ?? "",
|
85
|
+
finishReason: this.translateFinishReason(choice.finish_reason),
|
86
|
+
})),
|
84
87
|
usage: this.extractUsage(response),
|
85
88
|
};
|
86
89
|
}
|
90
|
+
translateFinishReason(finishReason) {
|
91
|
+
switch (finishReason) {
|
92
|
+
case "stop":
|
93
|
+
return "stop";
|
94
|
+
case "length":
|
95
|
+
return "length";
|
96
|
+
case "content_filter":
|
97
|
+
return "content-filter";
|
98
|
+
case "function_call":
|
99
|
+
case "tool_calls":
|
100
|
+
return "tool-calls";
|
101
|
+
default:
|
102
|
+
return "unknown";
|
103
|
+
}
|
104
|
+
}
|
87
105
|
doStreamText(prompt, options) {
|
88
106
|
return this.callAPI(prompt, {
|
89
107
|
...options,
|
@@ -5,6 +5,7 @@ import { ResponseHandler } from "../../../core/api/postToApi.js";
|
|
5
5
|
import { AbstractModel } from "../../../model-function/AbstractModel.js";
|
6
6
|
import { Delta } from "../../../model-function/Delta.js";
|
7
7
|
import { TextGenerationModelSettings } from "../../../model-function/generate-text/TextGenerationModel.js";
|
8
|
+
import { TextGenerationFinishReason } from "../../../model-function/generate-text/TextGenerationResult.js";
|
8
9
|
import { ToolDefinition } from "../../../tool/ToolDefinition.js";
|
9
10
|
import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
|
10
11
|
export interface AbstractOpenAIChatCallSettings {
|
@@ -126,13 +127,17 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
126
127
|
}[];
|
127
128
|
system_fingerprint?: string | null | undefined;
|
128
129
|
};
|
129
|
-
|
130
|
+
textGenerationResults: {
|
131
|
+
text: string;
|
132
|
+
finishReason: TextGenerationFinishReason;
|
133
|
+
}[];
|
130
134
|
usage: {
|
131
135
|
promptTokens: number;
|
132
136
|
completionTokens: number;
|
133
137
|
totalTokens: number;
|
134
138
|
};
|
135
139
|
}>;
|
140
|
+
private translateFinishReason;
|
136
141
|
doStreamText(prompt: OpenAIChatPrompt, options?: FunctionOptions): Promise<AsyncIterable<Delta<string>>>;
|
137
142
|
doGenerateToolCall(tool: ToolDefinition<string, unknown>, prompt: OpenAIChatPrompt, options?: FunctionOptions): Promise<{
|
138
143
|
response: {
|
@@ -77,10 +77,28 @@ export class AbstractOpenAIChatModel extends AbstractModel {
|
|
77
77
|
});
|
78
78
|
return {
|
79
79
|
response,
|
80
|
-
|
80
|
+
textGenerationResults: response.choices.map((choice) => ({
|
81
|
+
text: choice.message.content ?? "",
|
82
|
+
finishReason: this.translateFinishReason(choice.finish_reason),
|
83
|
+
})),
|
81
84
|
usage: this.extractUsage(response),
|
82
85
|
};
|
83
86
|
}
|
87
|
+
translateFinishReason(finishReason) {
|
88
|
+
switch (finishReason) {
|
89
|
+
case "stop":
|
90
|
+
return "stop";
|
91
|
+
case "length":
|
92
|
+
return "length";
|
93
|
+
case "content_filter":
|
94
|
+
return "content-filter";
|
95
|
+
case "function_call":
|
96
|
+
case "tool_calls":
|
97
|
+
return "tool-calls";
|
98
|
+
default:
|
99
|
+
return "unknown";
|
100
|
+
}
|
101
|
+
}
|
84
102
|
doStreamText(prompt, options) {
|
85
103
|
return this.callAPI(prompt, {
|
86
104
|
...options,
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OpenAIChatModel = exports.calculateOpenAIChatCostInMillicents = exports.isOpenAIChatModel = exports.getOpenAIChatModelInformation = exports.OPENAI_CHAT_MODELS = void 0;
|
4
4
|
const StructureFromTextStreamingModel_js_1 = require("../../../model-function/generate-structure/StructureFromTextStreamingModel.cjs");
|
5
5
|
const PromptTemplateTextStreamingModel_js_1 = require("../../../model-function/generate-text/PromptTemplateTextStreamingModel.cjs");
|
6
|
+
const TextGenerationModel_js_1 = require("../../../model-function/generate-text/TextGenerationModel.cjs");
|
6
7
|
const TikTokenTokenizer_js_1 = require("../TikTokenTokenizer.cjs");
|
7
8
|
const AbstractOpenAIChatModel_js_1 = require("./AbstractOpenAIChatModel.cjs");
|
8
9
|
const OpenAIChatFunctionCallStructureGenerationModel_js_1 = require("./OpenAIChatFunctionCallStructureGenerationModel.cjs");
|
@@ -196,9 +197,7 @@ class OpenAIChatModel extends AbstractOpenAIChatModel_js_1.AbstractOpenAIChatMod
|
|
196
197
|
}
|
197
198
|
get settingsForEvent() {
|
198
199
|
const eventSettingProperties = [
|
199
|
-
|
200
|
-
"stopSequences",
|
201
|
-
"numberOfGenerations",
|
200
|
+
...TextGenerationModel_js_1.textGenerationModelProperties,
|
202
201
|
"functions",
|
203
202
|
"functionCall",
|
204
203
|
"temperature",
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { StructureFromTextStreamingModel } from "../../../model-function/generate-structure/StructureFromTextStreamingModel.js";
|
2
2
|
import { PromptTemplateTextStreamingModel } from "../../../model-function/generate-text/PromptTemplateTextStreamingModel.js";
|
3
|
+
import { textGenerationModelProperties, } from "../../../model-function/generate-text/TextGenerationModel.js";
|
3
4
|
import { TikTokenTokenizer } from "../TikTokenTokenizer.js";
|
4
5
|
import { AbstractOpenAIChatModel, } from "./AbstractOpenAIChatModel.js";
|
5
6
|
import { OpenAIChatFunctionCallStructureGenerationModel } from "./OpenAIChatFunctionCallStructureGenerationModel.js";
|
@@ -190,9 +191,7 @@ export class OpenAIChatModel extends AbstractOpenAIChatModel {
|
|
190
191
|
}
|
191
192
|
get settingsForEvent() {
|
192
193
|
const eventSettingProperties = [
|
193
|
-
|
194
|
-
"stopSequences",
|
195
|
-
"numberOfGenerations",
|
194
|
+
...textGenerationModelProperties,
|
196
195
|
"functions",
|
197
196
|
"functionCall",
|
198
197
|
"temperature",
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OpenAICompatibleChatModel = void 0;
|
4
4
|
const StructureFromTextStreamingModel_js_1 = require("../../model-function/generate-structure/StructureFromTextStreamingModel.cjs");
|
5
5
|
const PromptTemplateTextStreamingModel_js_1 = require("../../model-function/generate-text/PromptTemplateTextStreamingModel.cjs");
|
6
|
+
const TextGenerationModel_js_1 = require("../../model-function/generate-text/TextGenerationModel.cjs");
|
6
7
|
const AbstractOpenAIChatModel_js_1 = require("../openai/chat/AbstractOpenAIChatModel.cjs");
|
7
8
|
const OpenAIChatPromptTemplate_js_1 = require("../openai/chat/OpenAIChatPromptTemplate.cjs");
|
8
9
|
/**
|
@@ -43,9 +44,7 @@ class OpenAICompatibleChatModel extends AbstractOpenAIChatModel_js_1.AbstractOpe
|
|
43
44
|
}
|
44
45
|
get settingsForEvent() {
|
45
46
|
const eventSettingProperties = [
|
46
|
-
|
47
|
-
"maxGenerationTokens",
|
48
|
-
"numberOfGenerations",
|
47
|
+
...TextGenerationModel_js_1.textGenerationModelProperties,
|
49
48
|
"functions",
|
50
49
|
"functionCall",
|
51
50
|
"temperature",
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { StructureFromTextStreamingModel } from "../../model-function/generate-structure/StructureFromTextStreamingModel.js";
|
2
2
|
import { PromptTemplateTextStreamingModel } from "../../model-function/generate-text/PromptTemplateTextStreamingModel.js";
|
3
|
+
import { textGenerationModelProperties, } from "../../model-function/generate-text/TextGenerationModel.js";
|
3
4
|
import { AbstractOpenAIChatModel, } from "../openai/chat/AbstractOpenAIChatModel.js";
|
4
5
|
import { chat, instruction, text, } from "../openai/chat/OpenAIChatPromptTemplate.js";
|
5
6
|
/**
|
@@ -40,9 +41,7 @@ export class OpenAICompatibleChatModel extends AbstractOpenAIChatModel {
|
|
40
41
|
}
|
41
42
|
get settingsForEvent() {
|
42
43
|
const eventSettingProperties = [
|
43
|
-
|
44
|
-
"maxGenerationTokens",
|
45
|
-
"numberOfGenerations",
|
44
|
+
...textGenerationModelProperties,
|
46
45
|
"functions",
|
47
46
|
"functionCall",
|
48
47
|
"temperature",
|
@@ -1,13 +1,20 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.StabilityApiConfiguration = void 0;
|
4
|
-
const
|
4
|
+
const BaseUrlPartsApiConfiguration_js_1 = require("../../core/api/BaseUrlPartsApiConfiguration.cjs");
|
5
5
|
const loadApiKey_js_1 = require("../../core/api/loadApiKey.cjs");
|
6
|
-
|
7
|
-
|
6
|
+
/**
|
7
|
+
* Creates an API configuration for the Stability AI API.
|
8
|
+
* It calls the API at https://api.stability.ai/v1 by default.
|
9
|
+
*/
|
10
|
+
class StabilityApiConfiguration extends BaseUrlPartsApiConfiguration_js_1.BaseUrlPartsApiConfiguration {
|
11
|
+
constructor({ protocol = "https", host = "api.stability.ai", port = "443", path = "/v1", apiKey, headers, retry, throttle, } = {}) {
|
8
12
|
super({
|
9
|
-
|
10
|
-
|
13
|
+
protocol,
|
14
|
+
host,
|
15
|
+
port,
|
16
|
+
path,
|
17
|
+
headers: headers ?? {
|
11
18
|
Authorization: `Bearer ${(0, loadApiKey_js_1.loadApiKey)({
|
12
19
|
apiKey,
|
13
20
|
environmentVariableName: "STABILITY_API_KEY",
|
@@ -1,11 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
import { BaseUrlPartsApiConfiguration, BaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlPartsApiConfiguration.js";
|
2
|
+
/**
|
3
|
+
* Creates an API configuration for the Stability AI API.
|
4
|
+
* It calls the API at https://api.stability.ai/v1 by default.
|
5
|
+
*/
|
6
|
+
export declare class StabilityApiConfiguration extends BaseUrlPartsApiConfiguration {
|
7
|
+
constructor({ protocol, host, port, path, apiKey, headers, retry, throttle, }?: Partial<BaseUrlPartsApiConfigurationOptions> & {
|
7
8
|
apiKey?: string;
|
8
|
-
retry?: RetryFunction;
|
9
|
-
throttle?: ThrottleFunction;
|
10
9
|
});
|
11
10
|
}
|
@@ -1,10 +1,17 @@
|
|
1
|
-
import {
|
1
|
+
import { BaseUrlPartsApiConfiguration, } from "../../core/api/BaseUrlPartsApiConfiguration.js";
|
2
2
|
import { loadApiKey } from "../../core/api/loadApiKey.js";
|
3
|
-
|
4
|
-
|
3
|
+
/**
|
4
|
+
* Creates an API configuration for the Stability AI API.
|
5
|
+
* It calls the API at https://api.stability.ai/v1 by default.
|
6
|
+
*/
|
7
|
+
export class StabilityApiConfiguration extends BaseUrlPartsApiConfiguration {
|
8
|
+
constructor({ protocol = "https", host = "api.stability.ai", port = "443", path = "/v1", apiKey, headers, retry, throttle, } = {}) {
|
5
9
|
super({
|
6
|
-
|
7
|
-
|
10
|
+
protocol,
|
11
|
+
host,
|
12
|
+
port,
|
13
|
+
path,
|
14
|
+
headers: headers ?? {
|
8
15
|
Authorization: `Bearer ${loadApiKey({
|
9
16
|
apiKey,
|
10
17
|
environmentVariableName: "STABILITY_API_KEY",
|
@@ -1,37 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.failedStabilityCallResponseHandler =
|
3
|
+
exports.failedStabilityCallResponseHandler = void 0;
|
4
4
|
const zod_1 = require("zod");
|
5
|
-
const
|
5
|
+
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
6
6
|
const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
7
|
-
const
|
8
|
-
exports.stabilityErrorDataSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.object({
|
7
|
+
const stabilityErrorDataSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.object({
|
9
8
|
message: zod_1.z.string(),
|
10
9
|
}));
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
enumerable: true,
|
16
|
-
configurable: true,
|
17
|
-
writable: true,
|
18
|
-
value: void 0
|
19
|
-
});
|
20
|
-
this.data = data;
|
21
|
-
}
|
22
|
-
}
|
23
|
-
exports.StabilityError = StabilityError;
|
24
|
-
const failedStabilityCallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
25
|
-
const responseBody = await response.text();
|
26
|
-
const parsedError = (0, parseJSON_js_1.parseJSON)({
|
27
|
-
text: responseBody,
|
28
|
-
schema: exports.stabilityErrorDataSchema,
|
29
|
-
});
|
30
|
-
return new StabilityError({
|
31
|
-
url,
|
32
|
-
requestBodyValues,
|
33
|
-
statusCode: response.status,
|
34
|
-
data: parsedError,
|
35
|
-
});
|
36
|
-
};
|
37
|
-
exports.failedStabilityCallResponseHandler = failedStabilityCallResponseHandler;
|
10
|
+
exports.failedStabilityCallResponseHandler = (0, postToApi_js_1.createJsonErrorResponseHandler)({
|
11
|
+
errorSchema: stabilityErrorDataSchema,
|
12
|
+
errorToMessage: (error) => error.message,
|
13
|
+
});
|
@@ -1,18 +1,9 @@
|
|
1
1
|
import { ApiCallError } from "../../core/api/ApiCallError.js";
|
2
2
|
import { ResponseHandler } from "../../core/api/postToApi.js";
|
3
3
|
import { ZodSchema } from "../../core/schema/ZodSchema.js";
|
4
|
-
|
4
|
+
declare const stabilityErrorDataSchema: ZodSchema<{
|
5
5
|
message: string;
|
6
6
|
}>;
|
7
7
|
export type StabilityErrorData = (typeof stabilityErrorDataSchema)["_type"];
|
8
|
-
export declare class StabilityError extends ApiCallError {
|
9
|
-
readonly data: StabilityErrorData;
|
10
|
-
constructor({ data, statusCode, url, requestBodyValues, message, }: {
|
11
|
-
message?: string;
|
12
|
-
statusCode: number;
|
13
|
-
url: string;
|
14
|
-
requestBodyValues: unknown;
|
15
|
-
data: StabilityErrorData;
|
16
|
-
});
|
17
|
-
}
|
18
8
|
export declare const failedStabilityCallResponseHandler: ResponseHandler<ApiCallError>;
|
9
|
+
export {};
|
@@ -1,32 +1,10 @@
|
|
1
1
|
import { z } from "zod";
|
2
|
-
import {
|
2
|
+
import { createJsonErrorResponseHandler, } from "../../core/api/postToApi.js";
|
3
3
|
import { ZodSchema } from "../../core/schema/ZodSchema.js";
|
4
|
-
|
5
|
-
export const stabilityErrorDataSchema = new ZodSchema(z.object({
|
4
|
+
const stabilityErrorDataSchema = new ZodSchema(z.object({
|
6
5
|
message: z.string(),
|
7
6
|
}));
|
8
|
-
export
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
enumerable: true,
|
13
|
-
configurable: true,
|
14
|
-
writable: true,
|
15
|
-
value: void 0
|
16
|
-
});
|
17
|
-
this.data = data;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
export const failedStabilityCallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
21
|
-
const responseBody = await response.text();
|
22
|
-
const parsedError = parseJSON({
|
23
|
-
text: responseBody,
|
24
|
-
schema: stabilityErrorDataSchema,
|
25
|
-
});
|
26
|
-
return new StabilityError({
|
27
|
-
url,
|
28
|
-
requestBodyValues,
|
29
|
-
statusCode: response.status,
|
30
|
-
data: parsedError,
|
31
|
-
});
|
32
|
-
};
|
7
|
+
export const failedStabilityCallResponseHandler = createJsonErrorResponseHandler({
|
8
|
+
errorSchema: stabilityErrorDataSchema,
|
9
|
+
errorToMessage: (error) => error.message,
|
10
|
+
});
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ImageGenerator = void 0;
|
3
|
+
exports.Api = exports.ImageGenerator = void 0;
|
4
|
+
const StabilityApiConfiguration_js_1 = require("./StabilityApiConfiguration.cjs");
|
4
5
|
const StabilityImageGenerationModel_js_1 = require("./StabilityImageGenerationModel.cjs");
|
5
6
|
/**
|
6
7
|
* Create an image generation model that calls the Stability AI image generation API.
|
@@ -10,12 +11,11 @@ const StabilityImageGenerationModel_js_1 = require("./StabilityImageGenerationMo
|
|
10
11
|
* @example
|
11
12
|
* const image = await generateImage(
|
12
13
|
* stability.ImageGenerator({
|
13
|
-
* model: "stable-diffusion-
|
14
|
+
* model: "stable-diffusion-v1-6",
|
14
15
|
* cfgScale: 7,
|
15
16
|
* clipGuidancePreset: "FAST_BLUE",
|
16
17
|
* height: 512,
|
17
18
|
* width: 512,
|
18
|
-
* samples: 1,
|
19
19
|
* steps: 30,
|
20
20
|
* })
|
21
21
|
* [
|
@@ -30,3 +30,11 @@ function ImageGenerator(settings) {
|
|
30
30
|
return new StabilityImageGenerationModel_js_1.StabilityImageGenerationModel(settings);
|
31
31
|
}
|
32
32
|
exports.ImageGenerator = ImageGenerator;
|
33
|
+
/**
|
34
|
+
* Creates an API configuration for the Stability AI API.
|
35
|
+
* It calls the API at https://api.stability.ai/v1 by default.
|
36
|
+
*/
|
37
|
+
function Api(settings) {
|
38
|
+
return new StabilityApiConfiguration_js_1.StabilityApiConfiguration(settings);
|
39
|
+
}
|
40
|
+
exports.Api = Api;
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import { BaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlPartsApiConfiguration.js";
|
2
|
+
import { StabilityApiConfiguration } from "./StabilityApiConfiguration.js";
|
1
3
|
import { StabilityImageGenerationModel, StabilityImageGenerationSettings } from "./StabilityImageGenerationModel.js";
|
2
4
|
/**
|
3
5
|
* Create an image generation model that calls the Stability AI image generation API.
|
@@ -7,12 +9,11 @@ import { StabilityImageGenerationModel, StabilityImageGenerationSettings } from
|
|
7
9
|
* @example
|
8
10
|
* const image = await generateImage(
|
9
11
|
* stability.ImageGenerator({
|
10
|
-
* model: "stable-diffusion-
|
12
|
+
* model: "stable-diffusion-v1-6",
|
11
13
|
* cfgScale: 7,
|
12
14
|
* clipGuidancePreset: "FAST_BLUE",
|
13
15
|
* height: 512,
|
14
16
|
* width: 512,
|
15
|
-
* samples: 1,
|
16
17
|
* steps: 30,
|
17
18
|
* })
|
18
19
|
* [
|
@@ -24,3 +25,10 @@ import { StabilityImageGenerationModel, StabilityImageGenerationSettings } from
|
|
24
25
|
* @returns A new instance of {@link StabilityImageGenerationModel}.
|
25
26
|
*/
|
26
27
|
export declare function ImageGenerator(settings: StabilityImageGenerationSettings): StabilityImageGenerationModel;
|
28
|
+
/**
|
29
|
+
* Creates an API configuration for the Stability AI API.
|
30
|
+
* It calls the API at https://api.stability.ai/v1 by default.
|
31
|
+
*/
|
32
|
+
export declare function Api(settings: Partial<BaseUrlPartsApiConfigurationOptions> & {
|
33
|
+
apiKey?: string;
|
34
|
+
}): StabilityApiConfiguration;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { StabilityApiConfiguration } from "./StabilityApiConfiguration.js";
|
1
2
|
import { StabilityImageGenerationModel, } from "./StabilityImageGenerationModel.js";
|
2
3
|
/**
|
3
4
|
* Create an image generation model that calls the Stability AI image generation API.
|
@@ -7,12 +8,11 @@ import { StabilityImageGenerationModel, } from "./StabilityImageGenerationModel.
|
|
7
8
|
* @example
|
8
9
|
* const image = await generateImage(
|
9
10
|
* stability.ImageGenerator({
|
10
|
-
* model: "stable-diffusion-
|
11
|
+
* model: "stable-diffusion-v1-6",
|
11
12
|
* cfgScale: 7,
|
12
13
|
* clipGuidancePreset: "FAST_BLUE",
|
13
14
|
* height: 512,
|
14
15
|
* width: 512,
|
15
|
-
* samples: 1,
|
16
16
|
* steps: 30,
|
17
17
|
* })
|
18
18
|
* [
|
@@ -26,3 +26,10 @@ import { StabilityImageGenerationModel, } from "./StabilityImageGenerationModel.
|
|
26
26
|
export function ImageGenerator(settings) {
|
27
27
|
return new StabilityImageGenerationModel(settings);
|
28
28
|
}
|
29
|
+
/**
|
30
|
+
* Creates an API configuration for the Stability AI API.
|
31
|
+
* It calls the API at https://api.stability.ai/v1 by default.
|
32
|
+
*/
|
33
|
+
export function Api(settings) {
|
34
|
+
return new StabilityApiConfiguration(settings);
|
35
|
+
}
|