modelfusion 0.27.0 → 0.27.2

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.
Files changed (128) hide show
  1. package/index.cjs +1 -0
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/model-function/ApiConfiguration.d.ts +14 -0
  5. package/model-function/BasicApiConfiguration.cjs +35 -0
  6. package/model-function/BasicApiConfiguration.d.ts +15 -0
  7. package/model-function/BasicApiConfiguration.js +31 -0
  8. package/model-function/index.cjs +2 -0
  9. package/model-function/index.d.ts +2 -0
  10. package/model-function/index.js +2 -0
  11. package/model-provider/automatic1111/Automatic1111ApiConfiguration.cjs +14 -0
  12. package/model-provider/automatic1111/Automatic1111ApiConfiguration.d.ts +10 -0
  13. package/model-provider/automatic1111/Automatic1111ApiConfiguration.js +10 -0
  14. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +10 -7
  15. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +2 -5
  16. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +10 -7
  17. package/model-provider/automatic1111/index.cjs +1 -0
  18. package/model-provider/automatic1111/index.d.ts +1 -0
  19. package/model-provider/automatic1111/index.js +1 -0
  20. package/model-provider/cohere/CohereApiConfiguration.cjs +29 -0
  21. package/model-provider/cohere/CohereApiConfiguration.d.ts +13 -0
  22. package/model-provider/cohere/CohereApiConfiguration.js +25 -0
  23. package/model-provider/cohere/CohereTextEmbeddingModel.cjs +11 -38
  24. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +2 -11
  25. package/model-provider/cohere/CohereTextEmbeddingModel.js +11 -38
  26. package/model-provider/cohere/CohereTextGenerationModel.cjs +7 -36
  27. package/model-provider/cohere/CohereTextGenerationModel.d.ts +2 -11
  28. package/model-provider/cohere/CohereTextGenerationModel.js +7 -36
  29. package/model-provider/cohere/CohereTokenizer.cjs +11 -33
  30. package/model-provider/cohere/CohereTokenizer.d.ts +4 -9
  31. package/model-provider/cohere/CohereTokenizer.js +11 -33
  32. package/model-provider/cohere/index.cjs +1 -0
  33. package/model-provider/cohere/index.d.ts +1 -0
  34. package/model-provider/cohere/index.js +1 -0
  35. package/model-provider/elevenlabs/ElevenLabsApiConfiguration.cjs +29 -0
  36. package/model-provider/elevenlabs/ElevenLabsApiConfiguration.d.ts +13 -0
  37. package/model-provider/elevenlabs/ElevenLabsApiConfiguration.js +25 -0
  38. package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.cjs +22 -32
  39. package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.d.ts +8 -8
  40. package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.js +22 -32
  41. package/model-provider/elevenlabs/index.cjs +1 -0
  42. package/model-provider/elevenlabs/index.d.ts +1 -0
  43. package/model-provider/elevenlabs/index.js +1 -0
  44. package/model-provider/huggingface/HuggingFaceApiConfiguration.cjs +29 -0
  45. package/model-provider/huggingface/HuggingFaceApiConfiguration.d.ts +13 -0
  46. package/model-provider/huggingface/HuggingFaceApiConfiguration.js +25 -0
  47. package/model-provider/huggingface/HuggingFaceError.cjs +3 -2
  48. package/model-provider/huggingface/HuggingFaceError.d.ts +3 -3
  49. package/model-provider/huggingface/HuggingFaceError.js +3 -2
  50. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +15 -21
  51. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +3 -8
  52. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +15 -21
  53. package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +7 -36
  54. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +2 -7
  55. package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +7 -36
  56. package/model-provider/huggingface/index.cjs +1 -0
  57. package/model-provider/huggingface/index.d.ts +1 -0
  58. package/model-provider/huggingface/index.js +1 -0
  59. package/model-provider/llamacpp/LlamaCppApiConfiguration.cjs +14 -0
  60. package/model-provider/llamacpp/LlamaCppApiConfiguration.d.ts +10 -0
  61. package/model-provider/llamacpp/LlamaCppApiConfiguration.js +10 -0
  62. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +11 -12
  63. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +2 -9
  64. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +11 -12
  65. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +9 -10
  66. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +2 -9
  67. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +9 -10
  68. package/model-provider/llamacpp/LlamaCppTokenizer.cjs +10 -8
  69. package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +4 -10
  70. package/model-provider/llamacpp/LlamaCppTokenizer.js +10 -8
  71. package/model-provider/llamacpp/index.cjs +1 -0
  72. package/model-provider/llamacpp/index.d.ts +1 -0
  73. package/model-provider/llamacpp/index.js +1 -0
  74. package/model-provider/lmnt/LmntApiConfiguration.cjs +29 -0
  75. package/model-provider/lmnt/LmntApiConfiguration.d.ts +13 -0
  76. package/model-provider/lmnt/LmntApiConfiguration.js +25 -0
  77. package/model-provider/lmnt/LmntSpeechSynthesisModel.cjs +18 -34
  78. package/model-provider/lmnt/LmntSpeechSynthesisModel.d.ts +8 -8
  79. package/model-provider/lmnt/LmntSpeechSynthesisModel.js +18 -34
  80. package/model-provider/lmnt/index.cjs +1 -0
  81. package/model-provider/lmnt/index.d.ts +1 -0
  82. package/model-provider/lmnt/index.js +1 -0
  83. package/model-provider/openai/AzureOpenAIApiConfiguration.cjs +51 -0
  84. package/model-provider/openai/AzureOpenAIApiConfiguration.d.ts +26 -0
  85. package/model-provider/openai/AzureOpenAIApiConfiguration.js +47 -0
  86. package/model-provider/openai/OpenAIApiConfiguration.cjs +31 -0
  87. package/model-provider/openai/OpenAIApiConfiguration.d.ts +13 -0
  88. package/model-provider/openai/OpenAIApiConfiguration.js +27 -0
  89. package/model-provider/openai/OpenAIImageGenerationModel.cjs +16 -20
  90. package/model-provider/openai/OpenAIImageGenerationModel.d.ts +4 -4
  91. package/model-provider/openai/OpenAIImageGenerationModel.js +16 -20
  92. package/model-provider/openai/OpenAITextEmbeddingModel.cjs +16 -35
  93. package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +2 -7
  94. package/model-provider/openai/OpenAITextEmbeddingModel.js +16 -35
  95. package/model-provider/openai/OpenAITextGenerationModel.cjs +6 -33
  96. package/model-provider/openai/OpenAITextGenerationModel.d.ts +4 -5
  97. package/model-provider/openai/OpenAITextGenerationModel.js +6 -33
  98. package/model-provider/openai/OpenAITranscriptionModel.cjs +16 -39
  99. package/model-provider/openai/OpenAITranscriptionModel.d.ts +4 -11
  100. package/model-provider/openai/OpenAITranscriptionModel.js +16 -39
  101. package/model-provider/openai/chat/OpenAIChatModel.cjs +9 -17
  102. package/model-provider/openai/chat/OpenAIChatModel.d.ts +4 -5
  103. package/model-provider/openai/chat/OpenAIChatModel.js +9 -17
  104. package/model-provider/openai/index.cjs +2 -1
  105. package/model-provider/openai/index.d.ts +2 -1
  106. package/model-provider/openai/index.js +2 -1
  107. package/model-provider/stability/StabilityApiConfiguration.cjs +31 -0
  108. package/model-provider/stability/StabilityApiConfiguration.d.ts +13 -0
  109. package/model-provider/stability/StabilityApiConfiguration.js +27 -0
  110. package/model-provider/stability/StabilityImageGenerationModel.cjs +12 -46
  111. package/model-provider/stability/StabilityImageGenerationModel.d.ts +2 -7
  112. package/model-provider/stability/StabilityImageGenerationModel.js +12 -46
  113. package/model-provider/stability/index.cjs +1 -0
  114. package/model-provider/stability/index.d.ts +1 -0
  115. package/model-provider/stability/index.js +1 -0
  116. package/observability/helicone/HeliconeOpenAIApiConfiguration.cjs +45 -0
  117. package/observability/helicone/HeliconeOpenAIApiConfiguration.d.ts +15 -0
  118. package/observability/helicone/HeliconeOpenAIApiConfiguration.js +41 -0
  119. package/observability/index.cjs +17 -0
  120. package/observability/index.d.ts +1 -0
  121. package/observability/index.js +1 -0
  122. package/package.json +1 -1
  123. package/util/api/loadApiKey.cjs +11 -0
  124. package/util/api/loadApiKey.d.ts +6 -0
  125. package/util/api/loadApiKey.js +7 -0
  126. package/model-provider/openai/OpenAIModelSettings.d.ts +0 -8
  127. /package/{model-provider/openai/OpenAIModelSettings.cjs → model-function/ApiConfiguration.cjs} +0 -0
  128. /package/{model-provider/openai/OpenAIModelSettings.js → model-function/ApiConfiguration.js} +0 -0
package/index.cjs CHANGED
@@ -19,6 +19,7 @@ __exportStar(require("./core/index.cjs"), exports);
19
19
  __exportStar(require("./cost/index.cjs"), exports);
20
20
  __exportStar(require("./model-function/index.cjs"), exports);
21
21
  __exportStar(require("./model-provider/index.cjs"), exports);
22
+ __exportStar(require("./observability/index.cjs"), exports);
22
23
  __exportStar(require("./prompt/index.cjs"), exports);
23
24
  __exportStar(require("./text-chunk/index.cjs"), exports);
24
25
  __exportStar(require("./tool/index.cjs"), exports);
package/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./core/index.js";
3
3
  export * from "./cost/index.js";
4
4
  export * from "./model-function/index.js";
5
5
  export * from "./model-provider/index.js";
6
+ export * from "./observability/index.js";
6
7
  export * from "./prompt/index.js";
7
8
  export * from "./text-chunk/index.js";
8
9
  export * from "./tool/index.js";
package/index.js CHANGED
@@ -3,6 +3,7 @@ export * from "./core/index.js";
3
3
  export * from "./cost/index.js";
4
4
  export * from "./model-function/index.js";
5
5
  export * from "./model-provider/index.js";
6
+ export * from "./observability/index.js";
6
7
  export * from "./prompt/index.js";
7
8
  export * from "./text-chunk/index.js";
8
9
  export * from "./tool/index.js";
@@ -0,0 +1,14 @@
1
+ import { RetryFunction } from "../util/api/RetryFunction.js";
2
+ import { ThrottleFunction } from "../util/api/ThrottleFunction.js";
3
+ /**
4
+ * Settings for a REST provider, e.g. OpenAI or Lmnt.
5
+ */
6
+ export interface ApiConfiguration {
7
+ /**
8
+ * Creates a full URL given a inner path.
9
+ */
10
+ assembleUrl(path: string): string;
11
+ readonly headers: Record<string, string>;
12
+ readonly retry?: RetryFunction;
13
+ readonly throttle?: ThrottleFunction;
14
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasicApiConfiguration = void 0;
4
+ class BasicApiConfiguration {
5
+ constructor({ baseUrl, retry, throttle, }) {
6
+ Object.defineProperty(this, "baseUrl", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: void 0
11
+ });
12
+ Object.defineProperty(this, "retry", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "throttle", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ this.baseUrl = baseUrl;
25
+ this.retry = retry;
26
+ this.throttle = throttle;
27
+ }
28
+ get headers() {
29
+ return {};
30
+ }
31
+ assembleUrl(path) {
32
+ return `${this.baseUrl}${path}`;
33
+ }
34
+ }
35
+ exports.BasicApiConfiguration = BasicApiConfiguration;
@@ -0,0 +1,15 @@
1
+ import { RetryFunction } from "../util/api/RetryFunction.js";
2
+ import { ThrottleFunction } from "../util/api/ThrottleFunction.js";
3
+ import { ApiConfiguration } from "./ApiConfiguration.js";
4
+ export declare class BasicApiConfiguration implements ApiConfiguration {
5
+ readonly baseUrl: string;
6
+ readonly retry?: RetryFunction;
7
+ readonly throttle?: ThrottleFunction;
8
+ constructor({ baseUrl, retry, throttle, }: {
9
+ baseUrl: string;
10
+ retry?: RetryFunction;
11
+ throttle?: ThrottleFunction;
12
+ });
13
+ get headers(): Record<string, string>;
14
+ assembleUrl(path: string): string;
15
+ }
@@ -0,0 +1,31 @@
1
+ export class BasicApiConfiguration {
2
+ constructor({ baseUrl, retry, throttle, }) {
3
+ Object.defineProperty(this, "baseUrl", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: void 0
8
+ });
9
+ Object.defineProperty(this, "retry", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: void 0
14
+ });
15
+ Object.defineProperty(this, "throttle", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ this.baseUrl = baseUrl;
22
+ this.retry = retry;
23
+ this.throttle = throttle;
24
+ }
25
+ get headers() {
26
+ return {};
27
+ }
28
+ assembleUrl(path) {
29
+ return `${this.baseUrl}${path}`;
30
+ }
31
+ }
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ApiConfiguration.cjs"), exports);
18
+ __exportStar(require("./BasicApiConfiguration.cjs"), exports);
17
19
  __exportStar(require("./Model.cjs"), exports);
18
20
  __exportStar(require("./ModelCallEvent.cjs"), exports);
19
21
  __exportStar(require("./ModelFunctionOptions.cjs"), exports);
@@ -1,3 +1,5 @@
1
+ export * from "./ApiConfiguration.js";
2
+ export * from "./BasicApiConfiguration.js";
1
3
  export * from "./Model.js";
2
4
  export * from "./ModelCallEvent.js";
3
5
  export * from "./ModelFunctionOptions.js";
@@ -1,3 +1,5 @@
1
+ export * from "./ApiConfiguration.js";
2
+ export * from "./BasicApiConfiguration.js";
1
3
  export * from "./Model.js";
2
4
  export * from "./ModelCallEvent.js";
3
5
  export * from "./ModelFunctionOptions.js";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Automatic1111ApiConfiguration = void 0;
4
+ const BasicApiConfiguration_js_1 = require("../../model-function/BasicApiConfiguration.cjs");
5
+ class Automatic1111ApiConfiguration extends BasicApiConfiguration_js_1.BasicApiConfiguration {
6
+ constructor({ baseUrl = "http://127.0.0.1:7860/sdapi/v1", retry, throttle, } = {}) {
7
+ super({
8
+ baseUrl,
9
+ retry,
10
+ throttle,
11
+ });
12
+ }
13
+ }
14
+ exports.Automatic1111ApiConfiguration = Automatic1111ApiConfiguration;
@@ -0,0 +1,10 @@
1
+ import { BasicApiConfiguration } from "../../model-function/BasicApiConfiguration.js";
2
+ import { RetryFunction } from "../../util/api/RetryFunction.js";
3
+ import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
4
+ export declare class Automatic1111ApiConfiguration extends BasicApiConfiguration {
5
+ constructor({ baseUrl, retry, throttle, }?: {
6
+ baseUrl?: string;
7
+ retry?: RetryFunction;
8
+ throttle?: ThrottleFunction;
9
+ });
10
+ }
@@ -0,0 +1,10 @@
1
+ import { BasicApiConfiguration } from "../../model-function/BasicApiConfiguration.js";
2
+ export class Automatic1111ApiConfiguration extends BasicApiConfiguration {
3
+ constructor({ baseUrl = "http://127.0.0.1:7860/sdapi/v1", retry, throttle, } = {}) {
4
+ super({
5
+ baseUrl,
6
+ retry,
7
+ throttle,
8
+ });
9
+ }
10
+ }
@@ -5,6 +5,7 @@ const zod_1 = require("zod");
5
5
  const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
6
6
  const callWithRetryAndThrottle_js_1 = require("../../util/api/callWithRetryAndThrottle.cjs");
7
7
  const postToApi_js_1 = require("../../util/api/postToApi.cjs");
8
+ const Automatic1111ApiConfiguration_js_1 = require("./Automatic1111ApiConfiguration.cjs");
8
9
  const Automatic1111Error_js_1 = require("./Automatic1111Error.cjs");
9
10
  /**
10
11
  * Create an image generation model that calls the AUTOMATIC1111 Stable Diffusion Web UI API.
@@ -27,20 +28,21 @@ class Automatic1111ImageGenerationModel extends AbstractModel_js_1.AbstractModel
27
28
  async callAPI(input, options) {
28
29
  const run = options?.run;
29
30
  const settings = options?.settings;
30
- const callSettings = Object.assign(this.settings, settings, {
31
+ const callSettings = {
32
+ ...this.settings,
33
+ ...settings,
31
34
  abortSignal: run?.abortSignal,
32
35
  engineId: this.settings.model,
33
36
  prompt: input.prompt,
34
- });
37
+ };
35
38
  return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
36
- retry: this.settings.retry,
37
- throttle: this.settings.throttle,
39
+ retry: callSettings.api?.retry,
40
+ throttle: callSettings.api?.throttle,
38
41
  call: async () => callAutomatic1111ImageGenerationAPI(callSettings),
39
42
  });
40
43
  }
41
44
  get settingsForEvent() {
42
45
  return {
43
- baseUrl: this.settings.baseUrl,
44
46
  height: this.settings.height,
45
47
  width: this.settings.width,
46
48
  sampler: this.settings.sampler,
@@ -63,9 +65,10 @@ const Automatic1111ImageGenerationResponseSchema = zod_1.z.object({
63
65
  parameters: zod_1.z.object({}),
64
66
  info: zod_1.z.string(),
65
67
  });
66
- async function callAutomatic1111ImageGenerationAPI({ baseUrl = "http://127.0.0.1:7860", abortSignal, height, width, prompt, negativePrompt, sampler, steps, seed, model, }) {
68
+ async function callAutomatic1111ImageGenerationAPI({ api = new Automatic1111ApiConfiguration_js_1.Automatic1111ApiConfiguration(), abortSignal, height, width, prompt, negativePrompt, sampler, steps, seed, model, }) {
67
69
  return (0, postToApi_js_1.postJsonToApi)({
68
- url: `${baseUrl}/sdapi/v1/txt2img`,
70
+ url: api.assembleUrl(`/txt2img`),
71
+ headers: api.headers,
69
72
  body: {
70
73
  height,
71
74
  width,
@@ -1,9 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import { AbstractModel } from "../../model-function/AbstractModel.js";
3
+ import { ApiConfiguration } from "../../model-function/ApiConfiguration.js";
3
4
  import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
4
5
  import { ImageGenerationModel, ImageGenerationModelSettings } from "../../model-function/generate-image/ImageGenerationModel.js";
5
- import { RetryFunction } from "../../util/api/RetryFunction.js";
6
- import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
7
6
  /**
8
7
  * Create an image generation model that calls the AUTOMATIC1111 Stable Diffusion Web UI API.
9
8
  *
@@ -24,9 +23,7 @@ export declare class Automatic1111ImageGenerationModel extends AbstractModel<Aut
24
23
  withSettings(additionalSettings: Automatic1111ImageGenerationModelSettings): this;
25
24
  }
26
25
  export interface Automatic1111ImageGenerationModelSettings extends ImageGenerationModelSettings {
27
- baseUrl?: string;
28
- retry?: RetryFunction;
29
- throttle?: ThrottleFunction;
26
+ api?: ApiConfiguration;
30
27
  model: string;
31
28
  height?: number;
32
29
  width?: number;
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import { AbstractModel } from "../../model-function/AbstractModel.js";
3
3
  import { callWithRetryAndThrottle } from "../../util/api/callWithRetryAndThrottle.js";
4
4
  import { createJsonResponseHandler, postJsonToApi, } from "../../util/api/postToApi.js";
5
+ import { Automatic1111ApiConfiguration } from "./Automatic1111ApiConfiguration.js";
5
6
  import { failedAutomatic1111CallResponseHandler } from "./Automatic1111Error.js";
6
7
  /**
7
8
  * Create an image generation model that calls the AUTOMATIC1111 Stable Diffusion Web UI API.
@@ -24,20 +25,21 @@ export class Automatic1111ImageGenerationModel extends AbstractModel {
24
25
  async callAPI(input, options) {
25
26
  const run = options?.run;
26
27
  const settings = options?.settings;
27
- const callSettings = Object.assign(this.settings, settings, {
28
+ const callSettings = {
29
+ ...this.settings,
30
+ ...settings,
28
31
  abortSignal: run?.abortSignal,
29
32
  engineId: this.settings.model,
30
33
  prompt: input.prompt,
31
- });
34
+ };
32
35
  return callWithRetryAndThrottle({
33
- retry: this.settings.retry,
34
- throttle: this.settings.throttle,
36
+ retry: callSettings.api?.retry,
37
+ throttle: callSettings.api?.throttle,
35
38
  call: async () => callAutomatic1111ImageGenerationAPI(callSettings),
36
39
  });
37
40
  }
38
41
  get settingsForEvent() {
39
42
  return {
40
- baseUrl: this.settings.baseUrl,
41
43
  height: this.settings.height,
42
44
  width: this.settings.width,
43
45
  sampler: this.settings.sampler,
@@ -59,9 +61,10 @@ const Automatic1111ImageGenerationResponseSchema = z.object({
59
61
  parameters: z.object({}),
60
62
  info: z.string(),
61
63
  });
62
- async function callAutomatic1111ImageGenerationAPI({ baseUrl = "http://127.0.0.1:7860", abortSignal, height, width, prompt, negativePrompt, sampler, steps, seed, model, }) {
64
+ async function callAutomatic1111ImageGenerationAPI({ api = new Automatic1111ApiConfiguration(), abortSignal, height, width, prompt, negativePrompt, sampler, steps, seed, model, }) {
63
65
  return postJsonToApi({
64
- url: `${baseUrl}/sdapi/v1/txt2img`,
66
+ url: api.assembleUrl(`/txt2img`),
67
+ headers: api.headers,
65
68
  body: {
66
69
  height,
67
70
  width,
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.Automatic1111Error = void 0;
18
+ __exportStar(require("./Automatic1111ApiConfiguration.cjs"), exports);
18
19
  var Automatic1111Error_js_1 = require("./Automatic1111Error.cjs");
19
20
  Object.defineProperty(exports, "Automatic1111Error", { enumerable: true, get: function () { return Automatic1111Error_js_1.Automatic1111Error; } });
20
21
  __exportStar(require("./Automatic1111ImageGenerationModel.cjs"), exports);
@@ -1,2 +1,3 @@
1
+ export * from "./Automatic1111ApiConfiguration.js";
1
2
  export { Automatic1111Error, Automatic1111ErrorData, } from "./Automatic1111Error.js";
2
3
  export * from "./Automatic1111ImageGenerationModel.js";
@@ -1,2 +1,3 @@
1
+ export * from "./Automatic1111ApiConfiguration.js";
1
2
  export { Automatic1111Error, } from "./Automatic1111Error.js";
2
3
  export * from "./Automatic1111ImageGenerationModel.js";
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CohereApiConfiguration = void 0;
4
+ const BasicApiConfiguration_js_1 = require("../../model-function/BasicApiConfiguration.cjs");
5
+ const loadApiKey_js_1 = require("../../util/api/loadApiKey.cjs");
6
+ class CohereApiConfiguration extends BasicApiConfiguration_js_1.BasicApiConfiguration {
7
+ constructor({ baseUrl = "https://api.cohere.ai/v1", apiKey, retry, throttle, } = {}) {
8
+ super({
9
+ baseUrl,
10
+ retry,
11
+ throttle,
12
+ });
13
+ Object.defineProperty(this, "apiKey", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ this.apiKey = (0, loadApiKey_js_1.loadApiKey)({
20
+ apiKey,
21
+ environmentVariableName: "COHERE_API_KEY",
22
+ description: "Cohere",
23
+ });
24
+ }
25
+ get headers() {
26
+ return { Authorization: `Bearer ${this.apiKey}` };
27
+ }
28
+ }
29
+ exports.CohereApiConfiguration = CohereApiConfiguration;
@@ -0,0 +1,13 @@
1
+ import { BasicApiConfiguration } from "../../model-function/BasicApiConfiguration.js";
2
+ import { RetryFunction } from "../../util/api/RetryFunction.js";
3
+ import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
4
+ export declare class CohereApiConfiguration extends BasicApiConfiguration {
5
+ readonly apiKey: string;
6
+ constructor({ baseUrl, apiKey, retry, throttle, }?: {
7
+ baseUrl?: string;
8
+ apiKey?: string;
9
+ retry?: RetryFunction;
10
+ throttle?: ThrottleFunction;
11
+ });
12
+ get headers(): Record<string, string>;
13
+ }
@@ -0,0 +1,25 @@
1
+ import { BasicApiConfiguration } from "../../model-function/BasicApiConfiguration.js";
2
+ import { loadApiKey } from "../../util/api/loadApiKey.js";
3
+ export class CohereApiConfiguration extends BasicApiConfiguration {
4
+ constructor({ baseUrl = "https://api.cohere.ai/v1", apiKey, retry, throttle, } = {}) {
5
+ super({
6
+ baseUrl,
7
+ retry,
8
+ throttle,
9
+ });
10
+ Object.defineProperty(this, "apiKey", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: void 0
15
+ });
16
+ this.apiKey = loadApiKey({
17
+ apiKey,
18
+ environmentVariableName: "COHERE_API_KEY",
19
+ description: "Cohere",
20
+ });
21
+ }
22
+ get headers() {
23
+ return { Authorization: `Bearer ${this.apiKey}` };
24
+ }
25
+ }
@@ -8,6 +8,7 @@ const zod_1 = __importDefault(require("zod"));
8
8
  const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
9
9
  const callWithRetryAndThrottle_js_1 = require("../../util/api/callWithRetryAndThrottle.cjs");
10
10
  const postToApi_js_1 = require("../../util/api/postToApi.cjs");
11
+ const CohereApiConfiguration_js_1 = require("./CohereApiConfiguration.cjs");
11
12
  const CohereError_js_1 = require("./CohereError.cjs");
12
13
  const CohereTokenizer_js_1 = require("./CohereTokenizer.cjs");
13
14
  exports.COHERE_TEXT_EMBEDDING_MODELS = {
@@ -74,11 +75,8 @@ class CohereTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
74
75
  this.contextWindowSize =
75
76
  exports.COHERE_TEXT_EMBEDDING_MODELS[this.modelName].contextWindowSize;
76
77
  this.tokenizer = new CohereTokenizer_js_1.CohereTokenizer({
77
- baseUrl: this.settings.baseUrl,
78
- apiKey: this.settings.apiKey,
78
+ api: this.settings.api,
79
79
  model: this.settings.model,
80
- retry: this.settings.tokenizerSettings?.retry,
81
- throttle: this.settings.tokenizerSettings?.throttle,
82
80
  });
83
81
  this.embeddingDimensions =
84
82
  exports.COHERE_TEXT_EMBEDDING_MODELS[this.modelName].embeddingDimensions;
@@ -95,34 +93,26 @@ class CohereTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
95
93
  async detokenize(tokens) {
96
94
  return this.tokenizer.detokenize(tokens);
97
95
  }
98
- get apiKey() {
99
- const apiKey = this.settings.apiKey ?? process.env.COHERE_API_KEY;
100
- if (apiKey == null) {
101
- throw new Error("No Cohere API key provided. Pass an API key to the constructor or set the COHERE_API_KEY environment variable.");
102
- }
103
- return apiKey;
104
- }
105
96
  async callAPI(texts, options) {
106
97
  if (texts.length > this.maxTextsPerCall) {
107
98
  throw new Error(`The Cohere embedding API only supports ${this.maxTextsPerCall} texts per API call.`);
108
99
  }
109
100
  const run = options?.run;
110
101
  const settings = options?.settings;
111
- const callSettings = Object.assign({
112
- apiKey: this.apiKey,
113
- }, this.settings, settings, {
102
+ const callSettings = {
103
+ ...this.settings,
104
+ ...settings,
114
105
  abortSignal: run?.abortSignal,
115
106
  texts,
116
- });
107
+ };
117
108
  return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
118
- retry: this.settings.retry,
119
- throttle: this.settings.throttle,
109
+ retry: callSettings.api?.retry,
110
+ throttle: callSettings.api?.throttle,
120
111
  call: async () => callCohereEmbeddingAPI(callSettings),
121
112
  });
122
113
  }
123
114
  get settingsForEvent() {
124
115
  return {
125
- baseUrl: this.settings.baseUrl,
126
116
  truncate: this.settings.truncate,
127
117
  };
128
118
  }
@@ -147,27 +137,10 @@ const cohereTextEmbeddingResponseSchema = zod_1.default.object({
147
137
  }),
148
138
  }),
149
139
  });
150
- /**
151
- * Call the Cohere Co.Embed API to generate an embedding for the given input.
152
- *
153
- * @see https://docs.cohere.com/reference/embed
154
- *
155
- * @example
156
- * const response = await callCohereEmbeddingAPI({
157
- * apiKey: COHERE_API_KEY,
158
- * model: "embed-english-light-v2.0",
159
- * texts: [
160
- * "At first, Nox didn't know what to do with the pup.",
161
- * "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
162
- * ],
163
- * });
164
- */
165
- async function callCohereEmbeddingAPI({ baseUrl = "https://api.cohere.ai/v1", abortSignal, apiKey, model, texts, truncate, }) {
140
+ async function callCohereEmbeddingAPI({ api = new CohereApiConfiguration_js_1.CohereApiConfiguration(), abortSignal, model, texts, truncate, }) {
166
141
  return (0, postToApi_js_1.postJsonToApi)({
167
- url: `${baseUrl}/embed`,
168
- headers: {
169
- Authorization: `Bearer ${apiKey}`,
170
- },
142
+ url: api.assembleUrl(`/embed`),
143
+ headers: api.headers,
171
144
  body: {
172
145
  model,
173
146
  texts,
@@ -1,10 +1,9 @@
1
1
  import z from "zod";
2
2
  import { AbstractModel } from "../../model-function/AbstractModel.js";
3
+ import { ApiConfiguration } from "../../model-function/ApiConfiguration.js";
3
4
  import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
4
5
  import { TextEmbeddingModel, TextEmbeddingModelSettings } from "../../model-function/embed-text/TextEmbeddingModel.js";
5
6
  import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
6
- import { RetryFunction } from "../../util/api/RetryFunction.js";
7
- import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
8
7
  export declare const COHERE_TEXT_EMBEDDING_MODELS: {
9
8
  "embed-english-light-v2.0": {
10
9
  contextWindowSize: number;
@@ -21,15 +20,8 @@ export declare const COHERE_TEXT_EMBEDDING_MODELS: {
21
20
  };
22
21
  export type CohereTextEmbeddingModelType = keyof typeof COHERE_TEXT_EMBEDDING_MODELS;
23
22
  export interface CohereTextEmbeddingModelSettings extends TextEmbeddingModelSettings {
23
+ api?: ApiConfiguration;
24
24
  model: CohereTextEmbeddingModelType;
25
- baseUrl?: string;
26
- apiKey?: string;
27
- retry?: RetryFunction;
28
- throttle?: ThrottleFunction;
29
- tokenizerSettings?: {
30
- retry?: RetryFunction;
31
- throttle?: ThrottleFunction;
32
- };
33
25
  truncate?: "NONE" | "START" | "END";
34
26
  }
35
27
  /**
@@ -60,7 +52,6 @@ export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEm
60
52
  tokenTexts: string[];
61
53
  }>;
62
54
  detokenize(tokens: number[]): Promise<string>;
63
- private get apiKey();
64
55
  callAPI(texts: Array<string>, options?: ModelFunctionOptions<CohereTextEmbeddingModelSettings>): Promise<CohereTextEmbeddingResponse>;
65
56
  get settingsForEvent(): Partial<CohereTextEmbeddingModelSettings>;
66
57
  generateEmbeddingResponse(texts: string[], options?: ModelFunctionOptions<CohereTextEmbeddingModelSettings>): Promise<{
@@ -2,6 +2,7 @@ import z from "zod";
2
2
  import { AbstractModel } from "../../model-function/AbstractModel.js";
3
3
  import { callWithRetryAndThrottle } from "../../util/api/callWithRetryAndThrottle.js";
4
4
  import { createJsonResponseHandler, postJsonToApi, } from "../../util/api/postToApi.js";
5
+ import { CohereApiConfiguration } from "./CohereApiConfiguration.js";
5
6
  import { failedCohereCallResponseHandler } from "./CohereError.js";
6
7
  import { CohereTokenizer } from "./CohereTokenizer.js";
7
8
  export const COHERE_TEXT_EMBEDDING_MODELS = {
@@ -68,11 +69,8 @@ export class CohereTextEmbeddingModel extends AbstractModel {
68
69
  this.contextWindowSize =
69
70
  COHERE_TEXT_EMBEDDING_MODELS[this.modelName].contextWindowSize;
70
71
  this.tokenizer = new CohereTokenizer({
71
- baseUrl: this.settings.baseUrl,
72
- apiKey: this.settings.apiKey,
72
+ api: this.settings.api,
73
73
  model: this.settings.model,
74
- retry: this.settings.tokenizerSettings?.retry,
75
- throttle: this.settings.tokenizerSettings?.throttle,
76
74
  });
77
75
  this.embeddingDimensions =
78
76
  COHERE_TEXT_EMBEDDING_MODELS[this.modelName].embeddingDimensions;
@@ -89,34 +87,26 @@ export class CohereTextEmbeddingModel extends AbstractModel {
89
87
  async detokenize(tokens) {
90
88
  return this.tokenizer.detokenize(tokens);
91
89
  }
92
- get apiKey() {
93
- const apiKey = this.settings.apiKey ?? process.env.COHERE_API_KEY;
94
- if (apiKey == null) {
95
- throw new Error("No Cohere API key provided. Pass an API key to the constructor or set the COHERE_API_KEY environment variable.");
96
- }
97
- return apiKey;
98
- }
99
90
  async callAPI(texts, options) {
100
91
  if (texts.length > this.maxTextsPerCall) {
101
92
  throw new Error(`The Cohere embedding API only supports ${this.maxTextsPerCall} texts per API call.`);
102
93
  }
103
94
  const run = options?.run;
104
95
  const settings = options?.settings;
105
- const callSettings = Object.assign({
106
- apiKey: this.apiKey,
107
- }, this.settings, settings, {
96
+ const callSettings = {
97
+ ...this.settings,
98
+ ...settings,
108
99
  abortSignal: run?.abortSignal,
109
100
  texts,
110
- });
101
+ };
111
102
  return callWithRetryAndThrottle({
112
- retry: this.settings.retry,
113
- throttle: this.settings.throttle,
103
+ retry: callSettings.api?.retry,
104
+ throttle: callSettings.api?.throttle,
114
105
  call: async () => callCohereEmbeddingAPI(callSettings),
115
106
  });
116
107
  }
117
108
  get settingsForEvent() {
118
109
  return {
119
- baseUrl: this.settings.baseUrl,
120
110
  truncate: this.settings.truncate,
121
111
  };
122
112
  }
@@ -140,27 +130,10 @@ const cohereTextEmbeddingResponseSchema = z.object({
140
130
  }),
141
131
  }),
142
132
  });
143
- /**
144
- * Call the Cohere Co.Embed API to generate an embedding for the given input.
145
- *
146
- * @see https://docs.cohere.com/reference/embed
147
- *
148
- * @example
149
- * const response = await callCohereEmbeddingAPI({
150
- * apiKey: COHERE_API_KEY,
151
- * model: "embed-english-light-v2.0",
152
- * texts: [
153
- * "At first, Nox didn't know what to do with the pup.",
154
- * "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
155
- * ],
156
- * });
157
- */
158
- async function callCohereEmbeddingAPI({ baseUrl = "https://api.cohere.ai/v1", abortSignal, apiKey, model, texts, truncate, }) {
133
+ async function callCohereEmbeddingAPI({ api = new CohereApiConfiguration(), abortSignal, model, texts, truncate, }) {
159
134
  return postJsonToApi({
160
- url: `${baseUrl}/embed`,
161
- headers: {
162
- Authorization: `Bearer ${apiKey}`,
163
- },
135
+ url: api.assembleUrl(`/embed`),
136
+ headers: api.headers,
164
137
  body: {
165
138
  model,
166
139
  texts,