@ax-llm/ax 10.0.49 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +189 -117
- package/index.cjs.map +1 -1
- package/index.d.cts +80 -103
- package/index.d.ts +80 -103
- package/index.js +189 -117
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -114,9 +114,9 @@ var import_api2 = require("@opentelemetry/api");
|
|
|
114
114
|
function getModelInfo({
|
|
115
115
|
model,
|
|
116
116
|
modelInfo,
|
|
117
|
-
|
|
117
|
+
models
|
|
118
118
|
}) {
|
|
119
|
-
const mappedModel =
|
|
119
|
+
const mappedModel = models?.find((v) => v.key === model)?.model ?? model;
|
|
120
120
|
const exactMatch = modelInfo.find((v) => v.name === model);
|
|
121
121
|
if (exactMatch) return exactMatch;
|
|
122
122
|
const normalizedName = mappedModel.replace(/^(anthropic\.|openai\.)/, "").replace(/-latest$/, "").replace(/-\d{8}$/, "").replace(/-v\d+:\d+$/, "").replace(/@\d{8}$/, "").replace(/-\d{2,}(-[a-zA-Z0-9-]+)?$/, "").replace(/-v\d+@\d{8}$/, "").replace(/-v\d+$/, "");
|
|
@@ -737,10 +737,10 @@ var AxBaseAI = class {
|
|
|
737
737
|
apiURL,
|
|
738
738
|
headers,
|
|
739
739
|
modelInfo,
|
|
740
|
-
|
|
740
|
+
defaults,
|
|
741
741
|
options = {},
|
|
742
742
|
supportFor,
|
|
743
|
-
|
|
743
|
+
models
|
|
744
744
|
}) {
|
|
745
745
|
this.aiImpl = aiImpl;
|
|
746
746
|
this.name = name;
|
|
@@ -749,12 +749,11 @@ var AxBaseAI = class {
|
|
|
749
749
|
this.supportFor = supportFor;
|
|
750
750
|
this.tracer = options.tracer;
|
|
751
751
|
this.modelInfo = modelInfo;
|
|
752
|
-
this.
|
|
753
|
-
this.models
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
if (!models.model || typeof models.model !== "string" || models.model === "") {
|
|
752
|
+
this.models = models;
|
|
753
|
+
const model = this.models?.find((v) => v.key === defaults.model)?.model ?? defaults.model;
|
|
754
|
+
const embedModel = this.models?.find((v) => v.key === defaults.embedModel)?.model ?? defaults.embedModel;
|
|
755
|
+
this.defaults = { model, embedModel };
|
|
756
|
+
if (!defaults.model || typeof defaults.model !== "string" || defaults.model === "") {
|
|
758
757
|
throw new Error("No model defined");
|
|
759
758
|
}
|
|
760
759
|
this.setOptions(options);
|
|
@@ -763,11 +762,11 @@ var AxBaseAI = class {
|
|
|
763
762
|
rt;
|
|
764
763
|
fetch;
|
|
765
764
|
tracer;
|
|
766
|
-
|
|
765
|
+
models;
|
|
767
766
|
modelInfo;
|
|
768
767
|
modelUsage;
|
|
769
768
|
embedModelUsage;
|
|
770
|
-
|
|
769
|
+
defaults;
|
|
771
770
|
apiURL;
|
|
772
771
|
name;
|
|
773
772
|
headers;
|
|
@@ -834,9 +833,9 @@ var AxBaseAI = class {
|
|
|
834
833
|
}
|
|
835
834
|
getModelInfo() {
|
|
836
835
|
const mi = getModelInfo({
|
|
837
|
-
model: this.
|
|
836
|
+
model: this.defaults.model,
|
|
838
837
|
modelInfo: this.modelInfo,
|
|
839
|
-
|
|
838
|
+
models: this.models
|
|
840
839
|
});
|
|
841
840
|
return {
|
|
842
841
|
...mi,
|
|
@@ -844,27 +843,27 @@ var AxBaseAI = class {
|
|
|
844
843
|
};
|
|
845
844
|
}
|
|
846
845
|
getEmbedModelInfo() {
|
|
847
|
-
if (!this.
|
|
846
|
+
if (!this.defaults.embedModel) {
|
|
848
847
|
return;
|
|
849
848
|
}
|
|
850
849
|
const mi = getModelInfo({
|
|
851
|
-
model: this.
|
|
850
|
+
model: this.defaults.embedModel,
|
|
852
851
|
modelInfo: this.modelInfo,
|
|
853
|
-
|
|
852
|
+
models: this.models
|
|
854
853
|
});
|
|
855
854
|
return {
|
|
856
855
|
...mi,
|
|
857
856
|
provider: this.name
|
|
858
857
|
};
|
|
859
858
|
}
|
|
860
|
-
|
|
861
|
-
return this.
|
|
859
|
+
getModelList() {
|
|
860
|
+
return this.models;
|
|
862
861
|
}
|
|
863
862
|
getName() {
|
|
864
863
|
return this.name;
|
|
865
864
|
}
|
|
866
865
|
getFeatures(model) {
|
|
867
|
-
return typeof this.supportFor === "function" ? this.supportFor(model ?? this.
|
|
866
|
+
return typeof this.supportFor === "function" ? this.supportFor(model ?? this.defaults.model) : this.supportFor;
|
|
868
867
|
}
|
|
869
868
|
// Method to calculate percentiles
|
|
870
869
|
calculatePercentile(samples, percentile) {
|
|
@@ -912,7 +911,7 @@ var AxBaseAI = class {
|
|
|
912
911
|
}
|
|
913
912
|
}
|
|
914
913
|
async _chat1(req, options) {
|
|
915
|
-
const model = req.model ? this.
|
|
914
|
+
const model = req.model ? this.models?.find((v) => v.key === req.model)?.model ?? req.model : this.defaults.model;
|
|
916
915
|
const modelConfig = {
|
|
917
916
|
...this.aiImpl.getModelConfig(),
|
|
918
917
|
...req.modelConfig
|
|
@@ -1056,7 +1055,7 @@ var AxBaseAI = class {
|
|
|
1056
1055
|
}
|
|
1057
1056
|
}
|
|
1058
1057
|
async _embed1(req, options) {
|
|
1059
|
-
const embedModel = req.embedModel ? this.
|
|
1058
|
+
const embedModel = req.embedModel ? this.models?.find((v) => v.key === req.embedModel)?.model ?? req.embedModel : this.defaults.embedModel;
|
|
1060
1059
|
if (!embedModel) {
|
|
1061
1060
|
throw new Error("No embed model defined");
|
|
1062
1061
|
}
|
|
@@ -1067,7 +1066,7 @@ var AxBaseAI = class {
|
|
|
1067
1066
|
kind: import_api2.SpanKind.SERVER,
|
|
1068
1067
|
attributes: {
|
|
1069
1068
|
[axSpanAttributes.LLM_SYSTEM]: this.name,
|
|
1070
|
-
[axSpanAttributes.LLM_REQUEST_MODEL]: req.embedModel ?? this.
|
|
1069
|
+
[axSpanAttributes.LLM_REQUEST_MODEL]: req.embedModel ?? this.defaults.embedModel
|
|
1071
1070
|
}
|
|
1072
1071
|
},
|
|
1073
1072
|
async (span) => {
|
|
@@ -1540,7 +1539,7 @@ var AxAIAnthropic = class extends AxBaseAI {
|
|
|
1540
1539
|
region,
|
|
1541
1540
|
config,
|
|
1542
1541
|
options,
|
|
1543
|
-
|
|
1542
|
+
models
|
|
1544
1543
|
}) {
|
|
1545
1544
|
const isVertex = projectId !== void 0 && region !== void 0;
|
|
1546
1545
|
let apiURL;
|
|
@@ -1576,10 +1575,10 @@ var AxAIAnthropic = class extends AxBaseAI {
|
|
|
1576
1575
|
apiURL,
|
|
1577
1576
|
headers,
|
|
1578
1577
|
modelInfo: axModelInfoAnthropic,
|
|
1579
|
-
|
|
1578
|
+
defaults: { model: _config.model },
|
|
1580
1579
|
options,
|
|
1581
|
-
supportFor: { functions: true, streaming: true },
|
|
1582
|
-
|
|
1580
|
+
supportFor: { functions: true, streaming: true, functionCot: true },
|
|
1581
|
+
models
|
|
1583
1582
|
});
|
|
1584
1583
|
}
|
|
1585
1584
|
};
|
|
@@ -2063,7 +2062,7 @@ var AxAIOpenAI = class extends AxBaseAI {
|
|
|
2063
2062
|
options,
|
|
2064
2063
|
apiURL,
|
|
2065
2064
|
modelInfo = axModelInfoOpenAI,
|
|
2066
|
-
|
|
2065
|
+
models
|
|
2067
2066
|
}) {
|
|
2068
2067
|
if (!apiKey || apiKey === "") {
|
|
2069
2068
|
throw new Error("OpenAI API key not set");
|
|
@@ -2082,7 +2081,7 @@ var AxAIOpenAI = class extends AxBaseAI {
|
|
|
2082
2081
|
apiURL: apiURL ? apiURL : "https://api.openai.com/v1",
|
|
2083
2082
|
headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
|
|
2084
2083
|
modelInfo,
|
|
2085
|
-
|
|
2084
|
+
defaults: {
|
|
2086
2085
|
model: _config.model,
|
|
2087
2086
|
embedModel: _config.embedModel
|
|
2088
2087
|
},
|
|
@@ -2090,7 +2089,7 @@ var AxAIOpenAI = class extends AxBaseAI {
|
|
|
2090
2089
|
supportFor: () => {
|
|
2091
2090
|
return { functions: true, streaming: true };
|
|
2092
2091
|
},
|
|
2093
|
-
|
|
2092
|
+
models
|
|
2094
2093
|
});
|
|
2095
2094
|
}
|
|
2096
2095
|
};
|
|
@@ -2108,7 +2107,7 @@ var AxAIAzureOpenAI = class extends AxAIOpenAI {
|
|
|
2108
2107
|
version = "api-version=2024-02-15-preview",
|
|
2109
2108
|
config,
|
|
2110
2109
|
options,
|
|
2111
|
-
|
|
2110
|
+
models
|
|
2112
2111
|
}) {
|
|
2113
2112
|
if (!apiKey || apiKey === "") {
|
|
2114
2113
|
throw new Error("Azure OpenAPI API key not set");
|
|
@@ -2123,7 +2122,7 @@ var AxAIAzureOpenAI = class extends AxAIOpenAI {
|
|
|
2123
2122
|
...axAIAzureOpenAIDefaultConfig(),
|
|
2124
2123
|
...config
|
|
2125
2124
|
};
|
|
2126
|
-
super({ apiKey, config: _config, options,
|
|
2125
|
+
super({ apiKey, config: _config, options, models });
|
|
2127
2126
|
const host = resourceName.includes("://") ? resourceName : `https://${resourceName}.openai.azure.com/`;
|
|
2128
2127
|
super.setName("Azure OpenAI");
|
|
2129
2128
|
super.setAPIURL(
|
|
@@ -2379,7 +2378,7 @@ var AxAICohere = class extends AxBaseAI {
|
|
|
2379
2378
|
apiKey,
|
|
2380
2379
|
config,
|
|
2381
2380
|
options,
|
|
2382
|
-
|
|
2381
|
+
models
|
|
2383
2382
|
}) {
|
|
2384
2383
|
if (!apiKey || apiKey === "") {
|
|
2385
2384
|
throw new Error("Cohere API key not set");
|
|
@@ -2394,10 +2393,10 @@ var AxAICohere = class extends AxBaseAI {
|
|
|
2394
2393
|
apiURL: "https://api.cohere.ai/v1",
|
|
2395
2394
|
headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
|
|
2396
2395
|
modelInfo: axModelInfoCohere,
|
|
2397
|
-
|
|
2396
|
+
defaults: { model: _config.model },
|
|
2398
2397
|
supportFor: { functions: true, streaming: true },
|
|
2399
2398
|
options,
|
|
2400
|
-
|
|
2399
|
+
models
|
|
2401
2400
|
});
|
|
2402
2401
|
}
|
|
2403
2402
|
};
|
|
@@ -2491,7 +2490,7 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
|
|
|
2491
2490
|
apiKey,
|
|
2492
2491
|
config,
|
|
2493
2492
|
options,
|
|
2494
|
-
|
|
2493
|
+
models
|
|
2495
2494
|
}) {
|
|
2496
2495
|
if (!apiKey || apiKey === "") {
|
|
2497
2496
|
throw new Error("DeepSeek API key not set");
|
|
@@ -2506,7 +2505,7 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
|
|
|
2506
2505
|
options,
|
|
2507
2506
|
apiURL: "https://api.deepseek.com",
|
|
2508
2507
|
modelInfo: axModelInfoDeepSeek,
|
|
2509
|
-
|
|
2508
|
+
models
|
|
2510
2509
|
});
|
|
2511
2510
|
super.setName("DeepSeek");
|
|
2512
2511
|
}
|
|
@@ -2514,6 +2513,10 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
|
|
|
2514
2513
|
|
|
2515
2514
|
// ai/google-gemini/types.ts
|
|
2516
2515
|
var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
|
|
2516
|
+
AxAIGoogleGeminiModel2["Gemini20Pro"] = "gemini-2.0-pro-exp-02-05";
|
|
2517
|
+
AxAIGoogleGeminiModel2["Gemini20Flash"] = "gemini-2.0-flash";
|
|
2518
|
+
AxAIGoogleGeminiModel2["Gemini20FlashLite"] = "gemini-2.0-flash-lite-preview-02-05";
|
|
2519
|
+
AxAIGoogleGeminiModel2["Gemini20FlashThinking"] = "gemini-2.0-flash-thinking-exp-01-21";
|
|
2517
2520
|
AxAIGoogleGeminiModel2["Gemini1Pro"] = "gemini-1.0-pro";
|
|
2518
2521
|
AxAIGoogleGeminiModel2["Gemini15Flash"] = "gemini-1.5-flash";
|
|
2519
2522
|
AxAIGoogleGeminiModel2["Gemini15Flash8B"] = "gemini-1.5-flash-8b";
|
|
@@ -2545,31 +2548,59 @@ var AxAIGoogleGeminiSafetyThreshold = /* @__PURE__ */ ((AxAIGoogleGeminiSafetyTh
|
|
|
2545
2548
|
|
|
2546
2549
|
// ai/google-gemini/info.ts
|
|
2547
2550
|
var axModelInfoGoogleGemini = [
|
|
2551
|
+
{
|
|
2552
|
+
name: "gemini-2.0-pro-exp-02-05" /* Gemini20Pro */,
|
|
2553
|
+
currency: "usd",
|
|
2554
|
+
characterIsToken: false,
|
|
2555
|
+
promptTokenCostPer1M: 0,
|
|
2556
|
+
completionTokenCostPer1M: 0
|
|
2557
|
+
},
|
|
2558
|
+
{
|
|
2559
|
+
name: "gemini-2.0-flash" /* Gemini20Flash */,
|
|
2560
|
+
currency: "usd",
|
|
2561
|
+
characterIsToken: false,
|
|
2562
|
+
promptTokenCostPer1M: 0.01,
|
|
2563
|
+
completionTokenCostPer1M: 0.4
|
|
2564
|
+
},
|
|
2565
|
+
{
|
|
2566
|
+
name: "gemini-2.0-flash-lite-preview-02-05" /* Gemini20FlashLite */,
|
|
2567
|
+
currency: "usd",
|
|
2568
|
+
characterIsToken: false,
|
|
2569
|
+
promptTokenCostPer1M: 0,
|
|
2570
|
+
completionTokenCostPer1M: 0
|
|
2571
|
+
},
|
|
2572
|
+
{
|
|
2573
|
+
name: "gemini-2.0-flash-thinking-exp-01-21" /* Gemini20FlashThinking */,
|
|
2574
|
+
currency: "usd",
|
|
2575
|
+
characterIsToken: false,
|
|
2576
|
+
promptTokenCostPer1M: 0,
|
|
2577
|
+
completionTokenCostPer1M: 0
|
|
2578
|
+
},
|
|
2548
2579
|
{
|
|
2549
2580
|
name: "gemini-1.5-flash" /* Gemini15Flash */,
|
|
2550
2581
|
currency: "usd",
|
|
2551
|
-
characterIsToken:
|
|
2582
|
+
characterIsToken: false,
|
|
2552
2583
|
promptTokenCostPer1M: 0.075,
|
|
2553
2584
|
completionTokenCostPer1M: 0.3
|
|
2554
2585
|
},
|
|
2555
2586
|
{
|
|
2556
2587
|
name: "gemini-1.5-flash-8b" /* Gemini15Flash8B */,
|
|
2557
2588
|
currency: "usd",
|
|
2558
|
-
characterIsToken:
|
|
2589
|
+
characterIsToken: false,
|
|
2559
2590
|
promptTokenCostPer1M: 0.0375,
|
|
2560
2591
|
completionTokenCostPer1M: 0.15
|
|
2561
2592
|
},
|
|
2562
2593
|
{
|
|
2563
2594
|
name: "gemini-1.5-pro" /* Gemini15Pro */,
|
|
2564
2595
|
currency: "usd",
|
|
2565
|
-
characterIsToken:
|
|
2596
|
+
characterIsToken: false,
|
|
2566
2597
|
promptTokenCostPer1M: 1.25,
|
|
2567
2598
|
completionTokenCostPer1M: 5
|
|
2568
2599
|
},
|
|
2569
2600
|
{
|
|
2570
2601
|
name: "gemini-1.0-pro" /* Gemini1Pro */,
|
|
2571
2602
|
currency: "usd",
|
|
2572
|
-
characterIsToken:
|
|
2603
|
+
characterIsToken: false,
|
|
2573
2604
|
promptTokenCostPer1M: 0.5,
|
|
2574
2605
|
completionTokenCostPer1M: 1.5
|
|
2575
2606
|
}
|
|
@@ -2883,7 +2914,7 @@ var AxAIGoogleGemini = class extends AxBaseAI {
|
|
|
2883
2914
|
region,
|
|
2884
2915
|
config,
|
|
2885
2916
|
options,
|
|
2886
|
-
|
|
2917
|
+
models
|
|
2887
2918
|
}) {
|
|
2888
2919
|
const isVertex = projectId !== void 0 && region !== void 0;
|
|
2889
2920
|
let apiURL;
|
|
@@ -2915,13 +2946,13 @@ var AxAIGoogleGemini = class extends AxBaseAI {
|
|
|
2915
2946
|
apiURL,
|
|
2916
2947
|
headers,
|
|
2917
2948
|
modelInfo: axModelInfoGoogleGemini,
|
|
2918
|
-
|
|
2949
|
+
defaults: {
|
|
2919
2950
|
model: _config.model,
|
|
2920
2951
|
embedModel: _config.embedModel
|
|
2921
2952
|
},
|
|
2922
2953
|
options,
|
|
2923
2954
|
supportFor: { functions: true, streaming: true },
|
|
2924
|
-
|
|
2955
|
+
models
|
|
2925
2956
|
});
|
|
2926
2957
|
}
|
|
2927
2958
|
};
|
|
@@ -3023,7 +3054,7 @@ var AxAIGroq = class extends AxAIOpenAI {
|
|
|
3023
3054
|
apiKey,
|
|
3024
3055
|
config,
|
|
3025
3056
|
options,
|
|
3026
|
-
|
|
3057
|
+
models
|
|
3027
3058
|
}) {
|
|
3028
3059
|
if (!apiKey || apiKey === "") {
|
|
3029
3060
|
throw new Error("Groq API key not set");
|
|
@@ -3042,7 +3073,7 @@ var AxAIGroq = class extends AxAIOpenAI {
|
|
|
3042
3073
|
options: _options,
|
|
3043
3074
|
modelInfo: axModelInfoGroq,
|
|
3044
3075
|
apiURL: "https://api.groq.com/openai/v1",
|
|
3045
|
-
|
|
3076
|
+
models
|
|
3046
3077
|
});
|
|
3047
3078
|
super.setName("Groq");
|
|
3048
3079
|
this.setOptions(_options);
|
|
@@ -3166,7 +3197,7 @@ var AxAIHuggingFace = class extends AxBaseAI {
|
|
|
3166
3197
|
apiKey,
|
|
3167
3198
|
config,
|
|
3168
3199
|
options,
|
|
3169
|
-
|
|
3200
|
+
models
|
|
3170
3201
|
}) {
|
|
3171
3202
|
if (!apiKey || apiKey === "") {
|
|
3172
3203
|
throw new Error("HuggingFace API key not set");
|
|
@@ -3181,10 +3212,10 @@ var AxAIHuggingFace = class extends AxBaseAI {
|
|
|
3181
3212
|
apiURL: "https://api-inference.huggingface.co",
|
|
3182
3213
|
headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
|
|
3183
3214
|
modelInfo: axModelInfoHuggingFace,
|
|
3184
|
-
|
|
3215
|
+
defaults: { model: _config.model },
|
|
3185
3216
|
options,
|
|
3186
3217
|
supportFor: { functions: false, streaming: false },
|
|
3187
|
-
|
|
3218
|
+
models
|
|
3188
3219
|
});
|
|
3189
3220
|
}
|
|
3190
3221
|
};
|
|
@@ -3268,7 +3299,7 @@ var AxAIMistral = class extends AxAIOpenAI {
|
|
|
3268
3299
|
apiKey,
|
|
3269
3300
|
config,
|
|
3270
3301
|
options,
|
|
3271
|
-
|
|
3302
|
+
models
|
|
3272
3303
|
}) {
|
|
3273
3304
|
if (!apiKey || apiKey === "") {
|
|
3274
3305
|
throw new Error("Mistral API key not set");
|
|
@@ -3283,7 +3314,7 @@ var AxAIMistral = class extends AxAIOpenAI {
|
|
|
3283
3314
|
options,
|
|
3284
3315
|
apiURL: "https://api.mistral.ai/v1",
|
|
3285
3316
|
modelInfo: axModelInfoMistral,
|
|
3286
|
-
|
|
3317
|
+
models
|
|
3287
3318
|
});
|
|
3288
3319
|
super.setName("Mistral");
|
|
3289
3320
|
}
|
|
@@ -3301,7 +3332,7 @@ var AxAIOllama = class extends AxAIOpenAI {
|
|
|
3301
3332
|
url = "http://localhost:11434/v1",
|
|
3302
3333
|
config,
|
|
3303
3334
|
options,
|
|
3304
|
-
|
|
3335
|
+
models
|
|
3305
3336
|
}) {
|
|
3306
3337
|
const _config = {
|
|
3307
3338
|
...axAIOllamaDefaultConfig(),
|
|
@@ -3312,7 +3343,7 @@ var AxAIOllama = class extends AxAIOpenAI {
|
|
|
3312
3343
|
options,
|
|
3313
3344
|
config: _config,
|
|
3314
3345
|
apiURL: url,
|
|
3315
|
-
|
|
3346
|
+
models
|
|
3316
3347
|
});
|
|
3317
3348
|
super.setName("Ollama");
|
|
3318
3349
|
}
|
|
@@ -3515,7 +3546,7 @@ var AxAIReka = class extends AxBaseAI {
|
|
|
3515
3546
|
options,
|
|
3516
3547
|
apiURL,
|
|
3517
3548
|
modelInfo = axModelInfoReka,
|
|
3518
|
-
|
|
3549
|
+
models
|
|
3519
3550
|
}) {
|
|
3520
3551
|
if (!apiKey || apiKey === "") {
|
|
3521
3552
|
throw new Error("Reka API key not set");
|
|
@@ -3530,12 +3561,12 @@ var AxAIReka = class extends AxBaseAI {
|
|
|
3530
3561
|
apiURL: apiURL ? apiURL : "https://api.reka.ai/v1/chat",
|
|
3531
3562
|
headers: async () => ({ "X-Api-Key": apiKey }),
|
|
3532
3563
|
modelInfo,
|
|
3533
|
-
|
|
3564
|
+
defaults: {
|
|
3534
3565
|
model: _config.model
|
|
3535
3566
|
},
|
|
3536
3567
|
options,
|
|
3537
3568
|
supportFor: { functions: true, streaming: true },
|
|
3538
|
-
|
|
3569
|
+
models
|
|
3539
3570
|
});
|
|
3540
3571
|
}
|
|
3541
3572
|
};
|
|
@@ -3554,7 +3585,7 @@ var AxAITogether = class extends AxAIOpenAI {
|
|
|
3554
3585
|
apiKey,
|
|
3555
3586
|
config,
|
|
3556
3587
|
options,
|
|
3557
|
-
|
|
3588
|
+
models
|
|
3558
3589
|
}) {
|
|
3559
3590
|
if (!apiKey || apiKey === "") {
|
|
3560
3591
|
throw new Error("Together API key not set");
|
|
@@ -3569,7 +3600,7 @@ var AxAITogether = class extends AxAIOpenAI {
|
|
|
3569
3600
|
options,
|
|
3570
3601
|
apiURL: "https://api.together.xyz/v1",
|
|
3571
3602
|
modelInfo: axModelInfoTogether,
|
|
3572
|
-
|
|
3603
|
+
models
|
|
3573
3604
|
});
|
|
3574
3605
|
super.setName("Together");
|
|
3575
3606
|
}
|
|
@@ -3632,8 +3663,8 @@ var AxAI = class {
|
|
|
3632
3663
|
getFeatures(model) {
|
|
3633
3664
|
return this.ai.getFeatures(model);
|
|
3634
3665
|
}
|
|
3635
|
-
|
|
3636
|
-
return this.ai.
|
|
3666
|
+
getModelList() {
|
|
3667
|
+
return this.ai.getModelList();
|
|
3637
3668
|
}
|
|
3638
3669
|
getMetrics() {
|
|
3639
3670
|
return this.ai.getMetrics();
|
|
@@ -5234,7 +5265,7 @@ var checkMissingRequiredFields = (xstate, values, currentIndex) => {
|
|
|
5234
5265
|
});
|
|
5235
5266
|
}
|
|
5236
5267
|
};
|
|
5237
|
-
var streamingExtractValues = (sig, values, xstate, content) => {
|
|
5268
|
+
var streamingExtractValues = (sig, values, xstate, content, streamingValidation = false) => {
|
|
5238
5269
|
const fields = sig.getOutputFields();
|
|
5239
5270
|
for (const [index, field] of fields.entries()) {
|
|
5240
5271
|
if (field.name in values) {
|
|
@@ -5244,6 +5275,12 @@ var streamingExtractValues = (sig, values, xstate, content) => {
|
|
|
5244
5275
|
let e = matchesContent(content, prefix, xstate.s + 1);
|
|
5245
5276
|
switch (e) {
|
|
5246
5277
|
case -1:
|
|
5278
|
+
if (streamingValidation && xstate.s == -1 && !field.isOptional) {
|
|
5279
|
+
throw new ValidationError({
|
|
5280
|
+
message: "Required field not found",
|
|
5281
|
+
fields: [field]
|
|
5282
|
+
});
|
|
5283
|
+
}
|
|
5247
5284
|
continue;
|
|
5248
5285
|
// Field is not found, continue to the next field
|
|
5249
5286
|
case -2:
|
|
@@ -5260,6 +5297,7 @@ var streamingExtractValues = (sig, values, xstate, content) => {
|
|
|
5260
5297
|
checkMissingRequiredFields(xstate, values, index);
|
|
5261
5298
|
xstate.s = e + prefixLen;
|
|
5262
5299
|
xstate.currField = field;
|
|
5300
|
+
xstate.currFieldIndex = index;
|
|
5263
5301
|
if (!xstate.extractedFields.includes(field)) {
|
|
5264
5302
|
xstate.extractedFields.push(field);
|
|
5265
5303
|
}
|
|
@@ -5273,8 +5311,8 @@ var streamingExtractFinalValue = (sig, values, xstate, content) => {
|
|
|
5273
5311
|
values[xstate.currField.name] = parsedValue;
|
|
5274
5312
|
}
|
|
5275
5313
|
}
|
|
5276
|
-
const
|
|
5277
|
-
checkMissingRequiredFields(xstate, values,
|
|
5314
|
+
const sigFields = sig.getOutputFields();
|
|
5315
|
+
checkMissingRequiredFields(xstate, values, sigFields.length);
|
|
5278
5316
|
};
|
|
5279
5317
|
var convertValueToType = (field, val) => {
|
|
5280
5318
|
switch (field.type?.name) {
|
|
@@ -5759,6 +5797,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5759
5797
|
traceId,
|
|
5760
5798
|
functions
|
|
5761
5799
|
}) {
|
|
5800
|
+
const streamingValidation = ai.getFeatures().functionCot !== true;
|
|
5762
5801
|
const functionCalls = [];
|
|
5763
5802
|
const values = {};
|
|
5764
5803
|
const xstate = {
|
|
@@ -5774,14 +5813,21 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5774
5813
|
if (v.modelUsage) {
|
|
5775
5814
|
this.usage.push({ ...usageInfo, ...v.modelUsage });
|
|
5776
5815
|
}
|
|
5777
|
-
if (result.
|
|
5816
|
+
if (result.functionCalls) {
|
|
5817
|
+
mergeFunctionCalls(functionCalls, result.functionCalls);
|
|
5818
|
+
mem.updateResult(
|
|
5819
|
+
{ name: result.name, content, functionCalls },
|
|
5820
|
+
sessionId
|
|
5821
|
+
);
|
|
5822
|
+
} else if (result.content) {
|
|
5778
5823
|
content += result.content;
|
|
5779
5824
|
mem.updateResult({ name: result.name, content }, sessionId);
|
|
5780
5825
|
const skip = streamingExtractValues(
|
|
5781
5826
|
this.signature,
|
|
5782
5827
|
values,
|
|
5783
5828
|
xstate,
|
|
5784
|
-
content
|
|
5829
|
+
content,
|
|
5830
|
+
streamingValidation
|
|
5785
5831
|
);
|
|
5786
5832
|
if (skip) {
|
|
5787
5833
|
continue;
|
|
@@ -5796,13 +5842,6 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5796
5842
|
assertAssertions(this.asserts, values);
|
|
5797
5843
|
yield* streamValues(this.signature, values, xstate, content);
|
|
5798
5844
|
}
|
|
5799
|
-
if (result.functionCalls) {
|
|
5800
|
-
mergeFunctionCalls(functionCalls, result.functionCalls);
|
|
5801
|
-
mem.updateResult(
|
|
5802
|
-
{ name: result.name, content, functionCalls },
|
|
5803
|
-
sessionId
|
|
5804
|
-
);
|
|
5805
|
-
}
|
|
5806
5845
|
if (result.finishReason === "length") {
|
|
5807
5846
|
throw new Error("Max tokens reached before completion");
|
|
5808
5847
|
}
|
|
@@ -5821,17 +5860,18 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5821
5860
|
traceId
|
|
5822
5861
|
);
|
|
5823
5862
|
this.functionsExecuted = /* @__PURE__ */ new Set([...this.functionsExecuted, ...fx]);
|
|
5863
|
+
} else {
|
|
5864
|
+
streamingExtractFinalValue(this.signature, values, xstate, content);
|
|
5865
|
+
assertStreamingAssertions(
|
|
5866
|
+
this.streamingAsserts,
|
|
5867
|
+
values,
|
|
5868
|
+
xstate,
|
|
5869
|
+
content,
|
|
5870
|
+
true
|
|
5871
|
+
);
|
|
5872
|
+
assertAssertions(this.asserts, values);
|
|
5873
|
+
yield* streamValues(this.signature, values, xstate, content, true);
|
|
5824
5874
|
}
|
|
5825
|
-
streamingExtractFinalValue(this.signature, values, xstate, content);
|
|
5826
|
-
assertStreamingAssertions(
|
|
5827
|
-
this.streamingAsserts,
|
|
5828
|
-
values,
|
|
5829
|
-
xstate,
|
|
5830
|
-
content,
|
|
5831
|
-
true
|
|
5832
|
-
);
|
|
5833
|
-
assertAssertions(this.asserts, values);
|
|
5834
|
-
yield* streamValues(this.signature, values, xstate, content, true);
|
|
5835
5875
|
}
|
|
5836
5876
|
async processResponse({
|
|
5837
5877
|
ai,
|
|
@@ -5843,15 +5883,15 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5843
5883
|
functions
|
|
5844
5884
|
}) {
|
|
5845
5885
|
const values = {};
|
|
5846
|
-
|
|
5886
|
+
let results = res.results ?? [];
|
|
5887
|
+
if (res.results.length > 1) {
|
|
5888
|
+
results = res.results.filter((r) => r.functionCalls);
|
|
5889
|
+
}
|
|
5890
|
+
for (const result of results) {
|
|
5847
5891
|
if (res.modelUsage) {
|
|
5848
5892
|
this.usage.push({ ...usageInfo, ...res.modelUsage });
|
|
5849
5893
|
}
|
|
5850
5894
|
mem.addResult(result, sessionId);
|
|
5851
|
-
if (result.content) {
|
|
5852
|
-
extractValues(this.signature, values, result.content);
|
|
5853
|
-
assertAssertions(this.asserts, values);
|
|
5854
|
-
}
|
|
5855
5895
|
if (result.functionCalls) {
|
|
5856
5896
|
const funcs = parseFunctionCalls(ai, result.functionCalls, values);
|
|
5857
5897
|
if (funcs) {
|
|
@@ -5868,6 +5908,9 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5868
5908
|
);
|
|
5869
5909
|
this.functionsExecuted = /* @__PURE__ */ new Set([...this.functionsExecuted, ...fx]);
|
|
5870
5910
|
}
|
|
5911
|
+
} else if (result.content) {
|
|
5912
|
+
extractValues(this.signature, values, result.content);
|
|
5913
|
+
assertAssertions(this.asserts, values);
|
|
5871
5914
|
}
|
|
5872
5915
|
if (result.finishReason === "length") {
|
|
5873
5916
|
throw new Error("Max tokens reached before completion");
|
|
@@ -6015,6 +6058,7 @@ var AxAgent = class {
|
|
|
6015
6058
|
ai;
|
|
6016
6059
|
signature;
|
|
6017
6060
|
program;
|
|
6061
|
+
functions;
|
|
6018
6062
|
agents;
|
|
6019
6063
|
name;
|
|
6020
6064
|
description;
|
|
@@ -6030,14 +6074,9 @@ var AxAgent = class {
|
|
|
6030
6074
|
}, options) {
|
|
6031
6075
|
this.ai = ai;
|
|
6032
6076
|
this.agents = agents;
|
|
6077
|
+
this.functions = functions;
|
|
6033
6078
|
this.signature = new AxSignature(signature);
|
|
6034
6079
|
this.signature.setDescription(description);
|
|
6035
|
-
const funcs = [
|
|
6036
|
-
...functions ?? [],
|
|
6037
|
-
...agents?.map((a) => a.getFunction()) ?? []
|
|
6038
|
-
];
|
|
6039
|
-
const opt = { ...options, functions: funcs };
|
|
6040
|
-
this.program = new AxGen(this.signature, opt);
|
|
6041
6080
|
if (!name || name.length < 5) {
|
|
6042
6081
|
throw new Error(
|
|
6043
6082
|
`Agent name must be at least 10 characters (more descriptive): ${name}`
|
|
@@ -6048,6 +6087,10 @@ var AxAgent = class {
|
|
|
6048
6087
|
`Agent description must be at least 20 characters (explain in detail what the agent does): ${description}`
|
|
6049
6088
|
);
|
|
6050
6089
|
}
|
|
6090
|
+
this.program = new AxGen(this.signature, options);
|
|
6091
|
+
for (const agent of agents ?? []) {
|
|
6092
|
+
this.program.register(agent);
|
|
6093
|
+
}
|
|
6051
6094
|
this.name = name;
|
|
6052
6095
|
this.description = description;
|
|
6053
6096
|
this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
|
|
@@ -6057,8 +6100,9 @@ var AxAgent = class {
|
|
|
6057
6100
|
parameters: this.signature.toJSONSchema(),
|
|
6058
6101
|
func: () => this.forward
|
|
6059
6102
|
};
|
|
6060
|
-
|
|
6061
|
-
|
|
6103
|
+
const mm = ai?.getModelList();
|
|
6104
|
+
if (mm) {
|
|
6105
|
+
this.func.parameters = addModelParameter(this.func.parameters, mm);
|
|
6062
6106
|
}
|
|
6063
6107
|
}
|
|
6064
6108
|
setExamples(examples) {
|
|
@@ -6084,38 +6128,41 @@ var AxAgent = class {
|
|
|
6084
6128
|
}
|
|
6085
6129
|
getFunction() {
|
|
6086
6130
|
const boundFunc = this.forward.bind(this);
|
|
6087
|
-
const wrappedFunc = (
|
|
6131
|
+
const wrappedFunc = (valuesAndModel, options) => {
|
|
6132
|
+
const { model, ...values } = valuesAndModel;
|
|
6088
6133
|
const ai = this.ai ?? options?.ai;
|
|
6089
6134
|
if (!ai) {
|
|
6090
6135
|
throw new Error("AI service is required to run the agent");
|
|
6091
6136
|
}
|
|
6092
|
-
return boundFunc(ai, values, options);
|
|
6137
|
+
return boundFunc(ai, values, { ...options, model });
|
|
6093
6138
|
};
|
|
6094
6139
|
return {
|
|
6095
6140
|
...this.func,
|
|
6096
6141
|
func: wrappedFunc
|
|
6097
6142
|
};
|
|
6098
6143
|
}
|
|
6099
|
-
init(
|
|
6100
|
-
const
|
|
6101
|
-
const
|
|
6102
|
-
|
|
6103
|
-
|
|
6144
|
+
init(parentAi, options) {
|
|
6145
|
+
const ai = this.ai ?? parentAi;
|
|
6146
|
+
const mm = ai?.getModelList();
|
|
6147
|
+
const agentFuncs = this.agents?.map((a) => a.getFunction())?.map(
|
|
6148
|
+
(f) => mm ? { ...f, parameters: addModelParameter(f.parameters, mm) } : f
|
|
6149
|
+
);
|
|
6150
|
+
const functions = [
|
|
6151
|
+
...options?.functions ?? this.functions ?? [],
|
|
6152
|
+
...agentFuncs ?? []
|
|
6104
6153
|
];
|
|
6105
|
-
|
|
6106
|
-
if (funcs.length > 0) {
|
|
6107
|
-
const opt2 = { ...options, functions: funcs };
|
|
6108
|
-
this.program = new AxGen(this.signature, opt2);
|
|
6109
|
-
}
|
|
6110
|
-
return { _ai, opt };
|
|
6154
|
+
return { ai, functions };
|
|
6111
6155
|
}
|
|
6112
|
-
async forward(
|
|
6113
|
-
const {
|
|
6114
|
-
return await this.program.forward(
|
|
6156
|
+
async forward(parentAi, values, options) {
|
|
6157
|
+
const { ai, functions } = this.init(parentAi, options);
|
|
6158
|
+
return await this.program.forward(ai, values, { ...options, functions });
|
|
6115
6159
|
}
|
|
6116
|
-
async *streamingForward(
|
|
6117
|
-
const {
|
|
6118
|
-
return yield* this.program.streamingForward(
|
|
6160
|
+
async *streamingForward(parentAi, values, options) {
|
|
6161
|
+
const { ai, functions } = this.init(parentAi, options);
|
|
6162
|
+
return yield* this.program.streamingForward(ai, values, {
|
|
6163
|
+
...options,
|
|
6164
|
+
functions
|
|
6165
|
+
});
|
|
6119
6166
|
}
|
|
6120
6167
|
};
|
|
6121
6168
|
function toCamelCase(inputString) {
|
|
@@ -6129,6 +6176,31 @@ function toCamelCase(inputString) {
|
|
|
6129
6176
|
}).join("");
|
|
6130
6177
|
return camelCaseString;
|
|
6131
6178
|
}
|
|
6179
|
+
function addModelParameter(parameters, models) {
|
|
6180
|
+
const baseSchema = parameters ? structuredClone(parameters) : {
|
|
6181
|
+
type: "object",
|
|
6182
|
+
properties: {},
|
|
6183
|
+
required: []
|
|
6184
|
+
};
|
|
6185
|
+
if (baseSchema.properties?.model) {
|
|
6186
|
+
return baseSchema;
|
|
6187
|
+
}
|
|
6188
|
+
const modelProperty = {
|
|
6189
|
+
type: "string",
|
|
6190
|
+
enum: models.map((m) => m.key),
|
|
6191
|
+
description: `The AI model to use for this function call. Available options: ${models.map((m) => `${m.key}: ${m.description}`).join(" | ")}`
|
|
6192
|
+
};
|
|
6193
|
+
const newProperties = {
|
|
6194
|
+
...baseSchema.properties ?? {},
|
|
6195
|
+
model: modelProperty
|
|
6196
|
+
};
|
|
6197
|
+
const newRequired = [...baseSchema.required ?? [], "model"];
|
|
6198
|
+
return {
|
|
6199
|
+
...baseSchema,
|
|
6200
|
+
properties: newProperties,
|
|
6201
|
+
required: newRequired
|
|
6202
|
+
};
|
|
6203
|
+
}
|
|
6132
6204
|
|
|
6133
6205
|
// docs/tika.ts
|
|
6134
6206
|
var import_node_fs = require("fs");
|
|
@@ -6211,7 +6283,7 @@ var AxBalancer = class _AxBalancer {
|
|
|
6211
6283
|
const bTotalCost = (bInfo.promptTokenCostPer1M || Infinity) + (bInfo.completionTokenCostPer1M || Infinity);
|
|
6212
6284
|
return aTotalCost - bTotalCost;
|
|
6213
6285
|
};
|
|
6214
|
-
|
|
6286
|
+
getModelList() {
|
|
6215
6287
|
throw new Error("Method not implemented.");
|
|
6216
6288
|
}
|
|
6217
6289
|
getNextService() {
|
|
@@ -7828,8 +7900,8 @@ var AxMockAIService = class {
|
|
|
7828
7900
|
streaming: this.config.features?.streaming ?? false
|
|
7829
7901
|
};
|
|
7830
7902
|
}
|
|
7831
|
-
|
|
7832
|
-
return this.config.
|
|
7903
|
+
getModelList() {
|
|
7904
|
+
return this.config.models;
|
|
7833
7905
|
}
|
|
7834
7906
|
getMetrics() {
|
|
7835
7907
|
return this.metrics;
|