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.
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/model-function/ApiConfiguration.d.ts +14 -0
- package/model-function/BasicApiConfiguration.cjs +35 -0
- package/model-function/BasicApiConfiguration.d.ts +15 -0
- package/model-function/BasicApiConfiguration.js +31 -0
- package/model-function/index.cjs +2 -0
- package/model-function/index.d.ts +2 -0
- package/model-function/index.js +2 -0
- package/model-provider/automatic1111/Automatic1111ApiConfiguration.cjs +14 -0
- package/model-provider/automatic1111/Automatic1111ApiConfiguration.d.ts +10 -0
- package/model-provider/automatic1111/Automatic1111ApiConfiguration.js +10 -0
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +10 -7
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +2 -5
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +10 -7
- package/model-provider/automatic1111/index.cjs +1 -0
- package/model-provider/automatic1111/index.d.ts +1 -0
- package/model-provider/automatic1111/index.js +1 -0
- package/model-provider/cohere/CohereApiConfiguration.cjs +29 -0
- package/model-provider/cohere/CohereApiConfiguration.d.ts +13 -0
- package/model-provider/cohere/CohereApiConfiguration.js +25 -0
- package/model-provider/cohere/CohereTextEmbeddingModel.cjs +11 -38
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +2 -11
- package/model-provider/cohere/CohereTextEmbeddingModel.js +11 -38
- package/model-provider/cohere/CohereTextGenerationModel.cjs +7 -36
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +2 -11
- package/model-provider/cohere/CohereTextGenerationModel.js +7 -36
- package/model-provider/cohere/CohereTokenizer.cjs +11 -33
- package/model-provider/cohere/CohereTokenizer.d.ts +4 -9
- package/model-provider/cohere/CohereTokenizer.js +11 -33
- package/model-provider/cohere/index.cjs +1 -0
- package/model-provider/cohere/index.d.ts +1 -0
- package/model-provider/cohere/index.js +1 -0
- package/model-provider/elevenlabs/ElevenLabsApiConfiguration.cjs +29 -0
- package/model-provider/elevenlabs/ElevenLabsApiConfiguration.d.ts +13 -0
- package/model-provider/elevenlabs/ElevenLabsApiConfiguration.js +25 -0
- package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.cjs +22 -32
- package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.d.ts +8 -8
- package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.js +22 -32
- package/model-provider/elevenlabs/index.cjs +1 -0
- package/model-provider/elevenlabs/index.d.ts +1 -0
- package/model-provider/elevenlabs/index.js +1 -0
- package/model-provider/huggingface/HuggingFaceApiConfiguration.cjs +29 -0
- package/model-provider/huggingface/HuggingFaceApiConfiguration.d.ts +13 -0
- package/model-provider/huggingface/HuggingFaceApiConfiguration.js +25 -0
- package/model-provider/huggingface/HuggingFaceError.cjs +3 -2
- package/model-provider/huggingface/HuggingFaceError.d.ts +3 -3
- package/model-provider/huggingface/HuggingFaceError.js +3 -2
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +15 -21
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +3 -8
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +15 -21
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +7 -36
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +2 -7
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +7 -36
- package/model-provider/huggingface/index.cjs +1 -0
- package/model-provider/huggingface/index.d.ts +1 -0
- package/model-provider/huggingface/index.js +1 -0
- package/model-provider/llamacpp/LlamaCppApiConfiguration.cjs +14 -0
- package/model-provider/llamacpp/LlamaCppApiConfiguration.d.ts +10 -0
- package/model-provider/llamacpp/LlamaCppApiConfiguration.js +10 -0
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +11 -12
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +2 -9
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +11 -12
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +9 -10
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +2 -9
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +9 -10
- package/model-provider/llamacpp/LlamaCppTokenizer.cjs +10 -8
- package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +4 -10
- package/model-provider/llamacpp/LlamaCppTokenizer.js +10 -8
- package/model-provider/llamacpp/index.cjs +1 -0
- package/model-provider/llamacpp/index.d.ts +1 -0
- package/model-provider/llamacpp/index.js +1 -0
- package/model-provider/lmnt/LmntApiConfiguration.cjs +29 -0
- package/model-provider/lmnt/LmntApiConfiguration.d.ts +13 -0
- package/model-provider/lmnt/LmntApiConfiguration.js +25 -0
- package/model-provider/lmnt/LmntSpeechSynthesisModel.cjs +18 -34
- package/model-provider/lmnt/LmntSpeechSynthesisModel.d.ts +8 -8
- package/model-provider/lmnt/LmntSpeechSynthesisModel.js +18 -34
- package/model-provider/lmnt/index.cjs +1 -0
- package/model-provider/lmnt/index.d.ts +1 -0
- package/model-provider/lmnt/index.js +1 -0
- package/model-provider/openai/AzureOpenAIApiConfiguration.cjs +51 -0
- package/model-provider/openai/AzureOpenAIApiConfiguration.d.ts +26 -0
- package/model-provider/openai/AzureOpenAIApiConfiguration.js +47 -0
- package/model-provider/openai/OpenAIApiConfiguration.cjs +31 -0
- package/model-provider/openai/OpenAIApiConfiguration.d.ts +13 -0
- package/model-provider/openai/OpenAIApiConfiguration.js +27 -0
- package/model-provider/openai/OpenAIImageGenerationModel.cjs +16 -20
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +4 -4
- package/model-provider/openai/OpenAIImageGenerationModel.js +16 -20
- package/model-provider/openai/OpenAITextEmbeddingModel.cjs +16 -35
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +2 -7
- package/model-provider/openai/OpenAITextEmbeddingModel.js +16 -35
- package/model-provider/openai/OpenAITextGenerationModel.cjs +6 -33
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +4 -5
- package/model-provider/openai/OpenAITextGenerationModel.js +6 -33
- package/model-provider/openai/OpenAITranscriptionModel.cjs +16 -39
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +4 -11
- package/model-provider/openai/OpenAITranscriptionModel.js +16 -39
- package/model-provider/openai/chat/OpenAIChatModel.cjs +9 -17
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +4 -5
- package/model-provider/openai/chat/OpenAIChatModel.js +9 -17
- package/model-provider/openai/index.cjs +2 -1
- package/model-provider/openai/index.d.ts +2 -1
- package/model-provider/openai/index.js +2 -1
- package/model-provider/stability/StabilityApiConfiguration.cjs +31 -0
- package/model-provider/stability/StabilityApiConfiguration.d.ts +13 -0
- package/model-provider/stability/StabilityApiConfiguration.js +27 -0
- package/model-provider/stability/StabilityImageGenerationModel.cjs +12 -46
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +2 -7
- package/model-provider/stability/StabilityImageGenerationModel.js +12 -46
- package/model-provider/stability/index.cjs +1 -0
- package/model-provider/stability/index.d.ts +1 -0
- package/model-provider/stability/index.js +1 -0
- package/observability/helicone/HeliconeOpenAIApiConfiguration.cjs +45 -0
- package/observability/helicone/HeliconeOpenAIApiConfiguration.d.ts +15 -0
- package/observability/helicone/HeliconeOpenAIApiConfiguration.js +41 -0
- package/observability/index.cjs +17 -0
- package/observability/index.d.ts +1 -0
- package/observability/index.js +1 -0
- package/package.json +1 -1
- package/util/api/loadApiKey.cjs +11 -0
- package/util/api/loadApiKey.d.ts +6 -0
- package/util/api/loadApiKey.js +7 -0
- package/model-provider/openai/OpenAIModelSettings.d.ts +0 -8
- /package/{model-provider/openai/OpenAIModelSettings.cjs → model-function/ApiConfiguration.cjs} +0 -0
- /package/{model-provider/openai/OpenAIModelSettings.js → model-function/ApiConfiguration.js} +0 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LlamaCppApiConfiguration = void 0;
|
4
|
+
const BasicApiConfiguration_js_1 = require("../../model-function/BasicApiConfiguration.cjs");
|
5
|
+
class LlamaCppApiConfiguration extends BasicApiConfiguration_js_1.BasicApiConfiguration {
|
6
|
+
constructor({ baseUrl = "http://127.0.0.1:8080", retry, throttle, } = {}) {
|
7
|
+
super({
|
8
|
+
baseUrl,
|
9
|
+
retry,
|
10
|
+
throttle,
|
11
|
+
});
|
12
|
+
}
|
13
|
+
}
|
14
|
+
exports.LlamaCppApiConfiguration = LlamaCppApiConfiguration;
|
@@ -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 LlamaCppApiConfiguration 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 LlamaCppApiConfiguration extends BasicApiConfiguration {
|
3
|
+
constructor({ baseUrl = "http://127.0.0.1:8080", retry, throttle, } = {}) {
|
4
|
+
super({
|
5
|
+
baseUrl,
|
6
|
+
retry,
|
7
|
+
throttle,
|
8
|
+
});
|
9
|
+
}
|
10
|
+
}
|
@@ -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 LlamaCppApiConfiguration_js_1 = require("./LlamaCppApiConfiguration.cjs");
|
11
12
|
const LlamaCppError_js_1 = require("./LlamaCppError.cjs");
|
12
13
|
const LlamaCppTokenizer_js_1 = require("./LlamaCppTokenizer.cjs");
|
13
14
|
class LlamaCppTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
|
@@ -43,11 +44,7 @@ class LlamaCppTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
|
|
43
44
|
writable: true,
|
44
45
|
value: void 0
|
45
46
|
});
|
46
|
-
this.tokenizer = new LlamaCppTokenizer_js_1.LlamaCppTokenizer(
|
47
|
-
baseUrl: this.settings.baseUrl,
|
48
|
-
retry: this.settings.tokenizerSettings?.retry,
|
49
|
-
throttle: this.settings.tokenizerSettings?.throttle,
|
50
|
-
});
|
47
|
+
this.tokenizer = new LlamaCppTokenizer_js_1.LlamaCppTokenizer(this.settings.api);
|
51
48
|
this.embeddingDimensions = this.settings.embeddingDimensions;
|
52
49
|
}
|
53
50
|
get modelName() {
|
@@ -62,19 +59,20 @@ class LlamaCppTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
|
|
62
59
|
}
|
63
60
|
const run = options?.run;
|
64
61
|
const settings = options?.settings;
|
65
|
-
const callSettings =
|
62
|
+
const callSettings = {
|
63
|
+
...this.settings,
|
64
|
+
...settings,
|
66
65
|
abortSignal: run?.abortSignal,
|
67
66
|
content: texts[0],
|
68
|
-
}
|
67
|
+
};
|
69
68
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
70
|
-
retry:
|
71
|
-
throttle:
|
69
|
+
retry: callSettings.api?.retry,
|
70
|
+
throttle: callSettings.api?.throttle,
|
72
71
|
call: async () => callLlamaCppEmbeddingAPI(callSettings),
|
73
72
|
});
|
74
73
|
}
|
75
74
|
get settingsForEvent() {
|
76
75
|
return {
|
77
|
-
baseUrl: this.settings.baseUrl,
|
78
76
|
embeddingDimensions: this.settings.embeddingDimensions,
|
79
77
|
};
|
80
78
|
}
|
@@ -92,9 +90,10 @@ exports.LlamaCppTextEmbeddingModel = LlamaCppTextEmbeddingModel;
|
|
92
90
|
const llamaCppTextEmbeddingResponseSchema = zod_1.default.object({
|
93
91
|
embedding: zod_1.default.array(zod_1.default.number()),
|
94
92
|
});
|
95
|
-
async function callLlamaCppEmbeddingAPI({
|
93
|
+
async function callLlamaCppEmbeddingAPI({ api = new LlamaCppApiConfiguration_js_1.LlamaCppApiConfiguration(), abortSignal, content, }) {
|
96
94
|
return (0, postToApi_js_1.postJsonToApi)({
|
97
|
-
url:
|
95
|
+
url: api.assembleUrl(`/embedding`),
|
96
|
+
headers: api.headers,
|
98
97
|
body: { content },
|
99
98
|
failedResponseHandler: LlamaCppError_js_1.failedLlamaCppCallResponseHandler,
|
100
99
|
successfulResponseHandler: (0, postToApi_js_1.createJsonResponseHandler)(llamaCppTextEmbeddingResponseSchema),
|
@@ -1,18 +1,11 @@
|
|
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
|
-
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
6
|
-
import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
7
6
|
export interface LlamaCppTextEmbeddingModelSettings extends TextEmbeddingModelSettings {
|
8
|
-
|
7
|
+
api?: ApiConfiguration;
|
9
8
|
embeddingDimensions?: number;
|
10
|
-
retry?: RetryFunction;
|
11
|
-
throttle?: ThrottleFunction;
|
12
|
-
tokenizerSettings?: {
|
13
|
-
retry?: RetryFunction;
|
14
|
-
throttle?: ThrottleFunction;
|
15
|
-
};
|
16
9
|
}
|
17
10
|
export declare class LlamaCppTextEmbeddingModel extends AbstractModel<LlamaCppTextEmbeddingModelSettings> implements TextEmbeddingModel<LlamaCppTextEmbeddingResponse, LlamaCppTextEmbeddingModelSettings> {
|
18
11
|
constructor(settings?: LlamaCppTextEmbeddingModelSettings);
|
@@ -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 { LlamaCppApiConfiguration } from "./LlamaCppApiConfiguration.js";
|
5
6
|
import { failedLlamaCppCallResponseHandler } from "./LlamaCppError.js";
|
6
7
|
import { LlamaCppTokenizer } from "./LlamaCppTokenizer.js";
|
7
8
|
export class LlamaCppTextEmbeddingModel extends AbstractModel {
|
@@ -37,11 +38,7 @@ export class LlamaCppTextEmbeddingModel extends AbstractModel {
|
|
37
38
|
writable: true,
|
38
39
|
value: void 0
|
39
40
|
});
|
40
|
-
this.tokenizer = new LlamaCppTokenizer(
|
41
|
-
baseUrl: this.settings.baseUrl,
|
42
|
-
retry: this.settings.tokenizerSettings?.retry,
|
43
|
-
throttle: this.settings.tokenizerSettings?.throttle,
|
44
|
-
});
|
41
|
+
this.tokenizer = new LlamaCppTokenizer(this.settings.api);
|
45
42
|
this.embeddingDimensions = this.settings.embeddingDimensions;
|
46
43
|
}
|
47
44
|
get modelName() {
|
@@ -56,19 +53,20 @@ export class LlamaCppTextEmbeddingModel extends AbstractModel {
|
|
56
53
|
}
|
57
54
|
const run = options?.run;
|
58
55
|
const settings = options?.settings;
|
59
|
-
const callSettings =
|
56
|
+
const callSettings = {
|
57
|
+
...this.settings,
|
58
|
+
...settings,
|
60
59
|
abortSignal: run?.abortSignal,
|
61
60
|
content: texts[0],
|
62
|
-
}
|
61
|
+
};
|
63
62
|
return callWithRetryAndThrottle({
|
64
|
-
retry:
|
65
|
-
throttle:
|
63
|
+
retry: callSettings.api?.retry,
|
64
|
+
throttle: callSettings.api?.throttle,
|
66
65
|
call: async () => callLlamaCppEmbeddingAPI(callSettings),
|
67
66
|
});
|
68
67
|
}
|
69
68
|
get settingsForEvent() {
|
70
69
|
return {
|
71
|
-
baseUrl: this.settings.baseUrl,
|
72
70
|
embeddingDimensions: this.settings.embeddingDimensions,
|
73
71
|
};
|
74
72
|
}
|
@@ -85,9 +83,10 @@ export class LlamaCppTextEmbeddingModel extends AbstractModel {
|
|
85
83
|
const llamaCppTextEmbeddingResponseSchema = z.object({
|
86
84
|
embedding: z.array(z.number()),
|
87
85
|
});
|
88
|
-
async function callLlamaCppEmbeddingAPI({
|
86
|
+
async function callLlamaCppEmbeddingAPI({ api = new LlamaCppApiConfiguration(), abortSignal, content, }) {
|
89
87
|
return postJsonToApi({
|
90
|
-
url:
|
88
|
+
url: api.assembleUrl(`/embedding`),
|
89
|
+
headers: api.headers,
|
91
90
|
body: { content },
|
92
91
|
failedResponseHandler: failedLlamaCppCallResponseHandler,
|
93
92
|
successfulResponseHandler: createJsonResponseHandler(llamaCppTextEmbeddingResponseSchema),
|
@@ -12,6 +12,7 @@ const parseEventSourceReadableStream_js_1 = require("../../model-function/genera
|
|
12
12
|
const PromptFormatTextGenerationModel_js_1 = require("../../prompt/PromptFormatTextGenerationModel.cjs");
|
13
13
|
const callWithRetryAndThrottle_js_1 = require("../../util/api/callWithRetryAndThrottle.cjs");
|
14
14
|
const postToApi_js_1 = require("../../util/api/postToApi.cjs");
|
15
|
+
const LlamaCppApiConfiguration_js_1 = require("./LlamaCppApiConfiguration.cjs");
|
15
16
|
const LlamaCppError_js_1 = require("./LlamaCppError.cjs");
|
16
17
|
const LlamaCppTokenizer_js_1 = require("./LlamaCppTokenizer.cjs");
|
17
18
|
class LlamaCppTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
@@ -29,11 +30,7 @@ class LlamaCppTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
29
30
|
writable: true,
|
30
31
|
value: void 0
|
31
32
|
});
|
32
|
-
this.tokenizer = new LlamaCppTokenizer_js_1.LlamaCppTokenizer(
|
33
|
-
baseUrl: this.settings.baseUrl,
|
34
|
-
retry: this.settings.tokenizerSettings?.retry,
|
35
|
-
throttle: this.settings.tokenizerSettings?.throttle,
|
36
|
-
});
|
33
|
+
this.tokenizer = new LlamaCppTokenizer_js_1.LlamaCppTokenizer(this.settings.api);
|
37
34
|
}
|
38
35
|
get modelName() {
|
39
36
|
return null;
|
@@ -49,15 +46,17 @@ class LlamaCppTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
49
46
|
};
|
50
47
|
const callSettings = {
|
51
48
|
...combinedSettings,
|
49
|
+
// mapping
|
52
50
|
nPredict: combinedSettings.maxCompletionTokens,
|
53
51
|
stop: combinedSettings.stopSequences,
|
52
|
+
// other
|
54
53
|
abortSignal: run?.abortSignal,
|
55
54
|
prompt,
|
56
55
|
responseFormat,
|
57
56
|
};
|
58
57
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
59
|
-
retry:
|
60
|
-
throttle:
|
58
|
+
retry: callSettings.api?.retry,
|
59
|
+
throttle: callSettings.api?.throttle,
|
61
60
|
call: async () => callLlamaCppTextGenerationAPI(callSettings),
|
62
61
|
});
|
63
62
|
}
|
@@ -65,7 +64,6 @@ class LlamaCppTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
65
64
|
const eventSettingProperties = [
|
66
65
|
"maxCompletionTokens",
|
67
66
|
"stopSequences",
|
68
|
-
"baseUrl",
|
69
67
|
"contextWindowSize",
|
70
68
|
"temperature",
|
71
69
|
"topK",
|
@@ -183,9 +181,10 @@ const llamaCppTextStreamingResponseSchema = zod_1.default.discriminatedUnion("st
|
|
183
181
|
}),
|
184
182
|
llamaCppTextGenerationResponseSchema,
|
185
183
|
]);
|
186
|
-
async function callLlamaCppTextGenerationAPI({
|
184
|
+
async function callLlamaCppTextGenerationAPI({ api = new LlamaCppApiConfiguration_js_1.LlamaCppApiConfiguration(), abortSignal, responseFormat, prompt, temperature, topK, topP, nPredict, nKeep, stop, tfsZ, typicalP, repeatPenalty, repeatLastN, penalizeNl, mirostat, mirostatTau, mirostatEta, seed, ignoreEos, logitBias, }) {
|
187
185
|
return (0, postToApi_js_1.postJsonToApi)({
|
188
|
-
url:
|
186
|
+
url: api.assembleUrl(`/completion`),
|
187
|
+
headers: api.headers,
|
189
188
|
body: {
|
190
189
|
stream: responseFormat.stream,
|
191
190
|
prompt,
|
@@ -1,22 +1,15 @@
|
|
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 { DeltaEvent } from "../../model-function/generate-text/DeltaEvent.js";
|
5
6
|
import { TextGenerationModel, TextGenerationModelSettings } from "../../model-function/generate-text/TextGenerationModel.js";
|
6
7
|
import { PromptFormat } from "../../prompt/PromptFormat.js";
|
7
8
|
import { PromptFormatTextGenerationModel } from "../../prompt/PromptFormatTextGenerationModel.js";
|
8
|
-
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
9
|
-
import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
10
9
|
import { ResponseHandler } from "../../util/api/postToApi.js";
|
11
10
|
import { LlamaCppTokenizer } from "./LlamaCppTokenizer.js";
|
12
11
|
export interface LlamaCppTextGenerationModelSettings<CONTEXT_WINDOW_SIZE extends number | undefined> extends TextGenerationModelSettings {
|
13
|
-
|
14
|
-
retry?: RetryFunction;
|
15
|
-
throttle?: ThrottleFunction;
|
16
|
-
tokenizerSettings?: {
|
17
|
-
retry?: RetryFunction;
|
18
|
-
throttle?: ThrottleFunction;
|
19
|
-
};
|
12
|
+
api?: ApiConfiguration;
|
20
13
|
/**
|
21
14
|
* Specify the context window size of the model that you have loaded in your
|
22
15
|
* Llama.cpp server.
|
@@ -6,6 +6,7 @@ import { parseEventSourceReadableStream } from "../../model-function/generate-te
|
|
6
6
|
import { PromptFormatTextGenerationModel } from "../../prompt/PromptFormatTextGenerationModel.js";
|
7
7
|
import { callWithRetryAndThrottle } from "../../util/api/callWithRetryAndThrottle.js";
|
8
8
|
import { createJsonResponseHandler, postJsonToApi, } from "../../util/api/postToApi.js";
|
9
|
+
import { LlamaCppApiConfiguration } from "./LlamaCppApiConfiguration.js";
|
9
10
|
import { failedLlamaCppCallResponseHandler } from "./LlamaCppError.js";
|
10
11
|
import { LlamaCppTokenizer } from "./LlamaCppTokenizer.js";
|
11
12
|
export class LlamaCppTextGenerationModel extends AbstractModel {
|
@@ -23,11 +24,7 @@ export class LlamaCppTextGenerationModel extends AbstractModel {
|
|
23
24
|
writable: true,
|
24
25
|
value: void 0
|
25
26
|
});
|
26
|
-
this.tokenizer = new LlamaCppTokenizer(
|
27
|
-
baseUrl: this.settings.baseUrl,
|
28
|
-
retry: this.settings.tokenizerSettings?.retry,
|
29
|
-
throttle: this.settings.tokenizerSettings?.throttle,
|
30
|
-
});
|
27
|
+
this.tokenizer = new LlamaCppTokenizer(this.settings.api);
|
31
28
|
}
|
32
29
|
get modelName() {
|
33
30
|
return null;
|
@@ -43,15 +40,17 @@ export class LlamaCppTextGenerationModel extends AbstractModel {
|
|
43
40
|
};
|
44
41
|
const callSettings = {
|
45
42
|
...combinedSettings,
|
43
|
+
// mapping
|
46
44
|
nPredict: combinedSettings.maxCompletionTokens,
|
47
45
|
stop: combinedSettings.stopSequences,
|
46
|
+
// other
|
48
47
|
abortSignal: run?.abortSignal,
|
49
48
|
prompt,
|
50
49
|
responseFormat,
|
51
50
|
};
|
52
51
|
return callWithRetryAndThrottle({
|
53
|
-
retry:
|
54
|
-
throttle:
|
52
|
+
retry: callSettings.api?.retry,
|
53
|
+
throttle: callSettings.api?.throttle,
|
55
54
|
call: async () => callLlamaCppTextGenerationAPI(callSettings),
|
56
55
|
});
|
57
56
|
}
|
@@ -59,7 +58,6 @@ export class LlamaCppTextGenerationModel extends AbstractModel {
|
|
59
58
|
const eventSettingProperties = [
|
60
59
|
"maxCompletionTokens",
|
61
60
|
"stopSequences",
|
62
|
-
"baseUrl",
|
63
61
|
"contextWindowSize",
|
64
62
|
"temperature",
|
65
63
|
"topK",
|
@@ -176,9 +174,10 @@ const llamaCppTextStreamingResponseSchema = z.discriminatedUnion("stop", [
|
|
176
174
|
}),
|
177
175
|
llamaCppTextGenerationResponseSchema,
|
178
176
|
]);
|
179
|
-
async function callLlamaCppTextGenerationAPI({
|
177
|
+
async function callLlamaCppTextGenerationAPI({ api = new LlamaCppApiConfiguration(), abortSignal, responseFormat, prompt, temperature, topK, topP, nPredict, nKeep, stop, tfsZ, typicalP, repeatPenalty, repeatLastN, penalizeNl, mirostat, mirostatTau, mirostatEta, seed, ignoreEos, logitBias, }) {
|
180
178
|
return postJsonToApi({
|
181
|
-
url:
|
179
|
+
url: api.assembleUrl(`/completion`),
|
180
|
+
headers: api.headers,
|
182
181
|
body: {
|
183
182
|
stream: responseFormat.stream,
|
184
183
|
prompt,
|
@@ -7,6 +7,7 @@ exports.LlamaCppTokenizer = void 0;
|
|
7
7
|
const zod_1 = __importDefault(require("zod"));
|
8
8
|
const callWithRetryAndThrottle_js_1 = require("../../util/api/callWithRetryAndThrottle.cjs");
|
9
9
|
const postToApi_js_1 = require("../../util/api/postToApi.cjs");
|
10
|
+
const LlamaCppApiConfiguration_js_1 = require("./LlamaCppApiConfiguration.cjs");
|
10
11
|
const LlamaCppError_js_1 = require("./LlamaCppError.cjs");
|
11
12
|
/**
|
12
13
|
* Tokenizer for LlamaCpp.
|
@@ -22,23 +23,23 @@ const LlamaCppError_js_1 = require("./LlamaCppError.cjs");
|
|
22
23
|
* const reconstructedText = await tokenizer.detokenize(tokens);
|
23
24
|
*/
|
24
25
|
class LlamaCppTokenizer {
|
25
|
-
constructor(
|
26
|
-
Object.defineProperty(this, "
|
26
|
+
constructor(api = new LlamaCppApiConfiguration_js_1.LlamaCppApiConfiguration()) {
|
27
|
+
Object.defineProperty(this, "api", {
|
27
28
|
enumerable: true,
|
28
29
|
configurable: true,
|
29
30
|
writable: true,
|
30
31
|
value: void 0
|
31
32
|
});
|
32
|
-
this.
|
33
|
+
this.api = api;
|
33
34
|
}
|
34
35
|
async callTokenizeAPI(text, context) {
|
35
36
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
36
|
-
retry: this.
|
37
|
-
throttle: this.
|
37
|
+
retry: this.api.retry,
|
38
|
+
throttle: this.api.throttle,
|
38
39
|
call: async () => callLlamaCppTokenizeAPI({
|
40
|
+
api: this.api,
|
39
41
|
abortSignal: context?.abortSignal,
|
40
42
|
text,
|
41
|
-
...this.settings,
|
42
43
|
}),
|
43
44
|
});
|
44
45
|
}
|
@@ -51,9 +52,10 @@ exports.LlamaCppTokenizer = LlamaCppTokenizer;
|
|
51
52
|
const llamaCppTokenizationResponseSchema = zod_1.default.object({
|
52
53
|
tokens: zod_1.default.array(zod_1.default.number()),
|
53
54
|
});
|
54
|
-
async function callLlamaCppTokenizeAPI({
|
55
|
+
async function callLlamaCppTokenizeAPI({ api, abortSignal, text, }) {
|
55
56
|
return (0, postToApi_js_1.postJsonToApi)({
|
56
|
-
url:
|
57
|
+
url: api.assembleUrl(`/tokenize`),
|
58
|
+
headers: api.headers,
|
57
59
|
body: {
|
58
60
|
content: text,
|
59
61
|
},
|
@@ -1,13 +1,7 @@
|
|
1
1
|
import z from "zod";
|
2
|
-
import { BasicTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
|
3
2
|
import { Run } from "../../core/Run.js";
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
export interface LlamaCppTokenizerSettings {
|
7
|
-
baseUrl?: string;
|
8
|
-
retry?: RetryFunction;
|
9
|
-
throttle?: ThrottleFunction;
|
10
|
-
}
|
3
|
+
import { ApiConfiguration } from "../../model-function/ApiConfiguration.js";
|
4
|
+
import { BasicTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
|
11
5
|
/**
|
12
6
|
* Tokenizer for LlamaCpp.
|
13
7
|
|
@@ -22,8 +16,8 @@ export interface LlamaCppTokenizerSettings {
|
|
22
16
|
* const reconstructedText = await tokenizer.detokenize(tokens);
|
23
17
|
*/
|
24
18
|
export declare class LlamaCppTokenizer implements BasicTokenizer {
|
25
|
-
readonly
|
26
|
-
constructor(
|
19
|
+
readonly api: ApiConfiguration;
|
20
|
+
constructor(api?: ApiConfiguration);
|
27
21
|
callTokenizeAPI(text: string, context?: Run): Promise<LlamaCppTokenizationResponse>;
|
28
22
|
tokenize(text: string): Promise<number[]>;
|
29
23
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import z from "zod";
|
2
2
|
import { callWithRetryAndThrottle } from "../../util/api/callWithRetryAndThrottle.js";
|
3
3
|
import { createJsonResponseHandler, postJsonToApi, } from "../../util/api/postToApi.js";
|
4
|
+
import { LlamaCppApiConfiguration } from "./LlamaCppApiConfiguration.js";
|
4
5
|
import { failedLlamaCppCallResponseHandler } from "./LlamaCppError.js";
|
5
6
|
/**
|
6
7
|
* Tokenizer for LlamaCpp.
|
@@ -16,23 +17,23 @@ import { failedLlamaCppCallResponseHandler } from "./LlamaCppError.js";
|
|
16
17
|
* const reconstructedText = await tokenizer.detokenize(tokens);
|
17
18
|
*/
|
18
19
|
export class LlamaCppTokenizer {
|
19
|
-
constructor(
|
20
|
-
Object.defineProperty(this, "
|
20
|
+
constructor(api = new LlamaCppApiConfiguration()) {
|
21
|
+
Object.defineProperty(this, "api", {
|
21
22
|
enumerable: true,
|
22
23
|
configurable: true,
|
23
24
|
writable: true,
|
24
25
|
value: void 0
|
25
26
|
});
|
26
|
-
this.
|
27
|
+
this.api = api;
|
27
28
|
}
|
28
29
|
async callTokenizeAPI(text, context) {
|
29
30
|
return callWithRetryAndThrottle({
|
30
|
-
retry: this.
|
31
|
-
throttle: this.
|
31
|
+
retry: this.api.retry,
|
32
|
+
throttle: this.api.throttle,
|
32
33
|
call: async () => callLlamaCppTokenizeAPI({
|
34
|
+
api: this.api,
|
33
35
|
abortSignal: context?.abortSignal,
|
34
36
|
text,
|
35
|
-
...this.settings,
|
36
37
|
}),
|
37
38
|
});
|
38
39
|
}
|
@@ -44,9 +45,10 @@ export class LlamaCppTokenizer {
|
|
44
45
|
const llamaCppTokenizationResponseSchema = z.object({
|
45
46
|
tokens: z.array(z.number()),
|
46
47
|
});
|
47
|
-
async function callLlamaCppTokenizeAPI({
|
48
|
+
async function callLlamaCppTokenizeAPI({ api, abortSignal, text, }) {
|
48
49
|
return postJsonToApi({
|
49
|
-
url:
|
50
|
+
url: api.assembleUrl(`/tokenize`),
|
51
|
+
headers: api.headers,
|
50
52
|
body: {
|
51
53
|
content: text,
|
52
54
|
},
|
@@ -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.LlamaCppError = void 0;
|
18
|
+
__exportStar(require("./LlamaCppApiConfiguration.cjs"), exports);
|
18
19
|
var LlamaCppError_js_1 = require("./LlamaCppError.cjs");
|
19
20
|
Object.defineProperty(exports, "LlamaCppError", { enumerable: true, get: function () { return LlamaCppError_js_1.LlamaCppError; } });
|
20
21
|
__exportStar(require("./LlamaCppTextEmbeddingModel.cjs"), exports);
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LmntApiConfiguration = void 0;
|
4
|
+
const BasicApiConfiguration_js_1 = require("../../model-function/BasicApiConfiguration.cjs");
|
5
|
+
const loadApiKey_js_1 = require("../../util/api/loadApiKey.cjs");
|
6
|
+
class LmntApiConfiguration extends BasicApiConfiguration_js_1.BasicApiConfiguration {
|
7
|
+
constructor({ baseUrl = "https://api.lmnt.com/speech/beta", 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: "LMNT_API_KEY",
|
22
|
+
description: "LMNT",
|
23
|
+
});
|
24
|
+
}
|
25
|
+
get headers() {
|
26
|
+
return { "X-API-Key": this.apiKey };
|
27
|
+
}
|
28
|
+
}
|
29
|
+
exports.LmntApiConfiguration = LmntApiConfiguration;
|
@@ -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 LmntApiConfiguration 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 LmntApiConfiguration extends BasicApiConfiguration {
|
4
|
+
constructor({ baseUrl = "https://api.lmnt.com/speech/beta", 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: "LMNT_API_KEY",
|
19
|
+
description: "LMNT",
|
20
|
+
});
|
21
|
+
}
|
22
|
+
get headers() {
|
23
|
+
return { "X-API-Key": this.apiKey };
|
24
|
+
}
|
25
|
+
}
|
@@ -4,7 +4,13 @@ exports.LmntSpeechSynthesisModel = void 0;
|
|
4
4
|
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
5
5
|
const callWithRetryAndThrottle_js_1 = require("../../util/api/callWithRetryAndThrottle.cjs");
|
6
6
|
const postToApi_js_1 = require("../../util/api/postToApi.cjs");
|
7
|
+
const LmntApiConfiguration_js_1 = require("./LmntApiConfiguration.cjs");
|
7
8
|
const LmntError_js_1 = require("./LmntError.cjs");
|
9
|
+
/**
|
10
|
+
* Synthesize speech using the LMNT API.
|
11
|
+
*
|
12
|
+
* @see https://www.lmnt.com/docs/rest/#synthesize-speech
|
13
|
+
*/
|
8
14
|
class LmntSpeechSynthesisModel extends AbstractModel_js_1.AbstractModel {
|
9
15
|
constructor(settings) {
|
10
16
|
super({ settings });
|
@@ -14,45 +20,28 @@ class LmntSpeechSynthesisModel extends AbstractModel_js_1.AbstractModel {
|
|
14
20
|
writable: true,
|
15
21
|
value: "lmnt"
|
16
22
|
});
|
17
|
-
Object.defineProperty(this, "modelName", {
|
18
|
-
enumerable: true,
|
19
|
-
configurable: true,
|
20
|
-
writable: true,
|
21
|
-
value: null
|
22
|
-
});
|
23
23
|
}
|
24
|
-
get
|
25
|
-
|
26
|
-
if (apiKey == null) {
|
27
|
-
throw new Error("No LMNT API key provided. Pass it in the constructor or set the LMNT_API_KEY environment variable.");
|
28
|
-
}
|
29
|
-
return apiKey;
|
24
|
+
get modelName() {
|
25
|
+
return this.settings.voice;
|
30
26
|
}
|
31
27
|
async callAPI(text, options) {
|
32
28
|
const run = options?.run;
|
33
29
|
const settings = options?.settings;
|
34
|
-
const
|
30
|
+
const callSettings = {
|
31
|
+
// copied settings:
|
35
32
|
...this.settings,
|
36
33
|
...settings,
|
34
|
+
abortSignal: run?.abortSignal,
|
35
|
+
text,
|
37
36
|
};
|
38
37
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
39
|
-
retry:
|
40
|
-
throttle:
|
41
|
-
call: async () => callLmntTextToSpeechAPI(
|
42
|
-
baseUrl: combinedSettings.baseUrl,
|
43
|
-
abortSignal: run?.abortSignal,
|
44
|
-
apiKey: this.apiKey,
|
45
|
-
text,
|
46
|
-
voice: combinedSettings.voice,
|
47
|
-
speed: combinedSettings.speed,
|
48
|
-
seed: combinedSettings.seed,
|
49
|
-
length: combinedSettings.length,
|
50
|
-
}),
|
38
|
+
retry: callSettings.api?.retry,
|
39
|
+
throttle: callSettings.api?.throttle,
|
40
|
+
call: async () => callLmntTextToSpeechAPI(callSettings),
|
51
41
|
});
|
52
42
|
}
|
53
43
|
get settingsForEvent() {
|
54
44
|
return {
|
55
|
-
baseUrl: this.settings.baseUrl,
|
56
45
|
voice: this.settings.voice,
|
57
46
|
speed: this.settings.speed,
|
58
47
|
seed: this.settings.seed,
|
@@ -70,10 +59,7 @@ class LmntSpeechSynthesisModel extends AbstractModel_js_1.AbstractModel {
|
|
70
59
|
}
|
71
60
|
}
|
72
61
|
exports.LmntSpeechSynthesisModel = LmntSpeechSynthesisModel;
|
73
|
-
|
74
|
-
* @see https://www.lmnt.com/docs/rest/#synthesize-speech
|
75
|
-
*/
|
76
|
-
async function callLmntTextToSpeechAPI({ baseUrl = "https://api.lmnt.com/speech/beta", abortSignal, apiKey, text, voice, speed, seed, length, }) {
|
62
|
+
async function callLmntTextToSpeechAPI({ api = new LmntApiConfiguration_js_1.LmntApiConfiguration(), abortSignal, text, voice, speed, seed, length, }) {
|
77
63
|
const formData = new FormData();
|
78
64
|
formData.append("text", text);
|
79
65
|
formData.append("voice", voice);
|
@@ -85,10 +71,8 @@ async function callLmntTextToSpeechAPI({ baseUrl = "https://api.lmnt.com/speech/
|
|
85
71
|
if (length != null)
|
86
72
|
formData.append("length", length.toString());
|
87
73
|
return (0, postToApi_js_1.postToApi)({
|
88
|
-
url:
|
89
|
-
headers:
|
90
|
-
"X-API-Key": apiKey,
|
91
|
-
},
|
74
|
+
url: api.assembleUrl(`/synthesize`),
|
75
|
+
headers: api.headers,
|
92
76
|
body: {
|
93
77
|
content: formData,
|
94
78
|
values: {
|