modelfusion 0.78.0 → 0.79.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/model-function/generate-text/PromptFormatTextGenerationModel.cjs +14 -0
- package/model-function/generate-text/PromptFormatTextGenerationModel.d.ts +4 -0
- package/model-function/generate-text/PromptFormatTextGenerationModel.js +14 -0
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.cjs +5 -2
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.js +5 -2
- package/model-provider/ollama/OllamaTextGenerationModel.cjs +7 -0
- package/model-provider/ollama/OllamaTextGenerationModel.d.ts +2 -0
- package/model-provider/ollama/OllamaTextGenerationModel.js +7 -0
- package/package.json +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.js +1 -1
- package/tool/{ToolCallParseError.cjs → generate-tool-call/ToolCallParseError.cjs} +1 -1
- package/tool/{ToolCallParseError.js → generate-tool-call/ToolCallParseError.js} +1 -1
- package/tool/generate-tool-call/index.cjs +1 -0
- package/tool/generate-tool-call/index.d.ts +1 -0
- package/tool/generate-tool-call/index.js +1 -0
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.cjs +60 -0
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.d.ts +41 -0
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js +56 -0
- package/tool/generate-tool-calls-or-text/ToolCallsOrTextParseError.cjs +36 -0
- package/tool/generate-tool-calls-or-text/ToolCallsOrTextParseError.d.ts +15 -0
- package/tool/generate-tool-calls-or-text/ToolCallsOrTextParseError.js +32 -0
- package/tool/generate-tool-calls-or-text/index.cjs +2 -0
- package/tool/generate-tool-calls-or-text/index.d.ts +2 -0
- package/tool/generate-tool-calls-or-text/index.js +2 -0
- /package/tool/{ToolCallParseError.d.ts → generate-tool-call/ToolCallParseError.d.ts} +0 -0
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.PromptFormatTextGenerationModel = void 0;
|
4
|
+
const TextGenerationToolCallModel_js_1 = require("../../tool/generate-tool-call/TextGenerationToolCallModel.cjs");
|
5
|
+
const TextGenerationToolCallsOrGenerateTextModel_js_1 = require("../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.cjs");
|
4
6
|
class PromptFormatTextGenerationModel {
|
5
7
|
constructor({ model, promptFormat, }) {
|
6
8
|
Object.defineProperty(this, "model", {
|
@@ -44,6 +46,18 @@ class PromptFormatTextGenerationModel {
|
|
44
46
|
get settingsForEvent() {
|
45
47
|
return this.model.settingsForEvent;
|
46
48
|
}
|
49
|
+
asToolCallGenerationModel(promptFormat) {
|
50
|
+
return new TextGenerationToolCallModel_js_1.TextGenerationToolCallModel({
|
51
|
+
model: this,
|
52
|
+
format: promptFormat,
|
53
|
+
});
|
54
|
+
}
|
55
|
+
asToolCallsOrTextGenerationModel(promptFormat) {
|
56
|
+
return new TextGenerationToolCallsOrGenerateTextModel_js_1.TextGenerationToolCallsOrGenerateTextModel({
|
57
|
+
model: this,
|
58
|
+
format: promptFormat,
|
59
|
+
});
|
60
|
+
}
|
47
61
|
withPromptFormat(promptFormat) {
|
48
62
|
return new PromptFormatTextGenerationModel({
|
49
63
|
model: this.withSettings({
|
@@ -1,4 +1,6 @@
|
|
1
1
|
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
2
|
+
import { TextGenerationToolCallModel, ToolCallPromptFormat } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
3
|
+
import { TextGenerationToolCallsOrGenerateTextModel, ToolCallsOrGenerateTextPromptFormat } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
2
4
|
import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerationModel.js";
|
3
5
|
import { TextGenerationPromptFormat } from "./TextGenerationPromptFormat.js";
|
4
6
|
export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, SETTINGS extends TextGenerationModelSettings, MODEL extends TextGenerationModel<MODEL_PROMPT, SETTINGS>> implements TextGenerationModel<PROMPT, SETTINGS> {
|
@@ -23,6 +25,8 @@ export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, SETTI
|
|
23
25
|
} | undefined;
|
24
26
|
}>;
|
25
27
|
get settingsForEvent(): Partial<SETTINGS>;
|
28
|
+
asToolCallGenerationModel<INPUT_PROMPT>(promptFormat: ToolCallPromptFormat<INPUT_PROMPT, PROMPT>): TextGenerationToolCallModel<INPUT_PROMPT, PROMPT, this>;
|
29
|
+
asToolCallsOrTextGenerationModel<INPUT_PROMPT>(promptFormat: ToolCallsOrGenerateTextPromptFormat<INPUT_PROMPT, PROMPT>): TextGenerationToolCallsOrGenerateTextModel<INPUT_PROMPT, PROMPT, this>;
|
26
30
|
withPromptFormat<INPUT_PROMPT>(promptFormat: TextGenerationPromptFormat<INPUT_PROMPT, PROMPT>): PromptFormatTextGenerationModel<INPUT_PROMPT, PROMPT, SETTINGS, this>;
|
27
31
|
withSettings(additionalSettings: Partial<SETTINGS>): this;
|
28
32
|
}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import { TextGenerationToolCallModel, } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
2
|
+
import { TextGenerationToolCallsOrGenerateTextModel, } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
1
3
|
export class PromptFormatTextGenerationModel {
|
2
4
|
constructor({ model, promptFormat, }) {
|
3
5
|
Object.defineProperty(this, "model", {
|
@@ -41,6 +43,18 @@ export class PromptFormatTextGenerationModel {
|
|
41
43
|
get settingsForEvent() {
|
42
44
|
return this.model.settingsForEvent;
|
43
45
|
}
|
46
|
+
asToolCallGenerationModel(promptFormat) {
|
47
|
+
return new TextGenerationToolCallModel({
|
48
|
+
model: this,
|
49
|
+
format: promptFormat,
|
50
|
+
});
|
51
|
+
}
|
52
|
+
asToolCallsOrTextGenerationModel(promptFormat) {
|
53
|
+
return new TextGenerationToolCallsOrGenerateTextModel({
|
54
|
+
model: this,
|
55
|
+
format: promptFormat,
|
56
|
+
});
|
57
|
+
}
|
44
58
|
withPromptFormat(promptFormat) {
|
45
59
|
return new PromptFormatTextGenerationModel({
|
46
60
|
model: this.withSettings({
|
@@ -16,7 +16,9 @@ function chatMLSegment(role, text) {
|
|
16
16
|
function text() {
|
17
17
|
return {
|
18
18
|
stopSequences: [END_SEGMENT],
|
19
|
-
format: (instruction) =>
|
19
|
+
format: (instruction) =>
|
20
|
+
// prompt and then prefix start of assistant response:
|
21
|
+
chatMLSegment("user", instruction) + chatMLStart("assistant"),
|
20
22
|
};
|
21
23
|
}
|
22
24
|
exports.text = text;
|
@@ -37,7 +39,8 @@ function instruction() {
|
|
37
39
|
return {
|
38
40
|
stopSequences: [END_SEGMENT],
|
39
41
|
format: (instruction) => chatMLSegment("system", instruction.system) +
|
40
|
-
chatMLSegment("user", instruction.instruction)
|
42
|
+
chatMLSegment("user", instruction.instruction) +
|
43
|
+
chatMLStart("assistant"), // prefix start of assistant response
|
41
44
|
};
|
42
45
|
}
|
43
46
|
exports.instruction = instruction;
|
@@ -13,7 +13,9 @@ function chatMLSegment(role, text) {
|
|
13
13
|
export function text() {
|
14
14
|
return {
|
15
15
|
stopSequences: [END_SEGMENT],
|
16
|
-
format: (instruction) =>
|
16
|
+
format: (instruction) =>
|
17
|
+
// prompt and then prefix start of assistant response:
|
18
|
+
chatMLSegment("user", instruction) + chatMLStart("assistant"),
|
17
19
|
};
|
18
20
|
}
|
19
21
|
/**
|
@@ -33,7 +35,8 @@ export function instruction() {
|
|
33
35
|
return {
|
34
36
|
stopSequences: [END_SEGMENT],
|
35
37
|
format: (instruction) => chatMLSegment("system", instruction.system) +
|
36
|
-
chatMLSegment("user", instruction.instruction)
|
38
|
+
chatMLSegment("user", instruction.instruction) +
|
39
|
+
chatMLStart("assistant"), // prefix start of assistant response
|
37
40
|
};
|
38
41
|
}
|
39
42
|
/**
|
@@ -8,6 +8,7 @@ const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
|
8
8
|
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
9
9
|
const PromptFormatTextStreamingModel_js_1 = require("../../model-function/generate-text/PromptFormatTextStreamingModel.cjs");
|
10
10
|
const TextGenerationToolCallModel_js_1 = require("../../tool/generate-tool-call/TextGenerationToolCallModel.cjs");
|
11
|
+
const TextGenerationToolCallsOrGenerateTextModel_js_1 = require("../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.cjs");
|
11
12
|
const AsyncQueue_js_1 = require("../../util/AsyncQueue.cjs");
|
12
13
|
const parseJsonStream_js_1 = require("../../util/streaming/parseJsonStream.cjs");
|
13
14
|
const OllamaApiConfiguration_js_1 = require("./OllamaApiConfiguration.cjs");
|
@@ -101,6 +102,12 @@ class OllamaTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
101
102
|
format: promptFormat,
|
102
103
|
});
|
103
104
|
}
|
105
|
+
asToolCallsOrTextGenerationModel(promptFormat) {
|
106
|
+
return new TextGenerationToolCallsOrGenerateTextModel_js_1.TextGenerationToolCallsOrGenerateTextModel({
|
107
|
+
model: this,
|
108
|
+
format: promptFormat,
|
109
|
+
});
|
110
|
+
}
|
104
111
|
withPromptFormat(promptFormat) {
|
105
112
|
return new PromptFormatTextStreamingModel_js_1.PromptFormatTextStreamingModel({
|
106
113
|
model: this.withSettings({
|
@@ -8,6 +8,7 @@ import { PromptFormatTextStreamingModel } from "../../model-function/generate-te
|
|
8
8
|
import { TextGenerationModelSettings, TextStreamingModel } from "../../model-function/generate-text/TextGenerationModel.js";
|
9
9
|
import { TextGenerationPromptFormat } from "../../model-function/generate-text/TextGenerationPromptFormat.js";
|
10
10
|
import { TextGenerationToolCallModel, ToolCallPromptFormat } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
11
|
+
import { TextGenerationToolCallsOrGenerateTextModel, ToolCallsOrGenerateTextPromptFormat } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
11
12
|
/**
|
12
13
|
* @see https://github.com/jmorganca/ollama/blob/main/docs/api.md#generate-a-completion
|
13
14
|
*/
|
@@ -137,6 +138,7 @@ export declare class OllamaTextGenerationModel<CONTEXT_WINDOW_SIZE extends numbe
|
|
137
138
|
}>;
|
138
139
|
doStreamText(prompt: string, options?: FunctionOptions): Promise<AsyncIterable<Delta<string>>>;
|
139
140
|
asToolCallGenerationModel<INPUT_PROMPT>(promptFormat: ToolCallPromptFormat<INPUT_PROMPT, string>): TextGenerationToolCallModel<INPUT_PROMPT, string, this>;
|
141
|
+
asToolCallsOrTextGenerationModel<INPUT_PROMPT>(promptFormat: ToolCallsOrGenerateTextPromptFormat<INPUT_PROMPT, string>): TextGenerationToolCallsOrGenerateTextModel<INPUT_PROMPT, string, this>;
|
140
142
|
withPromptFormat<INPUT_PROMPT>(promptFormat: TextGenerationPromptFormat<INPUT_PROMPT, string>): PromptFormatTextStreamingModel<INPUT_PROMPT, string, OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>, this>;
|
141
143
|
withSettings(additionalSettings: Partial<OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>>): this;
|
142
144
|
}
|
@@ -5,6 +5,7 @@ import { ZodSchema } from "../../core/schema/ZodSchema.js";
|
|
5
5
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
6
6
|
import { PromptFormatTextStreamingModel } from "../../model-function/generate-text/PromptFormatTextStreamingModel.js";
|
7
7
|
import { TextGenerationToolCallModel, } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
8
|
+
import { TextGenerationToolCallsOrGenerateTextModel, } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
8
9
|
import { AsyncQueue } from "../../util/AsyncQueue.js";
|
9
10
|
import { parseJsonStream } from "../../util/streaming/parseJsonStream.js";
|
10
11
|
import { OllamaApiConfiguration } from "./OllamaApiConfiguration.js";
|
@@ -98,6 +99,12 @@ export class OllamaTextGenerationModel extends AbstractModel {
|
|
98
99
|
format: promptFormat,
|
99
100
|
});
|
100
101
|
}
|
102
|
+
asToolCallsOrTextGenerationModel(promptFormat) {
|
103
|
+
return new TextGenerationToolCallsOrGenerateTextModel({
|
104
|
+
model: this,
|
105
|
+
format: promptFormat,
|
106
|
+
});
|
107
|
+
}
|
101
108
|
withPromptFormat(promptFormat) {
|
102
109
|
return new PromptFormatTextStreamingModel({
|
103
110
|
model: this.withSettings({
|
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.TextGenerationToolCallModel = void 0;
|
4
4
|
const generateText_js_1 = require("../../model-function/generate-text/generateText.cjs");
|
5
|
-
const ToolCallParseError_js_1 = require("
|
5
|
+
const ToolCallParseError_js_1 = require("./ToolCallParseError.cjs");
|
6
6
|
class TextGenerationToolCallModel {
|
7
7
|
constructor({ model, format, }) {
|
8
8
|
Object.defineProperty(this, "model", {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { generateText } from "../../model-function/generate-text/generateText.js";
|
2
|
-
import { ToolCallParseError } from "
|
2
|
+
import { ToolCallParseError } from "./ToolCallParseError.js";
|
3
3
|
export class TextGenerationToolCallModel {
|
4
4
|
constructor({ model, format, }) {
|
5
5
|
Object.defineProperty(this, "model", {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.ToolCallParseError = void 0;
|
4
|
-
const getErrorMessage_js_1 = require("
|
4
|
+
const getErrorMessage_js_1 = require("../../util/getErrorMessage.cjs");
|
5
5
|
class ToolCallParseError extends Error {
|
6
6
|
constructor({ toolName, valueText, cause, }) {
|
7
7
|
super(`Tool call parsing failed for '${toolName}'. ` +
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { getErrorMessage } from "
|
1
|
+
import { getErrorMessage } from "../../util/getErrorMessage.js";
|
2
2
|
export class ToolCallParseError extends Error {
|
3
3
|
constructor({ toolName, valueText, cause, }) {
|
4
4
|
super(`Tool call parsing failed for '${toolName}'. ` +
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./TextGenerationToolCallModel.cjs"), exports);
|
18
18
|
__exportStar(require("./ToolCallGenerationEvent.cjs"), exports);
|
19
19
|
__exportStar(require("./ToolCallGenerationModel.cjs"), exports);
|
20
|
+
__exportStar(require("./ToolCallParseError.cjs"), exports);
|
20
21
|
__exportStar(require("./generateToolCall.cjs"), exports);
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TextGenerationToolCallsOrGenerateTextModel = void 0;
|
4
|
+
const generateText_js_1 = require("../../model-function/generate-text/generateText.cjs");
|
5
|
+
const ToolCallsOrTextParseError_js_1 = require("./ToolCallsOrTextParseError.cjs");
|
6
|
+
class TextGenerationToolCallsOrGenerateTextModel {
|
7
|
+
constructor({ model, format, }) {
|
8
|
+
Object.defineProperty(this, "model", {
|
9
|
+
enumerable: true,
|
10
|
+
configurable: true,
|
11
|
+
writable: true,
|
12
|
+
value: void 0
|
13
|
+
});
|
14
|
+
Object.defineProperty(this, "format", {
|
15
|
+
enumerable: true,
|
16
|
+
configurable: true,
|
17
|
+
writable: true,
|
18
|
+
value: void 0
|
19
|
+
});
|
20
|
+
this.model = model;
|
21
|
+
this.format = format;
|
22
|
+
}
|
23
|
+
get modelInformation() {
|
24
|
+
return this.model.modelInformation;
|
25
|
+
}
|
26
|
+
get settings() {
|
27
|
+
return this.model.settings;
|
28
|
+
}
|
29
|
+
get settingsForEvent() {
|
30
|
+
return this.model.settingsForEvent;
|
31
|
+
}
|
32
|
+
async doGenerateToolCallsOrText(tools, prompt, options) {
|
33
|
+
const { response, value, metadata } = await (0, generateText_js_1.generateText)(this.model, this.format.createPrompt(prompt, tools), {
|
34
|
+
...options,
|
35
|
+
returnType: "full",
|
36
|
+
});
|
37
|
+
try {
|
38
|
+
const { text, toolCalls } = this.format.extractToolCallsAndText(value);
|
39
|
+
return {
|
40
|
+
response,
|
41
|
+
text,
|
42
|
+
toolCalls,
|
43
|
+
usage: metadata?.usage,
|
44
|
+
};
|
45
|
+
}
|
46
|
+
catch (error) {
|
47
|
+
throw new ToolCallsOrTextParseError_js_1.ToolCallsOrTextParseError({
|
48
|
+
valueText: value,
|
49
|
+
cause: error,
|
50
|
+
});
|
51
|
+
}
|
52
|
+
}
|
53
|
+
withSettings(additionalSettings) {
|
54
|
+
return new TextGenerationToolCallsOrGenerateTextModel({
|
55
|
+
model: this.model.withSettings(additionalSettings),
|
56
|
+
format: this.format,
|
57
|
+
});
|
58
|
+
}
|
59
|
+
}
|
60
|
+
exports.TextGenerationToolCallsOrGenerateTextModel = TextGenerationToolCallsOrGenerateTextModel;
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
2
|
+
import { TextGenerationModel } from "../../model-function/generate-text/TextGenerationModel.js";
|
3
|
+
import { ToolDefinition } from "../ToolDefinition.js";
|
4
|
+
import { ToolCallsOrTextGenerationModel, ToolCallsOrTextGenerationModelSettings } from "./ToolCallsOrTextGenerationModel.js";
|
5
|
+
export interface ToolCallsOrGenerateTextPromptFormat<SOURCE_PROMPT, TARGET_PROMPT> {
|
6
|
+
createPrompt: (prompt: SOURCE_PROMPT, tools: Array<ToolDefinition<string, unknown>>) => TARGET_PROMPT;
|
7
|
+
extractToolCallsAndText: (response: string) => {
|
8
|
+
text: string | null;
|
9
|
+
toolCalls: Array<{
|
10
|
+
id: string;
|
11
|
+
name: string;
|
12
|
+
args: unknown;
|
13
|
+
}> | null;
|
14
|
+
};
|
15
|
+
}
|
16
|
+
export declare class TextGenerationToolCallsOrGenerateTextModel<SOURCE_PROMPT, TARGET_PROMPT, MODEL extends TextGenerationModel<TARGET_PROMPT, ToolCallsOrTextGenerationModelSettings>> implements ToolCallsOrTextGenerationModel<SOURCE_PROMPT, MODEL["settings"]> {
|
17
|
+
private readonly model;
|
18
|
+
private readonly format;
|
19
|
+
constructor({ model, format, }: {
|
20
|
+
model: MODEL;
|
21
|
+
format: ToolCallsOrGenerateTextPromptFormat<SOURCE_PROMPT, TARGET_PROMPT>;
|
22
|
+
});
|
23
|
+
get modelInformation(): import("../../index.js").ModelInformation;
|
24
|
+
get settings(): ToolCallsOrTextGenerationModelSettings;
|
25
|
+
get settingsForEvent(): Partial<MODEL["settings"]>;
|
26
|
+
doGenerateToolCallsOrText(tools: Array<ToolDefinition<string, unknown>>, prompt: SOURCE_PROMPT, options?: FunctionOptions): Promise<{
|
27
|
+
response: unknown;
|
28
|
+
text: string | null;
|
29
|
+
toolCalls: {
|
30
|
+
id: string;
|
31
|
+
name: string;
|
32
|
+
args: unknown;
|
33
|
+
}[] | null;
|
34
|
+
usage: {
|
35
|
+
promptTokens: number;
|
36
|
+
completionTokens: number;
|
37
|
+
totalTokens: number;
|
38
|
+
} | undefined;
|
39
|
+
}>;
|
40
|
+
withSettings(additionalSettings: Partial<MODEL["settings"]>): this;
|
41
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import { generateText } from "../../model-function/generate-text/generateText.js";
|
2
|
+
import { ToolCallsOrTextParseError } from "./ToolCallsOrTextParseError.js";
|
3
|
+
export class TextGenerationToolCallsOrGenerateTextModel {
|
4
|
+
constructor({ model, format, }) {
|
5
|
+
Object.defineProperty(this, "model", {
|
6
|
+
enumerable: true,
|
7
|
+
configurable: true,
|
8
|
+
writable: true,
|
9
|
+
value: void 0
|
10
|
+
});
|
11
|
+
Object.defineProperty(this, "format", {
|
12
|
+
enumerable: true,
|
13
|
+
configurable: true,
|
14
|
+
writable: true,
|
15
|
+
value: void 0
|
16
|
+
});
|
17
|
+
this.model = model;
|
18
|
+
this.format = format;
|
19
|
+
}
|
20
|
+
get modelInformation() {
|
21
|
+
return this.model.modelInformation;
|
22
|
+
}
|
23
|
+
get settings() {
|
24
|
+
return this.model.settings;
|
25
|
+
}
|
26
|
+
get settingsForEvent() {
|
27
|
+
return this.model.settingsForEvent;
|
28
|
+
}
|
29
|
+
async doGenerateToolCallsOrText(tools, prompt, options) {
|
30
|
+
const { response, value, metadata } = await generateText(this.model, this.format.createPrompt(prompt, tools), {
|
31
|
+
...options,
|
32
|
+
returnType: "full",
|
33
|
+
});
|
34
|
+
try {
|
35
|
+
const { text, toolCalls } = this.format.extractToolCallsAndText(value);
|
36
|
+
return {
|
37
|
+
response,
|
38
|
+
text,
|
39
|
+
toolCalls,
|
40
|
+
usage: metadata?.usage,
|
41
|
+
};
|
42
|
+
}
|
43
|
+
catch (error) {
|
44
|
+
throw new ToolCallsOrTextParseError({
|
45
|
+
valueText: value,
|
46
|
+
cause: error,
|
47
|
+
});
|
48
|
+
}
|
49
|
+
}
|
50
|
+
withSettings(additionalSettings) {
|
51
|
+
return new TextGenerationToolCallsOrGenerateTextModel({
|
52
|
+
model: this.model.withSettings(additionalSettings),
|
53
|
+
format: this.format,
|
54
|
+
});
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ToolCallsOrTextParseError = void 0;
|
4
|
+
const getErrorMessage_js_1 = require("../../util/getErrorMessage.cjs");
|
5
|
+
class ToolCallsOrTextParseError extends Error {
|
6
|
+
constructor({ valueText, cause }) {
|
7
|
+
super(`Tool calls or text parsing failed. ` +
|
8
|
+
`Value: ${valueText}.\n` +
|
9
|
+
`Error message: ${(0, getErrorMessage_js_1.getErrorMessage)(cause)}`);
|
10
|
+
Object.defineProperty(this, "valueText", {
|
11
|
+
enumerable: true,
|
12
|
+
configurable: true,
|
13
|
+
writable: true,
|
14
|
+
value: void 0
|
15
|
+
});
|
16
|
+
Object.defineProperty(this, "cause", {
|
17
|
+
enumerable: true,
|
18
|
+
configurable: true,
|
19
|
+
writable: true,
|
20
|
+
value: void 0
|
21
|
+
});
|
22
|
+
this.name = "ToolCallsOrTextParseError";
|
23
|
+
this.cause = cause;
|
24
|
+
this.valueText = valueText;
|
25
|
+
}
|
26
|
+
toJSON() {
|
27
|
+
return {
|
28
|
+
name: this.name,
|
29
|
+
cause: this.cause,
|
30
|
+
message: this.message,
|
31
|
+
stack: this.stack,
|
32
|
+
valueText: this.valueText,
|
33
|
+
};
|
34
|
+
}
|
35
|
+
}
|
36
|
+
exports.ToolCallsOrTextParseError = ToolCallsOrTextParseError;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export declare class ToolCallsOrTextParseError extends Error {
|
2
|
+
readonly valueText: string;
|
3
|
+
readonly cause: unknown;
|
4
|
+
constructor({ valueText, cause }: {
|
5
|
+
valueText: string;
|
6
|
+
cause: unknown;
|
7
|
+
});
|
8
|
+
toJSON(): {
|
9
|
+
name: string;
|
10
|
+
cause: unknown;
|
11
|
+
message: string;
|
12
|
+
stack: string | undefined;
|
13
|
+
valueText: string;
|
14
|
+
};
|
15
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { getErrorMessage } from "../../util/getErrorMessage.js";
|
2
|
+
export class ToolCallsOrTextParseError extends Error {
|
3
|
+
constructor({ valueText, cause }) {
|
4
|
+
super(`Tool calls or text parsing failed. ` +
|
5
|
+
`Value: ${valueText}.\n` +
|
6
|
+
`Error message: ${getErrorMessage(cause)}`);
|
7
|
+
Object.defineProperty(this, "valueText", {
|
8
|
+
enumerable: true,
|
9
|
+
configurable: true,
|
10
|
+
writable: true,
|
11
|
+
value: void 0
|
12
|
+
});
|
13
|
+
Object.defineProperty(this, "cause", {
|
14
|
+
enumerable: true,
|
15
|
+
configurable: true,
|
16
|
+
writable: true,
|
17
|
+
value: void 0
|
18
|
+
});
|
19
|
+
this.name = "ToolCallsOrTextParseError";
|
20
|
+
this.cause = cause;
|
21
|
+
this.valueText = valueText;
|
22
|
+
}
|
23
|
+
toJSON() {
|
24
|
+
return {
|
25
|
+
name: this.name,
|
26
|
+
cause: this.cause,
|
27
|
+
message: this.message,
|
28
|
+
stack: this.stack,
|
29
|
+
valueText: this.valueText,
|
30
|
+
};
|
31
|
+
}
|
32
|
+
}
|
@@ -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("./TextGenerationToolCallsOrGenerateTextModel.cjs"), exports);
|
17
18
|
__exportStar(require("./ToolCallsOrTextGenerationEvent.cjs"), exports);
|
18
19
|
__exportStar(require("./ToolCallsOrTextGenerationModel.cjs"), exports);
|
20
|
+
__exportStar(require("./ToolCallsOrTextParseError.cjs"), exports);
|
19
21
|
__exportStar(require("./generateToolCallsOrText.cjs"), exports);
|
@@ -1,3 +1,5 @@
|
|
1
|
+
export * from "./TextGenerationToolCallsOrGenerateTextModel.js";
|
1
2
|
export * from "./ToolCallsOrTextGenerationEvent.js";
|
2
3
|
export * from "./ToolCallsOrTextGenerationModel.js";
|
4
|
+
export * from "./ToolCallsOrTextParseError.js";
|
3
5
|
export * from "./generateToolCallsOrText.js";
|
@@ -1,3 +1,5 @@
|
|
1
|
+
export * from "./TextGenerationToolCallsOrGenerateTextModel.js";
|
1
2
|
export * from "./ToolCallsOrTextGenerationEvent.js";
|
2
3
|
export * from "./ToolCallsOrTextGenerationModel.js";
|
4
|
+
export * from "./ToolCallsOrTextParseError.js";
|
3
5
|
export * from "./generateToolCallsOrText.js";
|
File without changes
|