@ax-llm/ax 11.0.34 → 11.0.36
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/index.cjs +272 -208
- package/index.cjs.map +1 -1
- package/index.d.cts +45 -50
- package/index.d.ts +45 -50
- package/index.js +271 -208
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -114,6 +114,7 @@ __export(index_exports, {
|
|
|
114
114
|
AxStringUtil: () => AxStringUtil,
|
|
115
115
|
AxTestPrompt: () => AxTestPrompt,
|
|
116
116
|
axAIAnthropicDefaultConfig: () => axAIAnthropicDefaultConfig,
|
|
117
|
+
axAIAnthropicVertexDefaultConfig: () => axAIAnthropicVertexDefaultConfig,
|
|
117
118
|
axAIAzureOpenAIBestConfig: () => axAIAzureOpenAIBestConfig,
|
|
118
119
|
axAIAzureOpenAICreativeConfig: () => axAIAzureOpenAICreativeConfig,
|
|
119
120
|
axAIAzureOpenAIDefaultConfig: () => axAIAzureOpenAIDefaultConfig,
|
|
@@ -884,8 +885,8 @@ var AxBaseAI = class {
|
|
|
884
885
|
this.modelInfo = modelInfo;
|
|
885
886
|
this.models = models;
|
|
886
887
|
this.id = crypto.randomUUID();
|
|
887
|
-
const model = this.
|
|
888
|
-
const embedModel = defaults.embedModel;
|
|
888
|
+
const model = this.getModel(defaults.model) ?? defaults.model;
|
|
889
|
+
const embedModel = this.getEmbedModel(defaults.embedModel);
|
|
889
890
|
this.defaults = { model, embedModel };
|
|
890
891
|
if (!defaults.model || typeof defaults.model !== "string" || defaults.model === "") {
|
|
891
892
|
throw new Error("No model defined");
|
|
@@ -951,18 +952,10 @@ var AxBaseAI = class {
|
|
|
951
952
|
this.headers = headers;
|
|
952
953
|
}
|
|
953
954
|
setOptions(options) {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
this.rt = options.rateLimiter;
|
|
959
|
-
}
|
|
960
|
-
if (options.fetch) {
|
|
961
|
-
this.fetch = options.fetch;
|
|
962
|
-
}
|
|
963
|
-
if (options.tracer) {
|
|
964
|
-
this.tracer = options.tracer;
|
|
965
|
-
}
|
|
955
|
+
this.debug = options.debug ?? false;
|
|
956
|
+
this.rt = options.rateLimiter;
|
|
957
|
+
this.fetch = options.fetch;
|
|
958
|
+
this.tracer = options.tracer;
|
|
966
959
|
}
|
|
967
960
|
getOptions() {
|
|
968
961
|
return {
|
|
@@ -973,17 +966,27 @@ var AxBaseAI = class {
|
|
|
973
966
|
};
|
|
974
967
|
}
|
|
975
968
|
getModelList() {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
969
|
+
const models = [];
|
|
970
|
+
for (const model of this.models ?? []) {
|
|
971
|
+
if (model.isInternal) {
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
if ("model" in model && model.model) {
|
|
975
|
+
models.push({
|
|
976
|
+
key: model.key,
|
|
977
|
+
description: model.description,
|
|
978
|
+
model: model.model
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
if ("embedModel" in model && model.embedModel) {
|
|
982
|
+
models.push({
|
|
983
|
+
key: model.key,
|
|
984
|
+
description: model.description,
|
|
985
|
+
embedModel: model.embedModel
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
return models;
|
|
987
990
|
}
|
|
988
991
|
getName() {
|
|
989
992
|
return this.name;
|
|
@@ -1038,7 +1041,7 @@ var AxBaseAI = class {
|
|
|
1038
1041
|
}
|
|
1039
1042
|
}
|
|
1040
1043
|
async _chat1(req, options) {
|
|
1041
|
-
const model =
|
|
1044
|
+
const model = this.getModel(req.model) ?? req.model ?? this.defaults.model;
|
|
1042
1045
|
const modelConfig = {
|
|
1043
1046
|
...this.aiImpl.getModelConfig(),
|
|
1044
1047
|
...req.modelConfig
|
|
@@ -1102,6 +1105,7 @@ var AxBaseAI = class {
|
|
|
1102
1105
|
if (!this.aiImpl.createChatReq) {
|
|
1103
1106
|
throw new Error("generateChatReq not implemented");
|
|
1104
1107
|
}
|
|
1108
|
+
const debug = options?.debug ?? this.debug;
|
|
1105
1109
|
let functions;
|
|
1106
1110
|
if (chatReq.functions && chatReq.functions.length > 0) {
|
|
1107
1111
|
functions = chatReq.functions.map((fn2) => this.cleanupFunctionSchema(fn2));
|
|
@@ -1123,7 +1127,7 @@ var AxBaseAI = class {
|
|
|
1123
1127
|
url: this.apiURL,
|
|
1124
1128
|
headers: await this.buildHeaders(apiConfig.headers),
|
|
1125
1129
|
stream: modelConfig.stream,
|
|
1126
|
-
debug
|
|
1130
|
+
debug,
|
|
1127
1131
|
fetch: this.fetch,
|
|
1128
1132
|
span
|
|
1129
1133
|
},
|
|
@@ -1131,7 +1135,7 @@ var AxBaseAI = class {
|
|
|
1131
1135
|
);
|
|
1132
1136
|
return res2;
|
|
1133
1137
|
};
|
|
1134
|
-
if (
|
|
1138
|
+
if (debug) {
|
|
1135
1139
|
logChatRequest(req.chatPrompt, options?.debugHideSystemPrompt);
|
|
1136
1140
|
}
|
|
1137
1141
|
const rt = options?.rateLimiter ?? this.rt;
|
|
@@ -1140,23 +1144,28 @@ var AxBaseAI = class {
|
|
|
1140
1144
|
if (!this.aiImpl.createChatStreamResp) {
|
|
1141
1145
|
throw new Error("generateChatResp not implemented");
|
|
1142
1146
|
}
|
|
1143
|
-
const respFn = this.aiImpl.createChatStreamResp;
|
|
1147
|
+
const respFn = this.aiImpl.createChatStreamResp.bind(this);
|
|
1144
1148
|
const wrappedRespFn = (state) => (resp) => {
|
|
1145
1149
|
const res2 = respFn(resp, state);
|
|
1146
1150
|
res2.sessionId = options?.sessionId;
|
|
1147
|
-
if (res2.modelUsage) {
|
|
1148
|
-
|
|
1151
|
+
if (!res2.modelUsage) {
|
|
1152
|
+
res2.modelUsage = {
|
|
1153
|
+
ai: this.name,
|
|
1154
|
+
model,
|
|
1155
|
+
tokens: this.aiImpl.getTokenUsage()
|
|
1156
|
+
};
|
|
1149
1157
|
}
|
|
1158
|
+
this.modelUsage = res2.modelUsage;
|
|
1150
1159
|
if (span?.isRecording()) {
|
|
1151
1160
|
setResponseAttr(res2, span);
|
|
1152
1161
|
}
|
|
1153
|
-
if (
|
|
1162
|
+
if (debug) {
|
|
1154
1163
|
logResponse(res2);
|
|
1155
1164
|
}
|
|
1156
1165
|
return res2;
|
|
1157
1166
|
};
|
|
1158
1167
|
const doneCb = async (_values) => {
|
|
1159
|
-
if (
|
|
1168
|
+
if (debug) {
|
|
1160
1169
|
process.stdout.write("\n");
|
|
1161
1170
|
}
|
|
1162
1171
|
};
|
|
@@ -1179,7 +1188,7 @@ var AxBaseAI = class {
|
|
|
1179
1188
|
if (span?.isRecording()) {
|
|
1180
1189
|
setResponseAttr(res, span);
|
|
1181
1190
|
}
|
|
1182
|
-
if (
|
|
1191
|
+
if (debug) {
|
|
1183
1192
|
logResponse(res);
|
|
1184
1193
|
}
|
|
1185
1194
|
span?.end();
|
|
@@ -1200,7 +1209,7 @@ var AxBaseAI = class {
|
|
|
1200
1209
|
}
|
|
1201
1210
|
}
|
|
1202
1211
|
async _embed1(req, options) {
|
|
1203
|
-
const embedModel = req.embedModel ?? this.defaults.embedModel;
|
|
1212
|
+
const embedModel = this.getEmbedModel(req.embedModel) ?? req.embedModel ?? this.defaults.embedModel;
|
|
1204
1213
|
if (!embedModel) {
|
|
1205
1214
|
throw new Error("No embed model defined");
|
|
1206
1215
|
}
|
|
@@ -1232,6 +1241,7 @@ var AxBaseAI = class {
|
|
|
1232
1241
|
if (!this.aiImpl.createEmbedResp) {
|
|
1233
1242
|
throw new Error("generateEmbedResp not implemented");
|
|
1234
1243
|
}
|
|
1244
|
+
const debug = options?.debug ?? this.debug;
|
|
1235
1245
|
const req = {
|
|
1236
1246
|
...embedReq,
|
|
1237
1247
|
embedModel
|
|
@@ -1243,7 +1253,7 @@ var AxBaseAI = class {
|
|
|
1243
1253
|
name: apiConfig.name,
|
|
1244
1254
|
url: this.apiURL,
|
|
1245
1255
|
headers: await this.buildHeaders(apiConfig.headers),
|
|
1246
|
-
debug
|
|
1256
|
+
debug,
|
|
1247
1257
|
fetch: this.fetch,
|
|
1248
1258
|
span
|
|
1249
1259
|
},
|
|
@@ -1251,15 +1261,23 @@ var AxBaseAI = class {
|
|
|
1251
1261
|
);
|
|
1252
1262
|
return res2;
|
|
1253
1263
|
};
|
|
1254
|
-
const resValue = this.rt ? await this.rt(fn, {
|
|
1264
|
+
const resValue = this.rt ? await this.rt(fn, { modelUsage: this.embedModelUsage }) : await fn();
|
|
1255
1265
|
const res = this.aiImpl.createEmbedResp(resValue);
|
|
1256
1266
|
res.sessionId = options?.sessionId;
|
|
1267
|
+
if (!res.modelUsage) {
|
|
1268
|
+
res.modelUsage = {
|
|
1269
|
+
ai: this.name,
|
|
1270
|
+
model: embedModel,
|
|
1271
|
+
tokens: this.aiImpl.getTokenUsage()
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
this.embedModelUsage = res.modelUsage;
|
|
1257
1275
|
if (span?.isRecording()) {
|
|
1258
1276
|
if (res.modelUsage) {
|
|
1259
1277
|
this.embedModelUsage = res.modelUsage;
|
|
1260
1278
|
span.setAttributes({
|
|
1261
|
-
[axSpanAttributes.LLM_USAGE_COMPLETION_TOKENS]: res.modelUsage.completionTokens ?? 0,
|
|
1262
|
-
[axSpanAttributes.LLM_USAGE_PROMPT_TOKENS]: res.modelUsage.promptTokens
|
|
1279
|
+
[axSpanAttributes.LLM_USAGE_COMPLETION_TOKENS]: res.modelUsage.tokens?.completionTokens ?? 0,
|
|
1280
|
+
[axSpanAttributes.LLM_USAGE_PROMPT_TOKENS]: res.modelUsage.tokens?.promptTokens
|
|
1263
1281
|
});
|
|
1264
1282
|
}
|
|
1265
1283
|
}
|
|
@@ -1269,12 +1287,27 @@ var AxBaseAI = class {
|
|
|
1269
1287
|
async buildHeaders(headers = {}) {
|
|
1270
1288
|
return { ...headers, ...await this.headers() };
|
|
1271
1289
|
}
|
|
1290
|
+
getModelByKey(modelName) {
|
|
1291
|
+
if (!modelName) {
|
|
1292
|
+
return void 0;
|
|
1293
|
+
}
|
|
1294
|
+
const item = this.models?.find((v) => v.key === modelName);
|
|
1295
|
+
return item;
|
|
1296
|
+
}
|
|
1297
|
+
getModel(modelName) {
|
|
1298
|
+
const item = this.getModelByKey(modelName);
|
|
1299
|
+
return item && "model" in item ? item.model : void 0;
|
|
1300
|
+
}
|
|
1301
|
+
getEmbedModel(modelName) {
|
|
1302
|
+
const item = this.getModelByKey(modelName);
|
|
1303
|
+
return item && "embedModel" in item ? item.embedModel : void 0;
|
|
1304
|
+
}
|
|
1272
1305
|
};
|
|
1273
1306
|
function setResponseAttr(res, span) {
|
|
1274
1307
|
if (res.modelUsage) {
|
|
1275
1308
|
span.setAttributes({
|
|
1276
|
-
[axSpanAttributes.LLM_USAGE_COMPLETION_TOKENS]: res.modelUsage.completionTokens ?? 0,
|
|
1277
|
-
[axSpanAttributes.LLM_USAGE_PROMPT_TOKENS]: res.modelUsage.promptTokens
|
|
1309
|
+
[axSpanAttributes.LLM_USAGE_COMPLETION_TOKENS]: res.modelUsage.tokens?.completionTokens ?? 0,
|
|
1310
|
+
[axSpanAttributes.LLM_USAGE_PROMPT_TOKENS]: res.modelUsage.tokens?.promptTokens
|
|
1278
1311
|
});
|
|
1279
1312
|
}
|
|
1280
1313
|
}
|
|
@@ -1329,14 +1362,14 @@ var AxAIAnthropicModel = /* @__PURE__ */ ((AxAIAnthropicModel2) => {
|
|
|
1329
1362
|
AxAIAnthropicModel2["ClaudeInstant12"] = "claude-instant-1.2";
|
|
1330
1363
|
return AxAIAnthropicModel2;
|
|
1331
1364
|
})(AxAIAnthropicModel || {});
|
|
1332
|
-
var AxAIAnthropicVertexModel = /* @__PURE__ */ ((
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
return
|
|
1365
|
+
var AxAIAnthropicVertexModel = /* @__PURE__ */ ((AxAIAnthropicVertexModel2) => {
|
|
1366
|
+
AxAIAnthropicVertexModel2["Claude37Sonnet"] = "claude-3-7-sonnet";
|
|
1367
|
+
AxAIAnthropicVertexModel2["Claude35Haiku"] = "claude-3-5-haiku";
|
|
1368
|
+
AxAIAnthropicVertexModel2["Claude35Sonnet"] = "claude-3-5-sonnet";
|
|
1369
|
+
AxAIAnthropicVertexModel2["Claude35SonnetV2"] = "claude-3-5-sonnet-v2";
|
|
1370
|
+
AxAIAnthropicVertexModel2["Claude3Haiku"] = "claude-3-haiku";
|
|
1371
|
+
AxAIAnthropicVertexModel2["Claude3Opus"] = "claude-3-opus";
|
|
1372
|
+
return AxAIAnthropicVertexModel2;
|
|
1340
1373
|
})(AxAIAnthropicVertexModel || {});
|
|
1341
1374
|
|
|
1342
1375
|
// ai/anthropic/info.ts
|
|
@@ -1390,7 +1423,11 @@ var axModelInfoAnthropic = [
|
|
|
1390
1423
|
|
|
1391
1424
|
// ai/anthropic/api.ts
|
|
1392
1425
|
var axAIAnthropicDefaultConfig = () => structuredClone({
|
|
1393
|
-
model: "claude-3-
|
|
1426
|
+
model: "claude-3-7-sonnet-latest" /* Claude37Sonnet */,
|
|
1427
|
+
...axBaseAIDefaultConfig()
|
|
1428
|
+
});
|
|
1429
|
+
var axAIAnthropicVertexDefaultConfig = () => structuredClone({
|
|
1430
|
+
model: "claude-3-7-sonnet" /* Claude37Sonnet */,
|
|
1394
1431
|
...axBaseAIDefaultConfig()
|
|
1395
1432
|
});
|
|
1396
1433
|
var AxAIAnthropicImpl = class {
|
|
@@ -1398,6 +1435,10 @@ var AxAIAnthropicImpl = class {
|
|
|
1398
1435
|
this.config = config;
|
|
1399
1436
|
this.isVertex = isVertex;
|
|
1400
1437
|
}
|
|
1438
|
+
tokensUsed;
|
|
1439
|
+
getTokenUsage() {
|
|
1440
|
+
return this.tokensUsed;
|
|
1441
|
+
}
|
|
1401
1442
|
getModelConfig() {
|
|
1402
1443
|
const { config } = this;
|
|
1403
1444
|
return {
|
|
@@ -1507,16 +1548,12 @@ var AxAIAnthropicImpl = class {
|
|
|
1507
1548
|
finishReason
|
|
1508
1549
|
};
|
|
1509
1550
|
});
|
|
1510
|
-
|
|
1551
|
+
this.tokensUsed = {
|
|
1511
1552
|
promptTokens: resp.usage.input_tokens,
|
|
1512
1553
|
completionTokens: resp.usage.output_tokens,
|
|
1513
1554
|
totalTokens: resp.usage.input_tokens + resp.usage.output_tokens
|
|
1514
1555
|
};
|
|
1515
|
-
return {
|
|
1516
|
-
results,
|
|
1517
|
-
modelUsage,
|
|
1518
|
-
remoteId: resp.id
|
|
1519
|
-
};
|
|
1556
|
+
return { results, remoteId: resp.id };
|
|
1520
1557
|
};
|
|
1521
1558
|
createChatStreamResp = (resp, state) => {
|
|
1522
1559
|
if (!("type" in resp)) {
|
|
@@ -1533,15 +1570,12 @@ var AxAIAnthropicImpl = class {
|
|
|
1533
1570
|
if (resp.type === "message_start") {
|
|
1534
1571
|
const { message } = resp;
|
|
1535
1572
|
const results = [{ content: "", id: message.id }];
|
|
1536
|
-
|
|
1573
|
+
this.tokensUsed = {
|
|
1537
1574
|
promptTokens: message.usage?.input_tokens ?? 0,
|
|
1538
1575
|
completionTokens: message.usage?.output_tokens ?? 0,
|
|
1539
1576
|
totalTokens: (message.usage?.input_tokens ?? 0) + (message.usage?.output_tokens ?? 0)
|
|
1540
1577
|
};
|
|
1541
|
-
return {
|
|
1542
|
-
results,
|
|
1543
|
-
modelUsage
|
|
1544
|
-
};
|
|
1578
|
+
return { results };
|
|
1545
1579
|
}
|
|
1546
1580
|
if (resp.type === "content_block_start") {
|
|
1547
1581
|
const { content_block: contentBlock } = resp;
|
|
@@ -1598,19 +1632,15 @@ var AxAIAnthropicImpl = class {
|
|
|
1598
1632
|
}
|
|
1599
1633
|
if (resp.type === "message_delta") {
|
|
1600
1634
|
const { delta, usage } = resp;
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
finishReason: mapFinishReason(delta.stop_reason)
|
|
1606
|
-
}
|
|
1607
|
-
],
|
|
1608
|
-
modelUsage: {
|
|
1609
|
-
promptTokens: 0,
|
|
1610
|
-
completionTokens: usage.output_tokens,
|
|
1611
|
-
totalTokens: usage.output_tokens
|
|
1612
|
-
}
|
|
1635
|
+
this.tokensUsed = {
|
|
1636
|
+
promptTokens: 0,
|
|
1637
|
+
completionTokens: usage.output_tokens,
|
|
1638
|
+
totalTokens: usage.output_tokens
|
|
1613
1639
|
};
|
|
1640
|
+
const results = [
|
|
1641
|
+
{ content: "", finishReason: mapFinishReason(delta.stop_reason) }
|
|
1642
|
+
];
|
|
1643
|
+
return { results };
|
|
1614
1644
|
}
|
|
1615
1645
|
return {
|
|
1616
1646
|
results: [{ content: "" }]
|
|
@@ -1795,10 +1825,13 @@ function mapFinishReason(stopReason) {
|
|
|
1795
1825
|
// ai/openai/types.ts
|
|
1796
1826
|
var AxAIOpenAIModel = /* @__PURE__ */ ((AxAIOpenAIModel2) => {
|
|
1797
1827
|
AxAIOpenAIModel2["O1"] = "o1";
|
|
1828
|
+
AxAIOpenAIModel2["O3"] = "o3";
|
|
1798
1829
|
AxAIOpenAIModel2["O1Mini"] = "o1-mini";
|
|
1799
1830
|
AxAIOpenAIModel2["O3Mini"] = "o3-mini";
|
|
1831
|
+
AxAIOpenAIModel2["O4Mini"] = "o4-mini";
|
|
1800
1832
|
AxAIOpenAIModel2["GPT4"] = "gpt-4";
|
|
1801
|
-
AxAIOpenAIModel2["
|
|
1833
|
+
AxAIOpenAIModel2["GPT41"] = "gpt-4.1";
|
|
1834
|
+
AxAIOpenAIModel2["GPT41Mini"] = "gpt-4.1-mini";
|
|
1802
1835
|
AxAIOpenAIModel2["GPT4O"] = "gpt-4o";
|
|
1803
1836
|
AxAIOpenAIModel2["GPT4OMini"] = "gpt-4o-mini";
|
|
1804
1837
|
AxAIOpenAIModel2["GPT4ChatGPT4O"] = "chatgpt-4o-latest";
|
|
@@ -1819,12 +1852,6 @@ var AxAIOpenAIEmbedModel = /* @__PURE__ */ ((AxAIOpenAIEmbedModel2) => {
|
|
|
1819
1852
|
|
|
1820
1853
|
// ai/openai/info.ts
|
|
1821
1854
|
var axModelInfoOpenAI = [
|
|
1822
|
-
{
|
|
1823
|
-
name: "gpt-4.5-preview" /* GPT45 */,
|
|
1824
|
-
currency: "usd",
|
|
1825
|
-
promptTokenCostPer1M: 75,
|
|
1826
|
-
completionTokenCostPer1M: 150
|
|
1827
|
-
},
|
|
1828
1855
|
{
|
|
1829
1856
|
name: "o1" /* O1 */,
|
|
1830
1857
|
currency: "usd",
|
|
@@ -1843,12 +1870,30 @@ var axModelInfoOpenAI = [
|
|
|
1843
1870
|
promptTokenCostPer1M: 1.1,
|
|
1844
1871
|
completionTokenCostPer1M: 4.4
|
|
1845
1872
|
},
|
|
1873
|
+
{
|
|
1874
|
+
name: "o4-mini" /* O4Mini */,
|
|
1875
|
+
currency: "usd",
|
|
1876
|
+
promptTokenCostPer1M: 1.1,
|
|
1877
|
+
completionTokenCostPer1M: 4.4
|
|
1878
|
+
},
|
|
1846
1879
|
{
|
|
1847
1880
|
name: "gpt-4" /* GPT4 */,
|
|
1848
1881
|
currency: "usd",
|
|
1849
1882
|
promptTokenCostPer1M: 30,
|
|
1850
1883
|
completionTokenCostPer1M: 60
|
|
1851
1884
|
},
|
|
1885
|
+
{
|
|
1886
|
+
name: "gpt-4.1" /* GPT41 */,
|
|
1887
|
+
currency: "usd",
|
|
1888
|
+
promptTokenCostPer1M: 2,
|
|
1889
|
+
completionTokenCostPer1M: 8
|
|
1890
|
+
},
|
|
1891
|
+
{
|
|
1892
|
+
name: "gpt-4.1-mini" /* GPT41Mini */,
|
|
1893
|
+
currency: "usd",
|
|
1894
|
+
promptTokenCostPer1M: 0.4,
|
|
1895
|
+
completionTokenCostPer1M: 1.6
|
|
1896
|
+
},
|
|
1852
1897
|
{
|
|
1853
1898
|
name: "gpt-4o" /* GPT4O */,
|
|
1854
1899
|
currency: "usd",
|
|
@@ -1901,28 +1946,32 @@ var axModelInfoOpenAI = [
|
|
|
1901
1946
|
|
|
1902
1947
|
// ai/openai/api.ts
|
|
1903
1948
|
var axAIOpenAIDefaultConfig = () => structuredClone({
|
|
1904
|
-
model: "gpt-
|
|
1949
|
+
model: "gpt-4.1" /* GPT41 */,
|
|
1905
1950
|
embedModel: "text-embedding-3-small" /* TextEmbedding3Small */,
|
|
1906
1951
|
...axBaseAIDefaultConfig()
|
|
1907
1952
|
});
|
|
1908
1953
|
var axAIOpenAIBestConfig = () => structuredClone({
|
|
1909
1954
|
...axAIOpenAIDefaultConfig(),
|
|
1910
|
-
model: "gpt-
|
|
1955
|
+
model: "gpt-4.1" /* GPT41 */
|
|
1911
1956
|
});
|
|
1912
1957
|
var axAIOpenAICreativeConfig = () => structuredClone({
|
|
1913
|
-
model: "gpt-
|
|
1958
|
+
model: "gpt-4.1" /* GPT41 */,
|
|
1914
1959
|
embedModel: "text-embedding-3-small" /* TextEmbedding3Small */,
|
|
1915
1960
|
...axBaseAIDefaultCreativeConfig()
|
|
1916
1961
|
});
|
|
1917
1962
|
var axAIOpenAIFastConfig = () => ({
|
|
1918
1963
|
...axAIOpenAIDefaultConfig(),
|
|
1919
|
-
model: "gpt-
|
|
1964
|
+
model: "gpt-4.1-mini" /* GPT41Mini */
|
|
1920
1965
|
});
|
|
1921
1966
|
var AxAIOpenAIImpl = class {
|
|
1922
1967
|
constructor(config, streamingUsage) {
|
|
1923
1968
|
this.config = config;
|
|
1924
1969
|
this.streamingUsage = streamingUsage;
|
|
1925
1970
|
}
|
|
1971
|
+
tokensUsed;
|
|
1972
|
+
getTokenUsage() {
|
|
1973
|
+
return this.tokensUsed;
|
|
1974
|
+
}
|
|
1926
1975
|
getModelConfig() {
|
|
1927
1976
|
const { config } = this;
|
|
1928
1977
|
return {
|
|
@@ -2002,7 +2051,7 @@ var AxAIOpenAIImpl = class {
|
|
|
2002
2051
|
if (error) {
|
|
2003
2052
|
throw error;
|
|
2004
2053
|
}
|
|
2005
|
-
|
|
2054
|
+
this.tokensUsed = usage ? {
|
|
2006
2055
|
promptTokens: usage.prompt_tokens,
|
|
2007
2056
|
completionTokens: usage.completion_tokens,
|
|
2008
2057
|
totalTokens: usage.total_tokens
|
|
@@ -2024,14 +2073,13 @@ var AxAIOpenAIImpl = class {
|
|
|
2024
2073
|
};
|
|
2025
2074
|
});
|
|
2026
2075
|
return {
|
|
2027
|
-
modelUsage,
|
|
2028
2076
|
results,
|
|
2029
2077
|
remoteId: id
|
|
2030
2078
|
};
|
|
2031
2079
|
}
|
|
2032
2080
|
createChatStreamResp(resp, state) {
|
|
2033
2081
|
const { id, usage, choices } = resp;
|
|
2034
|
-
|
|
2082
|
+
this.tokensUsed = usage ? {
|
|
2035
2083
|
promptTokens: usage.prompt_tokens,
|
|
2036
2084
|
completionTokens: usage.completion_tokens,
|
|
2037
2085
|
totalTokens: usage.total_tokens
|
|
@@ -2069,22 +2117,16 @@ var AxAIOpenAIImpl = class {
|
|
|
2069
2117
|
};
|
|
2070
2118
|
}
|
|
2071
2119
|
);
|
|
2072
|
-
return {
|
|
2073
|
-
results,
|
|
2074
|
-
modelUsage
|
|
2075
|
-
};
|
|
2120
|
+
return { results };
|
|
2076
2121
|
}
|
|
2077
2122
|
createEmbedResp(resp) {
|
|
2078
2123
|
const { data, usage } = resp;
|
|
2079
|
-
|
|
2124
|
+
this.tokensUsed = usage ? {
|
|
2080
2125
|
promptTokens: usage.prompt_tokens,
|
|
2081
2126
|
completionTokens: usage.completion_tokens,
|
|
2082
2127
|
totalTokens: usage.total_tokens
|
|
2083
2128
|
} : void 0;
|
|
2084
|
-
return {
|
|
2085
|
-
embeddings: data.map((v) => v.embedding),
|
|
2086
|
-
modelUsage
|
|
2087
|
-
};
|
|
2129
|
+
return { embeddings: data.map((v) => v.embedding) };
|
|
2088
2130
|
}
|
|
2089
2131
|
};
|
|
2090
2132
|
var mapFinishReason2 = (finishReason) => {
|
|
@@ -2349,6 +2391,10 @@ var AxAICohereImpl = class {
|
|
|
2349
2391
|
constructor(config) {
|
|
2350
2392
|
this.config = config;
|
|
2351
2393
|
}
|
|
2394
|
+
tokensUsed;
|
|
2395
|
+
getTokenUsage() {
|
|
2396
|
+
return this.tokensUsed;
|
|
2397
|
+
}
|
|
2352
2398
|
getModelConfig() {
|
|
2353
2399
|
const { config } = this;
|
|
2354
2400
|
return {
|
|
@@ -2440,7 +2486,7 @@ var AxAICohereImpl = class {
|
|
|
2440
2486
|
return [apiConfig, reqValue];
|
|
2441
2487
|
};
|
|
2442
2488
|
createChatResp = (resp) => {
|
|
2443
|
-
|
|
2489
|
+
this.tokensUsed = resp.meta.billed_units ? {
|
|
2444
2490
|
promptTokens: resp.meta.billed_units.input_tokens,
|
|
2445
2491
|
completionTokens: resp.meta.billed_units.output_tokens,
|
|
2446
2492
|
totalTokens: resp.meta.billed_units.input_tokens + resp.meta.billed_units.output_tokens
|
|
@@ -2483,17 +2529,18 @@ var AxAICohereImpl = class {
|
|
|
2483
2529
|
finishReason
|
|
2484
2530
|
}
|
|
2485
2531
|
];
|
|
2486
|
-
return {
|
|
2487
|
-
results,
|
|
2488
|
-
modelUsage,
|
|
2489
|
-
remoteId: resp.response_id
|
|
2490
|
-
};
|
|
2532
|
+
return { results, remoteId: resp.response_id };
|
|
2491
2533
|
};
|
|
2492
2534
|
createChatStreamResp = (resp, state) => {
|
|
2493
2535
|
const ss = state;
|
|
2494
2536
|
if (resp.event_type === "stream-start") {
|
|
2495
2537
|
ss.generation_id = resp.generation_id;
|
|
2496
2538
|
}
|
|
2539
|
+
this.tokensUsed = {
|
|
2540
|
+
promptTokens: 0,
|
|
2541
|
+
completionTokens: resp.meta.billed_units?.output_tokens ?? 0,
|
|
2542
|
+
totalTokens: resp.meta.billed_units?.output_tokens ?? 0
|
|
2543
|
+
};
|
|
2497
2544
|
const { results } = this.createChatResp(resp);
|
|
2498
2545
|
const result = results[0];
|
|
2499
2546
|
if (!result) {
|
|
@@ -2653,8 +2700,8 @@ var AxAIDeepSeek = class extends AxAIOpenAIBase {
|
|
|
2653
2700
|
|
|
2654
2701
|
// ai/google-gemini/types.ts
|
|
2655
2702
|
var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
|
|
2656
|
-
AxAIGoogleGeminiModel2["Gemini25Pro"] = "gemini-2.5-pro-
|
|
2657
|
-
AxAIGoogleGeminiModel2["
|
|
2703
|
+
AxAIGoogleGeminiModel2["Gemini25Pro"] = "gemini-2.5-pro-preview-03-25";
|
|
2704
|
+
AxAIGoogleGeminiModel2["Gemini25Flash"] = "gemini-2.5-flash-preview-04-17";
|
|
2658
2705
|
AxAIGoogleGeminiModel2["Gemini20Flash"] = "gemini-2.0-flash";
|
|
2659
2706
|
AxAIGoogleGeminiModel2["Gemini20FlashLite"] = "gemini-2.0-flash-lite-preview-02-05";
|
|
2660
2707
|
AxAIGoogleGeminiModel2["Gemini20FlashThinking"] = "gemini-2.0-flash-thinking-exp-01-21";
|
|
@@ -2702,11 +2749,18 @@ var AxAIGoogleGeminiEmbedTypes = /* @__PURE__ */ ((AxAIGoogleGeminiEmbedTypes2)
|
|
|
2702
2749
|
// ai/google-gemini/info.ts
|
|
2703
2750
|
var axModelInfoGoogleGemini = [
|
|
2704
2751
|
{
|
|
2705
|
-
name: "gemini-2.
|
|
2752
|
+
name: "gemini-2.5-pro-preview-03-25" /* Gemini25Pro */,
|
|
2706
2753
|
currency: "usd",
|
|
2707
2754
|
characterIsToken: false,
|
|
2708
|
-
promptTokenCostPer1M:
|
|
2709
|
-
completionTokenCostPer1M:
|
|
2755
|
+
promptTokenCostPer1M: 2.5,
|
|
2756
|
+
completionTokenCostPer1M: 15
|
|
2757
|
+
},
|
|
2758
|
+
{
|
|
2759
|
+
name: "gemini-2.5-flash-preview-04-17" /* Gemini25Flash */,
|
|
2760
|
+
currency: "usd",
|
|
2761
|
+
characterIsToken: false,
|
|
2762
|
+
promptTokenCostPer1M: 15,
|
|
2763
|
+
completionTokenCostPer1M: 3.5
|
|
2710
2764
|
},
|
|
2711
2765
|
{
|
|
2712
2766
|
name: "gemini-2.0-flash" /* Gemini20Flash */,
|
|
@@ -2780,13 +2834,13 @@ var safetySettings = [
|
|
|
2780
2834
|
];
|
|
2781
2835
|
var axAIGoogleGeminiDefaultConfig = () => structuredClone({
|
|
2782
2836
|
model: "gemini-2.0-flash" /* Gemini20Flash */,
|
|
2783
|
-
embedModel: "text-embedding-
|
|
2837
|
+
embedModel: "text-embedding-005" /* TextEmbedding005 */,
|
|
2784
2838
|
safetySettings,
|
|
2785
2839
|
...axBaseAIDefaultConfig()
|
|
2786
2840
|
});
|
|
2787
2841
|
var axAIGoogleGeminiDefaultCreativeConfig = () => structuredClone({
|
|
2788
2842
|
model: "gemini-2.0-flash" /* Gemini20Flash */,
|
|
2789
|
-
embedModel: "text-embedding-
|
|
2843
|
+
embedModel: "text-embedding-005" /* TextEmbedding005 */,
|
|
2790
2844
|
safetySettings,
|
|
2791
2845
|
...axBaseAIDefaultCreativeConfig()
|
|
2792
2846
|
});
|
|
@@ -2801,6 +2855,10 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
2801
2855
|
throw new Error("Auto truncate is not supported for GoogleGemini");
|
|
2802
2856
|
}
|
|
2803
2857
|
}
|
|
2858
|
+
tokensUsed;
|
|
2859
|
+
getTokenUsage() {
|
|
2860
|
+
return this.tokensUsed;
|
|
2861
|
+
}
|
|
2804
2862
|
getModelConfig() {
|
|
2805
2863
|
const { config } = this;
|
|
2806
2864
|
return {
|
|
@@ -2960,7 +3018,10 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
2960
3018
|
frequencyPenalty: req.modelConfig?.frequencyPenalty ?? this.config.frequencyPenalty,
|
|
2961
3019
|
candidateCount: 1,
|
|
2962
3020
|
stopSequences: req.modelConfig?.stopSequences ?? this.config.stopSequences,
|
|
2963
|
-
responseMimeType: "text/plain"
|
|
3021
|
+
responseMimeType: "text/plain",
|
|
3022
|
+
...this.config.thinkingConfig && {
|
|
3023
|
+
thinkingConfig: this.config.thinkingConfig
|
|
3024
|
+
}
|
|
2964
3025
|
};
|
|
2965
3026
|
const safetySettings2 = this.config.safetySettings;
|
|
2966
3027
|
const reqValue = {
|
|
@@ -3060,18 +3121,14 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
3060
3121
|
return result;
|
|
3061
3122
|
}
|
|
3062
3123
|
);
|
|
3063
|
-
let modelUsage;
|
|
3064
3124
|
if (resp.usageMetadata) {
|
|
3065
|
-
|
|
3125
|
+
this.tokensUsed = {
|
|
3066
3126
|
totalTokens: resp.usageMetadata.totalTokenCount,
|
|
3067
3127
|
promptTokens: resp.usageMetadata.promptTokenCount,
|
|
3068
3128
|
completionTokens: resp.usageMetadata.candidatesTokenCount
|
|
3069
3129
|
};
|
|
3070
3130
|
}
|
|
3071
|
-
return {
|
|
3072
|
-
results,
|
|
3073
|
-
modelUsage
|
|
3074
|
-
};
|
|
3131
|
+
return { results };
|
|
3075
3132
|
};
|
|
3076
3133
|
createChatStreamResp = (resp) => {
|
|
3077
3134
|
return this.createChatResp(resp);
|
|
@@ -3289,7 +3346,7 @@ var AxAIGroq = class extends AxAIOpenAIBase {
|
|
|
3289
3346
|
debug: options?.debug
|
|
3290
3347
|
});
|
|
3291
3348
|
const rtFunc = async (func, info) => {
|
|
3292
|
-
const totalTokens = info.modelUsage?.totalTokens || 0;
|
|
3349
|
+
const totalTokens = info.modelUsage?.tokens?.totalTokens || 0;
|
|
3293
3350
|
await rt.acquire(totalTokens);
|
|
3294
3351
|
return await func();
|
|
3295
3352
|
};
|
|
@@ -3319,6 +3376,10 @@ var AxAIHuggingFaceImpl = class {
|
|
|
3319
3376
|
constructor(config) {
|
|
3320
3377
|
this.config = config;
|
|
3321
3378
|
}
|
|
3379
|
+
tokensUsed;
|
|
3380
|
+
getTokenUsage() {
|
|
3381
|
+
return this.tokensUsed;
|
|
3382
|
+
}
|
|
3322
3383
|
getModelConfig() {
|
|
3323
3384
|
const { config } = this;
|
|
3324
3385
|
return {
|
|
@@ -3612,6 +3673,10 @@ var AxAIRekaImpl = class {
|
|
|
3612
3673
|
constructor(config) {
|
|
3613
3674
|
this.config = config;
|
|
3614
3675
|
}
|
|
3676
|
+
tokensUsed;
|
|
3677
|
+
getTokenUsage() {
|
|
3678
|
+
return this.tokensUsed;
|
|
3679
|
+
}
|
|
3615
3680
|
getModelConfig() {
|
|
3616
3681
|
const { config } = this;
|
|
3617
3682
|
return {
|
|
@@ -3652,7 +3717,7 @@ var AxAIRekaImpl = class {
|
|
|
3652
3717
|
};
|
|
3653
3718
|
createChatResp = (resp) => {
|
|
3654
3719
|
const { id, usage, responses } = resp;
|
|
3655
|
-
|
|
3720
|
+
this.tokensUsed = usage ? {
|
|
3656
3721
|
promptTokens: usage.input_tokens,
|
|
3657
3722
|
completionTokens: usage.output_tokens,
|
|
3658
3723
|
totalTokens: usage.input_tokens + usage.output_tokens
|
|
@@ -3671,15 +3736,11 @@ var AxAIRekaImpl = class {
|
|
|
3671
3736
|
finishReason
|
|
3672
3737
|
};
|
|
3673
3738
|
});
|
|
3674
|
-
return {
|
|
3675
|
-
modelUsage,
|
|
3676
|
-
results,
|
|
3677
|
-
remoteId: id
|
|
3678
|
-
};
|
|
3739
|
+
return { results, remoteId: id };
|
|
3679
3740
|
};
|
|
3680
3741
|
createChatStreamResp = (resp) => {
|
|
3681
3742
|
const { id, usage, responses } = resp;
|
|
3682
|
-
|
|
3743
|
+
this.tokensUsed = usage ? {
|
|
3683
3744
|
promptTokens: usage.input_tokens,
|
|
3684
3745
|
completionTokens: usage.output_tokens,
|
|
3685
3746
|
totalTokens: usage.input_tokens + usage.output_tokens
|
|
@@ -3698,10 +3759,7 @@ var AxAIRekaImpl = class {
|
|
|
3698
3759
|
finishReason
|
|
3699
3760
|
};
|
|
3700
3761
|
});
|
|
3701
|
-
return {
|
|
3702
|
-
results,
|
|
3703
|
-
modelUsage
|
|
3704
|
-
};
|
|
3762
|
+
return { results };
|
|
3705
3763
|
};
|
|
3706
3764
|
};
|
|
3707
3765
|
var mapFinishReason3 = (finishReason) => {
|
|
@@ -3887,9 +3945,6 @@ var AxAI = class {
|
|
|
3887
3945
|
getModelList() {
|
|
3888
3946
|
return this.ai.getModelList();
|
|
3889
3947
|
}
|
|
3890
|
-
getDefaultModels() {
|
|
3891
|
-
return this.ai.getDefaultModels();
|
|
3892
|
-
}
|
|
3893
3948
|
getMetrics() {
|
|
3894
3949
|
return this.ai.getMetrics();
|
|
3895
3950
|
}
|
|
@@ -4826,9 +4881,15 @@ function mergeProgramUsage(usages) {
|
|
|
4826
4881
|
}
|
|
4827
4882
|
const currentUsage = usageMap[key];
|
|
4828
4883
|
if (currentUsage) {
|
|
4829
|
-
currentUsage.
|
|
4830
|
-
|
|
4831
|
-
|
|
4884
|
+
const tokens = currentUsage.tokens ?? {
|
|
4885
|
+
promptTokens: 0,
|
|
4886
|
+
completionTokens: 0,
|
|
4887
|
+
totalTokens: 0
|
|
4888
|
+
};
|
|
4889
|
+
tokens.promptTokens += usage?.tokens?.promptTokens ?? 0;
|
|
4890
|
+
tokens.completionTokens += usage?.tokens?.completionTokens ?? 0;
|
|
4891
|
+
tokens.totalTokens += usage?.tokens?.totalTokens ?? 0;
|
|
4892
|
+
currentUsage.tokens = tokens;
|
|
4832
4893
|
}
|
|
4833
4894
|
}
|
|
4834
4895
|
return Object.values(usageMap);
|
|
@@ -6348,13 +6409,9 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6348
6409
|
mem,
|
|
6349
6410
|
options
|
|
6350
6411
|
}) {
|
|
6351
|
-
const { sessionId, traceId,
|
|
6412
|
+
const { sessionId, traceId, functions: _functions } = options ?? {};
|
|
6352
6413
|
const fastFail = options?.fastFail ?? this.options?.fastFail;
|
|
6353
|
-
const
|
|
6354
|
-
const usageInfo = {
|
|
6355
|
-
ai: ai.getName(),
|
|
6356
|
-
model: modelName
|
|
6357
|
-
};
|
|
6414
|
+
const model = options.model;
|
|
6358
6415
|
const functions = _functions?.map((f) => "toFunction" in f ? f.toFunction() : f)?.flat();
|
|
6359
6416
|
const res = await this.forwardSendRequest({
|
|
6360
6417
|
ai,
|
|
@@ -6366,7 +6423,6 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6366
6423
|
ai,
|
|
6367
6424
|
model,
|
|
6368
6425
|
res,
|
|
6369
|
-
usageInfo,
|
|
6370
6426
|
mem,
|
|
6371
6427
|
traceId,
|
|
6372
6428
|
sessionId,
|
|
@@ -6378,7 +6434,6 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6378
6434
|
ai,
|
|
6379
6435
|
model,
|
|
6380
6436
|
res,
|
|
6381
|
-
usageInfo,
|
|
6382
6437
|
mem,
|
|
6383
6438
|
traceId,
|
|
6384
6439
|
sessionId,
|
|
@@ -6390,14 +6445,13 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6390
6445
|
ai,
|
|
6391
6446
|
model,
|
|
6392
6447
|
res,
|
|
6393
|
-
usageInfo,
|
|
6394
6448
|
mem,
|
|
6395
6449
|
sessionId,
|
|
6396
6450
|
traceId,
|
|
6397
6451
|
functions,
|
|
6398
6452
|
fastFail
|
|
6399
6453
|
}) {
|
|
6400
|
-
const streamingValidation = fastFail ?? ai.getFeatures().functionCot !== true;
|
|
6454
|
+
const streamingValidation = fastFail ?? ai.getFeatures(model).functionCot !== true;
|
|
6401
6455
|
const functionCalls = [];
|
|
6402
6456
|
const values = {};
|
|
6403
6457
|
const xstate = {
|
|
@@ -6412,7 +6466,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6412
6466
|
continue;
|
|
6413
6467
|
}
|
|
6414
6468
|
if (v.modelUsage) {
|
|
6415
|
-
this.usage.push(
|
|
6469
|
+
this.usage.push(v.modelUsage);
|
|
6416
6470
|
}
|
|
6417
6471
|
if (result.functionCalls) {
|
|
6418
6472
|
mergeFunctionCalls(functionCalls, result.functionCalls);
|
|
@@ -6513,7 +6567,6 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6513
6567
|
async processResponse({
|
|
6514
6568
|
ai,
|
|
6515
6569
|
res,
|
|
6516
|
-
usageInfo,
|
|
6517
6570
|
mem,
|
|
6518
6571
|
sessionId,
|
|
6519
6572
|
traceId,
|
|
@@ -6526,7 +6579,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6526
6579
|
}
|
|
6527
6580
|
for (const result of results) {
|
|
6528
6581
|
if (res.modelUsage) {
|
|
6529
|
-
this.usage.push(
|
|
6582
|
+
this.usage.push(res.modelUsage);
|
|
6530
6583
|
}
|
|
6531
6584
|
mem.addResult(result, sessionId);
|
|
6532
6585
|
if (result.functionCalls?.length) {
|
|
@@ -6574,10 +6627,8 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6574
6627
|
const maxRetries = options.maxRetries ?? this.options?.maxRetries ?? 10;
|
|
6575
6628
|
const maxSteps = options.maxSteps ?? this.options?.maxSteps ?? 10;
|
|
6576
6629
|
const debug = options.debug ?? ai.getOptions().debug;
|
|
6577
|
-
const
|
|
6578
|
-
|
|
6579
|
-
debugHideSystemPrompt: options.debugHideSystemPrompt
|
|
6580
|
-
};
|
|
6630
|
+
const debugHideSystemPrompt = options.debugHideSystemPrompt;
|
|
6631
|
+
const memOptions = { debug, debugHideSystemPrompt };
|
|
6581
6632
|
const mem = options.mem ?? this.options?.mem ?? new AxMemory(1e4, memOptions);
|
|
6582
6633
|
let err;
|
|
6583
6634
|
if (options?.functions && options.functions.length > 0) {
|
|
@@ -6655,7 +6706,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6655
6706
|
return false;
|
|
6656
6707
|
}
|
|
6657
6708
|
async *_forward1(ai, values, options) {
|
|
6658
|
-
const tracer =
|
|
6709
|
+
const tracer = options?.tracer ?? this.options?.tracer;
|
|
6659
6710
|
let functions = this.functions;
|
|
6660
6711
|
if (options?.functions) {
|
|
6661
6712
|
functions = parseFunctions(options.functions, this.functions);
|
|
@@ -6691,9 +6742,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6691
6742
|
}
|
|
6692
6743
|
}
|
|
6693
6744
|
async forward(ai, values, options) {
|
|
6694
|
-
const generator = this._forward1(ai, values, {
|
|
6695
|
-
...options
|
|
6696
|
-
});
|
|
6745
|
+
const generator = this._forward1(ai, values, options ?? {});
|
|
6697
6746
|
let buffer = {};
|
|
6698
6747
|
let currentVersion = 0;
|
|
6699
6748
|
for await (const item of generator) {
|
|
@@ -7122,9 +7171,6 @@ var AxBalancer = class _AxBalancer {
|
|
|
7122
7171
|
getModelList() {
|
|
7123
7172
|
return this.currentService.getModelList();
|
|
7124
7173
|
}
|
|
7125
|
-
getDefaultModels() {
|
|
7126
|
-
return this.currentService.getDefaultModels();
|
|
7127
|
-
}
|
|
7128
7174
|
getNextService() {
|
|
7129
7175
|
const cs = this.services[++this.currentServiceIndex];
|
|
7130
7176
|
if (cs === void 0) {
|
|
@@ -9276,12 +9322,6 @@ var AxMockAIService = class {
|
|
|
9276
9322
|
getModelList() {
|
|
9277
9323
|
return this.config.models;
|
|
9278
9324
|
}
|
|
9279
|
-
getDefaultModels() {
|
|
9280
|
-
return {
|
|
9281
|
-
model: this.config.modelInfo?.name ?? "mock-model",
|
|
9282
|
-
embedModel: this.config.embedModelInfo?.name
|
|
9283
|
-
};
|
|
9284
|
-
}
|
|
9285
9325
|
getMetrics() {
|
|
9286
9326
|
return this.metrics;
|
|
9287
9327
|
}
|
|
@@ -9304,9 +9344,13 @@ var AxMockAIService = class {
|
|
|
9304
9344
|
}
|
|
9305
9345
|
],
|
|
9306
9346
|
modelUsage: {
|
|
9307
|
-
|
|
9308
|
-
|
|
9309
|
-
|
|
9347
|
+
ai: this.getName(),
|
|
9348
|
+
model: "mock-model",
|
|
9349
|
+
tokens: {
|
|
9350
|
+
promptTokens: 10,
|
|
9351
|
+
completionTokens: 5,
|
|
9352
|
+
totalTokens: 15
|
|
9353
|
+
}
|
|
9310
9354
|
}
|
|
9311
9355
|
};
|
|
9312
9356
|
}
|
|
@@ -9324,9 +9368,13 @@ var AxMockAIService = class {
|
|
|
9324
9368
|
return this.config.embedResponse ?? {
|
|
9325
9369
|
embeddings: [[0.1, 0.2, 0.3]],
|
|
9326
9370
|
modelUsage: {
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9371
|
+
ai: this.getName(),
|
|
9372
|
+
model: "mock-model",
|
|
9373
|
+
tokens: {
|
|
9374
|
+
promptTokens: 5,
|
|
9375
|
+
completionTokens: 0,
|
|
9376
|
+
totalTokens: 5
|
|
9377
|
+
}
|
|
9330
9378
|
}
|
|
9331
9379
|
};
|
|
9332
9380
|
}
|
|
@@ -9357,7 +9405,7 @@ var AxMockAIService = class {
|
|
|
9357
9405
|
}
|
|
9358
9406
|
};
|
|
9359
9407
|
|
|
9360
|
-
// dsp/
|
|
9408
|
+
// dsp/classifier.ts
|
|
9361
9409
|
var colorLog6 = new ColorLog();
|
|
9362
9410
|
var AxSimpleClassifierClass = class {
|
|
9363
9411
|
name;
|
|
@@ -11166,6 +11214,7 @@ var AxMCPStdioTransport = class {
|
|
|
11166
11214
|
|
|
11167
11215
|
// ai/multiservice.ts
|
|
11168
11216
|
var AxMultiServiceRouter = class {
|
|
11217
|
+
options;
|
|
11169
11218
|
services = /* @__PURE__ */ new Map();
|
|
11170
11219
|
/**
|
|
11171
11220
|
* Constructs a new multi-service router.
|
|
@@ -11186,9 +11235,7 @@ var AxMultiServiceRouter = class {
|
|
|
11186
11235
|
this.services.set(item.key, {
|
|
11187
11236
|
service,
|
|
11188
11237
|
description,
|
|
11189
|
-
isInternal
|
|
11190
|
-
model: item.service.getDefaultModels().model,
|
|
11191
|
-
useDefaultModel: true
|
|
11238
|
+
isInternal
|
|
11192
11239
|
});
|
|
11193
11240
|
} else {
|
|
11194
11241
|
const modelList = item.getModelList();
|
|
@@ -11197,18 +11244,31 @@ var AxMultiServiceRouter = class {
|
|
|
11197
11244
|
`Service ${index} \`${item.getName()}\` has no model list.`
|
|
11198
11245
|
);
|
|
11199
11246
|
}
|
|
11200
|
-
for (const
|
|
11201
|
-
if (this.services.has(key)) {
|
|
11202
|
-
const otherService = this.services.get(key)?.service;
|
|
11247
|
+
for (const v of modelList) {
|
|
11248
|
+
if (this.services.has(v.key)) {
|
|
11249
|
+
const otherService = this.services.get(v.key)?.service;
|
|
11203
11250
|
throw new Error(
|
|
11204
|
-
`Service ${index} \`${item.getName()}\` has duplicate model key: ${key} as service ${otherService?.getName()}`
|
|
11251
|
+
`Service ${index} \`${item.getName()}\` has duplicate model key: ${v.key} as service ${otherService?.getName()}`
|
|
11205
11252
|
);
|
|
11253
|
+
} else {
|
|
11254
|
+
if ("model" in v && typeof v.model) {
|
|
11255
|
+
this.services.set(v.key, {
|
|
11256
|
+
description: v.description,
|
|
11257
|
+
service: item,
|
|
11258
|
+
model: v.model
|
|
11259
|
+
});
|
|
11260
|
+
} else if ("embedModel" in v && v.embedModel) {
|
|
11261
|
+
this.services.set(v.key, {
|
|
11262
|
+
description: v.description,
|
|
11263
|
+
service: item,
|
|
11264
|
+
embedModel: v.embedModel
|
|
11265
|
+
});
|
|
11266
|
+
} else {
|
|
11267
|
+
throw new Error(
|
|
11268
|
+
`Key ${v.key} in model list for service ${index} \`${item.getName()}\` is missing a model or embedModel property.`
|
|
11269
|
+
);
|
|
11270
|
+
}
|
|
11206
11271
|
}
|
|
11207
|
-
this.services.set(key, {
|
|
11208
|
-
description,
|
|
11209
|
-
service: item,
|
|
11210
|
-
model
|
|
11211
|
-
});
|
|
11212
11272
|
}
|
|
11213
11273
|
}
|
|
11214
11274
|
}
|
|
@@ -11225,25 +11285,32 @@ var AxMultiServiceRouter = class {
|
|
|
11225
11285
|
if (!item) {
|
|
11226
11286
|
throw new Error(`No service found for model key: ${modelKey}`);
|
|
11227
11287
|
}
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11288
|
+
if (!item.model) {
|
|
11289
|
+
const { model, ...reqWithoutModel } = req;
|
|
11290
|
+
return await item.service.chat(reqWithoutModel, options);
|
|
11291
|
+
}
|
|
11292
|
+
return await item.service.chat({ model: modelKey, ...req }, options);
|
|
11231
11293
|
}
|
|
11232
11294
|
/**
|
|
11233
11295
|
* Delegates the embed call to the service matching the provided embed model key.
|
|
11234
11296
|
*/
|
|
11235
11297
|
async embed(req, options) {
|
|
11236
|
-
const
|
|
11237
|
-
if (!
|
|
11298
|
+
const embedModelKey = req.embedModel;
|
|
11299
|
+
if (!embedModelKey) {
|
|
11238
11300
|
throw new Error("Embed model key must be specified for multi-service");
|
|
11239
11301
|
}
|
|
11240
|
-
const item = this.services.get(
|
|
11302
|
+
const item = this.services.get(embedModelKey);
|
|
11241
11303
|
if (!item) {
|
|
11242
|
-
throw new Error(`No service found for embed model key: ${
|
|
11304
|
+
throw new Error(`No service found for embed model key: ${embedModelKey}`);
|
|
11243
11305
|
}
|
|
11244
|
-
|
|
11245
|
-
|
|
11246
|
-
|
|
11306
|
+
if (!item.model) {
|
|
11307
|
+
const { embedModel, ...reqWithoutEmbedModel } = req;
|
|
11308
|
+
return await item.service.embed(reqWithoutEmbedModel, options);
|
|
11309
|
+
}
|
|
11310
|
+
return await item.service.embed(
|
|
11311
|
+
{ embedModel: embedModelKey, ...req },
|
|
11312
|
+
options
|
|
11313
|
+
);
|
|
11247
11314
|
}
|
|
11248
11315
|
/**
|
|
11249
11316
|
* Returns a composite ID built from the IDs of the underlying services.
|
|
@@ -11261,16 +11328,15 @@ var AxMultiServiceRouter = class {
|
|
|
11261
11328
|
* Aggregates all available models across the underlying services.
|
|
11262
11329
|
*/
|
|
11263
11330
|
getModelList() {
|
|
11264
|
-
return Array.from(this.services).filter(([, value]) => !value.isInternal).map(([key,
|
|
11265
|
-
|
|
11266
|
-
|
|
11267
|
-
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
11273
|
-
);
|
|
11331
|
+
return Array.from(this.services).filter(([, value]) => !value.isInternal).map(([key, v]) => {
|
|
11332
|
+
if (v.model) {
|
|
11333
|
+
return { key, description: v.description, model: v.model };
|
|
11334
|
+
} else if (v.embedModel) {
|
|
11335
|
+
return { key, description: v.description, embedModel: v.embedModel };
|
|
11336
|
+
} else {
|
|
11337
|
+
throw new Error(`Service ${key} has no model or embedModel`);
|
|
11338
|
+
}
|
|
11339
|
+
});
|
|
11274
11340
|
}
|
|
11275
11341
|
/**
|
|
11276
11342
|
* If a model key is provided, delegate to the corresponding service's features.
|
|
@@ -11304,17 +11370,14 @@ var AxMultiServiceRouter = class {
|
|
|
11304
11370
|
for (const service of this.services.values()) {
|
|
11305
11371
|
service.service.setOptions(options);
|
|
11306
11372
|
}
|
|
11373
|
+
this.options = options;
|
|
11307
11374
|
}
|
|
11308
11375
|
/**
|
|
11309
11376
|
* Returns the options from the last used service,
|
|
11310
11377
|
* or falls back to the first service if none has been used.
|
|
11311
11378
|
*/
|
|
11312
11379
|
getOptions() {
|
|
11313
|
-
|
|
11314
|
-
if (!service) {
|
|
11315
|
-
throw new Error("No service available to get options.");
|
|
11316
|
-
}
|
|
11317
|
-
return service.service.getOptions();
|
|
11380
|
+
return this.options ?? {};
|
|
11318
11381
|
}
|
|
11319
11382
|
};
|
|
11320
11383
|
|
|
@@ -11437,6 +11500,7 @@ var AxRAG = class extends AxChainOfThought {
|
|
|
11437
11500
|
AxStringUtil,
|
|
11438
11501
|
AxTestPrompt,
|
|
11439
11502
|
axAIAnthropicDefaultConfig,
|
|
11503
|
+
axAIAnthropicVertexDefaultConfig,
|
|
11440
11504
|
axAIAzureOpenAIBestConfig,
|
|
11441
11505
|
axAIAzureOpenAICreativeConfig,
|
|
11442
11506
|
axAIAzureOpenAIDefaultConfig,
|