modelfusion 0.34.0 → 0.35.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 +47 -1
- package/model-function/AsyncIterableResultPromise.cjs +37 -0
- package/model-function/AsyncIterableResultPromise.d.ts +16 -0
- package/model-function/AsyncIterableResultPromise.js +33 -0
- package/model-function/{generate-text/DeltaEvent.d.ts → DeltaEvent.d.ts} +1 -1
- package/model-function/ModelCallEvent.d.ts +3 -2
- package/model-function/generate-structure/StructureFromTextGenerationModel.d.ts +1 -1
- package/model-function/generate-structure/StructureGenerationModel.d.ts +10 -1
- package/model-function/generate-structure/StructureStreamingEvent.cjs +2 -0
- package/model-function/generate-structure/StructureStreamingEvent.d.ts +7 -0
- package/model-function/generate-structure/StructureStreamingEvent.js +1 -0
- package/model-function/generate-structure/fixJson.cjs +215 -0
- package/model-function/generate-structure/fixJson.d.ts +1 -0
- package/model-function/generate-structure/fixJson.js +211 -0
- package/model-function/generate-structure/fixJson.test.cjs +130 -0
- package/model-function/generate-structure/fixJson.test.d.ts +1 -0
- package/model-function/generate-structure/fixJson.test.js +128 -0
- package/model-function/generate-structure/generateStructure.cjs +3 -1
- package/model-function/generate-structure/generateStructure.d.ts +1 -1
- package/model-function/generate-structure/generateStructure.js +3 -1
- package/model-function/generate-structure/parsePartialJson.cjs +29 -0
- package/model-function/generate-structure/parsePartialJson.d.ts +1 -0
- package/model-function/generate-structure/parsePartialJson.js +22 -0
- package/model-function/generate-structure/streamStructure.cjs +167 -0
- package/model-function/generate-structure/streamStructure.d.ts +17 -0
- package/model-function/generate-structure/streamStructure.js +160 -0
- package/model-function/generate-text/TextGenerationModel.d.ts +4 -4
- package/model-function/generate-text/streamText.cjs +47 -68
- package/model-function/generate-text/streamText.d.ts +3 -18
- package/model-function/generate-text/streamText.js +46 -66
- package/model-function/index.cjs +3 -1
- package/model-function/index.d.ts +3 -1
- package/model-function/index.js +3 -1
- package/model-provider/cohere/CohereTextGenerationModel.cjs +3 -3
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextGenerationModel.js +3 -3
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +0 -12
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +0 -2
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +0 -12
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +3 -3
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +3 -3
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +3 -3
- package/model-provider/openai/OpenAITextGenerationModel.cjs +3 -3
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +3 -3
- package/model-provider/openai/OpenAITextGenerationModel.js +3 -3
- package/model-provider/openai/chat/OpenAIChatModel.cjs +23 -2
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +4 -2
- package/model-provider/openai/chat/OpenAIChatModel.js +23 -2
- package/model-provider/openai/chat/OpenAIChatStreamIterable.d.ts +1 -1
- package/package.json +8 -4
- package/prompt/PromptFormatTextGenerationModel.d.ts +1 -1
- package/tool/useTool.cjs +3 -4
- package/tool/useTool.d.ts +1 -1
- package/tool/useTool.js +3 -4
- package/model-function/generate-text/extractTextDeltas.cjs +0 -23
- package/model-function/generate-text/extractTextDeltas.d.ts +0 -7
- package/model-function/generate-text/extractTextDeltas.js +0 -19
- /package/model-function/{generate-text/DeltaEvent.cjs → DeltaEvent.cjs} +0 -0
- /package/model-function/{generate-text/DeltaEvent.js → DeltaEvent.js} +0 -0
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.LlamaCppTextGenerationResponseFormat = exports.LlamaCppTextGenerationModel = void 0;
|
7
7
|
const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
|
8
8
|
const zod_1 = __importDefault(require("zod"));
|
9
|
-
const
|
9
|
+
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
10
|
+
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
10
11
|
const AsyncQueue_js_1 = require("../../event-source/AsyncQueue.cjs");
|
11
12
|
const parseEventSourceStream_js_1 = require("../../event-source/parseEventSourceStream.cjs");
|
13
|
+
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
12
14
|
const PromptFormatTextGenerationModel_js_1 = require("../../prompt/PromptFormatTextGenerationModel.cjs");
|
13
|
-
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
14
|
-
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
15
15
|
const LlamaCppApiConfiguration_js_1 = require("./LlamaCppApiConfiguration.cjs");
|
16
16
|
const LlamaCppError_js_1 = require("./LlamaCppError.cjs");
|
17
17
|
const LlamaCppTokenizer_js_1 = require("./LlamaCppTokenizer.cjs");
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import z from "zod";
|
2
|
-
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
3
2
|
import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
|
3
|
+
import { ResponseHandler } from "../../core/api/postToApi.js";
|
4
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
5
|
+
import { DeltaEvent } from "../../model-function/DeltaEvent.js";
|
4
6
|
import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
|
5
|
-
import { DeltaEvent } from "../../model-function/generate-text/DeltaEvent.js";
|
6
7
|
import { TextGenerationModel, TextGenerationModelSettings } from "../../model-function/generate-text/TextGenerationModel.js";
|
7
8
|
import { PromptFormat } from "../../prompt/PromptFormat.js";
|
8
9
|
import { PromptFormatTextGenerationModel } from "../../prompt/PromptFormatTextGenerationModel.js";
|
9
|
-
import { ResponseHandler } from "../../core/api/postToApi.js";
|
10
10
|
import { LlamaCppTokenizer } from "./LlamaCppTokenizer.js";
|
11
11
|
export interface LlamaCppTextGenerationModelSettings<CONTEXT_WINDOW_SIZE extends number | undefined> extends TextGenerationModelSettings {
|
12
12
|
api?: ApiConfiguration;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import SecureJSON from "secure-json-parse";
|
2
2
|
import z from "zod";
|
3
|
-
import {
|
3
|
+
import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
|
4
|
+
import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
|
4
5
|
import { AsyncQueue } from "../../event-source/AsyncQueue.js";
|
5
6
|
import { parseEventSourceStream } from "../../event-source/parseEventSourceStream.js";
|
7
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
6
8
|
import { PromptFormatTextGenerationModel } from "../../prompt/PromptFormatTextGenerationModel.js";
|
7
|
-
import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
|
8
|
-
import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
|
9
9
|
import { LlamaCppApiConfiguration } from "./LlamaCppApiConfiguration.js";
|
10
10
|
import { failedLlamaCppCallResponseHandler } from "./LlamaCppError.js";
|
11
11
|
import { LlamaCppTokenizer } from "./LlamaCppTokenizer.js";
|
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.OpenAITextResponseFormat = exports.OpenAITextGenerationModel = exports.calculateOpenAITextGenerationCostInMillicents = exports.isOpenAITextGenerationModel = exports.getOpenAITextGenerationModelInformation = exports.OPENAI_TEXT_GENERATION_MODELS = void 0;
|
7
7
|
const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
|
8
8
|
const zod_1 = __importDefault(require("zod"));
|
9
|
-
const
|
9
|
+
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
10
|
+
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
10
11
|
const AsyncQueue_js_1 = require("../../event-source/AsyncQueue.cjs");
|
11
12
|
const parseEventSourceStream_js_1 = require("../../event-source/parseEventSourceStream.cjs");
|
13
|
+
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
12
14
|
const countTokens_js_1 = require("../../model-function/tokenize-text/countTokens.cjs");
|
13
15
|
const PromptFormatTextGenerationModel_js_1 = require("../../prompt/PromptFormatTextGenerationModel.cjs");
|
14
|
-
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
15
|
-
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
16
16
|
const OpenAIApiConfiguration_js_1 = require("./OpenAIApiConfiguration.cjs");
|
17
17
|
const OpenAIError_js_1 = require("./OpenAIError.cjs");
|
18
18
|
const TikTokenTokenizer_js_1 = require("./TikTokenTokenizer.cjs");
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import z from "zod";
|
2
|
+
import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
|
3
|
+
import { ResponseHandler } from "../../core/api/postToApi.js";
|
2
4
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
5
|
+
import { DeltaEvent } from "../../model-function/DeltaEvent.js";
|
3
6
|
import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
|
4
|
-
import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
|
5
|
-
import { DeltaEvent } from "../../model-function/generate-text/DeltaEvent.js";
|
6
7
|
import { TextGenerationModel, TextGenerationModelSettings } from "../../model-function/generate-text/TextGenerationModel.js";
|
7
8
|
import { PromptFormat } from "../../prompt/PromptFormat.js";
|
8
9
|
import { PromptFormatTextGenerationModel } from "../../prompt/PromptFormatTextGenerationModel.js";
|
9
|
-
import { ResponseHandler } from "../../core/api/postToApi.js";
|
10
10
|
import { OpenAIImageGenerationCallSettings } from "./OpenAIImageGenerationModel.js";
|
11
11
|
import { TikTokenTokenizer } from "./TikTokenTokenizer.js";
|
12
12
|
/**
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import SecureJSON from "secure-json-parse";
|
2
2
|
import z from "zod";
|
3
|
-
import {
|
3
|
+
import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
|
4
|
+
import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
|
4
5
|
import { AsyncQueue } from "../../event-source/AsyncQueue.js";
|
5
6
|
import { parseEventSourceStream } from "../../event-source/parseEventSourceStream.js";
|
7
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
6
8
|
import { countTokens } from "../../model-function/tokenize-text/countTokens.js";
|
7
9
|
import { PromptFormatTextGenerationModel } from "../../prompt/PromptFormatTextGenerationModel.js";
|
8
|
-
import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
|
9
|
-
import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
|
10
10
|
import { OpenAIApiConfiguration } from "./OpenAIApiConfiguration.js";
|
11
11
|
import { failedOpenAICallResponseHandler } from "./OpenAIError.js";
|
12
12
|
import { TikTokenTokenizer } from "./TikTokenTokenizer.js";
|
@@ -9,6 +9,7 @@ const zod_1 = __importDefault(require("zod"));
|
|
9
9
|
const callWithRetryAndThrottle_js_1 = require("../../../core/api/callWithRetryAndThrottle.cjs");
|
10
10
|
const postToApi_js_1 = require("../../../core/api/postToApi.cjs");
|
11
11
|
const AbstractModel_js_1 = require("../../../model-function/AbstractModel.cjs");
|
12
|
+
const parsePartialJson_js_1 = require("../../../model-function/generate-structure/parsePartialJson.cjs");
|
12
13
|
const PromptFormatTextGenerationModel_js_1 = require("../../../prompt/PromptFormatTextGenerationModel.cjs");
|
13
14
|
const OpenAIApiConfiguration_js_1 = require("../OpenAIApiConfiguration.cjs");
|
14
15
|
const OpenAIError_js_1 = require("../OpenAIError.cjs");
|
@@ -264,8 +265,28 @@ class OpenAIChatModel extends AbstractModel_js_1.AbstractModel {
|
|
264
265
|
});
|
265
266
|
}
|
266
267
|
extractStructure(response) {
|
267
|
-
|
268
|
-
|
268
|
+
return secure_json_parse_1.default.parse(response.choices[0].message.function_call.arguments);
|
269
|
+
}
|
270
|
+
generateStructureStreamResponse(structureDefinition, prompt, options) {
|
271
|
+
return this.callAPI(prompt, {
|
272
|
+
responseFormat: exports.OpenAIChatResponseFormat.deltaIterable,
|
273
|
+
functionId: options?.functionId,
|
274
|
+
settings: {
|
275
|
+
...options,
|
276
|
+
functionCall: { name: structureDefinition.name },
|
277
|
+
functions: [
|
278
|
+
{
|
279
|
+
name: structureDefinition.name,
|
280
|
+
description: structureDefinition.description,
|
281
|
+
parameters: structureDefinition.schema.getJsonSchema(),
|
282
|
+
},
|
283
|
+
],
|
284
|
+
},
|
285
|
+
run: options?.run,
|
286
|
+
});
|
287
|
+
}
|
288
|
+
extractPartialStructure(fullDelta) {
|
289
|
+
return (0, parsePartialJson_js_1.parsePartialJson)(fullDelta[0]?.function_call?.arguments);
|
269
290
|
}
|
270
291
|
generateStructureOrTextResponse(structureDefinitions, prompt, options) {
|
271
292
|
return this.callAPI(prompt, {
|
@@ -3,10 +3,10 @@ import { ApiConfiguration } from "../../../core/api/ApiConfiguration.js";
|
|
3
3
|
import { ResponseHandler } from "../../../core/api/postToApi.js";
|
4
4
|
import { StructureDefinition } from "../../../core/structure/StructureDefinition.js";
|
5
5
|
import { AbstractModel } from "../../../model-function/AbstractModel.js";
|
6
|
+
import { DeltaEvent } from "../../../model-function/DeltaEvent.js";
|
6
7
|
import { ModelFunctionOptions } from "../../../model-function/ModelFunctionOptions.js";
|
7
8
|
import { StructureGenerationModel } from "../../../model-function/generate-structure/StructureGenerationModel.js";
|
8
9
|
import { StructureOrTextGenerationModel } from "../../../model-function/generate-structure/StructureOrTextGenerationModel.js";
|
9
|
-
import { DeltaEvent } from "../../../model-function/generate-text/DeltaEvent.js";
|
10
10
|
import { TextGenerationModel, TextGenerationModelSettings } from "../../../model-function/generate-text/TextGenerationModel.js";
|
11
11
|
import { PromptFormat } from "../../../prompt/PromptFormat.js";
|
12
12
|
import { PromptFormatTextGenerationModel } from "../../../prompt/PromptFormatTextGenerationModel.js";
|
@@ -132,7 +132,7 @@ export interface OpenAIChatSettings extends TextGenerationModelSettings, Omit<Op
|
|
132
132
|
* ),
|
133
133
|
* ]);
|
134
134
|
*/
|
135
|
-
export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> implements TextGenerationModel<OpenAIChatMessage[], OpenAIChatResponse, OpenAIChatDelta, OpenAIChatSettings>, StructureGenerationModel<OpenAIChatMessage[], OpenAIChatResponse, OpenAIChatSettings>, StructureOrTextGenerationModel<OpenAIChatMessage[], OpenAIChatResponse, OpenAIChatSettings> {
|
135
|
+
export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> implements TextGenerationModel<OpenAIChatMessage[], OpenAIChatResponse, OpenAIChatDelta, OpenAIChatSettings>, StructureGenerationModel<OpenAIChatMessage[], OpenAIChatResponse, OpenAIChatDelta, OpenAIChatSettings>, StructureOrTextGenerationModel<OpenAIChatMessage[], OpenAIChatResponse, OpenAIChatSettings> {
|
136
136
|
constructor(settings: OpenAIChatSettings);
|
137
137
|
readonly provider: "openai";
|
138
138
|
get modelName(): OpenAIChatModelType;
|
@@ -185,6 +185,8 @@ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> i
|
|
185
185
|
*/
|
186
186
|
generateStructureResponse(structureDefinition: StructureDefinition<string, unknown>, prompt: OpenAIChatMessage[], options?: ModelFunctionOptions<OpenAIChatSettings> | undefined): PromiseLike<OpenAIChatResponse>;
|
187
187
|
extractStructure(response: OpenAIChatResponse): unknown;
|
188
|
+
generateStructureStreamResponse(structureDefinition: StructureDefinition<string, unknown>, prompt: OpenAIChatMessage[], options?: ModelFunctionOptions<OpenAIChatSettings>): Promise<AsyncIterable<DeltaEvent<OpenAIChatDelta>>>;
|
189
|
+
extractPartialStructure(fullDelta: OpenAIChatDelta): unknown | undefined;
|
188
190
|
generateStructureOrTextResponse(structureDefinitions: Array<StructureDefinition<string, unknown>>, prompt: OpenAIChatMessage[], options?: ModelFunctionOptions<OpenAIChatSettings> | undefined): PromiseLike<OpenAIChatResponse>;
|
189
191
|
extractStructureAndText(response: OpenAIChatResponse): {
|
190
192
|
structure: null;
|
@@ -3,6 +3,7 @@ import z from "zod";
|
|
3
3
|
import { callWithRetryAndThrottle } from "../../../core/api/callWithRetryAndThrottle.js";
|
4
4
|
import { createJsonResponseHandler, postJsonToApi, } from "../../../core/api/postToApi.js";
|
5
5
|
import { AbstractModel } from "../../../model-function/AbstractModel.js";
|
6
|
+
import { parsePartialJson } from "../../../model-function/generate-structure/parsePartialJson.js";
|
6
7
|
import { PromptFormatTextGenerationModel } from "../../../prompt/PromptFormatTextGenerationModel.js";
|
7
8
|
import { OpenAIApiConfiguration } from "../OpenAIApiConfiguration.js";
|
8
9
|
import { failedOpenAICallResponseHandler } from "../OpenAIError.js";
|
@@ -255,8 +256,28 @@ export class OpenAIChatModel extends AbstractModel {
|
|
255
256
|
});
|
256
257
|
}
|
257
258
|
extractStructure(response) {
|
258
|
-
|
259
|
-
|
259
|
+
return SecureJSON.parse(response.choices[0].message.function_call.arguments);
|
260
|
+
}
|
261
|
+
generateStructureStreamResponse(structureDefinition, prompt, options) {
|
262
|
+
return this.callAPI(prompt, {
|
263
|
+
responseFormat: OpenAIChatResponseFormat.deltaIterable,
|
264
|
+
functionId: options?.functionId,
|
265
|
+
settings: {
|
266
|
+
...options,
|
267
|
+
functionCall: { name: structureDefinition.name },
|
268
|
+
functions: [
|
269
|
+
{
|
270
|
+
name: structureDefinition.name,
|
271
|
+
description: structureDefinition.description,
|
272
|
+
parameters: structureDefinition.schema.getJsonSchema(),
|
273
|
+
},
|
274
|
+
],
|
275
|
+
},
|
276
|
+
run: options?.run,
|
277
|
+
});
|
278
|
+
}
|
279
|
+
extractPartialStructure(fullDelta) {
|
280
|
+
return parsePartialJson(fullDelta[0]?.function_call?.arguments);
|
260
281
|
}
|
261
282
|
generateStructureOrTextResponse(structureDefinitions, prompt, options) {
|
262
283
|
return this.callAPI(prompt, {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "modelfusion",
|
3
3
|
"description": "Build multimodal applications, chatbots, and agents with JavaScript and TypeScript.",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.35.0",
|
5
5
|
"author": "Lars Grammel",
|
6
6
|
"license": "MIT",
|
7
7
|
"keywords": [
|
@@ -47,10 +47,12 @@
|
|
47
47
|
"build": "npm run build:esm && npm run build:cjs",
|
48
48
|
"build:esm": "tsc --outDir dist/",
|
49
49
|
"build:cjs": "tsc --outDir build/cjs/ -p tsconfig.cjs.json && node bin/prepare-cjs.js",
|
50
|
-
"
|
51
|
-
"dist": "npm run clean && npm run lint && npm run build && npm run dist:copy-files"
|
50
|
+
"test": "vitest",
|
51
|
+
"dist": "npm run clean && npm run lint && npm run build && npm run dist:copy-files",
|
52
|
+
"dist:copy-files": "copyfiles package.json README.md LICENSE dist"
|
52
53
|
},
|
53
54
|
"dependencies": {
|
55
|
+
"deep-equal": "2.2.2",
|
54
56
|
"eventsource-parser": "1.1.1",
|
55
57
|
"js-tiktoken": "1.0.7",
|
56
58
|
"nanoid": "3.3.6",
|
@@ -61,6 +63,7 @@
|
|
61
63
|
"devDependencies": {
|
62
64
|
"@pinecone-database/pinecone": "^0.1.6",
|
63
65
|
"@tsconfig/recommended": "1.0.3",
|
66
|
+
"@types/deep-equal": "^1.0.2",
|
64
67
|
"@types/node": "18.11.9",
|
65
68
|
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
66
69
|
"@typescript-eslint/parser": "^6.1.0",
|
@@ -71,7 +74,8 @@
|
|
71
74
|
"lint-staged": "14.0.1",
|
72
75
|
"prettier": "3.0.3",
|
73
76
|
"rimraf": "5.0.1",
|
74
|
-
"typescript": "5.2.2"
|
77
|
+
"typescript": "5.2.2",
|
78
|
+
"vitest": "^0.34.5"
|
75
79
|
},
|
76
80
|
"peerDependencies": {
|
77
81
|
"@pinecone-database/pinecone": "0.1.6"
|
@@ -1,5 +1,5 @@
|
|
1
|
+
import { DeltaEvent } from "../model-function/DeltaEvent.js";
|
1
2
|
import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
|
2
|
-
import { DeltaEvent } from "../model-function/generate-text/DeltaEvent.js";
|
3
3
|
import { TextGenerationModel, TextGenerationModelSettings } from "../model-function/generate-text/TextGenerationModel.js";
|
4
4
|
import { PromptFormat } from "./PromptFormat.js";
|
5
5
|
export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS extends TextGenerationModelSettings, MODEL extends TextGenerationModel<MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS>> implements TextGenerationModel<PROMPT, RESPONSE, FULL_DELTA, SETTINGS> {
|
package/tool/useTool.cjs
CHANGED
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useTool = void 0;
|
4
4
|
const generateStructure_js_1 = require("../model-function/generate-structure/generateStructure.cjs");
|
5
5
|
const executeTool_js_1 = require("./executeTool.cjs");
|
6
|
-
// In this file, using 'any' is required to allow for flexibility in the inputs. The actual types are
|
7
|
-
// retrieved through lookups such as TOOL["name"], such that any does not affect any client.
|
8
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
9
6
|
/**
|
10
7
|
* `useTool` uses `generateStructure` to generate parameters for a tool and then executes the tool with the parameters.
|
11
8
|
*
|
@@ -13,7 +10,9 @@ const executeTool_js_1 = require("./executeTool.cjs");
|
|
13
10
|
* the parameters (`parameters` property, typed),
|
14
11
|
* and the result of the tool execution (`result` property, typed).
|
15
12
|
*/
|
16
|
-
async function useTool(
|
13
|
+
async function useTool(
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
15
|
+
model, tool, prompt, options) {
|
17
16
|
// Note: PROMPT must not be a function.
|
18
17
|
const expandedPrompt = typeof prompt === "function"
|
19
18
|
? prompt(tool)
|
package/tool/useTool.d.ts
CHANGED
@@ -8,7 +8,7 @@ import { Tool } from "./Tool.js";
|
|
8
8
|
* the parameters (`parameters` property, typed),
|
9
9
|
* and the result of the tool execution (`result` property, typed).
|
10
10
|
*/
|
11
|
-
export declare function useTool<PROMPT, RESPONSE, SETTINGS extends StructureGenerationModelSettings, TOOL extends Tool<any, any, any>>(model: StructureGenerationModel<PROMPT, RESPONSE, SETTINGS>, tool: TOOL, prompt: PROMPT | ((tool: TOOL) => PROMPT), options?: ModelFunctionOptions<SETTINGS>): Promise<{
|
11
|
+
export declare function useTool<PROMPT, RESPONSE, SETTINGS extends StructureGenerationModelSettings, TOOL extends Tool<any, any, any>>(model: StructureGenerationModel<PROMPT, RESPONSE, any, SETTINGS>, tool: TOOL, prompt: PROMPT | ((tool: TOOL) => PROMPT), options?: ModelFunctionOptions<SETTINGS>): Promise<{
|
12
12
|
tool: TOOL["name"];
|
13
13
|
parameters: TOOL["inputSchema"];
|
14
14
|
result: Awaited<ReturnType<TOOL["execute"]>>;
|
package/tool/useTool.js
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
import { generateStructure } from "../model-function/generate-structure/generateStructure.js";
|
2
2
|
import { executeTool } from "./executeTool.js";
|
3
|
-
// In this file, using 'any' is required to allow for flexibility in the inputs. The actual types are
|
4
|
-
// retrieved through lookups such as TOOL["name"], such that any does not affect any client.
|
5
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
6
3
|
/**
|
7
4
|
* `useTool` uses `generateStructure` to generate parameters for a tool and then executes the tool with the parameters.
|
8
5
|
*
|
@@ -10,7 +7,9 @@ import { executeTool } from "./executeTool.js";
|
|
10
7
|
* the parameters (`parameters` property, typed),
|
11
8
|
* and the result of the tool execution (`result` property, typed).
|
12
9
|
*/
|
13
|
-
export async function useTool(
|
10
|
+
export async function useTool(
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
12
|
+
model, tool, prompt, options) {
|
14
13
|
// Note: PROMPT must not be a function.
|
15
14
|
const expandedPrompt = typeof prompt === "function"
|
16
15
|
? prompt(tool)
|
@@ -1,23 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.extractTextDeltas = void 0;
|
4
|
-
async function* extractTextDeltas({ deltaIterable, extractDelta, onDone, onError, }) {
|
5
|
-
let accumulatedText = "";
|
6
|
-
let lastFullDelta;
|
7
|
-
for await (const event of deltaIterable) {
|
8
|
-
if (event?.type === "error") {
|
9
|
-
onError(event.error);
|
10
|
-
throw event.error;
|
11
|
-
}
|
12
|
-
if (event?.type === "delta") {
|
13
|
-
lastFullDelta = event.fullDelta;
|
14
|
-
const delta = extractDelta(lastFullDelta);
|
15
|
-
if (delta != null && delta.length > 0) {
|
16
|
-
accumulatedText += delta;
|
17
|
-
yield delta;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
}
|
21
|
-
onDone(accumulatedText, lastFullDelta);
|
22
|
-
}
|
23
|
-
exports.extractTextDeltas = extractTextDeltas;
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { DeltaEvent } from "./DeltaEvent.js";
|
2
|
-
export declare function extractTextDeltas<FULL_DELTA>({ deltaIterable, extractDelta, onDone, onError, }: {
|
3
|
-
deltaIterable: AsyncIterable<DeltaEvent<FULL_DELTA>>;
|
4
|
-
extractDelta: (fullDelta: FULL_DELTA) => string | undefined;
|
5
|
-
onDone: (fullText: string, lastFullDelta: FULL_DELTA | undefined) => void;
|
6
|
-
onError: (error: unknown) => void;
|
7
|
-
}): AsyncIterable<string>;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
export async function* extractTextDeltas({ deltaIterable, extractDelta, onDone, onError, }) {
|
2
|
-
let accumulatedText = "";
|
3
|
-
let lastFullDelta;
|
4
|
-
for await (const event of deltaIterable) {
|
5
|
-
if (event?.type === "error") {
|
6
|
-
onError(event.error);
|
7
|
-
throw event.error;
|
8
|
-
}
|
9
|
-
if (event?.type === "delta") {
|
10
|
-
lastFullDelta = event.fullDelta;
|
11
|
-
const delta = extractDelta(lastFullDelta);
|
12
|
-
if (delta != null && delta.length > 0) {
|
13
|
-
accumulatedText += delta;
|
14
|
-
yield delta;
|
15
|
-
}
|
16
|
-
}
|
17
|
-
}
|
18
|
-
onDone(accumulatedText, lastFullDelta);
|
19
|
-
}
|
File without changes
|
File without changes
|