koishi-plugin-chatluna 1.2.0 → 1.2.2
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/lib/index.cjs +12 -6
- package/lib/index.mjs +6 -0
- package/lib/llm-core/agent/index.cjs +33 -33
- package/lib/llm-core/agent/index.mjs +33 -33
- package/lib/llm-core/agent/openai/index.d.ts +1 -1
- package/lib/llm-core/agent/react/index.d.ts +1 -1
- package/lib/llm-core/agent/react/prompt.d.ts +1 -1
- package/lib/llm-core/chain/prompt.cjs +0 -1
- package/lib/llm-core/chain/prompt.mjs +0 -1
- package/lib/services/chat.cjs +6 -1
- package/lib/services/chat.mjs +6 -1
- package/lib/utils/lock.cjs +9 -1
- package/lib/utils/lock.mjs +9 -1
- package/lib/utils/string.cjs +12 -0
- package/lib/utils/string.d.ts +1 -0
- package/lib/utils/string.mjs +11 -0
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -3885,6 +3885,7 @@ __name(apply40, "apply");
|
|
|
3885
3885
|
|
|
3886
3886
|
// src/middlewares/read_chat_message.ts
|
|
3887
3887
|
var import_koishi8 = require("koishi");
|
|
3888
|
+
var import_string = require("koishi-plugin-chatluna/utils/string");
|
|
3888
3889
|
function apply41(ctx, config, chain) {
|
|
3889
3890
|
chain.middleware("read_chat_message", async (session, context) => {
|
|
3890
3891
|
let message = context.command != null ? context.message : session.elements;
|
|
@@ -3922,6 +3923,7 @@ function apply41(ctx, config, chain) {
|
|
|
3922
3923
|
"img",
|
|
3923
3924
|
async (session, element, message) => {
|
|
3924
3925
|
const images = message.additional_kwargs.images ?? [];
|
|
3926
|
+
const imageHashs = message.additional_kwargs.imageHashs ?? [];
|
|
3925
3927
|
const url = element.attrs.url ?? element.attrs.src;
|
|
3926
3928
|
logger.debug(`image url: ${url}`);
|
|
3927
3929
|
const readImage = /* @__PURE__ */ __name(async (url2) => {
|
|
@@ -3940,6 +3942,9 @@ function apply41(ctx, config, chain) {
|
|
|
3940
3942
|
const base64 = Buffer.from(buffer).toString("base64");
|
|
3941
3943
|
images.push(`data:image/${ext ?? "jpeg"};base64,${base64}`);
|
|
3942
3944
|
}, "readImage");
|
|
3945
|
+
const imageHash = await (0, import_string.hashString)(url, 8);
|
|
3946
|
+
imageHashs.push(imageHash);
|
|
3947
|
+
element.attrs["imageHash"] = imageHash;
|
|
3943
3948
|
if (url.startsWith("data:image") && url.includes("base64")) {
|
|
3944
3949
|
images.push(url);
|
|
3945
3950
|
} else {
|
|
@@ -3954,6 +3959,7 @@ function apply41(ctx, config, chain) {
|
|
|
3954
3959
|
}
|
|
3955
3960
|
}
|
|
3956
3961
|
message.additional_kwargs.images = images;
|
|
3962
|
+
message.additional_kwargs.imageHashs = imageHashs;
|
|
3957
3963
|
if (message.content?.length < 1) {
|
|
3958
3964
|
message.content = "[image]";
|
|
3959
3965
|
}
|
|
@@ -4009,7 +4015,7 @@ var import_count_tokens3 = require("koishi-plugin-chatluna/llm-core/utils/count_
|
|
|
4009
4015
|
var import_error6 = require("koishi-plugin-chatluna/utils/error");
|
|
4010
4016
|
var import_logger5 = require("koishi-plugin-chatluna/utils/logger");
|
|
4011
4017
|
var import_chains = require("koishi-plugin-chatluna/chains");
|
|
4012
|
-
var
|
|
4018
|
+
var import_string2 = require("koishi-plugin-chatluna/utils/string");
|
|
4013
4019
|
|
|
4014
4020
|
// src/utils/buffer_text.ts
|
|
4015
4021
|
var import_koishi9 = require("koishi");
|
|
@@ -4160,7 +4166,7 @@ function apply43(ctx, config, chain) {
|
|
|
4160
4166
|
presetTemplate.config?.postHandler?.prefix,
|
|
4161
4167
|
presetTemplate.config?.postHandler?.postfix
|
|
4162
4168
|
);
|
|
4163
|
-
const postHandler = presetTemplate.config?.postHandler ? new
|
|
4169
|
+
const postHandler = presetTemplate.config?.postHandler ? new import_string2.PresetPostHandler(
|
|
4164
4170
|
ctx,
|
|
4165
4171
|
config,
|
|
4166
4172
|
presetTemplate.config?.postHandler
|
|
@@ -4343,7 +4349,7 @@ function getSystemPromptVariables(session, config, room) {
|
|
|
4343
4349
|
is_group: (!session.isDirect || session.guildId != null).toString(),
|
|
4344
4350
|
is_private: session.isDirect?.toString(),
|
|
4345
4351
|
user_id: session.author?.user?.id ?? session.event?.user?.id ?? "0",
|
|
4346
|
-
user: (0,
|
|
4352
|
+
user: (0, import_string2.getNotEmptyString)(
|
|
4347
4353
|
session.author?.nick,
|
|
4348
4354
|
session.author?.name,
|
|
4349
4355
|
session.event.user?.name,
|
|
@@ -4351,8 +4357,8 @@ function getSystemPromptVariables(session, config, room) {
|
|
|
4351
4357
|
),
|
|
4352
4358
|
noop: "",
|
|
4353
4359
|
time: (/* @__PURE__ */ new Date()).toLocaleTimeString(),
|
|
4354
|
-
weekday: (0,
|
|
4355
|
-
idle_duration: (0,
|
|
4360
|
+
weekday: (0, import_string2.getCurrentWeekday)(),
|
|
4361
|
+
idle_duration: (0, import_string2.getTimeDiffFormat)(
|
|
4356
4362
|
(/* @__PURE__ */ new Date()).getTime(),
|
|
4357
4363
|
room.updatedTime.getTime()
|
|
4358
4364
|
)
|
|
@@ -4391,7 +4397,7 @@ async function formatUserPromptString(config, presetTemplate, session, prompt, r
|
|
|
4391
4397
|
presetTemplate.formatUserPromptString,
|
|
4392
4398
|
{
|
|
4393
4399
|
sender_id: session.author?.user?.id ?? session.event?.user?.id ?? "0",
|
|
4394
|
-
sender: (0,
|
|
4400
|
+
sender: (0, import_string2.getNotEmptyString)(
|
|
4395
4401
|
session.author?.nick,
|
|
4396
4402
|
session.author?.name,
|
|
4397
4403
|
session.event.user?.name,
|
package/lib/index.mjs
CHANGED
|
@@ -3879,6 +3879,7 @@ __name(apply40, "apply");
|
|
|
3879
3879
|
|
|
3880
3880
|
// src/middlewares/read_chat_message.ts
|
|
3881
3881
|
import { h as h4 } from "koishi";
|
|
3882
|
+
import { hashString } from "koishi-plugin-chatluna/utils/string";
|
|
3882
3883
|
function apply41(ctx, config, chain) {
|
|
3883
3884
|
chain.middleware("read_chat_message", async (session, context) => {
|
|
3884
3885
|
let message = context.command != null ? context.message : session.elements;
|
|
@@ -3916,6 +3917,7 @@ function apply41(ctx, config, chain) {
|
|
|
3916
3917
|
"img",
|
|
3917
3918
|
async (session, element, message) => {
|
|
3918
3919
|
const images = message.additional_kwargs.images ?? [];
|
|
3920
|
+
const imageHashs = message.additional_kwargs.imageHashs ?? [];
|
|
3919
3921
|
const url = element.attrs.url ?? element.attrs.src;
|
|
3920
3922
|
logger.debug(`image url: ${url}`);
|
|
3921
3923
|
const readImage = /* @__PURE__ */ __name(async (url2) => {
|
|
@@ -3934,6 +3936,9 @@ function apply41(ctx, config, chain) {
|
|
|
3934
3936
|
const base64 = Buffer.from(buffer).toString("base64");
|
|
3935
3937
|
images.push(`data:image/${ext ?? "jpeg"};base64,${base64}`);
|
|
3936
3938
|
}, "readImage");
|
|
3939
|
+
const imageHash = await hashString(url, 8);
|
|
3940
|
+
imageHashs.push(imageHash);
|
|
3941
|
+
element.attrs["imageHash"] = imageHash;
|
|
3937
3942
|
if (url.startsWith("data:image") && url.includes("base64")) {
|
|
3938
3943
|
images.push(url);
|
|
3939
3944
|
} else {
|
|
@@ -3948,6 +3953,7 @@ function apply41(ctx, config, chain) {
|
|
|
3948
3953
|
}
|
|
3949
3954
|
}
|
|
3950
3955
|
message.additional_kwargs.images = images;
|
|
3956
|
+
message.additional_kwargs.imageHashs = imageHashs;
|
|
3951
3957
|
if (message.content?.length < 1) {
|
|
3952
3958
|
message.content = "[image]";
|
|
3953
3959
|
}
|
|
@@ -1139,10 +1139,10 @@ Your reasoning and thought process for the current step
|
|
|
1139
1139
|
|
|
1140
1140
|
<tool_calling>
|
|
1141
1141
|
[
|
|
1142
|
-
{
|
|
1142
|
+
{{
|
|
1143
1143
|
"name": "tool_name",
|
|
1144
|
-
"arguments": {"param1": "value1", "param2": "value2"}
|
|
1145
|
-
|
|
1144
|
+
"arguments": {{"param1": "value1", "param2": "value2"}}
|
|
1145
|
+
}}
|
|
1146
1146
|
]
|
|
1147
1147
|
</tool_calling>
|
|
1148
1148
|
|
|
@@ -1158,10 +1158,10 @@ I have gathered all the necessary information and can now provide the final answ
|
|
|
1158
1158
|
|
|
1159
1159
|
<tool_calling>
|
|
1160
1160
|
[
|
|
1161
|
-
{
|
|
1161
|
+
{{
|
|
1162
1162
|
"name": "final_answer",
|
|
1163
|
-
"arguments": {"answer": "insert your final answer here"}
|
|
1164
|
-
}
|
|
1163
|
+
"arguments": {{"answer": "insert your final answer here"}}
|
|
1164
|
+
}}
|
|
1165
1165
|
]
|
|
1166
1166
|
</tool_calling>
|
|
1167
1167
|
|
|
@@ -1175,10 +1175,10 @@ I need to first find out who is the oldest person in the document, then generate
|
|
|
1175
1175
|
|
|
1176
1176
|
<tool_calling>
|
|
1177
1177
|
[
|
|
1178
|
-
{
|
|
1178
|
+
{{
|
|
1179
1179
|
"name": "document_qa",
|
|
1180
|
-
"arguments": {"document": "document.pdf", "question": "Who is the oldest person mentioned?"}
|
|
1181
|
-
}
|
|
1180
|
+
"arguments": {{"document": "document.pdf", "question": "Who is the oldest person mentioned?"}}
|
|
1181
|
+
}}
|
|
1182
1182
|
]
|
|
1183
1183
|
</tool_calling>
|
|
1184
1184
|
|
|
@@ -1190,14 +1190,14 @@ Now I know the oldest person is John Doe, a 55-year-old lumberjack from Newfound
|
|
|
1190
1190
|
|
|
1191
1191
|
<tool_calling>
|
|
1192
1192
|
[
|
|
1193
|
-
|
|
1193
|
+
{{
|
|
1194
1194
|
"name": "image_generator",
|
|
1195
|
-
"arguments": {"prompt": "A portrait of John Doe, a 55-year-old lumberjack living in Newfoundland, Canada"}
|
|
1196
|
-
},
|
|
1197
|
-
{
|
|
1195
|
+
"arguments": {{"prompt": "A portrait of John Doe, a 55-year-old lumberjack living in Newfoundland, Canada"}}
|
|
1196
|
+
}},
|
|
1197
|
+
{{
|
|
1198
1198
|
"name": "search",
|
|
1199
|
-
"arguments": {"query": "John Doe lumberjack Newfoundland biography"}
|
|
1200
|
-
}
|
|
1199
|
+
"arguments": {{"query": "John Doe lumberjack Newfoundland biography"}}
|
|
1200
|
+
}}
|
|
1201
1201
|
]
|
|
1202
1202
|
</tool_calling>
|
|
1203
1203
|
|
|
@@ -1209,10 +1209,10 @@ I have successfully generated an image and found biographical information. Now I
|
|
|
1209
1209
|
|
|
1210
1210
|
<tool_calling>
|
|
1211
1211
|
[
|
|
1212
|
-
{
|
|
1212
|
+
{{
|
|
1213
1213
|
"name": "final_answer",
|
|
1214
|
-
"arguments": {"answer": "I have generated an image (image.png) of John Doe, the oldest person in the document, and found that he is a well-known lumberjack in Newfoundland with over 30 years of experience in forestry."}
|
|
1215
|
-
}
|
|
1214
|
+
"arguments": {{"answer": "I have generated an image (image.png) of John Doe, the oldest person in the document, and found that he is a well-known lumberjack in Newfoundland with over 30 years of experience in forestry."}}
|
|
1215
|
+
}}
|
|
1216
1216
|
]
|
|
1217
1217
|
</tool_calling>
|
|
1218
1218
|
|
|
@@ -1225,10 +1225,10 @@ I need to calculate the sum of 5 + 3 + 1294.678. I'll use the python_interpreter
|
|
|
1225
1225
|
|
|
1226
1226
|
<tool_calling>
|
|
1227
1227
|
[
|
|
1228
|
-
{
|
|
1228
|
+
{{
|
|
1229
1229
|
"name": "python_interpreter",
|
|
1230
|
-
"arguments": {"code": "5 + 3 + 1294.678"}
|
|
1231
|
-
}
|
|
1230
|
+
"arguments": {{"code": "5 + 3 + 1294.678"}}
|
|
1231
|
+
}}
|
|
1232
1232
|
]
|
|
1233
1233
|
</tool_calling>
|
|
1234
1234
|
|
|
@@ -1240,10 +1240,10 @@ I have calculated the result. Now I can provide the final answer.
|
|
|
1240
1240
|
|
|
1241
1241
|
<tool_calling>
|
|
1242
1242
|
[
|
|
1243
|
-
{
|
|
1243
|
+
{{
|
|
1244
1244
|
"name": "final_answer",
|
|
1245
|
-
"arguments": {"answer": "1302.678"}
|
|
1246
|
-
}
|
|
1245
|
+
"arguments": {{"answer": "1302.678"}}
|
|
1246
|
+
}}
|
|
1247
1247
|
]
|
|
1248
1248
|
</tool_calling>
|
|
1249
1249
|
|
|
@@ -1256,14 +1256,14 @@ I need to search for the population data of both Guangzhou and Shanghai to compa
|
|
|
1256
1256
|
|
|
1257
1257
|
<tool_calling>
|
|
1258
1258
|
[
|
|
1259
|
-
{
|
|
1259
|
+
{{
|
|
1260
1260
|
"name": "search",
|
|
1261
|
-
"arguments": {"query": "Population Guangzhou 2023"}
|
|
1262
|
-
},
|
|
1263
|
-
{
|
|
1261
|
+
"arguments": {{"query": "Population Guangzhou 2023"}}
|
|
1262
|
+
}},
|
|
1263
|
+
{{
|
|
1264
1264
|
"name": "search",
|
|
1265
|
-
"arguments": {"query": "Population Shanghai 2023"}
|
|
1266
|
-
}
|
|
1265
|
+
"arguments": {{"query": "Population Shanghai 2023"}}
|
|
1266
|
+
}}
|
|
1267
1267
|
]
|
|
1268
1268
|
</tool_calling>
|
|
1269
1269
|
|
|
@@ -1275,10 +1275,10 @@ Based on the search results, Shanghai has a population of 26 million while Guang
|
|
|
1275
1275
|
|
|
1276
1276
|
<tool_calling>
|
|
1277
1277
|
[
|
|
1278
|
-
{
|
|
1278
|
+
{{
|
|
1279
1279
|
"name": "final_answer",
|
|
1280
|
-
"arguments": {"answer": "Shanghai has the highest population with 26 million people, compared to Guangzhou's 15 million people."}
|
|
1281
|
-
}
|
|
1280
|
+
"arguments": {{"answer": "Shanghai has the highest population with 26 million people, compared to Guangzhou's 15 million people."}}
|
|
1281
|
+
}}
|
|
1282
1282
|
]
|
|
1283
1283
|
</tool_calling>
|
|
1284
1284
|
|
|
@@ -1127,10 +1127,10 @@ Your reasoning and thought process for the current step
|
|
|
1127
1127
|
|
|
1128
1128
|
<tool_calling>
|
|
1129
1129
|
[
|
|
1130
|
-
{
|
|
1130
|
+
{{
|
|
1131
1131
|
"name": "tool_name",
|
|
1132
|
-
"arguments": {"param1": "value1", "param2": "value2"}
|
|
1133
|
-
|
|
1132
|
+
"arguments": {{"param1": "value1", "param2": "value2"}}
|
|
1133
|
+
}}
|
|
1134
1134
|
]
|
|
1135
1135
|
</tool_calling>
|
|
1136
1136
|
|
|
@@ -1146,10 +1146,10 @@ I have gathered all the necessary information and can now provide the final answ
|
|
|
1146
1146
|
|
|
1147
1147
|
<tool_calling>
|
|
1148
1148
|
[
|
|
1149
|
-
{
|
|
1149
|
+
{{
|
|
1150
1150
|
"name": "final_answer",
|
|
1151
|
-
"arguments": {"answer": "insert your final answer here"}
|
|
1152
|
-
}
|
|
1151
|
+
"arguments": {{"answer": "insert your final answer here"}}
|
|
1152
|
+
}}
|
|
1153
1153
|
]
|
|
1154
1154
|
</tool_calling>
|
|
1155
1155
|
|
|
@@ -1163,10 +1163,10 @@ I need to first find out who is the oldest person in the document, then generate
|
|
|
1163
1163
|
|
|
1164
1164
|
<tool_calling>
|
|
1165
1165
|
[
|
|
1166
|
-
{
|
|
1166
|
+
{{
|
|
1167
1167
|
"name": "document_qa",
|
|
1168
|
-
"arguments": {"document": "document.pdf", "question": "Who is the oldest person mentioned?"}
|
|
1169
|
-
}
|
|
1168
|
+
"arguments": {{"document": "document.pdf", "question": "Who is the oldest person mentioned?"}}
|
|
1169
|
+
}}
|
|
1170
1170
|
]
|
|
1171
1171
|
</tool_calling>
|
|
1172
1172
|
|
|
@@ -1178,14 +1178,14 @@ Now I know the oldest person is John Doe, a 55-year-old lumberjack from Newfound
|
|
|
1178
1178
|
|
|
1179
1179
|
<tool_calling>
|
|
1180
1180
|
[
|
|
1181
|
-
|
|
1181
|
+
{{
|
|
1182
1182
|
"name": "image_generator",
|
|
1183
|
-
"arguments": {"prompt": "A portrait of John Doe, a 55-year-old lumberjack living in Newfoundland, Canada"}
|
|
1184
|
-
},
|
|
1185
|
-
{
|
|
1183
|
+
"arguments": {{"prompt": "A portrait of John Doe, a 55-year-old lumberjack living in Newfoundland, Canada"}}
|
|
1184
|
+
}},
|
|
1185
|
+
{{
|
|
1186
1186
|
"name": "search",
|
|
1187
|
-
"arguments": {"query": "John Doe lumberjack Newfoundland biography"}
|
|
1188
|
-
}
|
|
1187
|
+
"arguments": {{"query": "John Doe lumberjack Newfoundland biography"}}
|
|
1188
|
+
}}
|
|
1189
1189
|
]
|
|
1190
1190
|
</tool_calling>
|
|
1191
1191
|
|
|
@@ -1197,10 +1197,10 @@ I have successfully generated an image and found biographical information. Now I
|
|
|
1197
1197
|
|
|
1198
1198
|
<tool_calling>
|
|
1199
1199
|
[
|
|
1200
|
-
{
|
|
1200
|
+
{{
|
|
1201
1201
|
"name": "final_answer",
|
|
1202
|
-
"arguments": {"answer": "I have generated an image (image.png) of John Doe, the oldest person in the document, and found that he is a well-known lumberjack in Newfoundland with over 30 years of experience in forestry."}
|
|
1203
|
-
}
|
|
1202
|
+
"arguments": {{"answer": "I have generated an image (image.png) of John Doe, the oldest person in the document, and found that he is a well-known lumberjack in Newfoundland with over 30 years of experience in forestry."}}
|
|
1203
|
+
}}
|
|
1204
1204
|
]
|
|
1205
1205
|
</tool_calling>
|
|
1206
1206
|
|
|
@@ -1213,10 +1213,10 @@ I need to calculate the sum of 5 + 3 + 1294.678. I'll use the python_interpreter
|
|
|
1213
1213
|
|
|
1214
1214
|
<tool_calling>
|
|
1215
1215
|
[
|
|
1216
|
-
{
|
|
1216
|
+
{{
|
|
1217
1217
|
"name": "python_interpreter",
|
|
1218
|
-
"arguments": {"code": "5 + 3 + 1294.678"}
|
|
1219
|
-
}
|
|
1218
|
+
"arguments": {{"code": "5 + 3 + 1294.678"}}
|
|
1219
|
+
}}
|
|
1220
1220
|
]
|
|
1221
1221
|
</tool_calling>
|
|
1222
1222
|
|
|
@@ -1228,10 +1228,10 @@ I have calculated the result. Now I can provide the final answer.
|
|
|
1228
1228
|
|
|
1229
1229
|
<tool_calling>
|
|
1230
1230
|
[
|
|
1231
|
-
{
|
|
1231
|
+
{{
|
|
1232
1232
|
"name": "final_answer",
|
|
1233
|
-
"arguments": {"answer": "1302.678"}
|
|
1234
|
-
}
|
|
1233
|
+
"arguments": {{"answer": "1302.678"}}
|
|
1234
|
+
}}
|
|
1235
1235
|
]
|
|
1236
1236
|
</tool_calling>
|
|
1237
1237
|
|
|
@@ -1244,14 +1244,14 @@ I need to search for the population data of both Guangzhou and Shanghai to compa
|
|
|
1244
1244
|
|
|
1245
1245
|
<tool_calling>
|
|
1246
1246
|
[
|
|
1247
|
-
{
|
|
1247
|
+
{{
|
|
1248
1248
|
"name": "search",
|
|
1249
|
-
"arguments": {"query": "Population Guangzhou 2023"}
|
|
1250
|
-
},
|
|
1251
|
-
{
|
|
1249
|
+
"arguments": {{"query": "Population Guangzhou 2023"}}
|
|
1250
|
+
}},
|
|
1251
|
+
{{
|
|
1252
1252
|
"name": "search",
|
|
1253
|
-
"arguments": {"query": "Population Shanghai 2023"}
|
|
1254
|
-
}
|
|
1253
|
+
"arguments": {{"query": "Population Shanghai 2023"}}
|
|
1254
|
+
}}
|
|
1255
1255
|
]
|
|
1256
1256
|
</tool_calling>
|
|
1257
1257
|
|
|
@@ -1263,10 +1263,10 @@ Based on the search results, Shanghai has a population of 26 million while Guang
|
|
|
1263
1263
|
|
|
1264
1264
|
<tool_calling>
|
|
1265
1265
|
[
|
|
1266
|
-
{
|
|
1266
|
+
{{
|
|
1267
1267
|
"name": "final_answer",
|
|
1268
|
-
"arguments": {"answer": "Shanghai has the highest population with 26 million people, compared to Guangzhou's 15 million people."}
|
|
1269
|
-
}
|
|
1268
|
+
"arguments": {{"answer": "Shanghai has the highest population with 26 million people, compared to Guangzhou's 15 million people."}}
|
|
1269
|
+
}}
|
|
1270
1270
|
]
|
|
1271
1271
|
</tool_calling>
|
|
1272
1272
|
|
|
@@ -22,4 +22,4 @@ export type CreateOpenAIAgentParams = {
|
|
|
22
22
|
};
|
|
23
23
|
export declare function createOpenAIAgent({ llm, tools, prompt }: CreateOpenAIAgentParams): RunnableSequence<{
|
|
24
24
|
steps: AgentStep[];
|
|
25
|
-
}, AgentAction | AgentAction[]
|
|
25
|
+
}, AgentAction | AgentFinish | AgentAction[]>;
|
|
@@ -72,7 +72,7 @@ export type CreateReactAgentParams = {
|
|
|
72
72
|
*/
|
|
73
73
|
export declare function createReactAgent({ llm, tools, prompt, streamRunnable, instructions }: CreateReactAgentParams): Promise<AgentRunnableSequence<{
|
|
74
74
|
steps: AgentStep[];
|
|
75
|
-
}, import("@langchain/core/agents").
|
|
75
|
+
}, import("@langchain/core/agents").AgentFinish | import("@langchain/core/agents").AgentAction[]>>;
|
|
76
76
|
/**
|
|
77
77
|
* Construct the scratchpad that lets the agent continue its thought process.
|
|
78
78
|
* @param intermediateSteps
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const FORMAT_INSTRUCTIONS = "You are an expert assistant who can solve any task using tool calls. You will be given a task to solve as best you can.\nTo do so, you have been given access to the following tools: {tool_names}\n\nThe tool calls you write are actions: after the tools are executed, you will get the results of the tool calls as \"observations\".\nAt each step, you should first explain your reasoning towards solving the task and the tools that you want to use within <thought> tags.\nThen you should write one or more valid JSON tool calls within <tool_calling> tags.\nThis Thought/Tool_calling/Observation cycle can repeat N times, you should take several steps when needed.\n\nHere are the output format:\n\n<thought>\nYour reasoning and thought process for the current step\n</thought>\n\n<tool_calling>\n[\n {\n \"name\": \"tool_name\",\n \"arguments\": {\"param1\": \"value1\", \"param2\": \"value2\"}\n
|
|
1
|
+
export declare const FORMAT_INSTRUCTIONS = "You are an expert assistant who can solve any task using tool calls. You will be given a task to solve as best you can.\nTo do so, you have been given access to the following tools: {tool_names}\n\nThe tool calls you write are actions: after the tools are executed, you will get the results of the tool calls as \"observations\".\nAt each step, you should first explain your reasoning towards solving the task and the tools that you want to use within <thought> tags.\nThen you should write one or more valid JSON tool calls within <tool_calling> tags.\nThis Thought/Tool_calling/Observation cycle can repeat N times, you should take several steps when needed.\n\nHere are the output format:\n\n<thought>\nYour reasoning and thought process for the current step\n</thought>\n\n<tool_calling>\n[\n {{\n \"name\": \"tool_name\",\n \"arguments\": {{\"param1\": \"value1\", \"param2\": \"value2\"}}\n }}\n]\n</tool_calling>\n\nYou can call multiple tools at once by including multiple tool objects in the JSON array within the <tool_calling> tags.\n\nONLY output within the <thought> and <tool_calling> sequences. You will get the Observation from the tool calls. Do not output the Observation yourself.\n\nTo provide the final answer to the task, use a tool call with \"name\": \"final_answer\". It is the only way to complete the task, else you will be stuck on a loop. So your final output should look like this:\n\n<thought>\nI have gathered all the necessary information and can now provide the final answer.\n</thought>\n\n<tool_calling>\n[\n {{\n \"name\": \"final_answer\",\n \"arguments\": {{\"answer\": \"insert your final answer here\"}}\n }}\n]\n</tool_calling>\n\nHere are a few examples using notional tools:\n---\nTask: \"Generate an image of the oldest person in this document and also search for their biography.\"\n\n<thought>\nI need to first find out who is the oldest person in the document, then generate an image of them and search for their biography. I'll start by using the document_qa tool to find the oldest person.\n</thought>\n\n<tool_calling>\n[\n {{\n \"name\": \"document_qa\",\n \"arguments\": {{\"document\": \"document.pdf\", \"question\": \"Who is the oldest person mentioned?\"}}\n }}\n]\n</tool_calling>\n\nObservation: \"The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland.\"\n\n<thought>\nNow I know the oldest person is John Doe, a 55-year-old lumberjack from Newfoundland. I can generate an image of him and search for his biography at the same time.\n</thought>\n\n<tool_calling>\n[\n {{\n \"name\": \"image_generator\",\n \"arguments\": {{\"prompt\": \"A portrait of John Doe, a 55-year-old lumberjack living in Newfoundland, Canada\"}}\n }},\n {{\n \"name\": \"search\",\n \"arguments\": {{\"query\": \"John Doe lumberjack Newfoundland biography\"}}\n }}\n]\n</tool_calling>\n\nObservation: \"image.png\" and \"John Doe is a well-known lumberjack in Newfoundland with over 30 years of experience in forestry.\"\n\n<thought>\nI have successfully generated an image and found biographical information. Now I can provide the final answer with both pieces of information.\n</thought>\n\n<tool_calling>\n[\n {{\n \"name\": \"final_answer\",\n \"arguments\": {{\"answer\": \"I have generated an image (image.png) of John Doe, the oldest person in the document, and found that he is a well-known lumberjack in Newfoundland with over 30 years of experience in forestry.\"}}\n }}\n]\n</tool_calling>\n\n---\nTask: \"What is the result of the following operation: 5 + 3 + 1294.678?\"\n\n<thought>\nI need to calculate the sum of 5 + 3 + 1294.678. I'll use the python_interpreter tool to execute this calculation.\n</thought>\n\n<tool_calling>\n[\n {{\n \"name\": \"python_interpreter\",\n \"arguments\": {{\"code\": \"5 + 3 + 1294.678\"}}\n }}\n]\n</tool_calling>\n\nObservation: 1302.678\n\n<thought>\nI have calculated the result. Now I can provide the final answer.\n</thought>\n\n<tool_calling>\n[\n {{\n \"name\": \"final_answer\",\n \"arguments\": {{\"answer\": \"1302.678\"}}\n }}\n]\n</tool_calling>\n\n---\nTask: \"Which city has the highest population, Guangzhou or Shanghai?\"\n\n<thought>\nI need to search for the population data of both Guangzhou and Shanghai to compare them. I'll search for both cities' population information simultaneously.\n</thought>\n\n<tool_calling>\n[\n {{\n \"name\": \"search\",\n \"arguments\": {{\"query\": \"Population Guangzhou 2023\"}}\n }},\n {{\n \"name\": \"search\",\n \"arguments\": {{\"query\": \"Population Shanghai 2023\"}}\n }}\n]\n</tool_calling>\n\nObservation: ['Guangzhou has a population of 15 million inhabitants as of 2021.'] and ['Shanghai has a population of 26 million (2019)']\n\n<thought>\nBased on the search results, Shanghai has a population of 26 million while Guangzhou has 15 million. Therefore, Shanghai has the higher population.\n</thought>\n\n<tool_calling>\n[\n {{\n \"name\": \"final_answer\",\n \"arguments\": {{\"answer\": \"Shanghai has the highest population with 26 million people, compared to Guangzhou's 15 million people.\"}}\n }}\n]\n</tool_calling>\n\nAbove examples were using notional tools that might not exist for you. You only have access to these tools:\n\n{tool_descriptions}\n\nHere are the rules you should always follow to solve your task:\n1. ALWAYS provide tool calls within <tool_calling> tags, else you will fail.\n2. Always use the right arguments for the tools. Never use variable names as the action arguments, use the actual values instead.\n3. You can call multiple tools at once if it makes sense for efficiency.\n4. Call tools only when needed: do not call the search agent if you do not need information, try to solve the task yourself.\nIf no tool call is needed, use final_answer tool to return your answer.\n5. Never re-do a tool call that you previously did with the exact same parameters.\n6. Always include your reasoning in <thought> tags before making tool calls.\n\nNow Begin! If you solve the task correctly, you will receive a reward of $1,000,000.";
|
|
@@ -239,7 +239,6 @@ Your goal is to craft an insightful, engaging response that seamlessly integrate
|
|
|
239
239
|
[await loreBooksPrompt.format({ input: array.join("\n") })],
|
|
240
240
|
variables
|
|
241
241
|
).then((value) => value[0]);
|
|
242
|
-
console.log(message);
|
|
243
242
|
if (position === "default") {
|
|
244
243
|
if (hasLongMemory) {
|
|
245
244
|
const index = result.findIndex(
|
|
@@ -226,7 +226,6 @@ Your goal is to craft an insightful, engaging response that seamlessly integrate
|
|
|
226
226
|
[await loreBooksPrompt.format({ input: array.join("\n") })],
|
|
227
227
|
variables
|
|
228
228
|
).then((value) => value[0]);
|
|
229
|
-
console.log(message);
|
|
230
229
|
if (position === "default") {
|
|
231
230
|
if (hasLongMemory) {
|
|
232
231
|
const index = result.findIndex(
|
package/lib/services/chat.cjs
CHANGED
|
@@ -726,7 +726,7 @@ var MessageTransformer = class {
|
|
|
726
726
|
if (session.quote && !quote && this._config.includeQuoteReply) {
|
|
727
727
|
const quoteMessage = await this.transform(
|
|
728
728
|
session,
|
|
729
|
-
session.quote.elements,
|
|
729
|
+
session.quote.elements ?? [],
|
|
730
730
|
{
|
|
731
731
|
content: "",
|
|
732
732
|
additional_kwargs: {}
|
|
@@ -742,10 +742,15 @@ Please consider this quote when generating your response. User's message: ${mess
|
|
|
742
742
|
}
|
|
743
743
|
if (quoteMessage.additional_kwargs["images"]) {
|
|
744
744
|
const currentImages = message.additional_kwargs["images"] ?? [];
|
|
745
|
+
const currentImageHashs = message.additional_kwargs["imageHashs"] ?? [];
|
|
745
746
|
message.additional_kwargs["images"] = [
|
|
746
747
|
...currentImages,
|
|
747
748
|
...quoteMessage.additional_kwargs["images"]
|
|
748
749
|
];
|
|
750
|
+
message.additional_kwargs["imageHashs"] = [
|
|
751
|
+
...currentImageHashs,
|
|
752
|
+
...quoteMessage.additional_kwargs["imageHashs"]
|
|
753
|
+
];
|
|
749
754
|
}
|
|
750
755
|
}
|
|
751
756
|
return message;
|
package/lib/services/chat.mjs
CHANGED
|
@@ -713,7 +713,7 @@ var MessageTransformer = class {
|
|
|
713
713
|
if (session.quote && !quote && this._config.includeQuoteReply) {
|
|
714
714
|
const quoteMessage = await this.transform(
|
|
715
715
|
session,
|
|
716
|
-
session.quote.elements,
|
|
716
|
+
session.quote.elements ?? [],
|
|
717
717
|
{
|
|
718
718
|
content: "",
|
|
719
719
|
additional_kwargs: {}
|
|
@@ -729,10 +729,15 @@ Please consider this quote when generating your response. User's message: ${mess
|
|
|
729
729
|
}
|
|
730
730
|
if (quoteMessage.additional_kwargs["images"]) {
|
|
731
731
|
const currentImages = message.additional_kwargs["images"] ?? [];
|
|
732
|
+
const currentImageHashs = message.additional_kwargs["imageHashs"] ?? [];
|
|
732
733
|
message.additional_kwargs["images"] = [
|
|
733
734
|
...currentImages,
|
|
734
735
|
...quoteMessage.additional_kwargs["images"]
|
|
735
736
|
];
|
|
737
|
+
message.additional_kwargs["imageHashs"] = [
|
|
738
|
+
...currentImageHashs,
|
|
739
|
+
...quoteMessage.additional_kwargs["imageHashs"]
|
|
740
|
+
];
|
|
736
741
|
}
|
|
737
742
|
}
|
|
738
743
|
return message;
|
package/lib/utils/lock.cjs
CHANGED
|
@@ -44,6 +44,12 @@ var ObjectLock = class {
|
|
|
44
44
|
}
|
|
45
45
|
}, "unlock");
|
|
46
46
|
if (this._lock) {
|
|
47
|
+
let error = null;
|
|
48
|
+
try {
|
|
49
|
+
throw new Error(`Lock timeout after ${this._timeout}ms`);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
error = e;
|
|
52
|
+
}
|
|
47
53
|
return new Promise((resolve, reject) => {
|
|
48
54
|
const timeoutId = setTimeout(() => {
|
|
49
55
|
const index = this._queue.findIndex(
|
|
@@ -52,7 +58,9 @@ var ObjectLock = class {
|
|
|
52
58
|
if (index !== -1) {
|
|
53
59
|
this._queue.splice(index, 1);
|
|
54
60
|
}
|
|
55
|
-
reject(
|
|
61
|
+
reject(
|
|
62
|
+
error ?? new Error(`Lock timeout after ${this._timeout}ms`)
|
|
63
|
+
);
|
|
56
64
|
}, this._timeout);
|
|
57
65
|
this._queue.push({
|
|
58
66
|
resolve: /* @__PURE__ */ __name((unlockFn) => {
|
package/lib/utils/lock.mjs
CHANGED
|
@@ -23,6 +23,12 @@ var ObjectLock = class {
|
|
|
23
23
|
}
|
|
24
24
|
}, "unlock");
|
|
25
25
|
if (this._lock) {
|
|
26
|
+
let error = null;
|
|
27
|
+
try {
|
|
28
|
+
throw new Error(`Lock timeout after ${this._timeout}ms`);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
error = e;
|
|
31
|
+
}
|
|
26
32
|
return new Promise((resolve, reject) => {
|
|
27
33
|
const timeoutId = setTimeout(() => {
|
|
28
34
|
const index = this._queue.findIndex(
|
|
@@ -31,7 +37,9 @@ var ObjectLock = class {
|
|
|
31
37
|
if (index !== -1) {
|
|
32
38
|
this._queue.splice(index, 1);
|
|
33
39
|
}
|
|
34
|
-
reject(
|
|
40
|
+
reject(
|
|
41
|
+
error ?? new Error(`Lock timeout after ${this._timeout}ms`)
|
|
42
|
+
);
|
|
35
43
|
}, this._timeout);
|
|
36
44
|
this._queue.push({
|
|
37
45
|
resolve: /* @__PURE__ */ __name((unlockFn) => {
|
package/lib/utils/string.cjs
CHANGED
|
@@ -32,6 +32,7 @@ __export(string_exports, {
|
|
|
32
32
|
getTimeInUTC: () => getTimeInUTC,
|
|
33
33
|
gzipDecode: () => gzipDecode,
|
|
34
34
|
gzipEncode: () => gzipEncode,
|
|
35
|
+
hashString: () => hashString,
|
|
35
36
|
rollDice: () => rollDice,
|
|
36
37
|
selectFromList: () => selectFromList
|
|
37
38
|
});
|
|
@@ -224,6 +225,16 @@ function bufferToArrayBuffer(buffer) {
|
|
|
224
225
|
return arrayBuffer;
|
|
225
226
|
}
|
|
226
227
|
__name(bufferToArrayBuffer, "bufferToArrayBuffer");
|
|
228
|
+
async function hashString(text, length = 8) {
|
|
229
|
+
const hash = await crypto.subtle.digest(
|
|
230
|
+
"SHA-256",
|
|
231
|
+
new TextEncoder().encode(text)
|
|
232
|
+
);
|
|
233
|
+
const hashArray = Array.from(new Uint8Array(hash));
|
|
234
|
+
const hashString2 = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
235
|
+
return hashString2.substring(0, length);
|
|
236
|
+
}
|
|
237
|
+
__name(hashString, "hashString");
|
|
227
238
|
// Annotate the CommonJS export names for ESM import in node:
|
|
228
239
|
0 && (module.exports = {
|
|
229
240
|
PresetPostHandler,
|
|
@@ -238,6 +249,7 @@ __name(bufferToArrayBuffer, "bufferToArrayBuffer");
|
|
|
238
249
|
getTimeInUTC,
|
|
239
250
|
gzipDecode,
|
|
240
251
|
gzipEncode,
|
|
252
|
+
hashString,
|
|
241
253
|
rollDice,
|
|
242
254
|
selectFromList
|
|
243
255
|
});
|
package/lib/utils/string.d.ts
CHANGED
|
@@ -29,4 +29,5 @@ export declare class PresetPostHandler implements PostHandler {
|
|
|
29
29
|
export declare function gzipEncode<T extends Encoding = 'buffer'>(text: string, encoding?: T): Promise<BufferType<T>>;
|
|
30
30
|
export declare function gzipDecode(data: ArrayBuffer | Buffer | string, inputEncoding?: Encoding): Promise<string>;
|
|
31
31
|
export declare function bufferToArrayBuffer(buffer: Buffer): ArrayBuffer;
|
|
32
|
+
export declare function hashString(text: string, length?: number): Promise<string>;
|
|
32
33
|
export {};
|
package/lib/utils/string.mjs
CHANGED
|
@@ -190,6 +190,16 @@ function bufferToArrayBuffer(buffer) {
|
|
|
190
190
|
return arrayBuffer;
|
|
191
191
|
}
|
|
192
192
|
__name(bufferToArrayBuffer, "bufferToArrayBuffer");
|
|
193
|
+
async function hashString(text, length = 8) {
|
|
194
|
+
const hash = await crypto.subtle.digest(
|
|
195
|
+
"SHA-256",
|
|
196
|
+
new TextEncoder().encode(text)
|
|
197
|
+
);
|
|
198
|
+
const hashArray = Array.from(new Uint8Array(hash));
|
|
199
|
+
const hashString2 = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
200
|
+
return hashString2.substring(0, length);
|
|
201
|
+
}
|
|
202
|
+
__name(hashString, "hashString");
|
|
193
203
|
export {
|
|
194
204
|
PresetPostHandler,
|
|
195
205
|
bufferToArrayBuffer,
|
|
@@ -203,6 +213,7 @@ export {
|
|
|
203
213
|
getTimeInUTC,
|
|
204
214
|
gzipDecode,
|
|
205
215
|
gzipEncode,
|
|
216
|
+
hashString,
|
|
206
217
|
rollDice,
|
|
207
218
|
selectFromList
|
|
208
219
|
};
|