modelfusion 0.34.0 → 0.35.1
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 +327 -0
- package/model-function/generate-structure/fixJson.d.ts +1 -0
- package/model-function/generate-structure/fixJson.js +323 -0
- package/model-function/generate-structure/fixJson.test.cjs +186 -0
- package/model-function/generate-structure/fixJson.test.d.ts +1 -0
- package/model-function/generate-structure/fixJson.test.js +184 -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 +16 -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
@@ -1,51 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.streamText =
|
3
|
+
exports.streamText = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
5
|
const FunctionEventSource_js_1 = require("../../core/FunctionEventSource.cjs");
|
6
6
|
const GlobalFunctionLogging_js_1 = require("../../core/GlobalFunctionLogging.cjs");
|
7
7
|
const GlobalFunctionObservers_js_1 = require("../../core/GlobalFunctionObservers.cjs");
|
8
|
+
const AbortError_js_1 = require("../../core/api/AbortError.cjs");
|
8
9
|
const getFunctionCallLogger_js_1 = require("../../core/getFunctionCallLogger.cjs");
|
9
10
|
const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
|
10
|
-
const AbortError_js_1 = require("../../core/api/AbortError.cjs");
|
11
11
|
const runSafe_js_1 = require("../../util/runSafe.cjs");
|
12
|
-
const
|
13
|
-
class StreamTextPromise extends Promise {
|
14
|
-
constructor(fullPromise) {
|
15
|
-
super((resolve) => {
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
17
|
-
resolve(null); // we override the resolve function
|
18
|
-
});
|
19
|
-
Object.defineProperty(this, "fullPromise", {
|
20
|
-
enumerable: true,
|
21
|
-
configurable: true,
|
22
|
-
writable: true,
|
23
|
-
value: fullPromise
|
24
|
-
});
|
25
|
-
Object.defineProperty(this, "outputPromise", {
|
26
|
-
enumerable: true,
|
27
|
-
configurable: true,
|
28
|
-
writable: true,
|
29
|
-
value: void 0
|
30
|
-
});
|
31
|
-
this.outputPromise = fullPromise.then((result) => result.output);
|
32
|
-
}
|
33
|
-
asFullResponse() {
|
34
|
-
return this.fullPromise;
|
35
|
-
}
|
36
|
-
then(onfulfilled, onrejected) {
|
37
|
-
return this.outputPromise.then(onfulfilled, onrejected);
|
38
|
-
}
|
39
|
-
catch(onrejected) {
|
40
|
-
return this.outputPromise.catch(onrejected);
|
41
|
-
}
|
42
|
-
finally(onfinally) {
|
43
|
-
return this.outputPromise.finally(onfinally);
|
44
|
-
}
|
45
|
-
}
|
46
|
-
exports.StreamTextPromise = StreamTextPromise;
|
12
|
+
const AsyncIterableResultPromise_js_1 = require("../AsyncIterableResultPromise.cjs");
|
47
13
|
function streamText(model, prompt, options) {
|
48
|
-
return new
|
14
|
+
return new AsyncIterableResultPromise_js_1.AsyncIterableResultPromise(doStreamText(model, prompt, options));
|
49
15
|
}
|
50
16
|
exports.streamText = streamText;
|
51
17
|
async function doStreamText(model, prompt, options) {
|
@@ -87,14 +53,49 @@ async function doStreamText(model, prompt, options) {
|
|
87
53
|
eventType: "started",
|
88
54
|
...startMetadata,
|
89
55
|
});
|
90
|
-
const result = await (0, runSafe_js_1.runSafe)(async () =>
|
91
|
-
deltaIterable
|
56
|
+
const result = await (0, runSafe_js_1.runSafe)(async () => {
|
57
|
+
const deltaIterable = await model.generateDeltaStreamResponse(prompt, {
|
92
58
|
functionId: options?.functionId,
|
93
59
|
settings,
|
94
60
|
run,
|
95
|
-
})
|
96
|
-
|
97
|
-
|
61
|
+
});
|
62
|
+
return (async function* () {
|
63
|
+
let accumulatedText = "";
|
64
|
+
let lastFullDelta;
|
65
|
+
for await (const event of deltaIterable) {
|
66
|
+
if (event?.type === "error") {
|
67
|
+
const error = event.error;
|
68
|
+
const finishMetadata = {
|
69
|
+
eventType: "finished",
|
70
|
+
...startMetadata,
|
71
|
+
finishTimestamp: new Date(),
|
72
|
+
durationInMs: durationMeasurement.durationInMs,
|
73
|
+
};
|
74
|
+
eventSource.notify(error instanceof AbortError_js_1.AbortError
|
75
|
+
? {
|
76
|
+
...finishMetadata,
|
77
|
+
result: {
|
78
|
+
status: "abort",
|
79
|
+
},
|
80
|
+
}
|
81
|
+
: {
|
82
|
+
...finishMetadata,
|
83
|
+
result: {
|
84
|
+
status: "error",
|
85
|
+
error,
|
86
|
+
},
|
87
|
+
});
|
88
|
+
throw error;
|
89
|
+
}
|
90
|
+
if (event?.type === "delta") {
|
91
|
+
lastFullDelta = event.fullDelta;
|
92
|
+
const delta = model.extractTextDelta(lastFullDelta);
|
93
|
+
if (delta != null && delta.length > 0) {
|
94
|
+
accumulatedText += delta;
|
95
|
+
yield delta;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
98
99
|
const finishMetadata = {
|
99
100
|
eventType: "finished",
|
100
101
|
...startMetadata,
|
@@ -106,33 +107,11 @@ async function doStreamText(model, prompt, options) {
|
|
106
107
|
result: {
|
107
108
|
status: "success",
|
108
109
|
response: lastFullDelta,
|
109
|
-
output:
|
110
|
+
output: accumulatedText,
|
110
111
|
},
|
111
112
|
});
|
112
|
-
}
|
113
|
-
|
114
|
-
const finishMetadata = {
|
115
|
-
eventType: "finished",
|
116
|
-
...startMetadata,
|
117
|
-
finishTimestamp: new Date(),
|
118
|
-
durationInMs: durationMeasurement.durationInMs,
|
119
|
-
};
|
120
|
-
eventSource.notify(error instanceof AbortError_js_1.AbortError
|
121
|
-
? {
|
122
|
-
...finishMetadata,
|
123
|
-
result: {
|
124
|
-
status: "abort",
|
125
|
-
},
|
126
|
-
}
|
127
|
-
: {
|
128
|
-
...finishMetadata,
|
129
|
-
result: {
|
130
|
-
status: "error",
|
131
|
-
error,
|
132
|
-
},
|
133
|
-
});
|
134
|
-
},
|
135
|
-
}));
|
113
|
+
})();
|
114
|
+
});
|
136
115
|
if (!result.ok) {
|
137
116
|
const finishMetadata = {
|
138
117
|
eventType: "finished",
|
@@ -1,23 +1,8 @@
|
|
1
|
+
import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
|
2
|
+
import { DeltaEvent } from "../DeltaEvent.js";
|
1
3
|
import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
|
2
|
-
import { ModelCallMetadata } from "../executeCall.js";
|
3
|
-
import { DeltaEvent } from "./DeltaEvent.js";
|
4
4
|
import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerationModel.js";
|
5
|
-
export declare class StreamTextPromise extends Promise<AsyncIterable<string>> {
|
6
|
-
private fullPromise;
|
7
|
-
private outputPromise;
|
8
|
-
constructor(fullPromise: Promise<{
|
9
|
-
output: AsyncIterable<string>;
|
10
|
-
metadata: Omit<ModelCallMetadata, "durationInMs" | "finishTimestamp">;
|
11
|
-
}>);
|
12
|
-
asFullResponse(): Promise<{
|
13
|
-
output: AsyncIterable<string>;
|
14
|
-
metadata: Omit<ModelCallMetadata, "durationInMs" | "finishTimestamp">;
|
15
|
-
}>;
|
16
|
-
then<TResult1 = AsyncIterable<string>, TResult2 = never>(onfulfilled?: ((value: AsyncIterable<string>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
17
|
-
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<AsyncIterable<string> | TResult>;
|
18
|
-
finally(onfinally?: (() => void) | undefined | null): Promise<AsyncIterable<string>>;
|
19
|
-
}
|
20
5
|
export declare function streamText<PROMPT, FULL_DELTA, SETTINGS extends TextGenerationModelSettings>(model: TextGenerationModel<PROMPT, unknown, FULL_DELTA, SETTINGS> & {
|
21
6
|
generateDeltaStreamResponse: (prompt: PROMPT, options: ModelFunctionOptions<SETTINGS>) => PromiseLike<AsyncIterable<DeltaEvent<FULL_DELTA>>>;
|
22
7
|
extractTextDelta: (fullDelta: FULL_DELTA) => string | undefined;
|
23
|
-
}, prompt: PROMPT, options?: ModelFunctionOptions<SETTINGS>):
|
8
|
+
}, prompt: PROMPT, options?: ModelFunctionOptions<SETTINGS>): AsyncIterableResultPromise<string>;
|
@@ -2,46 +2,13 @@ import { nanoid as createId } from "nanoid";
|
|
2
2
|
import { FunctionEventSource } from "../../core/FunctionEventSource.js";
|
3
3
|
import { getGlobalFunctionLogging } from "../../core/GlobalFunctionLogging.js";
|
4
4
|
import { getGlobalFunctionObservers } from "../../core/GlobalFunctionObservers.js";
|
5
|
+
import { AbortError } from "../../core/api/AbortError.js";
|
5
6
|
import { getFunctionCallLogger } from "../../core/getFunctionCallLogger.js";
|
6
7
|
import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
|
7
|
-
import { AbortError } from "../../core/api/AbortError.js";
|
8
8
|
import { runSafe } from "../../util/runSafe.js";
|
9
|
-
import {
|
10
|
-
export class StreamTextPromise extends Promise {
|
11
|
-
constructor(fullPromise) {
|
12
|
-
super((resolve) => {
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
14
|
-
resolve(null); // we override the resolve function
|
15
|
-
});
|
16
|
-
Object.defineProperty(this, "fullPromise", {
|
17
|
-
enumerable: true,
|
18
|
-
configurable: true,
|
19
|
-
writable: true,
|
20
|
-
value: fullPromise
|
21
|
-
});
|
22
|
-
Object.defineProperty(this, "outputPromise", {
|
23
|
-
enumerable: true,
|
24
|
-
configurable: true,
|
25
|
-
writable: true,
|
26
|
-
value: void 0
|
27
|
-
});
|
28
|
-
this.outputPromise = fullPromise.then((result) => result.output);
|
29
|
-
}
|
30
|
-
asFullResponse() {
|
31
|
-
return this.fullPromise;
|
32
|
-
}
|
33
|
-
then(onfulfilled, onrejected) {
|
34
|
-
return this.outputPromise.then(onfulfilled, onrejected);
|
35
|
-
}
|
36
|
-
catch(onrejected) {
|
37
|
-
return this.outputPromise.catch(onrejected);
|
38
|
-
}
|
39
|
-
finally(onfinally) {
|
40
|
-
return this.outputPromise.finally(onfinally);
|
41
|
-
}
|
42
|
-
}
|
9
|
+
import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
|
43
10
|
export function streamText(model, prompt, options) {
|
44
|
-
return new
|
11
|
+
return new AsyncIterableResultPromise(doStreamText(model, prompt, options));
|
45
12
|
}
|
46
13
|
async function doStreamText(model, prompt, options) {
|
47
14
|
if (options?.settings != null) {
|
@@ -82,14 +49,49 @@ async function doStreamText(model, prompt, options) {
|
|
82
49
|
eventType: "started",
|
83
50
|
...startMetadata,
|
84
51
|
});
|
85
|
-
const result = await runSafe(async () =>
|
86
|
-
deltaIterable
|
52
|
+
const result = await runSafe(async () => {
|
53
|
+
const deltaIterable = await model.generateDeltaStreamResponse(prompt, {
|
87
54
|
functionId: options?.functionId,
|
88
55
|
settings,
|
89
56
|
run,
|
90
|
-
})
|
91
|
-
|
92
|
-
|
57
|
+
});
|
58
|
+
return (async function* () {
|
59
|
+
let accumulatedText = "";
|
60
|
+
let lastFullDelta;
|
61
|
+
for await (const event of deltaIterable) {
|
62
|
+
if (event?.type === "error") {
|
63
|
+
const error = event.error;
|
64
|
+
const finishMetadata = {
|
65
|
+
eventType: "finished",
|
66
|
+
...startMetadata,
|
67
|
+
finishTimestamp: new Date(),
|
68
|
+
durationInMs: durationMeasurement.durationInMs,
|
69
|
+
};
|
70
|
+
eventSource.notify(error instanceof AbortError
|
71
|
+
? {
|
72
|
+
...finishMetadata,
|
73
|
+
result: {
|
74
|
+
status: "abort",
|
75
|
+
},
|
76
|
+
}
|
77
|
+
: {
|
78
|
+
...finishMetadata,
|
79
|
+
result: {
|
80
|
+
status: "error",
|
81
|
+
error,
|
82
|
+
},
|
83
|
+
});
|
84
|
+
throw error;
|
85
|
+
}
|
86
|
+
if (event?.type === "delta") {
|
87
|
+
lastFullDelta = event.fullDelta;
|
88
|
+
const delta = model.extractTextDelta(lastFullDelta);
|
89
|
+
if (delta != null && delta.length > 0) {
|
90
|
+
accumulatedText += delta;
|
91
|
+
yield delta;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
93
95
|
const finishMetadata = {
|
94
96
|
eventType: "finished",
|
95
97
|
...startMetadata,
|
@@ -101,33 +103,11 @@ async function doStreamText(model, prompt, options) {
|
|
101
103
|
result: {
|
102
104
|
status: "success",
|
103
105
|
response: lastFullDelta,
|
104
|
-
output:
|
106
|
+
output: accumulatedText,
|
105
107
|
},
|
106
108
|
});
|
107
|
-
}
|
108
|
-
|
109
|
-
const finishMetadata = {
|
110
|
-
eventType: "finished",
|
111
|
-
...startMetadata,
|
112
|
-
finishTimestamp: new Date(),
|
113
|
-
durationInMs: durationMeasurement.durationInMs,
|
114
|
-
};
|
115
|
-
eventSource.notify(error instanceof AbortError
|
116
|
-
? {
|
117
|
-
...finishMetadata,
|
118
|
-
result: {
|
119
|
-
status: "abort",
|
120
|
-
},
|
121
|
-
}
|
122
|
-
: {
|
123
|
-
...finishMetadata,
|
124
|
-
result: {
|
125
|
-
status: "error",
|
126
|
-
error,
|
127
|
-
},
|
128
|
-
});
|
129
|
-
},
|
130
|
-
}));
|
109
|
+
})();
|
110
|
+
});
|
131
111
|
if (!result.ok) {
|
132
112
|
const finishMetadata = {
|
133
113
|
eventType: "finished",
|
package/model-function/index.cjs
CHANGED
@@ -14,6 +14,7 @@ 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("./DeltaEvent.cjs"), exports);
|
17
18
|
__exportStar(require("./Model.cjs"), exports);
|
18
19
|
__exportStar(require("./ModelCallEvent.cjs"), exports);
|
19
20
|
__exportStar(require("./ModelFunctionOptions.cjs"), exports);
|
@@ -33,10 +34,11 @@ __exportStar(require("./generate-structure/StructureFromTextGenerationModel.cjs"
|
|
33
34
|
__exportStar(require("./generate-structure/StructureGenerationEvent.cjs"), exports);
|
34
35
|
__exportStar(require("./generate-structure/StructureGenerationModel.cjs"), exports);
|
35
36
|
__exportStar(require("./generate-structure/StructureOrTextGenerationModel.cjs"), exports);
|
37
|
+
__exportStar(require("./generate-structure/StructureStreamingEvent.cjs"), exports);
|
36
38
|
__exportStar(require("./generate-structure/StructureValidationError.cjs"), exports);
|
37
39
|
__exportStar(require("./generate-structure/generateStructure.cjs"), exports);
|
38
40
|
__exportStar(require("./generate-structure/generateStructureOrText.cjs"), exports);
|
39
|
-
__exportStar(require("./generate-
|
41
|
+
__exportStar(require("./generate-structure/streamStructure.cjs"), exports);
|
40
42
|
__exportStar(require("./generate-text/TextGenerationEvent.cjs"), exports);
|
41
43
|
__exportStar(require("./generate-text/TextGenerationModel.cjs"), exports);
|
42
44
|
__exportStar(require("./generate-text/TextStreamingEvent.cjs"), exports);
|
@@ -1,3 +1,4 @@
|
|
1
|
+
export * from "./DeltaEvent.js";
|
1
2
|
export * from "./Model.js";
|
2
3
|
export * from "./ModelCallEvent.js";
|
3
4
|
export * from "./ModelFunctionOptions.js";
|
@@ -17,10 +18,11 @@ export * from "./generate-structure/StructureFromTextGenerationModel.js";
|
|
17
18
|
export * from "./generate-structure/StructureGenerationEvent.js";
|
18
19
|
export * from "./generate-structure/StructureGenerationModel.js";
|
19
20
|
export * from "./generate-structure/StructureOrTextGenerationModel.js";
|
21
|
+
export * from "./generate-structure/StructureStreamingEvent.js";
|
20
22
|
export * from "./generate-structure/StructureValidationError.js";
|
21
23
|
export * from "./generate-structure/generateStructure.js";
|
22
24
|
export * from "./generate-structure/generateStructureOrText.js";
|
23
|
-
export * from "./generate-
|
25
|
+
export * from "./generate-structure/streamStructure.js";
|
24
26
|
export * from "./generate-text/TextGenerationEvent.js";
|
25
27
|
export * from "./generate-text/TextGenerationModel.js";
|
26
28
|
export * from "./generate-text/TextStreamingEvent.js";
|
package/model-function/index.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
export * from "./DeltaEvent.js";
|
1
2
|
export * from "./Model.js";
|
2
3
|
export * from "./ModelCallEvent.js";
|
3
4
|
export * from "./ModelFunctionOptions.js";
|
@@ -17,10 +18,11 @@ export * from "./generate-structure/StructureFromTextGenerationModel.js";
|
|
17
18
|
export * from "./generate-structure/StructureGenerationEvent.js";
|
18
19
|
export * from "./generate-structure/StructureGenerationModel.js";
|
19
20
|
export * from "./generate-structure/StructureOrTextGenerationModel.js";
|
21
|
+
export * from "./generate-structure/StructureStreamingEvent.js";
|
20
22
|
export * from "./generate-structure/StructureValidationError.js";
|
21
23
|
export * from "./generate-structure/generateStructure.js";
|
22
24
|
export * from "./generate-structure/generateStructureOrText.js";
|
23
|
-
export * from "./generate-
|
25
|
+
export * from "./generate-structure/streamStructure.js";
|
24
26
|
export * from "./generate-text/TextGenerationEvent.js";
|
25
27
|
export * from "./generate-text/TextGenerationModel.js";
|
26
28
|
export * from "./generate-text/TextStreamingEvent.js";
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CohereTextGenerationResponseFormat = exports.CohereTextGenerationModel = exports.COHERE_TEXT_GENERATION_MODELS = void 0;
|
7
7
|
const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
|
8
8
|
const zod_1 = 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");
|
12
|
+
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
11
13
|
const countTokens_js_1 = require("../../model-function/tokenize-text/countTokens.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 CohereApiConfiguration_js_1 = require("./CohereApiConfiguration.cjs");
|
16
16
|
const CohereError_js_1 = require("./CohereError.cjs");
|
17
17
|
const CohereTokenizer_js_1 = require("./CohereTokenizer.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 { CohereTokenizer } from "./CohereTokenizer.js";
|
11
11
|
export declare const COHERE_TEXT_GENERATION_MODELS: {
|
12
12
|
command: {
|
@@ -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";
|
6
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
5
7
|
import { countTokens } from "../../model-function/tokenize-text/countTokens.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 { CohereApiConfiguration } from "./CohereApiConfiguration.js";
|
10
10
|
import { failedCohereCallResponseHandler } from "./CohereError.js";
|
11
11
|
import { CohereTokenizer } from "./CohereTokenizer.js";
|
@@ -56,18 +56,6 @@ class HuggingFaceTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
56
56
|
writable: true,
|
57
57
|
value: undefined
|
58
58
|
});
|
59
|
-
Object.defineProperty(this, "generateDeltaStreamResponse", {
|
60
|
-
enumerable: true,
|
61
|
-
configurable: true,
|
62
|
-
writable: true,
|
63
|
-
value: undefined
|
64
|
-
});
|
65
|
-
Object.defineProperty(this, "extractTextDelta", {
|
66
|
-
enumerable: true,
|
67
|
-
configurable: true,
|
68
|
-
writable: true,
|
69
|
-
value: undefined
|
70
|
-
});
|
71
59
|
}
|
72
60
|
get modelName() {
|
73
61
|
return this.settings.model;
|
@@ -51,8 +51,6 @@ export declare class HuggingFaceTextGenerationModel extends AbstractModel<Huggin
|
|
51
51
|
generated_text: string;
|
52
52
|
}[]>;
|
53
53
|
extractText(response: HuggingFaceTextGenerationResponse): string;
|
54
|
-
generateDeltaStreamResponse: undefined;
|
55
|
-
extractTextDelta: undefined;
|
56
54
|
withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, string>): PromptFormatTextGenerationModel<INPUT_PROMPT, string, HuggingFaceTextGenerationResponse, undefined, HuggingFaceTextGenerationModelSettings, this>;
|
57
55
|
withSettings(additionalSettings: Partial<HuggingFaceTextGenerationModelSettings>): this;
|
58
56
|
}
|
@@ -50,18 +50,6 @@ export class HuggingFaceTextGenerationModel extends AbstractModel {
|
|
50
50
|
writable: true,
|
51
51
|
value: undefined
|
52
52
|
});
|
53
|
-
Object.defineProperty(this, "generateDeltaStreamResponse", {
|
54
|
-
enumerable: true,
|
55
|
-
configurable: true,
|
56
|
-
writable: true,
|
57
|
-
value: undefined
|
58
|
-
});
|
59
|
-
Object.defineProperty(this, "extractTextDelta", {
|
60
|
-
enumerable: true,
|
61
|
-
configurable: true,
|
62
|
-
writable: true,
|
63
|
-
value: undefined
|
64
|
-
});
|
65
53
|
}
|
66
54
|
get modelName() {
|
67
55
|
return this.settings.model;
|
@@ -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, {
|