modelfusion 0.98.0 → 0.100.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/README.md +13 -19
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +1 -1
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +1 -1
- package/guard/fixStructure.cjs +3 -3
- package/guard/fixStructure.d.ts +3 -3
- package/guard/fixStructure.js +3 -3
- package/model-function/Model.d.ts +2 -2
- package/model-function/generate-structure/generateStructure.d.ts +2 -2
- package/model-function/generate-structure/streamStructure.d.ts +1 -1
- package/model-function/generate-text/PromptTemplateTextGenerationModel.cjs +2 -2
- package/model-function/generate-text/PromptTemplateTextGenerationModel.d.ts +2 -2
- package/model-function/generate-text/PromptTemplateTextGenerationModel.js +2 -2
- package/model-function/generate-text/TextGenerationModel.d.ts +31 -5
- package/model-function/generate-text/generateText.cjs +10 -4
- package/model-function/generate-text/generateText.d.ts +1 -0
- package/model-function/generate-text/generateText.js +10 -4
- package/model-function/generate-text/prompt-template/trimChatPrompt.cjs +1 -1
- package/model-function/generate-text/prompt-template/trimChatPrompt.js +1 -1
- package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +27 -31
- package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +2 -2
- package/model-provider/anthropic/AnthropicTextGenerationModel.js +27 -31
- package/model-provider/cohere/CohereFacade.cjs +1 -1
- package/model-provider/cohere/CohereFacade.d.ts +1 -1
- package/model-provider/cohere/CohereFacade.js +1 -1
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextGenerationModel.cjs +34 -43
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +3 -4
- package/model-provider/cohere/CohereTextGenerationModel.js +34 -43
- package/model-provider/huggingface/HuggingFaceFacade.cjs +1 -1
- package/model-provider/huggingface/HuggingFaceFacade.d.ts +1 -1
- package/model-provider/huggingface/HuggingFaceFacade.js +1 -1
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +31 -41
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +3 -4
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +31 -41
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +4 -4
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +2 -2
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +4 -4
- package/model-provider/mistral/{MistralTextGenerationModel.cjs → MistralChatModel.cjs} +18 -18
- package/model-provider/mistral/{MistralTextGenerationModel.d.ts → MistralChatModel.d.ts} +22 -21
- package/model-provider/mistral/{MistralTextGenerationModel.js → MistralChatModel.js} +16 -16
- 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} +17 -15
- package/model-provider/ollama/OllamaCompletionModel.d.ts +159 -0
- package/model-provider/ollama/{OllamaTextGenerationModel.js → OllamaCompletionModel.js} +15 -13
- 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/OpenAICompletionModel.cjs +48 -53
- package/model-provider/openai/OpenAICompletionModel.d.ts +3 -6
- package/model-provider/openai/OpenAICompletionModel.js +48 -53
- package/model-provider/openai/OpenAIFacade.cjs +6 -4
- package/model-provider/openai/OpenAIFacade.d.ts +5 -3
- package/model-provider/openai/OpenAIFacade.js +4 -3
- package/model-provider/openai/chat/AbstractOpenAIChatModel.cjs +50 -54
- package/model-provider/openai/chat/AbstractOpenAIChatModel.d.ts +7 -28
- package/model-provider/openai/chat/AbstractOpenAIChatModel.js +50 -54
- package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.d.ts +3 -3
- package/model-provider/openai/chat/OpenAIChatModel.cjs +4 -4
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +3 -3
- package/model-provider/openai/chat/OpenAIChatModel.js +4 -4
- package/model-provider/openai/chat/OpenAIChatModel.test.cjs +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.test.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/OpenAICompatibleChatModel.cjs +2 -2
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.js +2 -2
- package/model-provider/openai-compatible/OpenAICompatibleFacade.cjs +2 -2
- package/model-provider/openai-compatible/OpenAICompatibleFacade.d.ts +2 -2
- package/model-provider/openai-compatible/OpenAICompatibleFacade.js +2 -2
- package/package.json +1 -1
- package/model-provider/ollama/OllamaTextGenerationModel.d.ts +0 -230
- /package/model-provider/ollama/{OllamaTextGenerationModel.test.d.ts → OllamaCompletionModel.test.d.ts} +0 -0
@@ -74,6 +74,7 @@ export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEm
|
|
74
74
|
get settingsForEvent(): Partial<CohereTextEmbeddingModelSettings>;
|
75
75
|
doEmbedValues(texts: string[], options?: FunctionOptions): Promise<{
|
76
76
|
response: {
|
77
|
+
texts: string[];
|
77
78
|
embeddings: number[][];
|
78
79
|
id: string;
|
79
80
|
meta: {
|
@@ -81,7 +82,6 @@ export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEm
|
|
81
82
|
version: string;
|
82
83
|
};
|
83
84
|
};
|
84
|
-
texts: string[];
|
85
85
|
};
|
86
86
|
embeddings: number[][];
|
87
87
|
}>;
|
@@ -109,6 +109,7 @@ declare const cohereTextEmbeddingResponseSchema: z.ZodObject<{
|
|
109
109
|
};
|
110
110
|
}>;
|
111
111
|
}, "strip", z.ZodTypeAny, {
|
112
|
+
texts: string[];
|
112
113
|
embeddings: number[][];
|
113
114
|
id: string;
|
114
115
|
meta: {
|
@@ -116,8 +117,8 @@ declare const cohereTextEmbeddingResponseSchema: z.ZodObject<{
|
|
116
117
|
version: string;
|
117
118
|
};
|
118
119
|
};
|
119
|
-
texts: string[];
|
120
120
|
}, {
|
121
|
+
texts: string[];
|
121
122
|
embeddings: number[][];
|
122
123
|
id: string;
|
123
124
|
meta: {
|
@@ -125,7 +126,6 @@ declare const cohereTextEmbeddingResponseSchema: z.ZodObject<{
|
|
125
126
|
version: string;
|
126
127
|
};
|
127
128
|
};
|
128
|
-
texts: string[];
|
129
129
|
}>;
|
130
130
|
export type CohereTextEmbeddingResponse = z.infer<typeof cohereTextEmbeddingResponseSchema>;
|
131
131
|
export {};
|
@@ -37,7 +37,7 @@ exports.COHERE_TEXT_GENERATION_MODELS = {
|
|
37
37
|
* const model = new CohereTextGenerationModel({
|
38
38
|
* model: "command-nightly",
|
39
39
|
* temperature: 0.7,
|
40
|
-
*
|
40
|
+
* maxGenerationTokens: 500,
|
41
41
|
* });
|
42
42
|
*
|
43
43
|
* const text = await generateText(
|
@@ -80,28 +80,45 @@ class CohereTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
80
80
|
return (0, countTokens_js_1.countTokens)(this.tokenizer, input);
|
81
81
|
}
|
82
82
|
async callAPI(prompt, options) {
|
83
|
+
const api = this.settings.api ?? new CohereApiConfiguration_js_1.CohereApiConfiguration();
|
84
|
+
const responseFormat = options.responseFormat;
|
85
|
+
const abortSignal = options.run?.abortSignal;
|
83
86
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
84
87
|
retry: this.settings.api?.retry,
|
85
88
|
throttle: this.settings.api?.throttle,
|
86
|
-
call: async () =>
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
call: async () => {
|
90
|
+
return (0, postToApi_js_1.postJsonToApi)({
|
91
|
+
url: api.assembleUrl(`/generate`),
|
92
|
+
headers: api.headers,
|
93
|
+
body: {
|
94
|
+
stream: responseFormat.stream,
|
95
|
+
model: this.settings.model,
|
96
|
+
prompt,
|
97
|
+
num_generations: this.settings.numberOfGenerations,
|
98
|
+
max_tokens: this.settings.maxGenerationTokens,
|
99
|
+
temperature: this.settings.temperature,
|
100
|
+
k: this.settings.k,
|
101
|
+
p: this.settings.p,
|
102
|
+
frequency_penalty: this.settings.frequencyPenalty,
|
103
|
+
presence_penalty: this.settings.presencePenalty,
|
104
|
+
end_sequences: this.settings.stopSequences,
|
105
|
+
stop_sequences: this.settings.cohereStopSequences,
|
106
|
+
return_likelihoods: this.settings.returnLikelihoods,
|
107
|
+
logit_bias: this.settings.logitBias,
|
108
|
+
truncate: this.settings.truncate,
|
109
|
+
},
|
110
|
+
failedResponseHandler: CohereError_js_1.failedCohereCallResponseHandler,
|
111
|
+
successfulResponseHandler: responseFormat.handler,
|
112
|
+
abortSignal,
|
113
|
+
});
|
114
|
+
},
|
98
115
|
});
|
99
116
|
}
|
100
117
|
get settingsForEvent() {
|
101
118
|
const eventSettingProperties = [
|
102
|
-
"
|
119
|
+
"maxGenerationTokens",
|
103
120
|
"stopSequences",
|
104
|
-
"
|
121
|
+
"numberOfGenerations",
|
105
122
|
"temperature",
|
106
123
|
"k",
|
107
124
|
"p",
|
@@ -114,14 +131,14 @@ class CohereTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
114
131
|
];
|
115
132
|
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
116
133
|
}
|
117
|
-
async
|
134
|
+
async doGenerateTexts(prompt, options) {
|
118
135
|
const response = await this.callAPI(prompt, {
|
119
136
|
...options,
|
120
137
|
responseFormat: exports.CohereTextGenerationResponseFormat.json,
|
121
138
|
});
|
122
139
|
return {
|
123
140
|
response,
|
124
|
-
|
141
|
+
texts: response.generations.map((generation) => generation.text),
|
125
142
|
};
|
126
143
|
}
|
127
144
|
doStreamText(prompt, options) {
|
@@ -177,32 +194,6 @@ const cohereTextGenerationResponseSchema = zod_1.z.object({
|
|
177
194
|
})
|
178
195
|
.optional(),
|
179
196
|
});
|
180
|
-
async function callCohereTextGenerationAPI({ api = new CohereApiConfiguration_js_1.CohereApiConfiguration(), abortSignal, responseFormat, model, prompt, numGenerations, maxTokens, temperature, k, p, frequencyPenalty, presencePenalty, endSequences, stopSequences, returnLikelihoods, logitBias, truncate, }) {
|
181
|
-
return (0, postToApi_js_1.postJsonToApi)({
|
182
|
-
url: api.assembleUrl(`/generate`),
|
183
|
-
headers: api.headers,
|
184
|
-
body: {
|
185
|
-
stream: responseFormat.stream,
|
186
|
-
model,
|
187
|
-
prompt,
|
188
|
-
num_generations: numGenerations,
|
189
|
-
max_tokens: maxTokens,
|
190
|
-
temperature,
|
191
|
-
k,
|
192
|
-
p,
|
193
|
-
frequency_penalty: frequencyPenalty,
|
194
|
-
presence_penalty: presencePenalty,
|
195
|
-
end_sequences: endSequences,
|
196
|
-
stop_sequences: stopSequences,
|
197
|
-
return_likelihoods: returnLikelihoods,
|
198
|
-
logit_bias: logitBias,
|
199
|
-
truncate,
|
200
|
-
},
|
201
|
-
failedResponseHandler: CohereError_js_1.failedCohereCallResponseHandler,
|
202
|
-
successfulResponseHandler: responseFormat.handler,
|
203
|
-
abortSignal,
|
204
|
-
});
|
205
|
-
}
|
206
197
|
const cohereTextStreamingResponseSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.discriminatedUnion("is_finished", [
|
207
198
|
zod_1.z.object({
|
208
199
|
text: zod_1.z.string(),
|
@@ -26,7 +26,6 @@ export type CohereTextGenerationModelType = keyof typeof COHERE_TEXT_GENERATION_
|
|
26
26
|
export interface CohereTextGenerationModelSettings extends TextGenerationModelSettings {
|
27
27
|
api?: ApiConfiguration;
|
28
28
|
model: CohereTextGenerationModelType;
|
29
|
-
numGenerations?: number;
|
30
29
|
temperature?: number;
|
31
30
|
k?: number;
|
32
31
|
p?: number;
|
@@ -46,7 +45,7 @@ export interface CohereTextGenerationModelSettings extends TextGenerationModelSe
|
|
46
45
|
* const model = new CohereTextGenerationModel({
|
47
46
|
* model: "command-nightly",
|
48
47
|
* temperature: 0.7,
|
49
|
-
*
|
48
|
+
* maxGenerationTokens: 500,
|
50
49
|
* });
|
51
50
|
*
|
52
51
|
* const text = await generateText(
|
@@ -65,7 +64,7 @@ export declare class CohereTextGenerationModel extends AbstractModel<CohereTextG
|
|
65
64
|
responseFormat: CohereTextGenerationResponseFormatType<RESPONSE>;
|
66
65
|
} & FunctionOptions): Promise<RESPONSE>;
|
67
66
|
get settingsForEvent(): Partial<CohereTextGenerationModelSettings>;
|
68
|
-
|
67
|
+
doGenerateTexts(prompt: string, options?: FunctionOptions): Promise<{
|
69
68
|
response: {
|
70
69
|
prompt: string;
|
71
70
|
id: string;
|
@@ -80,7 +79,7 @@ export declare class CohereTextGenerationModel extends AbstractModel<CohereTextG
|
|
80
79
|
};
|
81
80
|
} | undefined;
|
82
81
|
};
|
83
|
-
|
82
|
+
texts: string[];
|
84
83
|
}>;
|
85
84
|
doStreamText(prompt: string, options?: FunctionOptions): Promise<AsyncIterable<Delta<string>>>;
|
86
85
|
extractTextDelta(fullDelta: CohereTextGenerationDelta): string | undefined;
|
@@ -34,7 +34,7 @@ export const COHERE_TEXT_GENERATION_MODELS = {
|
|
34
34
|
* const model = new CohereTextGenerationModel({
|
35
35
|
* model: "command-nightly",
|
36
36
|
* temperature: 0.7,
|
37
|
-
*
|
37
|
+
* maxGenerationTokens: 500,
|
38
38
|
* });
|
39
39
|
*
|
40
40
|
* const text = await generateText(
|
@@ -77,28 +77,45 @@ export class CohereTextGenerationModel extends AbstractModel {
|
|
77
77
|
return countTokens(this.tokenizer, input);
|
78
78
|
}
|
79
79
|
async callAPI(prompt, options) {
|
80
|
+
const api = this.settings.api ?? new CohereApiConfiguration();
|
81
|
+
const responseFormat = options.responseFormat;
|
82
|
+
const abortSignal = options.run?.abortSignal;
|
80
83
|
return callWithRetryAndThrottle({
|
81
84
|
retry: this.settings.api?.retry,
|
82
85
|
throttle: this.settings.api?.throttle,
|
83
|
-
call: async () =>
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
86
|
+
call: async () => {
|
87
|
+
return postJsonToApi({
|
88
|
+
url: api.assembleUrl(`/generate`),
|
89
|
+
headers: api.headers,
|
90
|
+
body: {
|
91
|
+
stream: responseFormat.stream,
|
92
|
+
model: this.settings.model,
|
93
|
+
prompt,
|
94
|
+
num_generations: this.settings.numberOfGenerations,
|
95
|
+
max_tokens: this.settings.maxGenerationTokens,
|
96
|
+
temperature: this.settings.temperature,
|
97
|
+
k: this.settings.k,
|
98
|
+
p: this.settings.p,
|
99
|
+
frequency_penalty: this.settings.frequencyPenalty,
|
100
|
+
presence_penalty: this.settings.presencePenalty,
|
101
|
+
end_sequences: this.settings.stopSequences,
|
102
|
+
stop_sequences: this.settings.cohereStopSequences,
|
103
|
+
return_likelihoods: this.settings.returnLikelihoods,
|
104
|
+
logit_bias: this.settings.logitBias,
|
105
|
+
truncate: this.settings.truncate,
|
106
|
+
},
|
107
|
+
failedResponseHandler: failedCohereCallResponseHandler,
|
108
|
+
successfulResponseHandler: responseFormat.handler,
|
109
|
+
abortSignal,
|
110
|
+
});
|
111
|
+
},
|
95
112
|
});
|
96
113
|
}
|
97
114
|
get settingsForEvent() {
|
98
115
|
const eventSettingProperties = [
|
99
|
-
"
|
116
|
+
"maxGenerationTokens",
|
100
117
|
"stopSequences",
|
101
|
-
"
|
118
|
+
"numberOfGenerations",
|
102
119
|
"temperature",
|
103
120
|
"k",
|
104
121
|
"p",
|
@@ -111,14 +128,14 @@ export class CohereTextGenerationModel extends AbstractModel {
|
|
111
128
|
];
|
112
129
|
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
113
130
|
}
|
114
|
-
async
|
131
|
+
async doGenerateTexts(prompt, options) {
|
115
132
|
const response = await this.callAPI(prompt, {
|
116
133
|
...options,
|
117
134
|
responseFormat: CohereTextGenerationResponseFormat.json,
|
118
135
|
});
|
119
136
|
return {
|
120
137
|
response,
|
121
|
-
|
138
|
+
texts: response.generations.map((generation) => generation.text),
|
122
139
|
};
|
123
140
|
}
|
124
141
|
doStreamText(prompt, options) {
|
@@ -173,32 +190,6 @@ const cohereTextGenerationResponseSchema = z.object({
|
|
173
190
|
})
|
174
191
|
.optional(),
|
175
192
|
});
|
176
|
-
async function callCohereTextGenerationAPI({ api = new CohereApiConfiguration(), abortSignal, responseFormat, model, prompt, numGenerations, maxTokens, temperature, k, p, frequencyPenalty, presencePenalty, endSequences, stopSequences, returnLikelihoods, logitBias, truncate, }) {
|
177
|
-
return postJsonToApi({
|
178
|
-
url: api.assembleUrl(`/generate`),
|
179
|
-
headers: api.headers,
|
180
|
-
body: {
|
181
|
-
stream: responseFormat.stream,
|
182
|
-
model,
|
183
|
-
prompt,
|
184
|
-
num_generations: numGenerations,
|
185
|
-
max_tokens: maxTokens,
|
186
|
-
temperature,
|
187
|
-
k,
|
188
|
-
p,
|
189
|
-
frequency_penalty: frequencyPenalty,
|
190
|
-
presence_penalty: presencePenalty,
|
191
|
-
end_sequences: endSequences,
|
192
|
-
stop_sequences: stopSequences,
|
193
|
-
return_likelihoods: returnLikelihoods,
|
194
|
-
logit_bias: logitBias,
|
195
|
-
truncate,
|
196
|
-
},
|
197
|
-
failedResponseHandler: failedCohereCallResponseHandler,
|
198
|
-
successfulResponseHandler: responseFormat.handler,
|
199
|
-
abortSignal,
|
200
|
-
});
|
201
|
-
}
|
202
193
|
const cohereTextStreamingResponseSchema = new ZodSchema(z.discriminatedUnion("is_finished", [
|
203
194
|
z.object({
|
204
195
|
text: z.string(),
|
@@ -12,7 +12,7 @@ const HuggingFaceTextGenerationModel_js_1 = require("./HuggingFaceTextGeneration
|
|
12
12
|
* const model = huggingface.TextGenerator({
|
13
13
|
* model: "tiiuae/falcon-7b",
|
14
14
|
* temperature: 0.7,
|
15
|
-
*
|
15
|
+
* maxGenerationTokens: 500,
|
16
16
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
17
17
|
* });
|
18
18
|
*
|
@@ -9,7 +9,7 @@ import { HuggingFaceTextGenerationModel, HuggingFaceTextGenerationModelSettings
|
|
9
9
|
* const model = huggingface.TextGenerator({
|
10
10
|
* model: "tiiuae/falcon-7b",
|
11
11
|
* temperature: 0.7,
|
12
|
-
*
|
12
|
+
* maxGenerationTokens: 500,
|
13
13
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
14
14
|
* });
|
15
15
|
*
|
@@ -9,7 +9,7 @@ import { HuggingFaceTextGenerationModel, } from "./HuggingFaceTextGenerationMode
|
|
9
9
|
* const model = huggingface.TextGenerator({
|
10
10
|
* model: "tiiuae/falcon-7b",
|
11
11
|
* temperature: 0.7,
|
12
|
-
*
|
12
|
+
* maxGenerationTokens: 500,
|
13
13
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
14
14
|
* });
|
15
15
|
*
|
@@ -17,7 +17,7 @@ const HuggingFaceError_js_1 = require("./HuggingFaceError.cjs");
|
|
17
17
|
* const model = new HuggingFaceTextGenerationModel({
|
18
18
|
* model: "tiiuae/falcon-7b",
|
19
19
|
* temperature: 0.7,
|
20
|
-
*
|
20
|
+
* maxGenerationTokens: 500,
|
21
21
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
22
22
|
* });
|
23
23
|
*
|
@@ -58,41 +58,57 @@ class HuggingFaceTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
58
58
|
return this.settings.model;
|
59
59
|
}
|
60
60
|
async callAPI(prompt, options) {
|
61
|
+
const api = this.settings.api ?? new HuggingFaceApiConfiguration_js_1.HuggingFaceApiConfiguration();
|
62
|
+
const abortSignal = options?.run?.abortSignal;
|
61
63
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
62
64
|
retry: this.settings.api?.retry,
|
63
65
|
throttle: this.settings.api?.throttle,
|
64
|
-
call: async () =>
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
call: async () => {
|
67
|
+
return (0, postToApi_js_1.postJsonToApi)({
|
68
|
+
url: api.assembleUrl(`/${this.settings.model}`),
|
69
|
+
headers: api.headers,
|
70
|
+
body: {
|
71
|
+
inputs: prompt,
|
72
|
+
top_k: this.settings.topK,
|
73
|
+
top_p: this.settings.topP,
|
74
|
+
temperature: this.settings.temperature,
|
75
|
+
repetition_penalty: this.settings.repetitionPenalty,
|
76
|
+
max_new_tokens: this.settings.maxGenerationTokens,
|
77
|
+
max_time: this.settings.maxTime,
|
78
|
+
num_return_sequences: this.settings.numberOfGenerations,
|
79
|
+
do_sample: this.settings.doSample,
|
80
|
+
options: {
|
81
|
+
use_cache: true,
|
82
|
+
wait_for_model: true,
|
83
|
+
},
|
84
|
+
},
|
85
|
+
failedResponseHandler: HuggingFaceError_js_1.failedHuggingFaceCallResponseHandler,
|
86
|
+
successfulResponseHandler: (0, postToApi_js_1.createJsonResponseHandler)(huggingFaceTextGenerationResponseSchema),
|
87
|
+
abortSignal,
|
88
|
+
});
|
89
|
+
},
|
74
90
|
});
|
75
91
|
}
|
76
92
|
get settingsForEvent() {
|
77
93
|
const eventSettingProperties = [
|
78
94
|
"stopSequences",
|
79
|
-
"
|
95
|
+
"maxGenerationTokens",
|
96
|
+
"numberOfGenerations",
|
80
97
|
"topK",
|
81
98
|
"topP",
|
82
99
|
"temperature",
|
83
100
|
"repetitionPenalty",
|
84
101
|
"maxTime",
|
85
|
-
"numReturnSequences",
|
86
102
|
"doSample",
|
87
103
|
"options",
|
88
104
|
];
|
89
105
|
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
90
106
|
}
|
91
|
-
async
|
107
|
+
async doGenerateTexts(prompt, options) {
|
92
108
|
const response = await this.callAPI(prompt, options);
|
93
109
|
return {
|
94
110
|
response,
|
95
|
-
|
111
|
+
texts: response.map((response) => response.generated_text),
|
96
112
|
};
|
97
113
|
}
|
98
114
|
withPromptTemplate(promptTemplate) {
|
@@ -109,29 +125,3 @@ exports.HuggingFaceTextGenerationModel = HuggingFaceTextGenerationModel;
|
|
109
125
|
const huggingFaceTextGenerationResponseSchema = zod_1.z.array(zod_1.z.object({
|
110
126
|
generated_text: zod_1.z.string(),
|
111
127
|
}));
|
112
|
-
async function callHuggingFaceTextGenerationAPI({ api = new HuggingFaceApiConfiguration_js_1.HuggingFaceApiConfiguration(), abortSignal, model, inputs, topK, topP, temperature, repetitionPenalty, maxNewTokens, maxTime, numReturnSequences, doSample, options, }) {
|
113
|
-
return (0, postToApi_js_1.postJsonToApi)({
|
114
|
-
url: api.assembleUrl(`/${model}`),
|
115
|
-
headers: api.headers,
|
116
|
-
body: {
|
117
|
-
inputs,
|
118
|
-
top_k: topK,
|
119
|
-
top_p: topP,
|
120
|
-
temperature,
|
121
|
-
repetition_penalty: repetitionPenalty,
|
122
|
-
max_new_tokens: maxNewTokens,
|
123
|
-
max_time: maxTime,
|
124
|
-
num_return_sequences: numReturnSequences,
|
125
|
-
do_sample: doSample,
|
126
|
-
options: options
|
127
|
-
? {
|
128
|
-
use_cache: options?.useCache,
|
129
|
-
wait_for_model: options?.waitForModel,
|
130
|
-
}
|
131
|
-
: undefined,
|
132
|
-
},
|
133
|
-
failedResponseHandler: HuggingFaceError_js_1.failedHuggingFaceCallResponseHandler,
|
134
|
-
successfulResponseHandler: (0, postToApi_js_1.createJsonResponseHandler)(huggingFaceTextGenerationResponseSchema),
|
135
|
-
abortSignal,
|
136
|
-
});
|
137
|
-
}
|
@@ -13,7 +13,6 @@ export interface HuggingFaceTextGenerationModelSettings extends TextGenerationMo
|
|
13
13
|
temperature?: number;
|
14
14
|
repetitionPenalty?: number;
|
15
15
|
maxTime?: number;
|
16
|
-
numReturnSequences?: number;
|
17
16
|
doSample?: boolean;
|
18
17
|
options?: {
|
19
18
|
useCache?: boolean;
|
@@ -29,7 +28,7 @@ export interface HuggingFaceTextGenerationModelSettings extends TextGenerationMo
|
|
29
28
|
* const model = new HuggingFaceTextGenerationModel({
|
30
29
|
* model: "tiiuae/falcon-7b",
|
31
30
|
* temperature: 0.7,
|
32
|
-
*
|
31
|
+
* maxGenerationTokens: 500,
|
33
32
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
34
33
|
* });
|
35
34
|
*
|
@@ -47,11 +46,11 @@ export declare class HuggingFaceTextGenerationModel extends AbstractModel<Huggin
|
|
47
46
|
readonly countPromptTokens: undefined;
|
48
47
|
callAPI(prompt: string, options?: FunctionOptions): Promise<HuggingFaceTextGenerationResponse>;
|
49
48
|
get settingsForEvent(): Partial<HuggingFaceTextGenerationModelSettings>;
|
50
|
-
|
49
|
+
doGenerateTexts(prompt: string, options?: FunctionOptions): Promise<{
|
51
50
|
response: {
|
52
51
|
generated_text: string;
|
53
52
|
}[];
|
54
|
-
|
53
|
+
texts: string[];
|
55
54
|
}>;
|
56
55
|
withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, string>): PromptTemplateTextGenerationModel<INPUT_PROMPT, string, HuggingFaceTextGenerationModelSettings, this>;
|
57
56
|
withSettings(additionalSettings: Partial<HuggingFaceTextGenerationModelSettings>): this;
|
@@ -14,7 +14,7 @@ import { failedHuggingFaceCallResponseHandler } from "./HuggingFaceError.js";
|
|
14
14
|
* const model = new HuggingFaceTextGenerationModel({
|
15
15
|
* model: "tiiuae/falcon-7b",
|
16
16
|
* temperature: 0.7,
|
17
|
-
*
|
17
|
+
* maxGenerationTokens: 500,
|
18
18
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
19
19
|
* });
|
20
20
|
*
|
@@ -55,41 +55,57 @@ export class HuggingFaceTextGenerationModel extends AbstractModel {
|
|
55
55
|
return this.settings.model;
|
56
56
|
}
|
57
57
|
async callAPI(prompt, options) {
|
58
|
+
const api = this.settings.api ?? new HuggingFaceApiConfiguration();
|
59
|
+
const abortSignal = options?.run?.abortSignal;
|
58
60
|
return callWithRetryAndThrottle({
|
59
61
|
retry: this.settings.api?.retry,
|
60
62
|
throttle: this.settings.api?.throttle,
|
61
|
-
call: async () =>
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
63
|
+
call: async () => {
|
64
|
+
return postJsonToApi({
|
65
|
+
url: api.assembleUrl(`/${this.settings.model}`),
|
66
|
+
headers: api.headers,
|
67
|
+
body: {
|
68
|
+
inputs: prompt,
|
69
|
+
top_k: this.settings.topK,
|
70
|
+
top_p: this.settings.topP,
|
71
|
+
temperature: this.settings.temperature,
|
72
|
+
repetition_penalty: this.settings.repetitionPenalty,
|
73
|
+
max_new_tokens: this.settings.maxGenerationTokens,
|
74
|
+
max_time: this.settings.maxTime,
|
75
|
+
num_return_sequences: this.settings.numberOfGenerations,
|
76
|
+
do_sample: this.settings.doSample,
|
77
|
+
options: {
|
78
|
+
use_cache: true,
|
79
|
+
wait_for_model: true,
|
80
|
+
},
|
81
|
+
},
|
82
|
+
failedResponseHandler: failedHuggingFaceCallResponseHandler,
|
83
|
+
successfulResponseHandler: createJsonResponseHandler(huggingFaceTextGenerationResponseSchema),
|
84
|
+
abortSignal,
|
85
|
+
});
|
86
|
+
},
|
71
87
|
});
|
72
88
|
}
|
73
89
|
get settingsForEvent() {
|
74
90
|
const eventSettingProperties = [
|
75
91
|
"stopSequences",
|
76
|
-
"
|
92
|
+
"maxGenerationTokens",
|
93
|
+
"numberOfGenerations",
|
77
94
|
"topK",
|
78
95
|
"topP",
|
79
96
|
"temperature",
|
80
97
|
"repetitionPenalty",
|
81
98
|
"maxTime",
|
82
|
-
"numReturnSequences",
|
83
99
|
"doSample",
|
84
100
|
"options",
|
85
101
|
];
|
86
102
|
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
87
103
|
}
|
88
|
-
async
|
104
|
+
async doGenerateTexts(prompt, options) {
|
89
105
|
const response = await this.callAPI(prompt, options);
|
90
106
|
return {
|
91
107
|
response,
|
92
|
-
|
108
|
+
texts: response.map((response) => response.generated_text),
|
93
109
|
};
|
94
110
|
}
|
95
111
|
withPromptTemplate(promptTemplate) {
|
@@ -105,29 +121,3 @@ export class HuggingFaceTextGenerationModel extends AbstractModel {
|
|
105
121
|
const huggingFaceTextGenerationResponseSchema = z.array(z.object({
|
106
122
|
generated_text: z.string(),
|
107
123
|
}));
|
108
|
-
async function callHuggingFaceTextGenerationAPI({ api = new HuggingFaceApiConfiguration(), abortSignal, model, inputs, topK, topP, temperature, repetitionPenalty, maxNewTokens, maxTime, numReturnSequences, doSample, options, }) {
|
109
|
-
return postJsonToApi({
|
110
|
-
url: api.assembleUrl(`/${model}`),
|
111
|
-
headers: api.headers,
|
112
|
-
body: {
|
113
|
-
inputs,
|
114
|
-
top_k: topK,
|
115
|
-
top_p: topP,
|
116
|
-
temperature,
|
117
|
-
repetition_penalty: repetitionPenalty,
|
118
|
-
max_new_tokens: maxNewTokens,
|
119
|
-
max_time: maxTime,
|
120
|
-
num_return_sequences: numReturnSequences,
|
121
|
-
do_sample: doSample,
|
122
|
-
options: options
|
123
|
-
? {
|
124
|
-
use_cache: options?.useCache,
|
125
|
-
wait_for_model: options?.waitForModel,
|
126
|
-
}
|
127
|
-
: undefined,
|
128
|
-
},
|
129
|
-
failedResponseHandler: failedHuggingFaceCallResponseHandler,
|
130
|
-
successfulResponseHandler: createJsonResponseHandler(huggingFaceTextGenerationResponseSchema),
|
131
|
-
abortSignal,
|
132
|
-
});
|
133
|
-
}
|
@@ -43,7 +43,7 @@ class LlamaCppTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
43
43
|
call: async () => callLlamaCppTextGenerationAPI({
|
44
44
|
...this.settings,
|
45
45
|
// mapping
|
46
|
-
nPredict: this.settings.
|
46
|
+
nPredict: this.settings.maxGenerationTokens,
|
47
47
|
stop: this.settings.stopSequences,
|
48
48
|
// other
|
49
49
|
abortSignal: options.run?.abortSignal,
|
@@ -54,7 +54,7 @@ class LlamaCppTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
54
54
|
}
|
55
55
|
get settingsForEvent() {
|
56
56
|
const eventSettingProperties = [
|
57
|
-
"
|
57
|
+
"maxGenerationTokens",
|
58
58
|
"stopSequences",
|
59
59
|
"contextWindowSize",
|
60
60
|
"cachePrompt",
|
@@ -80,14 +80,14 @@ class LlamaCppTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
80
80
|
const tokens = await this.tokenizer.tokenize(prompt.text);
|
81
81
|
return tokens.length;
|
82
82
|
}
|
83
|
-
async
|
83
|
+
async doGenerateTexts(prompt, options) {
|
84
84
|
const response = await this.callAPI(prompt, {
|
85
85
|
...options,
|
86
86
|
responseFormat: exports.LlamaCppTextGenerationResponseFormat.json,
|
87
87
|
});
|
88
88
|
return {
|
89
89
|
response,
|
90
|
-
|
90
|
+
texts: [response.content],
|
91
91
|
usage: {
|
92
92
|
promptTokens: response.tokens_evaluated,
|
93
93
|
completionTokens: response.tokens_predicted,
|
@@ -56,7 +56,7 @@ export declare class LlamaCppTextGenerationModel<CONTEXT_WINDOW_SIZE extends num
|
|
56
56
|
} & FunctionOptions): Promise<RESPONSE>;
|
57
57
|
get settingsForEvent(): Partial<LlamaCppTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>>;
|
58
58
|
countPromptTokens(prompt: LlamaCppTextGenerationPrompt): Promise<number>;
|
59
|
-
|
59
|
+
doGenerateTexts(prompt: LlamaCppTextGenerationPrompt, options?: FunctionOptions): Promise<{
|
60
60
|
response: {
|
61
61
|
model: string;
|
62
62
|
prompt: string;
|
@@ -106,7 +106,7 @@ export declare class LlamaCppTextGenerationModel<CONTEXT_WINDOW_SIZE extends num
|
|
106
106
|
tokens_predicted: number;
|
107
107
|
truncated: boolean;
|
108
108
|
};
|
109
|
-
|
109
|
+
texts: string[];
|
110
110
|
usage: {
|
111
111
|
promptTokens: number;
|
112
112
|
completionTokens: number;
|