modelfusion 0.99.0 → 0.101.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 +1411 -0
- package/README.md +9 -15
- package/core/api/BaseUrlApiConfiguration.d.ts +7 -6
- package/core/api/BaseUrlPartsApiConfiguration.cjs +53 -0
- package/core/api/BaseUrlPartsApiConfiguration.d.ts +26 -0
- package/core/api/BaseUrlPartsApiConfiguration.js +49 -0
- package/core/api/index.cjs +1 -0
- package/core/api/index.d.ts +1 -0
- package/core/api/index.js +1 -0
- package/guard/fixStructure.cjs +3 -3
- package/guard/fixStructure.d.ts +3 -3
- package/guard/fixStructure.js +3 -3
- package/model-function/generate-structure/generateStructure.d.ts +2 -2
- package/model-function/generate-structure/streamStructure.d.ts +1 -1
- package/model-provider/automatic1111/Automatic1111ApiConfiguration.cjs +8 -9
- package/model-provider/automatic1111/Automatic1111ApiConfiguration.d.ts +7 -9
- package/model-provider/automatic1111/Automatic1111ApiConfiguration.js +8 -9
- package/model-provider/automatic1111/Automatic1111Error.cjs +7 -31
- package/model-provider/automatic1111/Automatic1111Error.d.ts +2 -11
- package/model-provider/automatic1111/Automatic1111Error.js +6 -28
- package/model-provider/automatic1111/Automatic1111Facade.cjs +10 -1
- package/model-provider/automatic1111/Automatic1111Facade.d.ts +7 -0
- package/model-provider/automatic1111/Automatic1111Facade.js +8 -0
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +22 -27
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +8 -8
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +22 -27
- package/model-provider/automatic1111/index.cjs +1 -3
- package/model-provider/automatic1111/index.d.ts +1 -1
- package/model-provider/automatic1111/index.js +0 -1
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +6 -6
- package/model-provider/mistral/{MistralTextGenerationModel.cjs → MistralChatModel.cjs} +13 -13
- package/model-provider/mistral/{MistralTextGenerationModel.d.ts → MistralChatModel.d.ts} +21 -20
- package/model-provider/mistral/{MistralTextGenerationModel.js → MistralChatModel.js} +11 -11
- package/model-provider/mistral/MistralFacade.cjs +5 -5
- package/model-provider/mistral/MistralFacade.d.ts +3 -2
- package/model-provider/mistral/MistralFacade.js +3 -3
- package/model-provider/mistral/MistralPromptTemplate.d.ts +4 -4
- package/model-provider/mistral/index.cjs +1 -1
- package/model-provider/mistral/index.d.ts +1 -1
- package/model-provider/mistral/index.js +1 -1
- package/model-provider/ollama/OllamaApiConfiguration.d.ts +6 -5
- package/model-provider/ollama/OllamaChatModel.cjs +303 -0
- package/model-provider/ollama/OllamaChatModel.d.ts +171 -0
- package/model-provider/ollama/OllamaChatModel.js +299 -0
- package/model-provider/ollama/OllamaChatPromptTemplate.cjs +76 -0
- package/model-provider/ollama/OllamaChatPromptTemplate.d.ts +20 -0
- package/model-provider/ollama/OllamaChatPromptTemplate.js +69 -0
- package/model-provider/ollama/{OllamaTextGenerationModel.cjs → OllamaCompletionModel.cjs} +13 -11
- package/model-provider/ollama/OllamaCompletionModel.d.ts +159 -0
- package/model-provider/ollama/{OllamaTextGenerationModel.js → OllamaCompletionModel.js} +11 -9
- package/model-provider/ollama/{OllamaTextGenerationModel.test.cjs → OllamaCompletionModel.test.cjs} +3 -3
- package/model-provider/ollama/{OllamaTextGenerationModel.test.js → OllamaCompletionModel.test.js} +3 -3
- package/model-provider/ollama/OllamaFacade.cjs +15 -5
- package/model-provider/ollama/OllamaFacade.d.ts +7 -2
- package/model-provider/ollama/OllamaFacade.js +11 -3
- package/model-provider/ollama/OllamaTextGenerationSettings.cjs +2 -0
- package/model-provider/ollama/OllamaTextGenerationSettings.d.ts +87 -0
- package/model-provider/ollama/OllamaTextGenerationSettings.js +1 -0
- package/model-provider/ollama/index.cjs +4 -1
- package/model-provider/ollama/index.d.ts +4 -1
- package/model-provider/ollama/index.js +4 -1
- package/model-provider/openai/OpenAIFacade.cjs +4 -2
- package/model-provider/openai/OpenAIFacade.d.ts +3 -1
- package/model-provider/openai/OpenAIFacade.js +2 -1
- package/model-provider/openai/chat/AbstractOpenAIChatModel.d.ts +1 -1
- package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.d.ts +3 -3
- package/model-provider/openai/chat/OpenAIChatModel.cjs +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +2 -2
- package/model-provider/openai/chat/OpenAIChatModel.js +1 -1
- package/model-provider/openai/chat/OpenAIChatPromptTemplate.d.ts +5 -5
- package/model-provider/openai/chat/OpenAIChatPromptTemplate.js +1 -1
- package/model-provider/openai-compatible/OpenAICompatibleFacade.cjs +1 -1
- package/model-provider/openai-compatible/OpenAICompatibleFacade.d.ts +1 -1
- package/model-provider/openai-compatible/OpenAICompatibleFacade.js +1 -1
- package/package.json +15 -15
- package/model-provider/ollama/OllamaTextGenerationModel.d.ts +0 -230
- /package/model-provider/ollama/{OllamaTextGenerationModel.test.d.ts → OllamaCompletionModel.test.d.ts} +0 -0
package/README.md
CHANGED
@@ -85,7 +85,7 @@ Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai),
|
|
85
85
|
Multi-modal vision models such as GPT 4 Vision can process images as part of the prompt.
|
86
86
|
|
87
87
|
```ts
|
88
|
-
import { streamText, openai
|
88
|
+
import { streamText, openai } from "modelfusion";
|
89
89
|
import { readFileSync } from "fs";
|
90
90
|
|
91
91
|
const image = readFileSync("./image.png").toString("base64");
|
@@ -93,7 +93,7 @@ const image = readFileSync("./image.png").toString("base64");
|
|
93
93
|
const textStream = await streamText(
|
94
94
|
openai.ChatTextGenerator({ model: "gpt-4-vision-preview" }),
|
95
95
|
[
|
96
|
-
|
96
|
+
openai.ChatMessage.user([
|
97
97
|
{ type: "text", text: "Describe the image in detail:" },
|
98
98
|
{ type: "image", base64Image: image, mimeType: "image/png" },
|
99
99
|
]),
|
@@ -355,14 +355,14 @@ const result = await guard(
|
|
355
355
|
fixStructure({
|
356
356
|
modifyInputForRetry: async ({ input, error }) => [
|
357
357
|
...input,
|
358
|
-
|
358
|
+
openai.ChatMessage.assistant(null, {
|
359
359
|
functionCall: {
|
360
360
|
name: "sentiment",
|
361
361
|
arguments: JSON.stringify(error.valueText),
|
362
362
|
},
|
363
363
|
}),
|
364
|
-
|
365
|
-
|
364
|
+
openai.ChatMessage.user(error.message),
|
365
|
+
openai.ChatMessage.user("Please fix the error and try again."),
|
366
366
|
],
|
367
367
|
})
|
368
368
|
);
|
@@ -418,7 +418,7 @@ With `generateToolCall`, you can generate a tool call for a specific tool with a
|
|
418
418
|
const { id, name, args } = await generateToolCall(
|
419
419
|
openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }),
|
420
420
|
calculator,
|
421
|
-
[
|
421
|
+
[openai.ChatMessage.user("What's fourteen times twelve?")]
|
422
422
|
);
|
423
423
|
```
|
424
424
|
|
@@ -430,7 +430,7 @@ With `generateToolCallsOrText`, you can ask a language model to generate several
|
|
430
430
|
const { text, toolCalls } = await generateToolCallsOrText(
|
431
431
|
openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }),
|
432
432
|
[toolA, toolB, toolC],
|
433
|
-
[
|
433
|
+
[openai.ChatMessage.user(query)]
|
434
434
|
);
|
435
435
|
```
|
436
436
|
|
@@ -454,7 +454,7 @@ With `useTool`, you can use a tool with a language model that supports tools cal
|
|
454
454
|
const { tool, toolCall, args, ok, result } = await useTool(
|
455
455
|
openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }),
|
456
456
|
calculator,
|
457
|
-
[
|
457
|
+
[openai.ChatMessage.user("What's fourteen times twelve?")]
|
458
458
|
);
|
459
459
|
|
460
460
|
console.log(`Tool call:`, toolCall);
|
@@ -472,7 +472,7 @@ With `useToolsOrGenerateText`, you can ask a language model to generate several
|
|
472
472
|
const { text, toolResults } = await useToolsOrGenerateText(
|
473
473
|
openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }),
|
474
474
|
[calculator /* ... */],
|
475
|
-
[
|
475
|
+
[openai.ChatMessage.user("What's fourteen times twelve?")]
|
476
476
|
);
|
477
477
|
```
|
478
478
|
|
@@ -767,12 +767,6 @@ Examples for almost all of the individual functions and objects. Highly recommen
|
|
767
767
|
|
768
768
|
StoryTeller is an exploratory web application that creates short audio stories for pre-school kids.
|
769
769
|
|
770
|
-
### [Chatbot (Terminal)](https://github.com/lgrammel/modelfusion/tree/main/examples/chatbot-terminal)
|
771
|
-
|
772
|
-
> _Terminal app_, _chat_, _llama.cpp_
|
773
|
-
|
774
|
-
A chat with an AI assistant, implemented as a terminal app.
|
775
|
-
|
776
770
|
### [Chatbot (Next.JS)](https://github.com/lgrammel/modelfusion/tree/main/examples/chatbot-next-js)
|
777
771
|
|
778
772
|
> _Next.js app_, _OpenAI GPT-3.5-turbo_, _streaming_, _abort handling_
|
@@ -1,6 +1,12 @@
|
|
1
1
|
import { AbstractApiConfiguration } from "./AbstractApiConfiguration.js";
|
2
2
|
import { RetryFunction } from "./RetryFunction.js";
|
3
3
|
import { ThrottleFunction } from "./ThrottleFunction.js";
|
4
|
+
export type BaseUrlApiConfigurationOptions = {
|
5
|
+
baseUrl: string;
|
6
|
+
headers: Record<string, string>;
|
7
|
+
retry?: RetryFunction;
|
8
|
+
throttle?: ThrottleFunction;
|
9
|
+
};
|
4
10
|
/**
|
5
11
|
* An API configuration that uses a base URL and a set of headers.
|
6
12
|
*
|
@@ -9,11 +15,6 @@ import { ThrottleFunction } from "./ThrottleFunction.js";
|
|
9
15
|
export declare class BaseUrlApiConfiguration extends AbstractApiConfiguration {
|
10
16
|
readonly baseUrl: string;
|
11
17
|
readonly headers: Record<string, string>;
|
12
|
-
constructor({ baseUrl, headers, retry, throttle, }:
|
13
|
-
baseUrl: string;
|
14
|
-
headers: Record<string, string>;
|
15
|
-
retry?: RetryFunction;
|
16
|
-
throttle?: ThrottleFunction;
|
17
|
-
});
|
18
|
+
constructor({ baseUrl, headers, retry, throttle, }: BaseUrlApiConfigurationOptions);
|
18
19
|
assembleUrl(path: string): string;
|
19
20
|
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BaseUrlPartsApiConfiguration = void 0;
|
4
|
+
const AbstractApiConfiguration_js_1 = require("./AbstractApiConfiguration.cjs");
|
5
|
+
/**
|
6
|
+
* An API configuration that uses different URL parts and a set of headers.
|
7
|
+
*
|
8
|
+
* You can use it to configure custom APIs for models, e.g. your own internal OpenAI proxy with custom headers.
|
9
|
+
*/
|
10
|
+
class BaseUrlPartsApiConfiguration extends AbstractApiConfiguration_js_1.AbstractApiConfiguration {
|
11
|
+
constructor({ protocol, host, port, path, headers, retry, throttle, }) {
|
12
|
+
super({ retry, throttle });
|
13
|
+
Object.defineProperty(this, "protocol", {
|
14
|
+
enumerable: true,
|
15
|
+
configurable: true,
|
16
|
+
writable: true,
|
17
|
+
value: void 0
|
18
|
+
});
|
19
|
+
Object.defineProperty(this, "host", {
|
20
|
+
enumerable: true,
|
21
|
+
configurable: true,
|
22
|
+
writable: true,
|
23
|
+
value: void 0
|
24
|
+
});
|
25
|
+
Object.defineProperty(this, "port", {
|
26
|
+
enumerable: true,
|
27
|
+
configurable: true,
|
28
|
+
writable: true,
|
29
|
+
value: void 0
|
30
|
+
});
|
31
|
+
Object.defineProperty(this, "path", {
|
32
|
+
enumerable: true,
|
33
|
+
configurable: true,
|
34
|
+
writable: true,
|
35
|
+
value: void 0
|
36
|
+
});
|
37
|
+
Object.defineProperty(this, "headers", {
|
38
|
+
enumerable: true,
|
39
|
+
configurable: true,
|
40
|
+
writable: true,
|
41
|
+
value: void 0
|
42
|
+
});
|
43
|
+
this.protocol = protocol;
|
44
|
+
this.host = host;
|
45
|
+
this.port = port;
|
46
|
+
this.path = path;
|
47
|
+
this.headers = headers;
|
48
|
+
}
|
49
|
+
assembleUrl(path) {
|
50
|
+
return `${this.protocol}://${this.host}:${this.port}${this.path}${path}`;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
exports.BaseUrlPartsApiConfiguration = BaseUrlPartsApiConfiguration;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { AbstractApiConfiguration } from "./AbstractApiConfiguration.js";
|
2
|
+
import { RetryFunction } from "./RetryFunction.js";
|
3
|
+
import { ThrottleFunction } from "./ThrottleFunction.js";
|
4
|
+
export type BaseUrlPartsApiConfigurationOptions = {
|
5
|
+
protocol: string;
|
6
|
+
host: string;
|
7
|
+
port: string;
|
8
|
+
path: string;
|
9
|
+
headers: Record<string, string>;
|
10
|
+
retry?: RetryFunction;
|
11
|
+
throttle?: ThrottleFunction;
|
12
|
+
};
|
13
|
+
/**
|
14
|
+
* An API configuration that uses different URL parts and a set of headers.
|
15
|
+
*
|
16
|
+
* You can use it to configure custom APIs for models, e.g. your own internal OpenAI proxy with custom headers.
|
17
|
+
*/
|
18
|
+
export declare class BaseUrlPartsApiConfiguration extends AbstractApiConfiguration {
|
19
|
+
readonly protocol: string;
|
20
|
+
readonly host: string;
|
21
|
+
readonly port: string;
|
22
|
+
readonly path: string;
|
23
|
+
readonly headers: Record<string, string>;
|
24
|
+
constructor({ protocol, host, port, path, headers, retry, throttle, }: BaseUrlPartsApiConfigurationOptions);
|
25
|
+
assembleUrl(path: string): string;
|
26
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { AbstractApiConfiguration } from "./AbstractApiConfiguration.js";
|
2
|
+
/**
|
3
|
+
* An API configuration that uses different URL parts and a set of headers.
|
4
|
+
*
|
5
|
+
* You can use it to configure custom APIs for models, e.g. your own internal OpenAI proxy with custom headers.
|
6
|
+
*/
|
7
|
+
export class BaseUrlPartsApiConfiguration extends AbstractApiConfiguration {
|
8
|
+
constructor({ protocol, host, port, path, headers, retry, throttle, }) {
|
9
|
+
super({ retry, throttle });
|
10
|
+
Object.defineProperty(this, "protocol", {
|
11
|
+
enumerable: true,
|
12
|
+
configurable: true,
|
13
|
+
writable: true,
|
14
|
+
value: void 0
|
15
|
+
});
|
16
|
+
Object.defineProperty(this, "host", {
|
17
|
+
enumerable: true,
|
18
|
+
configurable: true,
|
19
|
+
writable: true,
|
20
|
+
value: void 0
|
21
|
+
});
|
22
|
+
Object.defineProperty(this, "port", {
|
23
|
+
enumerable: true,
|
24
|
+
configurable: true,
|
25
|
+
writable: true,
|
26
|
+
value: void 0
|
27
|
+
});
|
28
|
+
Object.defineProperty(this, "path", {
|
29
|
+
enumerable: true,
|
30
|
+
configurable: true,
|
31
|
+
writable: true,
|
32
|
+
value: void 0
|
33
|
+
});
|
34
|
+
Object.defineProperty(this, "headers", {
|
35
|
+
enumerable: true,
|
36
|
+
configurable: true,
|
37
|
+
writable: true,
|
38
|
+
value: void 0
|
39
|
+
});
|
40
|
+
this.protocol = protocol;
|
41
|
+
this.host = host;
|
42
|
+
this.port = port;
|
43
|
+
this.path = path;
|
44
|
+
this.headers = headers;
|
45
|
+
}
|
46
|
+
assembleUrl(path) {
|
47
|
+
return `${this.protocol}://${this.host}:${this.port}${this.path}${path}`;
|
48
|
+
}
|
49
|
+
}
|
package/core/api/index.cjs
CHANGED
@@ -18,6 +18,7 @@ __exportStar(require("./AbortError.cjs"), exports);
|
|
18
18
|
__exportStar(require("./ApiCallError.cjs"), exports);
|
19
19
|
__exportStar(require("./ApiConfiguration.cjs"), exports);
|
20
20
|
__exportStar(require("./BaseUrlApiConfiguration.cjs"), exports);
|
21
|
+
__exportStar(require("./BaseUrlPartsApiConfiguration.cjs"), exports);
|
21
22
|
__exportStar(require("./RetryError.cjs"), exports);
|
22
23
|
__exportStar(require("./RetryFunction.cjs"), exports);
|
23
24
|
__exportStar(require("./ThrottleFunction.cjs"), exports);
|
package/core/api/index.d.ts
CHANGED
@@ -2,6 +2,7 @@ export * from "./AbortError.js";
|
|
2
2
|
export * from "./ApiCallError.js";
|
3
3
|
export * from "./ApiConfiguration.js";
|
4
4
|
export * from "./BaseUrlApiConfiguration.js";
|
5
|
+
export * from "./BaseUrlPartsApiConfiguration.js";
|
5
6
|
export * from "./RetryError.js";
|
6
7
|
export * from "./RetryFunction.js";
|
7
8
|
export * from "./ThrottleFunction.js";
|
package/core/api/index.js
CHANGED
@@ -2,6 +2,7 @@ export * from "./AbortError.js";
|
|
2
2
|
export * from "./ApiCallError.js";
|
3
3
|
export * from "./ApiConfiguration.js";
|
4
4
|
export * from "./BaseUrlApiConfiguration.js";
|
5
|
+
export * from "./BaseUrlPartsApiConfiguration.js";
|
5
6
|
export * from "./RetryError.js";
|
6
7
|
export * from "./RetryFunction.js";
|
7
8
|
export * from "./ThrottleFunction.js";
|
package/guard/fixStructure.cjs
CHANGED
@@ -45,14 +45,14 @@ const StructureValidationError_js_1 = require("../model-function/generate-struct
|
|
45
45
|
* fixStructure({
|
46
46
|
* modifyInputForRetry: async ({ input, error }) => [
|
47
47
|
* ...input,
|
48
|
-
*
|
48
|
+
* openai.ChatMessage.assistant(null, {
|
49
49
|
* functionCall: {
|
50
50
|
* name: "sentiment",
|
51
51
|
* arguments: JSON.stringify(error.valueText),
|
52
52
|
* },
|
53
53
|
* }),
|
54
|
-
*
|
55
|
-
*
|
54
|
+
* openai.ChatMessage.user(error.message),
|
55
|
+
* openai.ChatMessage.user("Please fix the error and try again."),
|
56
56
|
* ],
|
57
57
|
* })
|
58
58
|
* );
|
package/guard/fixStructure.d.ts
CHANGED
@@ -43,14 +43,14 @@ import { Guard } from "./guard.js";
|
|
43
43
|
* fixStructure({
|
44
44
|
* modifyInputForRetry: async ({ input, error }) => [
|
45
45
|
* ...input,
|
46
|
-
*
|
46
|
+
* openai.ChatMessage.assistant(null, {
|
47
47
|
* functionCall: {
|
48
48
|
* name: "sentiment",
|
49
49
|
* arguments: JSON.stringify(error.valueText),
|
50
50
|
* },
|
51
51
|
* }),
|
52
|
-
*
|
53
|
-
*
|
52
|
+
* openai.ChatMessage.user(error.message),
|
53
|
+
* openai.ChatMessage.user("Please fix the error and try again."),
|
54
54
|
* ],
|
55
55
|
* })
|
56
56
|
* );
|
package/guard/fixStructure.js
CHANGED
@@ -42,14 +42,14 @@ import { StructureValidationError } from "../model-function/generate-structure/S
|
|
42
42
|
* fixStructure({
|
43
43
|
* modifyInputForRetry: async ({ input, error }) => [
|
44
44
|
* ...input,
|
45
|
-
*
|
45
|
+
* openai.ChatMessage.assistant(null, {
|
46
46
|
* functionCall: {
|
47
47
|
* name: "sentiment",
|
48
48
|
* arguments: JSON.stringify(error.valueText),
|
49
49
|
* },
|
50
50
|
* }),
|
51
|
-
*
|
52
|
-
*
|
51
|
+
* openai.ChatMessage.user(error.message),
|
52
|
+
* openai.ChatMessage.user("Please fix the error and try again."),
|
53
53
|
* ],
|
54
54
|
* })
|
55
55
|
* );
|
@@ -17,11 +17,11 @@ import { StructureGenerationModel, StructureGenerationModelSettings } from "./St
|
|
17
17
|
* .describe("Sentiment."),
|
18
18
|
* })),
|
19
19
|
* [
|
20
|
-
*
|
20
|
+
* openai.ChatMessage.system(
|
21
21
|
* "You are a sentiment evaluator. " +
|
22
22
|
* "Analyze the sentiment of the following product review:"
|
23
23
|
* ),
|
24
|
-
*
|
24
|
+
* openai.ChatMessage.user(
|
25
25
|
* "After I opened the package, I was met by a very unpleasant smell " +
|
26
26
|
* "that did not disappear even after washing. Never again!"
|
27
27
|
* ),
|
@@ -1,15 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.Automatic1111ApiConfiguration = void 0;
|
4
|
-
const
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
});
|
4
|
+
const BaseUrlPartsApiConfiguration_js_1 = require("../../core/api/BaseUrlPartsApiConfiguration.cjs");
|
5
|
+
/**
|
6
|
+
* Creates an API configuration for the AUTOMATIC1111 Stable Diffusion Web UI API.
|
7
|
+
* It calls the API at http://127.0.0.1:7860/sdapi/v1 by default.
|
8
|
+
*/
|
9
|
+
class Automatic1111ApiConfiguration extends BaseUrlPartsApiConfiguration_js_1.BaseUrlPartsApiConfiguration {
|
10
|
+
constructor({ protocol = "http", host = "127.0.0.1", port = "7860", path = "/sdapi/v1", headers = {}, retry, throttle, } = {}) {
|
11
|
+
super({ protocol, host, port, path, headers, retry, throttle });
|
13
12
|
}
|
14
13
|
}
|
15
14
|
exports.Automatic1111ApiConfiguration = Automatic1111ApiConfiguration;
|
@@ -1,10 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
throttle?: ThrottleFunction;
|
9
|
-
});
|
1
|
+
import { BaseUrlPartsApiConfiguration, BaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlPartsApiConfiguration.js";
|
2
|
+
/**
|
3
|
+
* Creates an API configuration for the AUTOMATIC1111 Stable Diffusion Web UI API.
|
4
|
+
* It calls the API at http://127.0.0.1:7860/sdapi/v1 by default.
|
5
|
+
*/
|
6
|
+
export declare class Automatic1111ApiConfiguration extends BaseUrlPartsApiConfiguration {
|
7
|
+
constructor({ protocol, host, port, path, headers, retry, throttle, }?: Partial<BaseUrlPartsApiConfigurationOptions>);
|
10
8
|
}
|
@@ -1,11 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
});
|
1
|
+
import { BaseUrlPartsApiConfiguration, } from "../../core/api/BaseUrlPartsApiConfiguration.js";
|
2
|
+
/**
|
3
|
+
* Creates an API configuration for the AUTOMATIC1111 Stable Diffusion Web UI API.
|
4
|
+
* It calls the API at http://127.0.0.1:7860/sdapi/v1 by default.
|
5
|
+
*/
|
6
|
+
export class Automatic1111ApiConfiguration extends BaseUrlPartsApiConfiguration {
|
7
|
+
constructor({ protocol = "http", host = "127.0.0.1", port = "7860", path = "/sdapi/v1", headers = {}, retry, throttle, } = {}) {
|
8
|
+
super({ protocol, host, port, path, headers, retry, throttle });
|
10
9
|
}
|
11
10
|
}
|
@@ -1,40 +1,16 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.failedAutomatic1111CallResponseHandler =
|
3
|
+
exports.failedAutomatic1111CallResponseHandler = 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.automatic1111ErrorDataSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.object({
|
7
|
+
const automatic1111ErrorDataSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.object({
|
9
8
|
error: zod_1.z.string(),
|
10
9
|
detail: zod_1.z.string(),
|
11
10
|
body: zod_1.z.string(),
|
12
11
|
errors: zod_1.z.string(),
|
13
12
|
}));
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
enumerable: true,
|
19
|
-
configurable: true,
|
20
|
-
writable: true,
|
21
|
-
value: void 0
|
22
|
-
});
|
23
|
-
this.data = data;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
exports.Automatic1111Error = Automatic1111Error;
|
27
|
-
const failedAutomatic1111CallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
28
|
-
const responseBody = await response.text();
|
29
|
-
const parsedError = (0, parseJSON_js_1.parseJSON)({
|
30
|
-
text: responseBody,
|
31
|
-
schema: exports.automatic1111ErrorDataSchema,
|
32
|
-
});
|
33
|
-
return new Automatic1111Error({
|
34
|
-
url,
|
35
|
-
requestBodyValues,
|
36
|
-
statusCode: response.status,
|
37
|
-
data: parsedError,
|
38
|
-
});
|
39
|
-
};
|
40
|
-
exports.failedAutomatic1111CallResponseHandler = failedAutomatic1111CallResponseHandler;
|
13
|
+
exports.failedAutomatic1111CallResponseHandler = (0, postToApi_js_1.createJsonErrorResponseHandler)({
|
14
|
+
errorSchema: automatic1111ErrorDataSchema,
|
15
|
+
errorToMessage: (error) => error.detail,
|
16
|
+
});
|
@@ -1,21 +1,12 @@
|
|
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 automatic1111ErrorDataSchema: ZodSchema<{
|
5
5
|
error: string;
|
6
6
|
errors: string;
|
7
7
|
body: string;
|
8
8
|
detail: string;
|
9
9
|
}>;
|
10
10
|
export type Automatic1111ErrorData = (typeof automatic1111ErrorDataSchema)["_type"];
|
11
|
-
export declare class Automatic1111Error extends ApiCallError {
|
12
|
-
readonly data: Automatic1111ErrorData;
|
13
|
-
constructor({ data, statusCode, url, requestBodyValues, message, }: {
|
14
|
-
message?: string;
|
15
|
-
statusCode: number;
|
16
|
-
url: string;
|
17
|
-
requestBodyValues: unknown;
|
18
|
-
data: Automatic1111ErrorData;
|
19
|
-
});
|
20
|
-
}
|
21
11
|
export declare const failedAutomatic1111CallResponseHandler: ResponseHandler<ApiCallError>;
|
12
|
+
export {};
|
@@ -1,35 +1,13 @@
|
|
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 automatic1111ErrorDataSchema = new ZodSchema(z.object({
|
4
|
+
const automatic1111ErrorDataSchema = new ZodSchema(z.object({
|
6
5
|
error: z.string(),
|
7
6
|
detail: z.string(),
|
8
7
|
body: z.string(),
|
9
8
|
errors: z.string(),
|
10
9
|
}));
|
11
|
-
export
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
enumerable: true,
|
16
|
-
configurable: true,
|
17
|
-
writable: true,
|
18
|
-
value: void 0
|
19
|
-
});
|
20
|
-
this.data = data;
|
21
|
-
}
|
22
|
-
}
|
23
|
-
export const failedAutomatic1111CallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
24
|
-
const responseBody = await response.text();
|
25
|
-
const parsedError = parseJSON({
|
26
|
-
text: responseBody,
|
27
|
-
schema: automatic1111ErrorDataSchema,
|
28
|
-
});
|
29
|
-
return new Automatic1111Error({
|
30
|
-
url,
|
31
|
-
requestBodyValues,
|
32
|
-
statusCode: response.status,
|
33
|
-
data: parsedError,
|
34
|
-
});
|
35
|
-
};
|
10
|
+
export const failedAutomatic1111CallResponseHandler = createJsonErrorResponseHandler({
|
11
|
+
errorSchema: automatic1111ErrorDataSchema,
|
12
|
+
errorToMessage: (error) => error.detail,
|
13
|
+
});
|
@@ -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 Automatic1111ApiConfiguration_js_1 = require("./Automatic1111ApiConfiguration.cjs");
|
4
5
|
const Automatic1111ImageGenerationModel_js_1 = require("./Automatic1111ImageGenerationModel.cjs");
|
5
6
|
/**
|
6
7
|
* Create an image generation model that calls the AUTOMATIC1111 Stable Diffusion Web UI API.
|
@@ -13,3 +14,11 @@ function ImageGenerator(settings) {
|
|
13
14
|
return new Automatic1111ImageGenerationModel_js_1.Automatic1111ImageGenerationModel(settings);
|
14
15
|
}
|
15
16
|
exports.ImageGenerator = ImageGenerator;
|
17
|
+
/**
|
18
|
+
* Creates an API configuration for the AUTOMATIC1111 Stable Diffusion Web UI API.
|
19
|
+
* It calls the API at http://127.0.0.1:7860/sdapi/v1 by default.
|
20
|
+
*/
|
21
|
+
function Api(settings) {
|
22
|
+
return new Automatic1111ApiConfiguration_js_1.Automatic1111ApiConfiguration(settings);
|
23
|
+
}
|
24
|
+
exports.Api = Api;
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import { BaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlPartsApiConfiguration.js";
|
2
|
+
import { Automatic1111ApiConfiguration } from "./Automatic1111ApiConfiguration.js";
|
1
3
|
import { Automatic1111ImageGenerationModel, Automatic1111ImageGenerationSettings } from "./Automatic1111ImageGenerationModel.js";
|
2
4
|
/**
|
3
5
|
* Create an image generation model that calls the AUTOMATIC1111 Stable Diffusion Web UI API.
|
@@ -7,3 +9,8 @@ import { Automatic1111ImageGenerationModel, Automatic1111ImageGenerationSettings
|
|
7
9
|
* @return A new instance of ${@link Automatic1111ImageGenerationModel}.
|
8
10
|
*/
|
9
11
|
export declare function ImageGenerator(settings: Automatic1111ImageGenerationSettings): Automatic1111ImageGenerationModel;
|
12
|
+
/**
|
13
|
+
* Creates an API configuration for the AUTOMATIC1111 Stable Diffusion Web UI API.
|
14
|
+
* It calls the API at http://127.0.0.1:7860/sdapi/v1 by default.
|
15
|
+
*/
|
16
|
+
export declare function Api(settings: Partial<BaseUrlPartsApiConfigurationOptions>): Automatic1111ApiConfiguration;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Automatic1111ApiConfiguration } from "./Automatic1111ApiConfiguration.js";
|
1
2
|
import { Automatic1111ImageGenerationModel, } from "./Automatic1111ImageGenerationModel.js";
|
2
3
|
/**
|
3
4
|
* Create an image generation model that calls the AUTOMATIC1111 Stable Diffusion Web UI API.
|
@@ -9,3 +10,10 @@ import { Automatic1111ImageGenerationModel, } from "./Automatic1111ImageGenerati
|
|
9
10
|
export function ImageGenerator(settings) {
|
10
11
|
return new Automatic1111ImageGenerationModel(settings);
|
11
12
|
}
|
13
|
+
/**
|
14
|
+
* Creates an API configuration for the AUTOMATIC1111 Stable Diffusion Web UI API.
|
15
|
+
* It calls the API at http://127.0.0.1:7860/sdapi/v1 by default.
|
16
|
+
*/
|
17
|
+
export function Api(settings) {
|
18
|
+
return new Automatic1111ApiConfiguration(settings);
|
19
|
+
}
|
@@ -28,13 +28,29 @@ class Automatic1111ImageGenerationModel extends AbstractModel_js_1.AbstractModel
|
|
28
28
|
return this.settings.model;
|
29
29
|
}
|
30
30
|
async callAPI(input, options) {
|
31
|
+
const api = this.settings.api ?? new Automatic1111ApiConfiguration_js_1.Automatic1111ApiConfiguration();
|
32
|
+
const abortSignal = options?.run?.abortSignal;
|
31
33
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
32
|
-
retry:
|
33
|
-
throttle:
|
34
|
-
call: async () =>
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
retry: api.retry,
|
35
|
+
throttle: api.throttle,
|
36
|
+
call: async () => (0, postToApi_js_1.postJsonToApi)({
|
37
|
+
url: api.assembleUrl(`/txt2img`),
|
38
|
+
headers: api.headers,
|
39
|
+
body: {
|
40
|
+
height: this.settings.height,
|
41
|
+
width: this.settings.width,
|
42
|
+
prompt: input.prompt,
|
43
|
+
negative_prompt: input.negativePrompt,
|
44
|
+
sampler_index: this.settings.sampler,
|
45
|
+
steps: this.settings.steps,
|
46
|
+
seed: input.seed,
|
47
|
+
override_settings: {
|
48
|
+
sd_model_checkpoint: this.settings.model,
|
49
|
+
},
|
50
|
+
},
|
51
|
+
failedResponseHandler: Automatic1111Error_js_1.failedAutomatic1111CallResponseHandler,
|
52
|
+
successfulResponseHandler: (0, postToApi_js_1.createJsonResponseHandler)(Automatic1111ImageGenerationResponseSchema),
|
53
|
+
abortSignal,
|
38
54
|
}),
|
39
55
|
});
|
40
56
|
}
|
@@ -72,24 +88,3 @@ const Automatic1111ImageGenerationResponseSchema = zod_1.z.object({
|
|
72
88
|
parameters: zod_1.z.object({}),
|
73
89
|
info: zod_1.z.string(),
|
74
90
|
});
|
75
|
-
async function callAutomatic1111ImageGenerationAPI({ api = new Automatic1111ApiConfiguration_js_1.Automatic1111ApiConfiguration(), abortSignal, height, width, prompt, negativePrompt, sampler, steps, seed, model, }) {
|
76
|
-
return (0, postToApi_js_1.postJsonToApi)({
|
77
|
-
url: api.assembleUrl(`/txt2img`),
|
78
|
-
headers: api.headers,
|
79
|
-
body: {
|
80
|
-
height,
|
81
|
-
width,
|
82
|
-
prompt,
|
83
|
-
negative_prompt: negativePrompt,
|
84
|
-
sampler_index: sampler,
|
85
|
-
steps,
|
86
|
-
seed,
|
87
|
-
override_settings: {
|
88
|
-
sd_model_checkpoint: model,
|
89
|
-
},
|
90
|
-
},
|
91
|
-
failedResponseHandler: Automatic1111Error_js_1.failedAutomatic1111CallResponseHandler,
|
92
|
-
successfulResponseHandler: (0, postToApi_js_1.createJsonResponseHandler)(Automatic1111ImageGenerationResponseSchema),
|
93
|
-
abortSignal,
|
94
|
-
});
|
95
|
-
}
|