@agentica/vector-selector 0.20.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/tools.ts","../src/extract_query.ts","../src/select.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":[null,null,null,null,null],"names":["Tools","extract_query","type","function","name","description","parameters","properties","query_list","items","reason","query","required","select_functions","function_list","function_name","async","extractQuery","ctx","completionStream","request","messages","role","content","join","histories","map","factory","flat","prompt","text","tool_choice","tools","chunks","utils","StreamUtil","readAll","completion","ChatGptCompletionMessageUtil","merge","queries","choices","message","tool_calls","flatMap","v","arg","JSON","parse","arguments","Array","isArray","selectFunction","props","toolList","prevFailures","restRetry","selectCompletion","AgenticaDefaultPrompt","write","config","id","stringify","tool_call_id","systemPrompt","select","AgenticaSystemPrompt","SELECT","emendMessages","parallel_tool_calls","then","toolCalls","filter","length","createTextHistory","failures","reduce","acc","cur","forEach","tc","errors","push","path","expected","value","idx","validation","data","feedback","Error","prompts","collection","selections","toJSON","s","operation","operations","get","undefined","selection","createOperationSelection","stack","dispatch","createSelectEvent","catch","f","uniqBy","array","selector","seen","Set","item","key","has","add","BootAgenticaVectorSelector","isEmbedded","setEmbedded","useEmbeddedContext","searchTool","embedContext","strategy","selectorExecute","Promise","all","res","output","op","protocol","method","tags","arr","set"],"mappings":";;;;;;AAEO,MAAMA,QAAQ;IACnBC,eAAe;QACbC,MAAM;QACNC,UAAU;YACRC,MAAM;YACNC,aAAa;YACbC,YAAY;gBACVJ,MAAM;gBACNK,YAAY;oBACVC,YAAY;wBACVN,MAAM;wBACNO,OAAO;4BACLP,MAAM;4BACNK,YAAY;gCACVG,QAAQ;oCACNR,MAAM;oCACNG,aAAa;;gCAEfM,OAAO;oCACLT,MAAM;oCACNG,aAAa;;;4BAGjBO,UAAU,EAAC,UAAU;;;;gBAI3BA,UAAU,EAAC;;;;IAKjBC,kBAAkB;QACh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AAI+E,WAAWrE,KAAKsE,IAAIrD,EAAEzC;YACrC,IAAI4H,OAAO7B,aAAa6B,GAAGC,aAAa,QAAQ;gBAC9C,OAAOpF;;YAGT,OAAO;mBACFA;gBACHqF,QAAQF,GAAG7H,SAAS+H;gBACpB/C,MAAM6C,GAAG7H,SAASgF;gBAClBgD,MAAMH,GAAG7H,SAASgI;;AACnB,cAEH7D,MAAK8D,OAAOzB,OAAOyB,MAAKvF,KAAKA,EAAEzC;QAEjC,IAAIkD,SAASmB,WAAW,GAAG;YACzB,OAAO;;QAGT,MAAMkB,gBAAgBvC,eAAe;YAAElC;YAAKoC;;QAC5C,OAAOqC;AAAO;IAGhB,OAAOgC;AACT;;SAEgBJ;IACd,MAAMc,MAAM,IAAItB;IAChB,OAAO;QACLM,YAAanG,OACXmH,IAAInB,IAAInE,KAAKe,UAAU5C,IAAI+E,WAAWW;QACxCU,aAAcpG;YACZmH,IAAIlB,IAAIpE,KAAKe,UAAU5C,IAAI+E,WAAWW;AAAO;;AAGnD;;"}
@@ -0,0 +1,17 @@
1
+ import type { AgenticaContext, AgenticaSelectHistory } from "@agentica/core";
2
+ import type { ILlmSchema } from "@samchon/openapi";
3
+ interface IFailure {
4
+ id: string;
5
+ name: string;
6
+ validation: {
7
+ data: string;
8
+ errors: string[];
9
+ };
10
+ }
11
+ export declare function selectFunction<SchemaModel extends ILlmSchema.Model>(props: {
12
+ ctx: AgenticaContext<SchemaModel>;
13
+ toolList: object[];
14
+ prevFailures?: IFailure[];
15
+ restRetry?: number;
16
+ }): Promise<import("@agentica/core").AgenticaTextHistory<"assistant">[] | AgenticaSelectHistory<SchemaModel>[]>;
17
+ export {};
package/lib/select.js ADDED
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.selectFunction = selectFunction;
13
+ const core_1 = require("@agentica/core");
14
+ const AgenticaDefaultPrompt_1 = require("@agentica/core/src/constants/AgenticaDefaultPrompt");
15
+ const AgenticaSystemPrompt_1 = require("@agentica/core/src/constants/AgenticaSystemPrompt");
16
+ const tools_1 = require("./tools");
17
+ function selectFunction(props) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ var _a, _b, _c, _d;
20
+ const { ctx, toolList, prevFailures = [], restRetry = 5 } = props;
21
+ const selectCompletion = yield ctx.request("select", {
22
+ messages: [
23
+ {
24
+ role: "system",
25
+ content: AgenticaDefaultPrompt_1.AgenticaDefaultPrompt.write(ctx.config),
26
+ },
27
+ {
28
+ role: "assistant",
29
+ tool_calls: [
30
+ {
31
+ type: "function",
32
+ id: "getApiFunctions",
33
+ function: {
34
+ name: "getApiFunctions",
35
+ arguments: JSON.stringify({}),
36
+ },
37
+ },
38
+ ],
39
+ },
40
+ {
41
+ role: "tool",
42
+ tool_call_id: "getApiFunctions",
43
+ content: JSON.stringify(toolList),
44
+ },
45
+ ...ctx.histories.flatMap((core_1.factory.decodeHistory)),
46
+ {
47
+ role: "user",
48
+ content: ctx.prompt.text,
49
+ },
50
+ {
51
+ role: "system",
52
+ content: `${(_d = (_c = (_b = (_a = ctx.config) === null || _a === void 0 ? void 0 : _a.systemPrompt) === null || _b === void 0 ? void 0 : _b.select) === null || _c === void 0 ? void 0 : _c.call(_b, ctx.histories)) !== null && _d !== void 0 ? _d : AgenticaSystemPrompt_1.AgenticaSystemPrompt.SELECT}
53
+
54
+
55
+ When selecting functions, consider what the user can call from their perspective, and choose all the functions necessary to accomplish the task.
56
+ Select them in a logical sequence, taking into account the relationships between each function.
57
+ `,
58
+ },
59
+ ...emendMessages(prevFailures),
60
+ ],
61
+ tool_choice: {
62
+ type: "function",
63
+ function: {
64
+ name: "select_functions",
65
+ },
66
+ },
67
+ parallel_tool_calls: false,
68
+ tools: [tools_1.Tools.select_functions],
69
+ })
70
+ .then((v) => __awaiter(this, void 0, void 0, function* () { return core_1.utils.StreamUtil.readAll(v); }))
71
+ .then(core_1.utils.ChatGptCompletionMessageUtil.merge);
72
+ const toolCalls = selectCompletion.choices
73
+ .filter(v => v.message.tool_calls != null);
74
+ if (toolCalls.length === 0) {
75
+ return selectCompletion.choices.flatMap((v) => {
76
+ if (v.message.content != null && v.message.content !== "") {
77
+ return [core_1.factory.createTextHistory({ role: "assistant", text: v.message.content })];
78
+ }
79
+ return [];
80
+ });
81
+ }
82
+ const failures = toolCalls.reduce((acc, cur) => {
83
+ var _a;
84
+ (_a = cur.message.tool_calls) === null || _a === void 0 ? void 0 : _a.forEach((tc) => {
85
+ const errors = [];
86
+ const arg = JSON.parse(tc.function.arguments);
87
+ if (!Array.isArray(arg)) {
88
+ errors.push(JSON.stringify({
89
+ path: "$input",
90
+ expected: "array",
91
+ value: arg,
92
+ }));
93
+ return;
94
+ }
95
+ arg.forEach((v, idx) => {
96
+ if (v.reason == null || typeof v.reason !== "string") {
97
+ errors.push(JSON.stringify({
98
+ path: `$$input[${idx}].reason`,
99
+ expected: "string",
100
+ value: v.reason,
101
+ }));
102
+ }
103
+ if (v.function_name == null || typeof v.function_name !== "string") {
104
+ errors.push(JSON.stringify({
105
+ path: `$$input[${idx}].function_name`,
106
+ expected: "string",
107
+ value: v.function_name,
108
+ }));
109
+ }
110
+ });
111
+ if (errors.length !== 0) {
112
+ acc.push({
113
+ id: tc.id,
114
+ name: tc.function.name,
115
+ validation: { data: tc.function.arguments, errors },
116
+ });
117
+ }
118
+ });
119
+ return acc;
120
+ }, []);
121
+ if (failures.length !== 0) {
122
+ const feedback = [...prevFailures, ...failures];
123
+ if (restRetry === 0) {
124
+ throw new Error(`Failed to select function after ${restRetry} retries\n${JSON.stringify(feedback)}`);
125
+ }
126
+ return selectFunction({
127
+ ctx,
128
+ toolList,
129
+ prevFailures: feedback,
130
+ restRetry: restRetry - 1,
131
+ });
132
+ }
133
+ const prompts = [];
134
+ toolCalls.forEach((v) => {
135
+ v.message.tool_calls.forEach((tc) => {
136
+ const collection = {
137
+ type: "select",
138
+ id: tc.id,
139
+ selections: [],
140
+ toJSON: () => ({
141
+ type: "select",
142
+ id: tc.id,
143
+ selections: collection.selections.map(s => s.toJSON()),
144
+ }),
145
+ };
146
+ const arg = JSON.parse(tc.function.arguments);
147
+ arg.function_list.forEach((v) => {
148
+ const operation = ctx.operations.flat.get(v.function_name);
149
+ if (operation === undefined) {
150
+ return;
151
+ }
152
+ const selection = core_1.factory.createOperationSelection({
153
+ reason: v.reason,
154
+ operation,
155
+ });
156
+ ctx.stack.push(selection);
157
+ ctx.dispatch(core_1.factory.createSelectEvent({ selection })).catch(() => { });
158
+ collection.selections.push(selection);
159
+ });
160
+ prompts.push(collection);
161
+ });
162
+ });
163
+ return prompts;
164
+ });
165
+ }
166
+ function emendMessages(failures) {
167
+ return failures
168
+ .flatMap(f => [
169
+ {
170
+ role: "assistant",
171
+ tool_calls: [
172
+ {
173
+ type: "function",
174
+ id: f.id,
175
+ function: {
176
+ name: f.name,
177
+ arguments: JSON.stringify(f.validation.data),
178
+ },
179
+ },
180
+ ],
181
+ },
182
+ {
183
+ role: "tool",
184
+ content: JSON.stringify(f.validation.errors),
185
+ tool_call_id: f.id,
186
+ },
187
+ {
188
+ role: "system",
189
+ content: [
190
+ "You A.I. assistant has composed wrong typed arguments.",
191
+ "",
192
+ "Correct it at the next function calling.",
193
+ ].join("\n"),
194
+ },
195
+ ]);
196
+ }
197
+ //# sourceMappingURL=select.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.js","sourceRoot":"","sources":["../src/select.ts"],"names":[],"mappings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,QAAQ;YACd,OAAO,EAAE;gBACP,wDAAwD;gBACxD,EAAE;gBACF,0CAA0C;aAC3C,CAAC,IAAI,CAAC,IAAI,CAAC;SACb;KACF,CAAiE,CAAC;AACvE,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./postgres.strategy";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./postgres.strategy"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/strategy/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
@@ -0,0 +1,4 @@
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
+ import type { IConnection } from "@wrtnlabs/connector-hive-api";
3
+ import type { IAgenticaVectorSelectorStrategy } from "..";
4
+ export declare function configurePostgresStrategy<SchemaModel extends ILlmSchema.Model>(connection: IConnection<object | undefined>): IAgenticaVectorSelectorStrategy<SchemaModel>;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.configurePostgresStrategy = configurePostgresStrategy;
13
+ const connector_hive_api_1 = require("@wrtnlabs/connector-hive-api");
14
+ const utils_1 = require("../utils");
15
+ const retry = (0, utils_1.getRetry)(3);
16
+ const filterMap = new Map();
17
+ function searchTool(connection) {
18
+ return (ctx, query) => __awaiter(this, void 0, void 0, function* () {
19
+ const filter = filterMap.get(JSON.stringify(ctx.operations.array));
20
+ return retry(() => __awaiter(this, void 0, void 0, function* () {
21
+ return connector_hive_api_1.functional.connector_retrievals.createRetrievalRequest(connection, {
22
+ query,
23
+ limit: 10,
24
+ filter,
25
+ });
26
+ }));
27
+ });
28
+ }
29
+ function embedOperation(connection) {
30
+ return (controllerName, opList) => __awaiter(this, void 0, void 0, function* () {
31
+ const application = yield retry(() => __awaiter(this, void 0, void 0, function* () {
32
+ return connector_hive_api_1.functional.applications.create(connection, {
33
+ name: controllerName,
34
+ description: undefined,
35
+ });
36
+ })).catch((e) => __awaiter(this, void 0, void 0, function* () {
37
+ if (!(e instanceof connector_hive_api_1.HttpError)) {
38
+ throw e;
39
+ }
40
+ if (e.status !== 409) {
41
+ throw e;
42
+ }
43
+ return retry(() => __awaiter(this, void 0, void 0, function* () {
44
+ return connector_hive_api_1.functional.applications.by_names.getByName(connection, controllerName);
45
+ }));
46
+ }));
47
+ const version = yield retry(() => __awaiter(this, void 0, void 0, function* () {
48
+ return connector_hive_api_1.functional.applications.by_ids.versions.create(connection, application.id, {});
49
+ }));
50
+ // concurrency request count
51
+ yield (0, utils_1.groupByArray)(opList, 10).reduce((accPromise, cur) => __awaiter(this, void 0, void 0, function* () {
52
+ yield accPromise;
53
+ yield Promise.all(cur.map((v) => __awaiter(this, void 0, void 0, function* () {
54
+ return retry(() => __awaiter(this, void 0, void 0, function* () {
55
+ var _a;
56
+ return connector_hive_api_1.functional.application_versions.by_ids.connectors.create(connection, version.id, { name: v.name, description: (_a = v.function.description) !== null && _a !== void 0 ? _a : "" });
57
+ }));
58
+ })));
59
+ return Promise.resolve();
60
+ }), Promise.resolve());
61
+ return { version, applicationId: application.id };
62
+ });
63
+ }
64
+ function embedContext(connection) {
65
+ return (props) => __awaiter(this, void 0, void 0, function* () {
66
+ const { ctx, setEmbedded } = props;
67
+ const filter = yield Promise.all(Array.from(ctx.operations.group.entries()).map((_a) => __awaiter(this, [_a], void 0, function* ([key, value]) {
68
+ const result = yield embedOperation(connection)(key, Array.from(value.values()));
69
+ return {
70
+ id: result.applicationId,
71
+ version: result.version.version,
72
+ type: "byId",
73
+ };
74
+ })));
75
+ filterMap.set(JSON.stringify(ctx.operations.array), {
76
+ applications: filter,
77
+ });
78
+ setEmbedded();
79
+ });
80
+ }
81
+ function configurePostgresStrategy(connection) {
82
+ return {
83
+ searchTool: searchTool(connection),
84
+ embedContext: embedContext(connection),
85
+ };
86
+ }
87
+ //# sourceMappingURL=postgres.strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.strategy.js","sourceRoot":"","sources":["../../src/strategy/postgres.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;AA+GA,8DAKC;AA/GD,qEAAqE;AAIrE,oCAAkD;AAElD,MAAM,KAAK,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAC;AAE1B,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkD,CAAC;AAC5E,SAAS,UAAU,CAAuC,UAA2C;IACnG,OAAO,CAAO,GAAiC,EAAE,KAAa,EAAE,EAAE;QAChE,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,KAA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M;aACmD,CAAC;QACpE,CAAC,CAAA,CACF,CACF,CAAC;QACF,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAClD,YAAY,EAAE,MAAM;SACrB,CAAC,CAAC;QACH,WAAW,EAAE,CAAC;IAChB,CAAC,CAAA,CAAC;AACJ,CAAC;AAED,SAAgB,yBAAyB,CAAuC,UAA2C;IACzH,OAAO;QACL,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC;QAClC,YAAY,EAAE,YAAY,CAAC,UAAU,CAAC;KACvC,CAAC;AACJ,CAAC"}
package/lib/tools.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ export declare const Tools: {
2
+ readonly extract_query: {
3
+ readonly type: "function";
4
+ readonly function: {
5
+ readonly name: "extract_search_query";
6
+ readonly description: "extract search query from user message\n";
7
+ readonly parameters: {
8
+ readonly type: "object";
9
+ readonly properties: {
10
+ readonly query_list: {
11
+ readonly type: "array";
12
+ readonly items: {
13
+ readonly type: "object";
14
+ readonly properties: {
15
+ readonly reason: {
16
+ readonly type: "string";
17
+ readonly description: "The reason of the query selection.\n\nJust write the reason why you've determined to select this query.";
18
+ };
19
+ readonly query: {
20
+ readonly type: "string";
21
+ readonly description: "the search query";
22
+ };
23
+ };
24
+ readonly required: readonly ["reason", "query"];
25
+ };
26
+ };
27
+ };
28
+ readonly required: readonly ["query_list"];
29
+ };
30
+ };
31
+ };
32
+ readonly select_functions: {
33
+ readonly type: "function";
34
+ readonly function: {
35
+ readonly name: "select_functions";
36
+ readonly description: "Select proper API functions to call.\n\nIf you A.I. agent has found some proper API functions to call\nfrom the conversation with user, please select the API functions\njust by calling this function.\n\nWhen user wants to call a same function multiply, you A.I. agent must\nlist up it multiply in the `functions` property. Otherwise the user has\nrequested to call many different functions, you A.I. agent have to assign\nthem all into the `functions` property.\n\nAlso, if you A.I. agent can't specify a specific function to call due to lack\nof specificity or homogeneity of candidate functions, just assign all of them\nby in the `functions` property too. Instead, when you A.I. agent can specify\na specific function to call, the others would be eliminated.\n\n@example\n```json\n[\n {\n \"reason\": \"The user wants to call the function multiply.\",\n \"function_name\": \"get_user_info\"\n },\n {\n \"reason\": \"The user wants to modify the user info.\",\n \"function_name\": \"modify_user_info\"\n }\n]\n```\n";
37
+ readonly parameters: {
38
+ readonly type: "object";
39
+ readonly properties: {
40
+ readonly function_list: {
41
+ readonly type: "array";
42
+ readonly items: {
43
+ readonly type: "object";
44
+ readonly properties: {
45
+ readonly reason: {
46
+ readonly type: "string";
47
+ readonly description: "The reason of the function selection.\n\nJust write the reason why you've determined to select this function.";
48
+ };
49
+ readonly function_name: {
50
+ readonly type: "string";
51
+ readonly description: "Name of the target function to call.";
52
+ };
53
+ };
54
+ readonly required: readonly ["reason", "function_name"];
55
+ };
56
+ };
57
+ };
58
+ readonly required: readonly ["function_list"];
59
+ };
60
+ };
61
+ };
62
+ };
package/lib/tools.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tools = void 0;
4
+ exports.Tools = {
5
+ extract_query: {
6
+ type: "function",
7
+ function: {
8
+ name: "extract_search_query",
9
+ description: "extract search query from user message\n",
10
+ parameters: {
11
+ type: "object",
12
+ properties: {
13
+ query_list: {
14
+ type: "array",
15
+ items: {
16
+ type: "object",
17
+ properties: {
18
+ reason: {
19
+ type: "string",
20
+ description: "The reason of the query selection.\n\nJust write the reason why you've determined to select this query.",
21
+ },
22
+ query: {
23
+ type: "string",
24
+ description: "the search query",
25
+ },
26
+ },
27
+ required: ["reason", "query"],
28
+ },
29
+ },
30
+ },
31
+ required: ["query_list"],
32
+ },
33
+ },
34
+ },
35
+ select_functions: {
36
+ type: "function",
37
+ function: {
38
+ name: "select_functions",
39
+ description: `Select proper API functions to call.
40
+
41
+ If you A.I. agent has found some proper API functions to call
42
+ from the conversation with user, please select the API functions
43
+ just by calling this function.
44
+
45
+ When user wants to call a same function multiply, you A.I. agent must
46
+ list up it multiply in the \`functions\` property. Otherwise the user has
47
+ requested to call many different functions, you A.I. agent have to assign
48
+ them all into the \`functions\` property.
49
+
50
+ Also, if you A.I. agent can't specify a specific function to call due to lack
51
+ of specificity or homogeneity of candidate functions, just assign all of them
52
+ by in the \`functions\` property too. Instead, when you A.I. agent can specify
53
+ a specific function to call, the others would be eliminated.
54
+
55
+ @example
56
+ \`\`\`json
57
+ [
58
+ {
59
+ "reason": "The user wants to call the function multiply.",
60
+ "function_name": "get_user_info"
61
+ },
62
+ {
63
+ "reason": "The user wants to modify the user info.",
64
+ "function_name": "modify_user_info"
65
+ }
66
+ ]
67
+ \`\`\`
68
+ `,
69
+ parameters: {
70
+ type: "object",
71
+ properties: {
72
+ function_list: {
73
+ type: "array",
74
+ items: {
75
+ type: "object",
76
+ properties: {
77
+ reason: {
78
+ type: "string",
79
+ description: "The reason of the function selection.\n\nJust write the reason why you've determined to select this function.",
80
+ },
81
+ function_name: {
82
+ type: "string",
83
+ description: "Name of the target function to call.",
84
+ },
85
+ },
86
+ required: ["reason", "function_name"],
87
+ },
88
+ },
89
+ },
90
+ required: ["function_list"],
91
+ },
92
+ },
93
+ },
94
+ };
95
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":";;;AAEa,QAAA,KAAK,GAAG;IACnB,aAAa,EAAE;QACb,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,sBAAsB;YAC5B,WAAW,EAAE,0CAA0C;YACvD,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,UAAU,EAAE;wBACV,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE;4BACL,IAAI,EAAE,QAAQ;4BACd,UAAU,EAAE;gCACV,MAAM,EAAE;oCACN,IAAI,EAAE,QAAQ;oCACd,WAAW,EAAE,yGAAyG;iCACvH;gCACD,KAAK,EAAE;oCACL,IAAI,EAAE,QAAQ;oCACd,WAAW,EAAE,kBAAkB;iCAChC;6BACF;4BACD,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC;yBAC9B;qBACF;iBACF;gBACD,QAAQ,EAAE,CAAC,YAAY,CAAC;aACzB;SACF;KACF;IAED,gBAAgB,EAAE;QAChB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,kBAAkB;YACxB,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BlB;YACK,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,aAAa,EAAE;wBACb,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE;4BACL,IAAI,EAAE,QAAQ;4BACd,UAAU,EAAE;gCACV,MAAM,EAAE;oCACN,IAAI,EAAE,QAAQ;oCACd,WAAW,EAAE,+GAA+G;iCAC7H;gCACD,aAAa,EAAE;oCACb,IAAI,EAAE,QAAQ;oCACd,WAAW,EAAE,sCAAsC;iCACpD;6BACF;4BACD,QAAQ,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC;yBACtC;qBACF;iBACF;gBACD,QAAQ,EAAE,CAAC,eAAe,CAAC;aAC5B;SACF;KACF;CAMF,CAAC"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ import type { GreaterThan, Integer } from "type-fest";
2
+ /** type function to check if a number is greater than 0 */
3
+ type GreaterThanZeroInteger<T extends number> = GreaterThan<Integer<T>, 0> extends true ? T : never;
4
+ /**
5
+ * This function is used to get a retry function.
6
+ *
7
+ * It will throw an error if the count is not a number,
8
+ * or if the count is not a finite number,
9
+ * or if the count is not an integer,
10
+ * or if the count is less than 1.
11
+ *
12
+ * @param count - The number of times to retry the function.
13
+ * @returns A retry function.
14
+ * @throws {TypeError} If the count is not a number, or if the count is not a finite number, or if the count is not an integer, or if the count is less than 1.
15
+ * @throws {Error} If the function fails to return a value after the specified number of retries.
16
+ */
17
+ export declare function getRetry<TCount extends number>(count: GreaterThanZeroInteger<TCount>): <T>(fn: () => Promise<T>) => Promise<T>;
18
+ /**
19
+ * This function is used to group an array into a 2-dimensional array.
20
+ *
21
+ * It will throw an error if the count is not a number,
22
+ * or if the count is not a finite number,
23
+ * or if the count is not an integer,
24
+ * or if the count is less than 1.
25
+ *
26
+ * @param array - The array to group.
27
+ * @param count - The number of elements in each group.
28
+ * @returns A 2-dimensional array.
29
+ */
30
+ export declare function groupByArray<T, TCount extends number>(array: T[], count: GreaterThanZeroInteger<TCount>): T[][];
31
+ /**
32
+ * Removes duplicates from an array.
33
+ * You can specify which value to compare using a property selector function.
34
+ *
35
+ * @param array - Array to remove duplicates from
36
+ * @param selector - Function that selects the value to compare
37
+ * @returns New array with duplicates removed
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const users = [
42
+ * { id: 1, name: 'John' },
43
+ * { id: 2, name: 'Jane' },
44
+ * { id: 1, name: 'John' }
45
+ * ];
46
+ *
47
+ * const uniqueUsers = uniqBy(users, user => user.id);
48
+ * // Result: [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
49
+ * ```
50
+ */
51
+ export declare function uniqBy<T, K>(array: T[], selector: (item: T) => K): T[];
52
+ export {};