@ax-llm/ax 11.0.33 → 11.0.35
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 +145 -83
- package/index.cjs.map +1 -1
- package/index.d.cts +33 -16
- package/index.d.ts +33 -16
- package/index.js +145 -83
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -884,8 +884,8 @@ var AxBaseAI = class {
|
|
|
884
884
|
this.modelInfo = modelInfo;
|
|
885
885
|
this.models = models;
|
|
886
886
|
this.id = crypto.randomUUID();
|
|
887
|
-
const model = this.
|
|
888
|
-
const embedModel = defaults.embedModel;
|
|
887
|
+
const model = this.getModel(defaults.model) ?? defaults.model;
|
|
888
|
+
const embedModel = this.getEmbedModel(defaults.embedModel);
|
|
889
889
|
this.defaults = { model, embedModel };
|
|
890
890
|
if (!defaults.model || typeof defaults.model !== "string" || defaults.model === "") {
|
|
891
891
|
throw new Error("No model defined");
|
|
@@ -951,18 +951,10 @@ var AxBaseAI = class {
|
|
|
951
951
|
this.headers = headers;
|
|
952
952
|
}
|
|
953
953
|
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
|
-
}
|
|
954
|
+
this.debug = options.debug ?? false;
|
|
955
|
+
this.rt = options.rateLimiter;
|
|
956
|
+
this.fetch = options.fetch;
|
|
957
|
+
this.tracer = options.tracer;
|
|
966
958
|
}
|
|
967
959
|
getOptions() {
|
|
968
960
|
return {
|
|
@@ -973,11 +965,27 @@ var AxBaseAI = class {
|
|
|
973
965
|
};
|
|
974
966
|
}
|
|
975
967
|
getModelList() {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
968
|
+
const models = [];
|
|
969
|
+
for (const model of this.models ?? []) {
|
|
970
|
+
if (model.isInternal) {
|
|
971
|
+
continue;
|
|
972
|
+
}
|
|
973
|
+
if ("model" in model && model.model) {
|
|
974
|
+
models.push({
|
|
975
|
+
key: model.key,
|
|
976
|
+
description: model.description,
|
|
977
|
+
model: model.model
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
if ("embedModel" in model && model.embedModel) {
|
|
981
|
+
models.push({
|
|
982
|
+
key: model.key,
|
|
983
|
+
description: model.description,
|
|
984
|
+
embedModel: model.embedModel
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
return models;
|
|
981
989
|
}
|
|
982
990
|
getDefaultModels() {
|
|
983
991
|
return {
|
|
@@ -1038,7 +1046,7 @@ var AxBaseAI = class {
|
|
|
1038
1046
|
}
|
|
1039
1047
|
}
|
|
1040
1048
|
async _chat1(req, options) {
|
|
1041
|
-
const model =
|
|
1049
|
+
const model = this.getModel(req.model) ?? req.model ?? this.defaults.model;
|
|
1042
1050
|
const modelConfig = {
|
|
1043
1051
|
...this.aiImpl.getModelConfig(),
|
|
1044
1052
|
...req.modelConfig
|
|
@@ -1102,6 +1110,7 @@ var AxBaseAI = class {
|
|
|
1102
1110
|
if (!this.aiImpl.createChatReq) {
|
|
1103
1111
|
throw new Error("generateChatReq not implemented");
|
|
1104
1112
|
}
|
|
1113
|
+
const debug = options?.debug ?? this.debug;
|
|
1105
1114
|
let functions;
|
|
1106
1115
|
if (chatReq.functions && chatReq.functions.length > 0) {
|
|
1107
1116
|
functions = chatReq.functions.map((fn2) => this.cleanupFunctionSchema(fn2));
|
|
@@ -1123,7 +1132,7 @@ var AxBaseAI = class {
|
|
|
1123
1132
|
url: this.apiURL,
|
|
1124
1133
|
headers: await this.buildHeaders(apiConfig.headers),
|
|
1125
1134
|
stream: modelConfig.stream,
|
|
1126
|
-
debug
|
|
1135
|
+
debug,
|
|
1127
1136
|
fetch: this.fetch,
|
|
1128
1137
|
span
|
|
1129
1138
|
},
|
|
@@ -1131,7 +1140,7 @@ var AxBaseAI = class {
|
|
|
1131
1140
|
);
|
|
1132
1141
|
return res2;
|
|
1133
1142
|
};
|
|
1134
|
-
if (
|
|
1143
|
+
if (debug) {
|
|
1135
1144
|
logChatRequest(req.chatPrompt, options?.debugHideSystemPrompt);
|
|
1136
1145
|
}
|
|
1137
1146
|
const rt = options?.rateLimiter ?? this.rt;
|
|
@@ -1150,13 +1159,13 @@ var AxBaseAI = class {
|
|
|
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
|
},
|
|
@@ -1269,6 +1279,21 @@ var AxBaseAI = class {
|
|
|
1269
1279
|
async buildHeaders(headers = {}) {
|
|
1270
1280
|
return { ...headers, ...await this.headers() };
|
|
1271
1281
|
}
|
|
1282
|
+
getModelByKey(modelName) {
|
|
1283
|
+
if (!modelName) {
|
|
1284
|
+
return void 0;
|
|
1285
|
+
}
|
|
1286
|
+
const item = this.models?.find((v) => v.key === modelName);
|
|
1287
|
+
return item;
|
|
1288
|
+
}
|
|
1289
|
+
getModel(modelName) {
|
|
1290
|
+
const item = this.getModelByKey(modelName);
|
|
1291
|
+
return item && "model" in item ? item.model : void 0;
|
|
1292
|
+
}
|
|
1293
|
+
getEmbedModel(modelName) {
|
|
1294
|
+
const item = this.getModelByKey(modelName);
|
|
1295
|
+
return item && "embedModel" in item ? item.embedModel : void 0;
|
|
1296
|
+
}
|
|
1272
1297
|
};
|
|
1273
1298
|
function setResponseAttr(res, span) {
|
|
1274
1299
|
if (res.modelUsage) {
|
|
@@ -1795,10 +1820,12 @@ function mapFinishReason(stopReason) {
|
|
|
1795
1820
|
// ai/openai/types.ts
|
|
1796
1821
|
var AxAIOpenAIModel = /* @__PURE__ */ ((AxAIOpenAIModel2) => {
|
|
1797
1822
|
AxAIOpenAIModel2["O1"] = "o1";
|
|
1823
|
+
AxAIOpenAIModel2["O3"] = "o3";
|
|
1798
1824
|
AxAIOpenAIModel2["O1Mini"] = "o1-mini";
|
|
1799
1825
|
AxAIOpenAIModel2["O3Mini"] = "o3-mini";
|
|
1826
|
+
AxAIOpenAIModel2["O4Mini"] = "o4-mini";
|
|
1800
1827
|
AxAIOpenAIModel2["GPT4"] = "gpt-4";
|
|
1801
|
-
AxAIOpenAIModel2["
|
|
1828
|
+
AxAIOpenAIModel2["GPT41"] = "gpt-4.1";
|
|
1802
1829
|
AxAIOpenAIModel2["GPT4O"] = "gpt-4o";
|
|
1803
1830
|
AxAIOpenAIModel2["GPT4OMini"] = "gpt-4o-mini";
|
|
1804
1831
|
AxAIOpenAIModel2["GPT4ChatGPT4O"] = "chatgpt-4o-latest";
|
|
@@ -1819,12 +1846,6 @@ var AxAIOpenAIEmbedModel = /* @__PURE__ */ ((AxAIOpenAIEmbedModel2) => {
|
|
|
1819
1846
|
|
|
1820
1847
|
// ai/openai/info.ts
|
|
1821
1848
|
var axModelInfoOpenAI = [
|
|
1822
|
-
{
|
|
1823
|
-
name: "gpt-4.5-preview" /* GPT45 */,
|
|
1824
|
-
currency: "usd",
|
|
1825
|
-
promptTokenCostPer1M: 75,
|
|
1826
|
-
completionTokenCostPer1M: 150
|
|
1827
|
-
},
|
|
1828
1849
|
{
|
|
1829
1850
|
name: "o1" /* O1 */,
|
|
1830
1851
|
currency: "usd",
|
|
@@ -1843,12 +1864,24 @@ var axModelInfoOpenAI = [
|
|
|
1843
1864
|
promptTokenCostPer1M: 1.1,
|
|
1844
1865
|
completionTokenCostPer1M: 4.4
|
|
1845
1866
|
},
|
|
1867
|
+
{
|
|
1868
|
+
name: "o4-mini" /* O4Mini */,
|
|
1869
|
+
currency: "usd",
|
|
1870
|
+
promptTokenCostPer1M: 1.1,
|
|
1871
|
+
completionTokenCostPer1M: 4.4
|
|
1872
|
+
},
|
|
1846
1873
|
{
|
|
1847
1874
|
name: "gpt-4" /* GPT4 */,
|
|
1848
1875
|
currency: "usd",
|
|
1849
1876
|
promptTokenCostPer1M: 30,
|
|
1850
1877
|
completionTokenCostPer1M: 60
|
|
1851
1878
|
},
|
|
1879
|
+
{
|
|
1880
|
+
name: "gpt-4.1" /* GPT41 */,
|
|
1881
|
+
currency: "usd",
|
|
1882
|
+
promptTokenCostPer1M: 2,
|
|
1883
|
+
completionTokenCostPer1M: 8
|
|
1884
|
+
},
|
|
1852
1885
|
{
|
|
1853
1886
|
name: "gpt-4o" /* GPT4O */,
|
|
1854
1887
|
currency: "usd",
|
|
@@ -2653,8 +2686,8 @@ var AxAIDeepSeek = class extends AxAIOpenAIBase {
|
|
|
2653
2686
|
|
|
2654
2687
|
// ai/google-gemini/types.ts
|
|
2655
2688
|
var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
|
|
2656
|
-
AxAIGoogleGeminiModel2["Gemini25Pro"] = "gemini-2.5-pro-
|
|
2657
|
-
AxAIGoogleGeminiModel2["
|
|
2689
|
+
AxAIGoogleGeminiModel2["Gemini25Pro"] = "gemini-2.5-pro-preview-03-25";
|
|
2690
|
+
AxAIGoogleGeminiModel2["Gemini25Flash"] = "gemini-2.5-flash-preview-04-17";
|
|
2658
2691
|
AxAIGoogleGeminiModel2["Gemini20Flash"] = "gemini-2.0-flash";
|
|
2659
2692
|
AxAIGoogleGeminiModel2["Gemini20FlashLite"] = "gemini-2.0-flash-lite-preview-02-05";
|
|
2660
2693
|
AxAIGoogleGeminiModel2["Gemini20FlashThinking"] = "gemini-2.0-flash-thinking-exp-01-21";
|
|
@@ -2702,11 +2735,18 @@ var AxAIGoogleGeminiEmbedTypes = /* @__PURE__ */ ((AxAIGoogleGeminiEmbedTypes2)
|
|
|
2702
2735
|
// ai/google-gemini/info.ts
|
|
2703
2736
|
var axModelInfoGoogleGemini = [
|
|
2704
2737
|
{
|
|
2705
|
-
name: "gemini-2.
|
|
2738
|
+
name: "gemini-2.5-pro-preview-03-25" /* Gemini25Pro */,
|
|
2706
2739
|
currency: "usd",
|
|
2707
2740
|
characterIsToken: false,
|
|
2708
|
-
promptTokenCostPer1M:
|
|
2709
|
-
completionTokenCostPer1M:
|
|
2741
|
+
promptTokenCostPer1M: 2.5,
|
|
2742
|
+
completionTokenCostPer1M: 15
|
|
2743
|
+
},
|
|
2744
|
+
{
|
|
2745
|
+
name: "gemini-2.5-flash-preview-04-17" /* Gemini25Flash */,
|
|
2746
|
+
currency: "usd",
|
|
2747
|
+
characterIsToken: false,
|
|
2748
|
+
promptTokenCostPer1M: 15,
|
|
2749
|
+
completionTokenCostPer1M: 3.5
|
|
2710
2750
|
},
|
|
2711
2751
|
{
|
|
2712
2752
|
name: "gemini-2.0-flash" /* Gemini20Flash */,
|
|
@@ -2960,7 +3000,10 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
2960
3000
|
frequencyPenalty: req.modelConfig?.frequencyPenalty ?? this.config.frequencyPenalty,
|
|
2961
3001
|
candidateCount: 1,
|
|
2962
3002
|
stopSequences: req.modelConfig?.stopSequences ?? this.config.stopSequences,
|
|
2963
|
-
responseMimeType: "text/plain"
|
|
3003
|
+
responseMimeType: "text/plain",
|
|
3004
|
+
...this.config.thinkingConfig && {
|
|
3005
|
+
thinkingConfig: this.config.thinkingConfig
|
|
3006
|
+
}
|
|
2964
3007
|
};
|
|
2965
3008
|
const safetySettings2 = this.config.safetySettings;
|
|
2966
3009
|
const reqValue = {
|
|
@@ -4923,6 +4966,9 @@ function matchesContent(content, prefix, startIndex = 0, prefixCache = globalPre
|
|
|
4923
4966
|
);
|
|
4924
4967
|
for (let i = 0; i < prefixes.length - 1; i++) {
|
|
4925
4968
|
const partialPrefix = prefixes[i];
|
|
4969
|
+
if (partialPrefix === "\n" || partialPrefix === ":") {
|
|
4970
|
+
continue;
|
|
4971
|
+
}
|
|
4926
4972
|
if (partialPrefix && contentEnd.endsWith(partialPrefix)) {
|
|
4927
4973
|
return -2;
|
|
4928
4974
|
}
|
|
@@ -5705,7 +5751,7 @@ var streamingExtractValues = (sig, values, xstate, content, streamingValidation
|
|
|
5705
5751
|
}
|
|
5706
5752
|
const isFirst = xstate.extractedFields.length === 0;
|
|
5707
5753
|
const prefix = (isFirst ? "" : "\n") + field.title + ":";
|
|
5708
|
-
let e = matchesContent(content, prefix, xstate.s
|
|
5754
|
+
let e = matchesContent(content, prefix, xstate.s);
|
|
5709
5755
|
switch (e) {
|
|
5710
5756
|
case -1:
|
|
5711
5757
|
if (streamingValidation && values.length == 0 && !field.isOptional) {
|
|
@@ -6571,10 +6617,8 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6571
6617
|
const maxRetries = options.maxRetries ?? this.options?.maxRetries ?? 10;
|
|
6572
6618
|
const maxSteps = options.maxSteps ?? this.options?.maxSteps ?? 10;
|
|
6573
6619
|
const debug = options.debug ?? ai.getOptions().debug;
|
|
6574
|
-
const
|
|
6575
|
-
|
|
6576
|
-
debugHideSystemPrompt: options.debugHideSystemPrompt
|
|
6577
|
-
};
|
|
6620
|
+
const debugHideSystemPrompt = options.debugHideSystemPrompt;
|
|
6621
|
+
const memOptions = { debug, debugHideSystemPrompt };
|
|
6578
6622
|
const mem = options.mem ?? this.options?.mem ?? new AxMemory(1e4, memOptions);
|
|
6579
6623
|
let err;
|
|
6580
6624
|
if (options?.functions && options.functions.length > 0) {
|
|
@@ -6635,7 +6679,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6635
6679
|
}
|
|
6636
6680
|
}
|
|
6637
6681
|
}
|
|
6638
|
-
throw new Error(`Unable to fix validation error: ${err}`);
|
|
6682
|
+
throw new Error(`Unable to fix validation error: ${err?.toString()}`);
|
|
6639
6683
|
}
|
|
6640
6684
|
throw new Error(`Max steps reached: ${maxSteps}`);
|
|
6641
6685
|
}
|
|
@@ -6652,7 +6696,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6652
6696
|
return false;
|
|
6653
6697
|
}
|
|
6654
6698
|
async *_forward1(ai, values, options) {
|
|
6655
|
-
const tracer =
|
|
6699
|
+
const tracer = options?.tracer ?? this.options?.tracer;
|
|
6656
6700
|
let functions = this.functions;
|
|
6657
6701
|
if (options?.functions) {
|
|
6658
6702
|
functions = parseFunctions(options.functions, this.functions);
|
|
@@ -6688,9 +6732,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6688
6732
|
}
|
|
6689
6733
|
}
|
|
6690
6734
|
async forward(ai, values, options) {
|
|
6691
|
-
const generator = this._forward1(ai, values, {
|
|
6692
|
-
...options
|
|
6693
|
-
});
|
|
6735
|
+
const generator = this._forward1(ai, values, options ?? {});
|
|
6694
6736
|
let buffer = {};
|
|
6695
6737
|
let currentVersion = 0;
|
|
6696
6738
|
for await (const item of generator) {
|
|
@@ -9354,7 +9396,7 @@ var AxMockAIService = class {
|
|
|
9354
9396
|
}
|
|
9355
9397
|
};
|
|
9356
9398
|
|
|
9357
|
-
// dsp/
|
|
9399
|
+
// dsp/classifier.ts
|
|
9358
9400
|
var colorLog6 = new ColorLog();
|
|
9359
9401
|
var AxSimpleClassifierClass = class {
|
|
9360
9402
|
name;
|
|
@@ -11163,6 +11205,7 @@ var AxMCPStdioTransport = class {
|
|
|
11163
11205
|
|
|
11164
11206
|
// ai/multiservice.ts
|
|
11165
11207
|
var AxMultiServiceRouter = class {
|
|
11208
|
+
options;
|
|
11166
11209
|
services = /* @__PURE__ */ new Map();
|
|
11167
11210
|
/**
|
|
11168
11211
|
* Constructs a new multi-service router.
|
|
@@ -11183,9 +11226,7 @@ var AxMultiServiceRouter = class {
|
|
|
11183
11226
|
this.services.set(item.key, {
|
|
11184
11227
|
service,
|
|
11185
11228
|
description,
|
|
11186
|
-
isInternal
|
|
11187
|
-
model: item.service.getDefaultModels().model,
|
|
11188
|
-
useDefaultModel: true
|
|
11229
|
+
isInternal
|
|
11189
11230
|
});
|
|
11190
11231
|
} else {
|
|
11191
11232
|
const modelList = item.getModelList();
|
|
@@ -11194,18 +11235,31 @@ var AxMultiServiceRouter = class {
|
|
|
11194
11235
|
`Service ${index} \`${item.getName()}\` has no model list.`
|
|
11195
11236
|
);
|
|
11196
11237
|
}
|
|
11197
|
-
for (const
|
|
11198
|
-
if (this.services.has(key)) {
|
|
11199
|
-
const otherService = this.services.get(key)?.service;
|
|
11238
|
+
for (const v of modelList) {
|
|
11239
|
+
if (this.services.has(v.key)) {
|
|
11240
|
+
const otherService = this.services.get(v.key)?.service;
|
|
11200
11241
|
throw new Error(
|
|
11201
|
-
`Service ${index} \`${item.getName()}\` has duplicate model key: ${key} as service ${otherService?.getName()}`
|
|
11242
|
+
`Service ${index} \`${item.getName()}\` has duplicate model key: ${v.key} as service ${otherService?.getName()}`
|
|
11202
11243
|
);
|
|
11244
|
+
} else {
|
|
11245
|
+
if ("model" in v && typeof v.model) {
|
|
11246
|
+
this.services.set(v.key, {
|
|
11247
|
+
description: v.description,
|
|
11248
|
+
service: item,
|
|
11249
|
+
model: v.model
|
|
11250
|
+
});
|
|
11251
|
+
} else if ("embedModel" in v && v.embedModel) {
|
|
11252
|
+
this.services.set(v.key, {
|
|
11253
|
+
description: v.description,
|
|
11254
|
+
service: item,
|
|
11255
|
+
embedModel: v.embedModel
|
|
11256
|
+
});
|
|
11257
|
+
} else {
|
|
11258
|
+
throw new Error(
|
|
11259
|
+
`Key ${v.key} in model list for service ${index} \`${item.getName()}\` is missing a model or embedModel property.`
|
|
11260
|
+
);
|
|
11261
|
+
}
|
|
11203
11262
|
}
|
|
11204
|
-
this.services.set(key, {
|
|
11205
|
-
description,
|
|
11206
|
-
service: item,
|
|
11207
|
-
model
|
|
11208
|
-
});
|
|
11209
11263
|
}
|
|
11210
11264
|
}
|
|
11211
11265
|
}
|
|
@@ -11222,25 +11276,32 @@ var AxMultiServiceRouter = class {
|
|
|
11222
11276
|
if (!item) {
|
|
11223
11277
|
throw new Error(`No service found for model key: ${modelKey}`);
|
|
11224
11278
|
}
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11279
|
+
if (!item.model) {
|
|
11280
|
+
const { model, ...reqWithoutModel } = req;
|
|
11281
|
+
return await item.service.chat(reqWithoutModel, options);
|
|
11282
|
+
}
|
|
11283
|
+
return await item.service.chat({ model: modelKey, ...req }, options);
|
|
11228
11284
|
}
|
|
11229
11285
|
/**
|
|
11230
11286
|
* Delegates the embed call to the service matching the provided embed model key.
|
|
11231
11287
|
*/
|
|
11232
11288
|
async embed(req, options) {
|
|
11233
|
-
const
|
|
11234
|
-
if (!
|
|
11289
|
+
const embedModelKey = req.embedModel;
|
|
11290
|
+
if (!embedModelKey) {
|
|
11235
11291
|
throw new Error("Embed model key must be specified for multi-service");
|
|
11236
11292
|
}
|
|
11237
|
-
const item = this.services.get(
|
|
11293
|
+
const item = this.services.get(embedModelKey);
|
|
11238
11294
|
if (!item) {
|
|
11239
|
-
throw new Error(`No service found for embed model key: ${
|
|
11295
|
+
throw new Error(`No service found for embed model key: ${embedModelKey}`);
|
|
11296
|
+
}
|
|
11297
|
+
if (!item.model) {
|
|
11298
|
+
const { embedModel, ...reqWithoutEmbedModel } = req;
|
|
11299
|
+
return await item.service.embed(reqWithoutEmbedModel, options);
|
|
11240
11300
|
}
|
|
11241
|
-
|
|
11242
|
-
|
|
11243
|
-
|
|
11301
|
+
return await item.service.embed(
|
|
11302
|
+
{ embedModel: embedModelKey, ...req },
|
|
11303
|
+
options
|
|
11304
|
+
);
|
|
11244
11305
|
}
|
|
11245
11306
|
/**
|
|
11246
11307
|
* Returns a composite ID built from the IDs of the underlying services.
|
|
@@ -11258,11 +11319,15 @@ var AxMultiServiceRouter = class {
|
|
|
11258
11319
|
* Aggregates all available models across the underlying services.
|
|
11259
11320
|
*/
|
|
11260
11321
|
getModelList() {
|
|
11261
|
-
return Array.from(this.services).filter(([, value]) => !value.isInternal).map(([key,
|
|
11262
|
-
|
|
11263
|
-
|
|
11264
|
-
|
|
11265
|
-
|
|
11322
|
+
return Array.from(this.services).filter(([, value]) => !value.isInternal).map(([key, v]) => {
|
|
11323
|
+
if (v.model) {
|
|
11324
|
+
return { key, description: v.description, model: v.model };
|
|
11325
|
+
} else if (v.embedModel) {
|
|
11326
|
+
return { key, description: v.description, embedModel: v.embedModel };
|
|
11327
|
+
} else {
|
|
11328
|
+
throw new Error(`Service ${key} has no model or embedModel`);
|
|
11329
|
+
}
|
|
11330
|
+
});
|
|
11266
11331
|
}
|
|
11267
11332
|
getDefaultModels() {
|
|
11268
11333
|
throw new Error(
|
|
@@ -11301,17 +11366,14 @@ var AxMultiServiceRouter = class {
|
|
|
11301
11366
|
for (const service of this.services.values()) {
|
|
11302
11367
|
service.service.setOptions(options);
|
|
11303
11368
|
}
|
|
11369
|
+
this.options = options;
|
|
11304
11370
|
}
|
|
11305
11371
|
/**
|
|
11306
11372
|
* Returns the options from the last used service,
|
|
11307
11373
|
* or falls back to the first service if none has been used.
|
|
11308
11374
|
*/
|
|
11309
11375
|
getOptions() {
|
|
11310
|
-
|
|
11311
|
-
if (!service) {
|
|
11312
|
-
throw new Error("No service available to get options.");
|
|
11313
|
-
}
|
|
11314
|
-
return service.service.getOptions();
|
|
11376
|
+
return this.options ?? {};
|
|
11315
11377
|
}
|
|
11316
11378
|
};
|
|
11317
11379
|
|