modelfusion 0.21.0 → 0.22.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/composed-function/summarize/SummarizationFunction.d.ts +1 -1
- package/composed-function/summarize/summarizeRecursively.d.ts +1 -1
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +1 -1
- package/{run → core}/DefaultRun.cjs +1 -1
- package/{run → core}/DefaultRun.js +1 -1
- package/{run → core}/FunctionEvent.d.ts +30 -6
- package/index.cjs +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/model-function/Model.d.ts +1 -1
- package/model-function/ModelCallEvent.d.ts +20 -5
- package/model-function/ModelFunctionOptions.d.ts +1 -1
- package/model-function/SuccessfulModelCall.cjs +4 -2
- package/model-function/SuccessfulModelCall.d.ts +1 -1
- package/model-function/SuccessfulModelCall.js +4 -2
- package/model-function/embed-text/TextEmbeddingEvent.d.ts +12 -12
- package/model-function/embed-text/TextEmbeddingModel.d.ts +1 -1
- package/model-function/embed-text/embedText.cjs +6 -61
- package/model-function/embed-text/embedText.d.ts +1 -1
- package/model-function/embed-text/embedText.js +6 -61
- package/model-function/executeCall.cjs +32 -19
- package/model-function/executeCall.d.ts +4 -12
- package/model-function/executeCall.js +32 -19
- package/model-function/generate-image/ImageGenerationEvent.d.ts +9 -11
- package/model-function/generate-image/generateImage.cjs +2 -27
- package/model-function/generate-image/generateImage.js +2 -27
- package/model-function/generate-json/JsonGenerationEvent.d.ts +3 -16
- package/model-function/generate-json/generateJson.cjs +2 -27
- package/model-function/generate-json/generateJson.js +2 -27
- package/model-function/generate-json/generateJsonOrText.cjs +2 -27
- package/model-function/generate-json/generateJsonOrText.js +2 -27
- package/model-function/generate-text/TextGenerationEvent.d.ts +10 -10
- package/model-function/generate-text/TextStreamingEvent.d.ts +4 -17
- package/model-function/generate-text/generateText.cjs +2 -27
- package/model-function/generate-text/generateText.js +2 -27
- package/model-function/generate-text/streamText.cjs +24 -29
- package/model-function/generate-text/streamText.js +24 -29
- package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +11 -10
- package/model-function/synthesize-speech/synthesizeSpeech.cjs +2 -28
- package/model-function/synthesize-speech/synthesizeSpeech.js +2 -28
- package/model-function/transcribe-speech/TranscriptionEvent.d.ts +9 -11
- package/model-function/transcribe-speech/transcribe.cjs +2 -27
- package/model-function/transcribe-speech/transcribe.js +2 -27
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
- package/model-provider/cohere/CohereTokenizer.d.ts +1 -1
- package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +1 -1
- package/package.json +1 -1
- package/text-chunk/split/SplitFunction.d.ts +1 -1
- package/tool/ExecuteToolEvent.d.ts +7 -16
- package/tool/Tool.d.ts +1 -1
- package/tool/WebSearchTool.cjs +25 -0
- package/tool/WebSearchTool.d.ts +56 -1
- package/tool/WebSearchTool.js +25 -0
- package/tool/executeTool.cjs +14 -8
- package/tool/executeTool.d.ts +1 -1
- package/tool/executeTool.js +14 -8
- package/vector-index/VectorIndex.d.ts +1 -1
- package/vector-index/memory/MemoryVectorIndex.d.ts +1 -1
- package/vector-index/pinecone/PineconeVectorIndex.d.ts +1 -1
- /package/{run → core}/ConsoleLogger.cjs +0 -0
- /package/{run → core}/ConsoleLogger.d.ts +0 -0
- /package/{run → core}/ConsoleLogger.js +0 -0
- /package/{run → core}/DefaultRun.d.ts +0 -0
- /package/{run → core}/FunctionEvent.cjs +0 -0
- /package/{run → core}/FunctionEvent.js +0 -0
- /package/{run → core}/FunctionEventSource.cjs +0 -0
- /package/{run → core}/FunctionEventSource.d.ts +0 -0
- /package/{run → core}/FunctionEventSource.js +0 -0
- /package/{run → core}/FunctionObserver.cjs +0 -0
- /package/{run → core}/FunctionObserver.d.ts +0 -0
- /package/{run → core}/FunctionObserver.js +0 -0
- /package/{run → core}/FunctionOptions.cjs +0 -0
- /package/{run → core}/FunctionOptions.d.ts +0 -0
- /package/{run → core}/FunctionOptions.js +0 -0
- /package/{run → core}/GlobalFunctionObservers.cjs +0 -0
- /package/{run → core}/GlobalFunctionObservers.d.ts +0 -0
- /package/{run → core}/GlobalFunctionObservers.js +0 -0
- /package/{run → core}/Run.cjs +0 -0
- /package/{run → core}/Run.d.ts +0 -0
- /package/{run → core}/Run.js +0 -0
- /package/{run → core}/Vector.cjs +0 -0
- /package/{run → core}/Vector.d.ts +0 -0
- /package/{run → core}/Vector.js +0 -0
- /package/{run → core}/index.cjs +0 -0
- /package/{run → core}/index.d.ts +0 -0
- /package/{run → core}/index.js +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
|
-
import { FunctionEventSource } from "../../
|
3
|
-
import { getGlobalFunctionObservers } from "../../
|
2
|
+
import { FunctionEventSource } from "../../core/FunctionEventSource.js";
|
3
|
+
import { getGlobalFunctionObservers } from "../../core/GlobalFunctionObservers.js";
|
4
4
|
import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
|
5
5
|
import { AbortError } from "../../util/api/AbortError.js";
|
6
6
|
import { runSafe } from "../../util/runSafe.js";
|
@@ -69,15 +69,15 @@ async function doStreamText(model, prompt, options) {
|
|
69
69
|
userId: run?.userId,
|
70
70
|
functionId: options?.functionId,
|
71
71
|
model: model.modelInformation,
|
72
|
+
functionType: "text-streaming",
|
73
|
+
input: prompt,
|
74
|
+
settings,
|
72
75
|
timestamp: durationMeasurement.startDate,
|
73
76
|
startTimestamp: durationMeasurement.startDate,
|
74
77
|
};
|
75
78
|
eventSource.notify({
|
76
79
|
...startMetadata,
|
77
|
-
functionType: "text-streaming",
|
78
80
|
eventType: "started",
|
79
|
-
settings,
|
80
|
-
prompt,
|
81
81
|
});
|
82
82
|
const result = await runSafe(async () => extractTextDeltas({
|
83
83
|
deltaIterable: await model.generateDeltaStreamResponse(prompt, {
|
@@ -95,12 +95,11 @@ async function doStreamText(model, prompt, options) {
|
|
95
95
|
};
|
96
96
|
eventSource.notify({
|
97
97
|
...finishMetadata,
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
generatedText: fullText,
|
98
|
+
result: {
|
99
|
+
status: "success",
|
100
|
+
response: lastFullDelta,
|
101
|
+
output: fullText,
|
102
|
+
},
|
104
103
|
});
|
105
104
|
},
|
106
105
|
onError: (error) => {
|
@@ -113,18 +112,16 @@ async function doStreamText(model, prompt, options) {
|
|
113
112
|
eventSource.notify(error instanceof AbortError
|
114
113
|
? {
|
115
114
|
...finishMetadata,
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
prompt,
|
115
|
+
result: {
|
116
|
+
status: "abort",
|
117
|
+
},
|
120
118
|
}
|
121
119
|
: {
|
122
120
|
...finishMetadata,
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
error,
|
121
|
+
result: {
|
122
|
+
status: "error",
|
123
|
+
error,
|
124
|
+
},
|
128
125
|
});
|
129
126
|
},
|
130
127
|
}));
|
@@ -138,20 +135,18 @@ async function doStreamText(model, prompt, options) {
|
|
138
135
|
if (result.isAborted) {
|
139
136
|
eventSource.notify({
|
140
137
|
...finishMetadata,
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
prompt,
|
138
|
+
result: {
|
139
|
+
status: "abort",
|
140
|
+
},
|
145
141
|
});
|
146
142
|
throw new AbortError();
|
147
143
|
}
|
148
144
|
eventSource.notify({
|
149
145
|
...finishMetadata,
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
error: result.error,
|
146
|
+
result: {
|
147
|
+
status: "error",
|
148
|
+
error: result.error,
|
149
|
+
},
|
155
150
|
});
|
156
151
|
throw result.error;
|
157
152
|
}
|
@@ -1,20 +1,21 @@
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
2
2
|
import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
|
3
|
-
export
|
3
|
+
export interface SpeechSynthesisStartedEvent extends BaseModelCallStartedEvent {
|
4
4
|
functionType: "speech-synthesis";
|
5
|
-
settings: unknown;
|
6
5
|
text: string;
|
7
|
-
}
|
8
|
-
export type
|
9
|
-
functionType: "speech-synthesis";
|
10
|
-
settings: unknown;
|
11
|
-
text: string;
|
12
|
-
} & ({
|
6
|
+
}
|
7
|
+
export type SpeechSynthesisFinishedEventResult = {
|
13
8
|
status: "success";
|
14
|
-
response:
|
9
|
+
response: unknown;
|
10
|
+
output: Buffer;
|
15
11
|
} | {
|
16
12
|
status: "error";
|
17
13
|
error: unknown;
|
18
14
|
} | {
|
19
15
|
status: "abort";
|
20
|
-
}
|
16
|
+
};
|
17
|
+
export interface SpeechSynthesisFinishedEvent extends BaseModelCallFinishedEvent {
|
18
|
+
functionType: "speech-synthesis";
|
19
|
+
text: string;
|
20
|
+
result: SpeechSynthesisFinishedEventResult;
|
21
|
+
}
|
@@ -7,38 +7,12 @@ const executeCall_js_1 = require("../executeCall.cjs");
|
|
7
7
|
*/
|
8
8
|
function synthesizeSpeech(model, text, options) {
|
9
9
|
return (0, executeCall_js_1.executeCall)({
|
10
|
+
functionType: "speech-synthesis",
|
11
|
+
input: text,
|
10
12
|
model,
|
11
13
|
options,
|
12
14
|
generateResponse: (options) => model.generateSpeechResponse(text, options),
|
13
15
|
extractOutputValue: (buffer) => buffer,
|
14
|
-
getStartEvent: (metadata, settings) => ({
|
15
|
-
...metadata,
|
16
|
-
functionType: "speech-synthesis",
|
17
|
-
settings,
|
18
|
-
text,
|
19
|
-
}),
|
20
|
-
getAbortEvent: (metadata, settings) => ({
|
21
|
-
...metadata,
|
22
|
-
functionType: "speech-synthesis",
|
23
|
-
status: "abort",
|
24
|
-
settings,
|
25
|
-
text,
|
26
|
-
}),
|
27
|
-
getFailureEvent: (metadata, settings, error) => ({
|
28
|
-
...metadata,
|
29
|
-
functionType: "speech-synthesis",
|
30
|
-
settings,
|
31
|
-
text,
|
32
|
-
error,
|
33
|
-
}),
|
34
|
-
getSuccessEvent: (metadata, settings, response, output) => ({
|
35
|
-
...metadata,
|
36
|
-
functionType: "speech-synthesis",
|
37
|
-
settings,
|
38
|
-
text,
|
39
|
-
response,
|
40
|
-
speech: output,
|
41
|
-
}),
|
42
16
|
});
|
43
17
|
}
|
44
18
|
exports.synthesizeSpeech = synthesizeSpeech;
|
@@ -4,37 +4,11 @@ import { executeCall } from "../executeCall.js";
|
|
4
4
|
*/
|
5
5
|
export function synthesizeSpeech(model, text, options) {
|
6
6
|
return executeCall({
|
7
|
+
functionType: "speech-synthesis",
|
8
|
+
input: text,
|
7
9
|
model,
|
8
10
|
options,
|
9
11
|
generateResponse: (options) => model.generateSpeechResponse(text, options),
|
10
12
|
extractOutputValue: (buffer) => buffer,
|
11
|
-
getStartEvent: (metadata, settings) => ({
|
12
|
-
...metadata,
|
13
|
-
functionType: "speech-synthesis",
|
14
|
-
settings,
|
15
|
-
text,
|
16
|
-
}),
|
17
|
-
getAbortEvent: (metadata, settings) => ({
|
18
|
-
...metadata,
|
19
|
-
functionType: "speech-synthesis",
|
20
|
-
status: "abort",
|
21
|
-
settings,
|
22
|
-
text,
|
23
|
-
}),
|
24
|
-
getFailureEvent: (metadata, settings, error) => ({
|
25
|
-
...metadata,
|
26
|
-
functionType: "speech-synthesis",
|
27
|
-
settings,
|
28
|
-
text,
|
29
|
-
error,
|
30
|
-
}),
|
31
|
-
getSuccessEvent: (metadata, settings, response, output) => ({
|
32
|
-
...metadata,
|
33
|
-
functionType: "speech-synthesis",
|
34
|
-
settings,
|
35
|
-
text,
|
36
|
-
response,
|
37
|
-
speech: output,
|
38
|
-
}),
|
39
13
|
});
|
40
14
|
}
|
@@ -1,20 +1,18 @@
|
|
1
1
|
import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
|
2
|
-
export
|
2
|
+
export interface TranscriptionStartedEvent extends BaseModelCallStartedEvent {
|
3
3
|
functionType: "transcription";
|
4
|
-
|
5
|
-
|
6
|
-
};
|
7
|
-
export type TranscriptionFinishedEvent = BaseModelCallFinishedEvent & {
|
8
|
-
functionType: "transcription";
|
9
|
-
settings: unknown;
|
10
|
-
data: unknown;
|
11
|
-
} & ({
|
4
|
+
}
|
5
|
+
export type TranscriptionFinishedEventResult = {
|
12
6
|
status: "success";
|
13
7
|
response: unknown;
|
14
|
-
|
8
|
+
output: string;
|
15
9
|
} | {
|
16
10
|
status: "error";
|
17
11
|
error: unknown;
|
18
12
|
} | {
|
19
13
|
status: "abort";
|
20
|
-
}
|
14
|
+
};
|
15
|
+
export interface TranscriptionFinishedEvent extends BaseModelCallFinishedEvent {
|
16
|
+
functionType: "transcription";
|
17
|
+
result: TranscriptionFinishedEventResult;
|
18
|
+
}
|
@@ -18,37 +18,12 @@ const executeCall_js_1 = require("../executeCall.cjs");
|
|
18
18
|
*/
|
19
19
|
function transcribe(model, data, options) {
|
20
20
|
return (0, executeCall_js_1.executeCall)({
|
21
|
+
functionType: "transcription",
|
22
|
+
input: data,
|
21
23
|
model,
|
22
24
|
options,
|
23
25
|
generateResponse: (options) => model.generateTranscriptionResponse(data, options),
|
24
26
|
extractOutputValue: model.extractTranscriptionText,
|
25
|
-
getStartEvent: (metadata, settings) => ({
|
26
|
-
...metadata,
|
27
|
-
functionType: "transcription",
|
28
|
-
settings,
|
29
|
-
data,
|
30
|
-
}),
|
31
|
-
getAbortEvent: (metadata, settings) => ({
|
32
|
-
...metadata,
|
33
|
-
functionType: "transcription",
|
34
|
-
settings,
|
35
|
-
data,
|
36
|
-
}),
|
37
|
-
getFailureEvent: (metadata, settings, error) => ({
|
38
|
-
...metadata,
|
39
|
-
functionType: "transcription",
|
40
|
-
settings,
|
41
|
-
data,
|
42
|
-
error,
|
43
|
-
}),
|
44
|
-
getSuccessEvent: (metadata, settings, response, output) => ({
|
45
|
-
...metadata,
|
46
|
-
functionType: "transcription",
|
47
|
-
settings,
|
48
|
-
data,
|
49
|
-
response,
|
50
|
-
transcription: output,
|
51
|
-
}),
|
52
27
|
});
|
53
28
|
}
|
54
29
|
exports.transcribe = transcribe;
|
@@ -15,36 +15,11 @@ import { executeCall } from "../executeCall.js";
|
|
15
15
|
*/
|
16
16
|
export function transcribe(model, data, options) {
|
17
17
|
return executeCall({
|
18
|
+
functionType: "transcription",
|
19
|
+
input: data,
|
18
20
|
model,
|
19
21
|
options,
|
20
22
|
generateResponse: (options) => model.generateTranscriptionResponse(data, options),
|
21
23
|
extractOutputValue: model.extractTranscriptionText,
|
22
|
-
getStartEvent: (metadata, settings) => ({
|
23
|
-
...metadata,
|
24
|
-
functionType: "transcription",
|
25
|
-
settings,
|
26
|
-
data,
|
27
|
-
}),
|
28
|
-
getAbortEvent: (metadata, settings) => ({
|
29
|
-
...metadata,
|
30
|
-
functionType: "transcription",
|
31
|
-
settings,
|
32
|
-
data,
|
33
|
-
}),
|
34
|
-
getFailureEvent: (metadata, settings, error) => ({
|
35
|
-
...metadata,
|
36
|
-
functionType: "transcription",
|
37
|
-
settings,
|
38
|
-
data,
|
39
|
-
error,
|
40
|
-
}),
|
41
|
-
getSuccessEvent: (metadata, settings, response, output) => ({
|
42
|
-
...metadata,
|
43
|
-
functionType: "transcription",
|
44
|
-
settings,
|
45
|
-
data,
|
46
|
-
response,
|
47
|
-
transcription: output,
|
48
|
-
}),
|
49
24
|
});
|
50
25
|
}
|
@@ -63,13 +63,13 @@ export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEm
|
|
63
63
|
private get apiKey();
|
64
64
|
callAPI(texts: Array<string>, options?: ModelFunctionOptions<CohereTextEmbeddingModelSettings>): Promise<CohereTextEmbeddingResponse>;
|
65
65
|
generateEmbeddingResponse(texts: string[], options?: ModelFunctionOptions<CohereTextEmbeddingModelSettings>): Promise<{
|
66
|
-
texts: string[];
|
67
66
|
id: string;
|
68
67
|
meta: {
|
69
68
|
api_version: {
|
70
69
|
version: string;
|
71
70
|
};
|
72
71
|
};
|
72
|
+
texts: string[];
|
73
73
|
embeddings: number[][];
|
74
74
|
}>;
|
75
75
|
extractEmbeddings(response: CohereTextEmbeddingResponse): number[][];
|
@@ -97,22 +97,22 @@ declare const cohereTextEmbeddingResponseSchema: z.ZodObject<{
|
|
97
97
|
};
|
98
98
|
}>;
|
99
99
|
}, "strip", z.ZodTypeAny, {
|
100
|
-
texts: string[];
|
101
100
|
id: string;
|
102
101
|
meta: {
|
103
102
|
api_version: {
|
104
103
|
version: string;
|
105
104
|
};
|
106
105
|
};
|
106
|
+
texts: string[];
|
107
107
|
embeddings: number[][];
|
108
108
|
}, {
|
109
|
-
texts: string[];
|
110
109
|
id: string;
|
111
110
|
meta: {
|
112
111
|
api_version: {
|
113
112
|
version: string;
|
114
113
|
};
|
115
114
|
};
|
115
|
+
texts: string[];
|
116
116
|
embeddings: number[][];
|
117
117
|
}>;
|
118
118
|
export type CohereTextEmbeddingResponse = z.infer<typeof cohereTextEmbeddingResponseSchema>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import z from "zod";
|
2
2
|
import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
|
3
|
-
import { Run } from "../../
|
3
|
+
import { Run } from "../../core/Run.js";
|
4
4
|
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
5
5
|
import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
6
6
|
import { CohereTextGenerationModelType } from "./CohereTextGenerationModel.js";
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import z from "zod";
|
2
2
|
import { BasicTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
|
3
|
-
import { Run } from "../../
|
3
|
+
import { Run } from "../../core/Run.js";
|
4
4
|
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
5
5
|
import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
6
6
|
export interface LlamaCppTokenizerSettings {
|
package/package.json
CHANGED
@@ -1,20 +1,11 @@
|
|
1
|
-
import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../
|
2
|
-
|
3
|
-
export type ExecuteToolStartedEvent = BaseFunctionStartedEvent & {
|
1
|
+
import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../core/FunctionEvent.js";
|
2
|
+
export interface ExecuteToolStartedEvent extends BaseFunctionStartedEvent {
|
4
3
|
functionType: "execute-tool";
|
5
|
-
|
4
|
+
toolName: string;
|
6
5
|
input: unknown;
|
7
|
-
}
|
8
|
-
export
|
6
|
+
}
|
7
|
+
export interface ExecuteToolFinishedEvent extends BaseFunctionFinishedEvent {
|
9
8
|
functionType: "execute-tool";
|
10
|
-
|
9
|
+
toolName: string;
|
11
10
|
input: unknown;
|
12
|
-
}
|
13
|
-
status: "success";
|
14
|
-
output: unknown;
|
15
|
-
} | {
|
16
|
-
status: "error";
|
17
|
-
error: unknown;
|
18
|
-
} | {
|
19
|
-
status: "abort";
|
20
|
-
});
|
11
|
+
}
|
package/tool/Tool.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
import { SchemaDefinition } from "../model-function/generate-json/SchemaDefinition.js";
|
3
|
-
import { FunctionOptions } from "../
|
3
|
+
import { FunctionOptions } from "../core/FunctionOptions.js";
|
4
4
|
/**
|
5
5
|
* A tool is a function with a name, description and defined inputs that can be used
|
6
6
|
* by agents and chatbots.
|
package/tool/WebSearchTool.cjs
CHANGED
@@ -16,6 +16,31 @@ const createInputSchema = (description) =>
|
|
16
16
|
zod_1.z.object({
|
17
17
|
query: zod_1.z.string().describe(description),
|
18
18
|
});
|
19
|
+
/**
|
20
|
+
* A tool for searching the web.
|
21
|
+
*
|
22
|
+
* The input schema takes a query string.
|
23
|
+
* ```ts
|
24
|
+
* {
|
25
|
+
* query: "How many people live in Berlin?"
|
26
|
+
* }
|
27
|
+
* ```
|
28
|
+
*
|
29
|
+
* The output schema is an array of search results with title, link and snippet.
|
30
|
+
* ```ts
|
31
|
+
* {
|
32
|
+
* results:
|
33
|
+
* [
|
34
|
+
* {
|
35
|
+
* title: "Berlin - Wikipedia",
|
36
|
+
* link: "https://en.wikipedia.org/wiki/Berlin",
|
37
|
+
* snippet: "Berlin is the capital and largest city of Germany by...",
|
38
|
+
* },
|
39
|
+
* ...
|
40
|
+
* ]
|
41
|
+
* }
|
42
|
+
* ```
|
43
|
+
*/
|
19
44
|
class WebSearchTool extends Tool_js_1.Tool {
|
20
45
|
constructor({ name, description, queryDescription = "Search query", execute, }) {
|
21
46
|
super({
|
package/tool/WebSearchTool.d.ts
CHANGED
@@ -1,5 +1,33 @@
|
|
1
|
-
import {
|
1
|
+
import { z } from "zod";
|
2
|
+
import { FunctionOptions } from "../core/FunctionOptions.js";
|
2
3
|
import { Tool } from "./Tool.js";
|
4
|
+
declare const OUTPUT_SCHEMA: z.ZodObject<{
|
5
|
+
results: z.ZodArray<z.ZodObject<{
|
6
|
+
title: z.ZodString;
|
7
|
+
link: z.ZodString;
|
8
|
+
snippet: z.ZodString;
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
10
|
+
link: string;
|
11
|
+
title: string;
|
12
|
+
snippet: string;
|
13
|
+
}, {
|
14
|
+
link: string;
|
15
|
+
title: string;
|
16
|
+
snippet: string;
|
17
|
+
}>, "many">;
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
19
|
+
results: {
|
20
|
+
link: string;
|
21
|
+
title: string;
|
22
|
+
snippet: string;
|
23
|
+
}[];
|
24
|
+
}, {
|
25
|
+
results: {
|
26
|
+
link: string;
|
27
|
+
title: string;
|
28
|
+
snippet: string;
|
29
|
+
}[];
|
30
|
+
}>;
|
3
31
|
export type WebSearchToolInput = {
|
4
32
|
query: string;
|
5
33
|
};
|
@@ -10,7 +38,33 @@ export type WebSearchToolOutput = {
|
|
10
38
|
snippet: string;
|
11
39
|
}[];
|
12
40
|
};
|
41
|
+
/**
|
42
|
+
* A tool for searching the web.
|
43
|
+
*
|
44
|
+
* The input schema takes a query string.
|
45
|
+
* ```ts
|
46
|
+
* {
|
47
|
+
* query: "How many people live in Berlin?"
|
48
|
+
* }
|
49
|
+
* ```
|
50
|
+
*
|
51
|
+
* The output schema is an array of search results with title, link and snippet.
|
52
|
+
* ```ts
|
53
|
+
* {
|
54
|
+
* results:
|
55
|
+
* [
|
56
|
+
* {
|
57
|
+
* title: "Berlin - Wikipedia",
|
58
|
+
* link: "https://en.wikipedia.org/wiki/Berlin",
|
59
|
+
* snippet: "Berlin is the capital and largest city of Germany by...",
|
60
|
+
* },
|
61
|
+
* ...
|
62
|
+
* ]
|
63
|
+
* }
|
64
|
+
* ```
|
65
|
+
*/
|
13
66
|
export declare class WebSearchTool<NAME extends string> extends Tool<NAME, WebSearchToolInput, WebSearchToolOutput> {
|
67
|
+
readonly outputSchema: typeof OUTPUT_SCHEMA;
|
14
68
|
constructor({ name, description, queryDescription, execute, }: {
|
15
69
|
name: NAME;
|
16
70
|
description: string;
|
@@ -18,3 +72,4 @@ export declare class WebSearchTool<NAME extends string> extends Tool<NAME, WebSe
|
|
18
72
|
execute(input: WebSearchToolInput, options?: FunctionOptions): PromiseLike<WebSearchToolOutput>;
|
19
73
|
});
|
20
74
|
}
|
75
|
+
export {};
|
package/tool/WebSearchTool.js
CHANGED
@@ -13,6 +13,31 @@ const createInputSchema = (description) =>
|
|
13
13
|
z.object({
|
14
14
|
query: z.string().describe(description),
|
15
15
|
});
|
16
|
+
/**
|
17
|
+
* A tool for searching the web.
|
18
|
+
*
|
19
|
+
* The input schema takes a query string.
|
20
|
+
* ```ts
|
21
|
+
* {
|
22
|
+
* query: "How many people live in Berlin?"
|
23
|
+
* }
|
24
|
+
* ```
|
25
|
+
*
|
26
|
+
* The output schema is an array of search results with title, link and snippet.
|
27
|
+
* ```ts
|
28
|
+
* {
|
29
|
+
* results:
|
30
|
+
* [
|
31
|
+
* {
|
32
|
+
* title: "Berlin - Wikipedia",
|
33
|
+
* link: "https://en.wikipedia.org/wiki/Berlin",
|
34
|
+
* snippet: "Berlin is the capital and largest city of Germany by...",
|
35
|
+
* },
|
36
|
+
* ...
|
37
|
+
* ]
|
38
|
+
* }
|
39
|
+
* ```
|
40
|
+
*/
|
16
41
|
export class WebSearchTool extends Tool {
|
17
42
|
constructor({ name, description, queryDescription = "Search query", execute, }) {
|
18
43
|
super({
|
package/tool/executeTool.cjs
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.executeTool = exports.ExecuteToolPromise = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
|
-
const FunctionEventSource_js_1 = require("../
|
6
|
-
const GlobalFunctionObservers_js_1 = require("../
|
5
|
+
const FunctionEventSource_js_1 = require("../core/FunctionEventSource.cjs");
|
6
|
+
const GlobalFunctionObservers_js_1 = require("../core/GlobalFunctionObservers.cjs");
|
7
7
|
const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
|
8
8
|
const AbortError_js_1 = require("../util/api/AbortError.cjs");
|
9
9
|
const runSafe_js_1 = require("../util/runSafe.cjs");
|
@@ -69,7 +69,7 @@ async function doExecuteTool(tool, input, options) {
|
|
69
69
|
sessionId: run?.sessionId,
|
70
70
|
userId: run?.userId,
|
71
71
|
functionId: options?.functionId,
|
72
|
-
|
72
|
+
toolName: tool.name,
|
73
73
|
input,
|
74
74
|
};
|
75
75
|
eventSource.notify({
|
@@ -91,14 +91,18 @@ async function doExecuteTool(tool, input, options) {
|
|
91
91
|
if (result.isAborted) {
|
92
92
|
eventSource.notify({
|
93
93
|
...finishMetadata,
|
94
|
-
|
94
|
+
result: {
|
95
|
+
status: "abort",
|
96
|
+
},
|
95
97
|
});
|
96
98
|
throw new AbortError_js_1.AbortError();
|
97
99
|
}
|
98
100
|
eventSource.notify({
|
99
101
|
...finishMetadata,
|
100
|
-
|
101
|
-
|
102
|
+
result: {
|
103
|
+
status: "error",
|
104
|
+
error: result.error,
|
105
|
+
},
|
102
106
|
});
|
103
107
|
throw new ToolExecutionError_js_1.ToolExecutionError({
|
104
108
|
toolName: tool.name,
|
@@ -111,8 +115,10 @@ async function doExecuteTool(tool, input, options) {
|
|
111
115
|
const output = result.output;
|
112
116
|
eventSource.notify({
|
113
117
|
...finishMetadata,
|
114
|
-
|
115
|
-
|
118
|
+
result: {
|
119
|
+
status: "success",
|
120
|
+
output,
|
121
|
+
},
|
116
122
|
});
|
117
123
|
return {
|
118
124
|
output,
|
package/tool/executeTool.d.ts
CHANGED