modelfusion 0.98.0 → 0.99.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 +4 -4
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +1 -1
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +1 -1
- package/model-function/Model.d.ts +2 -2
- 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 +5 -5
- package/model-provider/mistral/MistralTextGenerationModel.d.ts +2 -2
- package/model-provider/mistral/MistralTextGenerationModel.js +5 -5
- package/model-provider/ollama/OllamaTextGenerationModel.cjs +4 -4
- package/model-provider/ollama/OllamaTextGenerationModel.d.ts +2 -2
- package/model-provider/ollama/OllamaTextGenerationModel.js +4 -4
- 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 +2 -2
- package/model-provider/openai/OpenAIFacade.d.ts +2 -2
- package/model-provider/openai/OpenAIFacade.js +2 -2
- package/model-provider/openai/chat/AbstractOpenAIChatModel.cjs +50 -54
- package/model-provider/openai/chat/AbstractOpenAIChatModel.d.ts +6 -27
- package/model-provider/openai/chat/AbstractOpenAIChatModel.js +50 -54
- package/model-provider/openai/chat/OpenAIChatModel.cjs +3 -3
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.js +3 -3
- package/model-provider/openai/chat/OpenAIChatModel.test.cjs +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.test.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 +1 -1
- package/model-provider/openai-compatible/OpenAICompatibleFacade.d.ts +1 -1
- package/model-provider/openai-compatible/OpenAICompatibleFacade.js +1 -1
- package/package.json +1 -1
@@ -32,19 +32,6 @@ export interface AbstractOpenAIChatCallSettings {
|
|
32
32
|
name: string;
|
33
33
|
};
|
34
34
|
};
|
35
|
-
/**
|
36
|
-
* An array of strings or a single string that the model will recognize as end-of-text indicators.
|
37
|
-
* The model stops generating more content when it encounters any of these strings.
|
38
|
-
* This is particularly useful in scripted or formatted text generation, where a specific end point is required.
|
39
|
-
* Example: stop: ['\n', 'END']
|
40
|
-
*/
|
41
|
-
stop?: string | string[];
|
42
|
-
/**
|
43
|
-
* Specifies the maximum number of tokens (words, punctuation, parts of words) that the model can generate in a single response.
|
44
|
-
* It helps to control the length of the output, this can help prevent wasted time and tokens when tweaker topP or temperature.
|
45
|
-
* Example: maxTokens: 1000
|
46
|
-
*/
|
47
|
-
maxTokens?: number;
|
48
35
|
/**
|
49
36
|
* `temperature`: Controls the randomness and creativity in the model's responses.
|
50
37
|
* A lower temperature (close to 0) results in more predictable, conservative text, while a higher temperature (close to 1) produces more varied and creative output.
|
@@ -67,17 +54,6 @@ export interface AbstractOpenAIChatCallSettings {
|
|
67
54
|
* Example: seed: 89 (or) seed: null
|
68
55
|
*/
|
69
56
|
seed?: number | null;
|
70
|
-
responseFormat?: {
|
71
|
-
type?: "text" | "json_object";
|
72
|
-
};
|
73
|
-
/**
|
74
|
-
* Specifies the number of responses or completions the model should generate for a given prompt.
|
75
|
-
* This is useful when you need multiple different outputs or ideas for a single prompt.
|
76
|
-
* The model will generate 'n' distinct responses, each based on the same initial prompt.
|
77
|
-
* In a streaming model this will result in both responses streamed back in real time.
|
78
|
-
* Example: n: 3 // The model will produce 3 different responses.
|
79
|
-
*/
|
80
|
-
n?: number;
|
81
57
|
/**
|
82
58
|
* Discourages the model from repeating the same information or context already mentioned in the conversation or prompt.
|
83
59
|
* Increasing this value encourages the model to introduce new topics or ideas, rather than reiterating what has been said.
|
@@ -92,9 +68,12 @@ export interface AbstractOpenAIChatCallSettings {
|
|
92
68
|
* Example: frequencyPenalty: 0.5 // Moderately discourages repetitive language.
|
93
69
|
*/
|
94
70
|
frequencyPenalty?: number;
|
71
|
+
responseFormat?: {
|
72
|
+
type?: "text" | "json_object";
|
73
|
+
};
|
95
74
|
logitBias?: Record<number, number>;
|
96
75
|
}
|
97
|
-
export interface AbstractOpenAIChatSettings extends TextGenerationModelSettings,
|
76
|
+
export interface AbstractOpenAIChatSettings extends TextGenerationModelSettings, AbstractOpenAIChatCallSettings {
|
98
77
|
isUserIdForwardingEnabled?: boolean;
|
99
78
|
}
|
100
79
|
export type OpenAIChatPrompt = OpenAIChatMessage[];
|
@@ -113,7 +92,7 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
113
92
|
tools?: AbstractOpenAIChatCallSettings["tools"];
|
114
93
|
toolChoice?: AbstractOpenAIChatCallSettings["toolChoice"];
|
115
94
|
}): Promise<RESULT>;
|
116
|
-
|
95
|
+
doGenerateTexts(prompt: OpenAIChatPrompt, options?: FunctionOptions): Promise<{
|
117
96
|
response: {
|
118
97
|
object: "chat.completion";
|
119
98
|
usage: {
|
@@ -147,7 +126,7 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
147
126
|
}[];
|
148
127
|
system_fingerprint?: string | null | undefined;
|
149
128
|
};
|
150
|
-
|
129
|
+
texts: string[];
|
151
130
|
usage: {
|
152
131
|
promptTokens: number;
|
153
132
|
completionTokens: number;
|
@@ -17,38 +17,67 @@ export class AbstractOpenAIChatModel extends AbstractModel {
|
|
17
17
|
super({ settings });
|
18
18
|
}
|
19
19
|
async callAPI(messages, options) {
|
20
|
+
const api = this.settings.api ?? new OpenAIApiConfiguration();
|
21
|
+
const responseFormat = options.responseFormat;
|
22
|
+
const abortSignal = options.run?.abortSignal;
|
23
|
+
const user = this.settings.isUserIdForwardingEnabled
|
24
|
+
? options.run?.userId
|
25
|
+
: undefined;
|
26
|
+
const openAIResponseFormat = this.settings.responseFormat;
|
27
|
+
// function & tool calling:
|
28
|
+
const functions = options.functions ?? this.settings.functions;
|
29
|
+
const functionCall = options.functionCall ?? this.settings.functionCall;
|
30
|
+
const tools = options.tools ?? this.settings.tools;
|
31
|
+
const toolChoice = options.toolChoice ?? this.settings.toolChoice;
|
32
|
+
let { stopSequences } = this.settings;
|
20
33
|
return callWithRetryAndThrottle({
|
21
34
|
retry: this.settings.api?.retry,
|
22
35
|
throttle: this.settings.api?.throttle,
|
23
|
-
call: async () =>
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
call: async () => {
|
37
|
+
// empty arrays are not allowed for stopSequences:
|
38
|
+
if (stopSequences != null &&
|
39
|
+
Array.isArray(stopSequences) &&
|
40
|
+
stopSequences.length === 0) {
|
41
|
+
stopSequences = undefined;
|
42
|
+
}
|
43
|
+
return postJsonToApi({
|
44
|
+
url: api.assembleUrl("/chat/completions"),
|
45
|
+
headers: api.headers,
|
46
|
+
body: {
|
47
|
+
stream: responseFormat.stream,
|
48
|
+
model: this.settings.model,
|
49
|
+
messages,
|
50
|
+
functions,
|
51
|
+
function_call: functionCall,
|
52
|
+
tools,
|
53
|
+
tool_choice: toolChoice,
|
54
|
+
temperature: this.settings.temperature,
|
55
|
+
top_p: this.settings.topP,
|
56
|
+
n: this.settings.numberOfGenerations,
|
57
|
+
stop: this.settings.stopSequences,
|
58
|
+
max_tokens: this.settings.maxGenerationTokens,
|
59
|
+
presence_penalty: this.settings.presencePenalty,
|
60
|
+
frequency_penalty: this.settings.frequencyPenalty,
|
61
|
+
logit_bias: this.settings.logitBias,
|
62
|
+
seed: this.settings.seed,
|
63
|
+
response_format: openAIResponseFormat,
|
64
|
+
user,
|
65
|
+
},
|
66
|
+
failedResponseHandler: failedOpenAICallResponseHandler,
|
67
|
+
successfulResponseHandler: responseFormat.handler,
|
68
|
+
abortSignal,
|
69
|
+
});
|
70
|
+
},
|
42
71
|
});
|
43
72
|
}
|
44
|
-
async
|
73
|
+
async doGenerateTexts(prompt, options) {
|
45
74
|
const response = await this.callAPI(prompt, {
|
46
75
|
...options,
|
47
76
|
responseFormat: OpenAIChatResponseFormat.json,
|
48
77
|
});
|
49
78
|
return {
|
50
79
|
response,
|
51
|
-
|
80
|
+
texts: response.choices.map((choice) => choice.message.content ?? ""),
|
52
81
|
usage: this.extractUsage(response),
|
53
82
|
};
|
54
83
|
}
|
@@ -169,39 +198,6 @@ const openAIChatResponseSchema = z.object({
|
|
169
198
|
total_tokens: z.number(),
|
170
199
|
}),
|
171
200
|
});
|
172
|
-
async function callOpenAIChatCompletionAPI({ api = new OpenAIApiConfiguration(), abortSignal, responseFormat, model, messages, functions, functionCall, tools, toolChoice, temperature, topP, n, stop, maxTokens, presencePenalty, frequencyPenalty, logitBias, user, openAIResponseFormat, seed, }) {
|
173
|
-
// empty arrays are not allowed for stop:
|
174
|
-
if (stop != null && Array.isArray(stop) && stop.length === 0) {
|
175
|
-
stop = undefined;
|
176
|
-
}
|
177
|
-
return postJsonToApi({
|
178
|
-
url: api.assembleUrl("/chat/completions"),
|
179
|
-
headers: api.headers,
|
180
|
-
body: {
|
181
|
-
stream: responseFormat.stream,
|
182
|
-
model,
|
183
|
-
messages,
|
184
|
-
functions,
|
185
|
-
function_call: functionCall,
|
186
|
-
tools,
|
187
|
-
tool_choice: toolChoice,
|
188
|
-
temperature,
|
189
|
-
top_p: topP,
|
190
|
-
n,
|
191
|
-
stop,
|
192
|
-
max_tokens: maxTokens,
|
193
|
-
presence_penalty: presencePenalty,
|
194
|
-
frequency_penalty: frequencyPenalty,
|
195
|
-
logit_bias: logitBias,
|
196
|
-
seed,
|
197
|
-
response_format: openAIResponseFormat,
|
198
|
-
user,
|
199
|
-
},
|
200
|
-
failedResponseHandler: failedOpenAICallResponseHandler,
|
201
|
-
successfulResponseHandler: responseFormat.handler,
|
202
|
-
abortSignal,
|
203
|
-
});
|
204
|
-
}
|
205
201
|
export const OpenAIChatResponseFormat = {
|
206
202
|
/**
|
207
203
|
* Returns the response as a JSON object.
|
@@ -144,7 +144,7 @@ exports.calculateOpenAIChatCostInMillicents = calculateOpenAIChatCostInMillicent
|
|
144
144
|
* const model = new OpenAIChatModel({
|
145
145
|
* model: "gpt-3.5-turbo",
|
146
146
|
* temperature: 0.7,
|
147
|
-
*
|
147
|
+
* maxGenerationTokens: 500,
|
148
148
|
* });
|
149
149
|
*
|
150
150
|
* const text = await generateText([
|
@@ -196,13 +196,13 @@ class OpenAIChatModel extends AbstractOpenAIChatModel_js_1.AbstractOpenAIChatMod
|
|
196
196
|
}
|
197
197
|
get settingsForEvent() {
|
198
198
|
const eventSettingProperties = [
|
199
|
+
"maxGenerationTokens",
|
199
200
|
"stopSequences",
|
200
|
-
"
|
201
|
+
"numberOfGenerations",
|
201
202
|
"functions",
|
202
203
|
"functionCall",
|
203
204
|
"temperature",
|
204
205
|
"topP",
|
205
|
-
"n",
|
206
206
|
"presencePenalty",
|
207
207
|
"frequencyPenalty",
|
208
208
|
"logitBias",
|
@@ -117,7 +117,7 @@ export interface OpenAIChatSettings extends TextGenerationModelSettings, Omit<Op
|
|
117
117
|
* const model = new OpenAIChatModel({
|
118
118
|
* model: "gpt-3.5-turbo",
|
119
119
|
* temperature: 0.7,
|
120
|
-
*
|
120
|
+
* maxGenerationTokens: 500,
|
121
121
|
* });
|
122
122
|
*
|
123
123
|
* const text = await generateText([
|
@@ -138,7 +138,7 @@ export const calculateOpenAIChatCostInMillicents = ({ model, response, }) => {
|
|
138
138
|
* const model = new OpenAIChatModel({
|
139
139
|
* model: "gpt-3.5-turbo",
|
140
140
|
* temperature: 0.7,
|
141
|
-
*
|
141
|
+
* maxGenerationTokens: 500,
|
142
142
|
* });
|
143
143
|
*
|
144
144
|
* const text = await generateText([
|
@@ -190,13 +190,13 @@ export class OpenAIChatModel extends AbstractOpenAIChatModel {
|
|
190
190
|
}
|
191
191
|
get settingsForEvent() {
|
192
192
|
const eventSettingProperties = [
|
193
|
+
"maxGenerationTokens",
|
193
194
|
"stopSequences",
|
194
|
-
"
|
195
|
+
"numberOfGenerations",
|
195
196
|
"functions",
|
196
197
|
"functionCall",
|
197
198
|
"temperature",
|
198
199
|
"topP",
|
199
|
-
"n",
|
200
200
|
"presencePenalty",
|
201
201
|
"frequencyPenalty",
|
202
202
|
"logitBias",
|
@@ -50,7 +50,7 @@ describe("streamText", () => {
|
|
50
50
|
const stream = await (0, streamText_js_1.streamText)(new OpenAIChatModel_js_1.OpenAIChatModel({
|
51
51
|
api: new OpenAIApiConfiguration_js_1.OpenAIApiConfiguration({ apiKey: "test" }),
|
52
52
|
model: "gpt-3.5-turbo",
|
53
|
-
|
53
|
+
numberOfGenerations: 2,
|
54
54
|
}).withTextPrompt(), "test prompt");
|
55
55
|
const chunks = [];
|
56
56
|
for await (const part of stream) {
|
@@ -48,7 +48,7 @@ describe("streamText", () => {
|
|
48
48
|
const stream = await streamText(new OpenAIChatModel({
|
49
49
|
api: new OpenAIApiConfiguration({ apiKey: "test" }),
|
50
50
|
model: "gpt-3.5-turbo",
|
51
|
-
|
51
|
+
numberOfGenerations: 2,
|
52
52
|
}).withTextPrompt(), "test prompt");
|
53
53
|
const chunks = [];
|
54
54
|
for await (const part of stream) {
|
@@ -44,12 +44,12 @@ class OpenAICompatibleChatModel extends AbstractOpenAIChatModel_js_1.AbstractOpe
|
|
44
44
|
get settingsForEvent() {
|
45
45
|
const eventSettingProperties = [
|
46
46
|
"stopSequences",
|
47
|
-
"
|
47
|
+
"maxGenerationTokens",
|
48
|
+
"numberOfGenerations",
|
48
49
|
"functions",
|
49
50
|
"functionCall",
|
50
51
|
"temperature",
|
51
52
|
"topP",
|
52
|
-
"n",
|
53
53
|
"presencePenalty",
|
54
54
|
"frequencyPenalty",
|
55
55
|
"logitBias",
|
@@ -41,12 +41,12 @@ export class OpenAICompatibleChatModel extends AbstractOpenAIChatModel {
|
|
41
41
|
get settingsForEvent() {
|
42
42
|
const eventSettingProperties = [
|
43
43
|
"stopSequences",
|
44
|
-
"
|
44
|
+
"maxGenerationTokens",
|
45
|
+
"numberOfGenerations",
|
45
46
|
"functions",
|
46
47
|
"functionCall",
|
47
48
|
"temperature",
|
48
49
|
"topP",
|
49
|
-
"n",
|
50
50
|
"presencePenalty",
|
51
51
|
"frequencyPenalty",
|
52
52
|
"logitBias",
|
@@ -14,7 +14,7 @@ const OpenAICompatibleChatModel_js_1 = require("./OpenAICompatibleChatModel.cjs"
|
|
14
14
|
* const model = openaicompatible.ChatTextGenerator({
|
15
15
|
* model: "provider-specific-model-name",
|
16
16
|
* temperature: 0.7,
|
17
|
-
*
|
17
|
+
* maxGenerationTokens: 500,
|
18
18
|
* });
|
19
19
|
*
|
20
20
|
* const text = await generateText([
|
@@ -11,7 +11,7 @@ import { OpenAICompatibleChatModel, OpenAICompatibleChatSettings } from "./OpenA
|
|
11
11
|
* const model = openaicompatible.ChatTextGenerator({
|
12
12
|
* model: "provider-specific-model-name",
|
13
13
|
* temperature: 0.7,
|
14
|
-
*
|
14
|
+
* maxGenerationTokens: 500,
|
15
15
|
* });
|
16
16
|
*
|
17
17
|
* const text = await generateText([
|
@@ -11,7 +11,7 @@ import { OpenAICompatibleChatModel, } from "./OpenAICompatibleChatModel.js";
|
|
11
11
|
* const model = openaicompatible.ChatTextGenerator({
|
12
12
|
* model: "provider-specific-model-name",
|
13
13
|
* temperature: 0.7,
|
14
|
-
*
|
14
|
+
* maxGenerationTokens: 500,
|
15
15
|
* });
|
16
16
|
*
|
17
17
|
* const text = await generateText([
|