@ax-llm/ax 10.0.50 → 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 +151 -91
- package/index.cjs.map +1 -1
- package/index.d.cts +80 -103
- package/index.d.ts +80 -103
- package/index.js +151 -91
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import { SpanKind } from "@opentelemetry/api";
|
|
|
5
5
|
function getModelInfo({
|
|
6
6
|
model,
|
|
7
7
|
modelInfo,
|
|
8
|
-
|
|
8
|
+
models
|
|
9
9
|
}) {
|
|
10
|
-
const mappedModel =
|
|
10
|
+
const mappedModel = models?.find((v) => v.key === model)?.model ?? model;
|
|
11
11
|
const exactMatch = modelInfo.find((v) => v.name === model);
|
|
12
12
|
if (exactMatch) return exactMatch;
|
|
13
13
|
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+$/, "");
|
|
@@ -636,10 +636,10 @@ var AxBaseAI = class {
|
|
|
636
636
|
apiURL,
|
|
637
637
|
headers,
|
|
638
638
|
modelInfo,
|
|
639
|
-
|
|
639
|
+
defaults,
|
|
640
640
|
options = {},
|
|
641
641
|
supportFor,
|
|
642
|
-
|
|
642
|
+
models
|
|
643
643
|
}) {
|
|
644
644
|
this.aiImpl = aiImpl;
|
|
645
645
|
this.name = name;
|
|
@@ -648,12 +648,11 @@ var AxBaseAI = class {
|
|
|
648
648
|
this.supportFor = supportFor;
|
|
649
649
|
this.tracer = options.tracer;
|
|
650
650
|
this.modelInfo = modelInfo;
|
|
651
|
-
this.
|
|
652
|
-
this.models
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
if (!models.model || typeof models.model !== "string" || models.model === "") {
|
|
651
|
+
this.models = models;
|
|
652
|
+
const model = this.models?.find((v) => v.key === defaults.model)?.model ?? defaults.model;
|
|
653
|
+
const embedModel = this.models?.find((v) => v.key === defaults.embedModel)?.model ?? defaults.embedModel;
|
|
654
|
+
this.defaults = { model, embedModel };
|
|
655
|
+
if (!defaults.model || typeof defaults.model !== "string" || defaults.model === "") {
|
|
657
656
|
throw new Error("No model defined");
|
|
658
657
|
}
|
|
659
658
|
this.setOptions(options);
|
|
@@ -662,11 +661,11 @@ var AxBaseAI = class {
|
|
|
662
661
|
rt;
|
|
663
662
|
fetch;
|
|
664
663
|
tracer;
|
|
665
|
-
|
|
664
|
+
models;
|
|
666
665
|
modelInfo;
|
|
667
666
|
modelUsage;
|
|
668
667
|
embedModelUsage;
|
|
669
|
-
|
|
668
|
+
defaults;
|
|
670
669
|
apiURL;
|
|
671
670
|
name;
|
|
672
671
|
headers;
|
|
@@ -733,9 +732,9 @@ var AxBaseAI = class {
|
|
|
733
732
|
}
|
|
734
733
|
getModelInfo() {
|
|
735
734
|
const mi = getModelInfo({
|
|
736
|
-
model: this.
|
|
735
|
+
model: this.defaults.model,
|
|
737
736
|
modelInfo: this.modelInfo,
|
|
738
|
-
|
|
737
|
+
models: this.models
|
|
739
738
|
});
|
|
740
739
|
return {
|
|
741
740
|
...mi,
|
|
@@ -743,27 +742,27 @@ var AxBaseAI = class {
|
|
|
743
742
|
};
|
|
744
743
|
}
|
|
745
744
|
getEmbedModelInfo() {
|
|
746
|
-
if (!this.
|
|
745
|
+
if (!this.defaults.embedModel) {
|
|
747
746
|
return;
|
|
748
747
|
}
|
|
749
748
|
const mi = getModelInfo({
|
|
750
|
-
model: this.
|
|
749
|
+
model: this.defaults.embedModel,
|
|
751
750
|
modelInfo: this.modelInfo,
|
|
752
|
-
|
|
751
|
+
models: this.models
|
|
753
752
|
});
|
|
754
753
|
return {
|
|
755
754
|
...mi,
|
|
756
755
|
provider: this.name
|
|
757
756
|
};
|
|
758
757
|
}
|
|
759
|
-
|
|
760
|
-
return this.
|
|
758
|
+
getModelList() {
|
|
759
|
+
return this.models;
|
|
761
760
|
}
|
|
762
761
|
getName() {
|
|
763
762
|
return this.name;
|
|
764
763
|
}
|
|
765
764
|
getFeatures(model) {
|
|
766
|
-
return typeof this.supportFor === "function" ? this.supportFor(model ?? this.
|
|
765
|
+
return typeof this.supportFor === "function" ? this.supportFor(model ?? this.defaults.model) : this.supportFor;
|
|
767
766
|
}
|
|
768
767
|
// Method to calculate percentiles
|
|
769
768
|
calculatePercentile(samples, percentile) {
|
|
@@ -811,7 +810,7 @@ var AxBaseAI = class {
|
|
|
811
810
|
}
|
|
812
811
|
}
|
|
813
812
|
async _chat1(req, options) {
|
|
814
|
-
const model = req.model ? this.
|
|
813
|
+
const model = req.model ? this.models?.find((v) => v.key === req.model)?.model ?? req.model : this.defaults.model;
|
|
815
814
|
const modelConfig = {
|
|
816
815
|
...this.aiImpl.getModelConfig(),
|
|
817
816
|
...req.modelConfig
|
|
@@ -955,7 +954,7 @@ var AxBaseAI = class {
|
|
|
955
954
|
}
|
|
956
955
|
}
|
|
957
956
|
async _embed1(req, options) {
|
|
958
|
-
const embedModel = req.embedModel ? this.
|
|
957
|
+
const embedModel = req.embedModel ? this.models?.find((v) => v.key === req.embedModel)?.model ?? req.embedModel : this.defaults.embedModel;
|
|
959
958
|
if (!embedModel) {
|
|
960
959
|
throw new Error("No embed model defined");
|
|
961
960
|
}
|
|
@@ -966,7 +965,7 @@ var AxBaseAI = class {
|
|
|
966
965
|
kind: SpanKind.SERVER,
|
|
967
966
|
attributes: {
|
|
968
967
|
[axSpanAttributes.LLM_SYSTEM]: this.name,
|
|
969
|
-
[axSpanAttributes.LLM_REQUEST_MODEL]: req.embedModel ?? this.
|
|
968
|
+
[axSpanAttributes.LLM_REQUEST_MODEL]: req.embedModel ?? this.defaults.embedModel
|
|
970
969
|
}
|
|
971
970
|
},
|
|
972
971
|
async (span) => {
|
|
@@ -1439,7 +1438,7 @@ var AxAIAnthropic = class extends AxBaseAI {
|
|
|
1439
1438
|
region,
|
|
1440
1439
|
config,
|
|
1441
1440
|
options,
|
|
1442
|
-
|
|
1441
|
+
models
|
|
1443
1442
|
}) {
|
|
1444
1443
|
const isVertex = projectId !== void 0 && region !== void 0;
|
|
1445
1444
|
let apiURL;
|
|
@@ -1475,10 +1474,10 @@ var AxAIAnthropic = class extends AxBaseAI {
|
|
|
1475
1474
|
apiURL,
|
|
1476
1475
|
headers,
|
|
1477
1476
|
modelInfo: axModelInfoAnthropic,
|
|
1478
|
-
|
|
1477
|
+
defaults: { model: _config.model },
|
|
1479
1478
|
options,
|
|
1480
|
-
supportFor: { functions: true, streaming: true },
|
|
1481
|
-
|
|
1479
|
+
supportFor: { functions: true, streaming: true, functionCot: true },
|
|
1480
|
+
models
|
|
1482
1481
|
});
|
|
1483
1482
|
}
|
|
1484
1483
|
};
|
|
@@ -1962,7 +1961,7 @@ var AxAIOpenAI = class extends AxBaseAI {
|
|
|
1962
1961
|
options,
|
|
1963
1962
|
apiURL,
|
|
1964
1963
|
modelInfo = axModelInfoOpenAI,
|
|
1965
|
-
|
|
1964
|
+
models
|
|
1966
1965
|
}) {
|
|
1967
1966
|
if (!apiKey || apiKey === "") {
|
|
1968
1967
|
throw new Error("OpenAI API key not set");
|
|
@@ -1981,7 +1980,7 @@ var AxAIOpenAI = class extends AxBaseAI {
|
|
|
1981
1980
|
apiURL: apiURL ? apiURL : "https://api.openai.com/v1",
|
|
1982
1981
|
headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
|
|
1983
1982
|
modelInfo,
|
|
1984
|
-
|
|
1983
|
+
defaults: {
|
|
1985
1984
|
model: _config.model,
|
|
1986
1985
|
embedModel: _config.embedModel
|
|
1987
1986
|
},
|
|
@@ -1989,7 +1988,7 @@ var AxAIOpenAI = class extends AxBaseAI {
|
|
|
1989
1988
|
supportFor: () => {
|
|
1990
1989
|
return { functions: true, streaming: true };
|
|
1991
1990
|
},
|
|
1992
|
-
|
|
1991
|
+
models
|
|
1993
1992
|
});
|
|
1994
1993
|
}
|
|
1995
1994
|
};
|
|
@@ -2007,7 +2006,7 @@ var AxAIAzureOpenAI = class extends AxAIOpenAI {
|
|
|
2007
2006
|
version = "api-version=2024-02-15-preview",
|
|
2008
2007
|
config,
|
|
2009
2008
|
options,
|
|
2010
|
-
|
|
2009
|
+
models
|
|
2011
2010
|
}) {
|
|
2012
2011
|
if (!apiKey || apiKey === "") {
|
|
2013
2012
|
throw new Error("Azure OpenAPI API key not set");
|
|
@@ -2022,7 +2021,7 @@ var AxAIAzureOpenAI = class extends AxAIOpenAI {
|
|
|
2022
2021
|
...axAIAzureOpenAIDefaultConfig(),
|
|
2023
2022
|
...config
|
|
2024
2023
|
};
|
|
2025
|
-
super({ apiKey, config: _config, options,
|
|
2024
|
+
super({ apiKey, config: _config, options, models });
|
|
2026
2025
|
const host = resourceName.includes("://") ? resourceName : `https://${resourceName}.openai.azure.com/`;
|
|
2027
2026
|
super.setName("Azure OpenAI");
|
|
2028
2027
|
super.setAPIURL(
|
|
@@ -2278,7 +2277,7 @@ var AxAICohere = class extends AxBaseAI {
|
|
|
2278
2277
|
apiKey,
|
|
2279
2278
|
config,
|
|
2280
2279
|
options,
|
|
2281
|
-
|
|
2280
|
+
models
|
|
2282
2281
|
}) {
|
|
2283
2282
|
if (!apiKey || apiKey === "") {
|
|
2284
2283
|
throw new Error("Cohere API key not set");
|
|
@@ -2293,10 +2292,10 @@ var AxAICohere = class extends AxBaseAI {
|
|
|
2293
2292
|
apiURL: "https://api.cohere.ai/v1",
|
|
2294
2293
|
headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
|
|
2295
2294
|
modelInfo: axModelInfoCohere,
|
|
2296
|
-
|
|
2295
|
+
defaults: { model: _config.model },
|
|
2297
2296
|
supportFor: { functions: true, streaming: true },
|
|
2298
2297
|
options,
|
|
2299
|
-
|
|
2298
|
+
models
|
|
2300
2299
|
});
|
|
2301
2300
|
}
|
|
2302
2301
|
};
|
|
@@ -2390,7 +2389,7 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
|
|
|
2390
2389
|
apiKey,
|
|
2391
2390
|
config,
|
|
2392
2391
|
options,
|
|
2393
|
-
|
|
2392
|
+
models
|
|
2394
2393
|
}) {
|
|
2395
2394
|
if (!apiKey || apiKey === "") {
|
|
2396
2395
|
throw new Error("DeepSeek API key not set");
|
|
@@ -2405,7 +2404,7 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
|
|
|
2405
2404
|
options,
|
|
2406
2405
|
apiURL: "https://api.deepseek.com",
|
|
2407
2406
|
modelInfo: axModelInfoDeepSeek,
|
|
2408
|
-
|
|
2407
|
+
models
|
|
2409
2408
|
});
|
|
2410
2409
|
super.setName("DeepSeek");
|
|
2411
2410
|
}
|
|
@@ -2413,6 +2412,10 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
|
|
|
2413
2412
|
|
|
2414
2413
|
// ai/google-gemini/types.ts
|
|
2415
2414
|
var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
|
|
2415
|
+
AxAIGoogleGeminiModel2["Gemini20Pro"] = "gemini-2.0-pro-exp-02-05";
|
|
2416
|
+
AxAIGoogleGeminiModel2["Gemini20Flash"] = "gemini-2.0-flash";
|
|
2417
|
+
AxAIGoogleGeminiModel2["Gemini20FlashLite"] = "gemini-2.0-flash-lite-preview-02-05";
|
|
2418
|
+
AxAIGoogleGeminiModel2["Gemini20FlashThinking"] = "gemini-2.0-flash-thinking-exp-01-21";
|
|
2416
2419
|
AxAIGoogleGeminiModel2["Gemini1Pro"] = "gemini-1.0-pro";
|
|
2417
2420
|
AxAIGoogleGeminiModel2["Gemini15Flash"] = "gemini-1.5-flash";
|
|
2418
2421
|
AxAIGoogleGeminiModel2["Gemini15Flash8B"] = "gemini-1.5-flash-8b";
|
|
@@ -2444,31 +2447,59 @@ var AxAIGoogleGeminiSafetyThreshold = /* @__PURE__ */ ((AxAIGoogleGeminiSafetyTh
|
|
|
2444
2447
|
|
|
2445
2448
|
// ai/google-gemini/info.ts
|
|
2446
2449
|
var axModelInfoGoogleGemini = [
|
|
2450
|
+
{
|
|
2451
|
+
name: "gemini-2.0-pro-exp-02-05" /* Gemini20Pro */,
|
|
2452
|
+
currency: "usd",
|
|
2453
|
+
characterIsToken: false,
|
|
2454
|
+
promptTokenCostPer1M: 0,
|
|
2455
|
+
completionTokenCostPer1M: 0
|
|
2456
|
+
},
|
|
2457
|
+
{
|
|
2458
|
+
name: "gemini-2.0-flash" /* Gemini20Flash */,
|
|
2459
|
+
currency: "usd",
|
|
2460
|
+
characterIsToken: false,
|
|
2461
|
+
promptTokenCostPer1M: 0.01,
|
|
2462
|
+
completionTokenCostPer1M: 0.4
|
|
2463
|
+
},
|
|
2464
|
+
{
|
|
2465
|
+
name: "gemini-2.0-flash-lite-preview-02-05" /* Gemini20FlashLite */,
|
|
2466
|
+
currency: "usd",
|
|
2467
|
+
characterIsToken: false,
|
|
2468
|
+
promptTokenCostPer1M: 0,
|
|
2469
|
+
completionTokenCostPer1M: 0
|
|
2470
|
+
},
|
|
2471
|
+
{
|
|
2472
|
+
name: "gemini-2.0-flash-thinking-exp-01-21" /* Gemini20FlashThinking */,
|
|
2473
|
+
currency: "usd",
|
|
2474
|
+
characterIsToken: false,
|
|
2475
|
+
promptTokenCostPer1M: 0,
|
|
2476
|
+
completionTokenCostPer1M: 0
|
|
2477
|
+
},
|
|
2447
2478
|
{
|
|
2448
2479
|
name: "gemini-1.5-flash" /* Gemini15Flash */,
|
|
2449
2480
|
currency: "usd",
|
|
2450
|
-
characterIsToken:
|
|
2481
|
+
characterIsToken: false,
|
|
2451
2482
|
promptTokenCostPer1M: 0.075,
|
|
2452
2483
|
completionTokenCostPer1M: 0.3
|
|
2453
2484
|
},
|
|
2454
2485
|
{
|
|
2455
2486
|
name: "gemini-1.5-flash-8b" /* Gemini15Flash8B */,
|
|
2456
2487
|
currency: "usd",
|
|
2457
|
-
characterIsToken:
|
|
2488
|
+
characterIsToken: false,
|
|
2458
2489
|
promptTokenCostPer1M: 0.0375,
|
|
2459
2490
|
completionTokenCostPer1M: 0.15
|
|
2460
2491
|
},
|
|
2461
2492
|
{
|
|
2462
2493
|
name: "gemini-1.5-pro" /* Gemini15Pro */,
|
|
2463
2494
|
currency: "usd",
|
|
2464
|
-
characterIsToken:
|
|
2495
|
+
characterIsToken: false,
|
|
2465
2496
|
promptTokenCostPer1M: 1.25,
|
|
2466
2497
|
completionTokenCostPer1M: 5
|
|
2467
2498
|
},
|
|
2468
2499
|
{
|
|
2469
2500
|
name: "gemini-1.0-pro" /* Gemini1Pro */,
|
|
2470
2501
|
currency: "usd",
|
|
2471
|
-
characterIsToken:
|
|
2502
|
+
characterIsToken: false,
|
|
2472
2503
|
promptTokenCostPer1M: 0.5,
|
|
2473
2504
|
completionTokenCostPer1M: 1.5
|
|
2474
2505
|
}
|
|
@@ -2782,7 +2813,7 @@ var AxAIGoogleGemini = class extends AxBaseAI {
|
|
|
2782
2813
|
region,
|
|
2783
2814
|
config,
|
|
2784
2815
|
options,
|
|
2785
|
-
|
|
2816
|
+
models
|
|
2786
2817
|
}) {
|
|
2787
2818
|
const isVertex = projectId !== void 0 && region !== void 0;
|
|
2788
2819
|
let apiURL;
|
|
@@ -2814,13 +2845,13 @@ var AxAIGoogleGemini = class extends AxBaseAI {
|
|
|
2814
2845
|
apiURL,
|
|
2815
2846
|
headers,
|
|
2816
2847
|
modelInfo: axModelInfoGoogleGemini,
|
|
2817
|
-
|
|
2848
|
+
defaults: {
|
|
2818
2849
|
model: _config.model,
|
|
2819
2850
|
embedModel: _config.embedModel
|
|
2820
2851
|
},
|
|
2821
2852
|
options,
|
|
2822
2853
|
supportFor: { functions: true, streaming: true },
|
|
2823
|
-
|
|
2854
|
+
models
|
|
2824
2855
|
});
|
|
2825
2856
|
}
|
|
2826
2857
|
};
|
|
@@ -2922,7 +2953,7 @@ var AxAIGroq = class extends AxAIOpenAI {
|
|
|
2922
2953
|
apiKey,
|
|
2923
2954
|
config,
|
|
2924
2955
|
options,
|
|
2925
|
-
|
|
2956
|
+
models
|
|
2926
2957
|
}) {
|
|
2927
2958
|
if (!apiKey || apiKey === "") {
|
|
2928
2959
|
throw new Error("Groq API key not set");
|
|
@@ -2941,7 +2972,7 @@ var AxAIGroq = class extends AxAIOpenAI {
|
|
|
2941
2972
|
options: _options,
|
|
2942
2973
|
modelInfo: axModelInfoGroq,
|
|
2943
2974
|
apiURL: "https://api.groq.com/openai/v1",
|
|
2944
|
-
|
|
2975
|
+
models
|
|
2945
2976
|
});
|
|
2946
2977
|
super.setName("Groq");
|
|
2947
2978
|
this.setOptions(_options);
|
|
@@ -3065,7 +3096,7 @@ var AxAIHuggingFace = class extends AxBaseAI {
|
|
|
3065
3096
|
apiKey,
|
|
3066
3097
|
config,
|
|
3067
3098
|
options,
|
|
3068
|
-
|
|
3099
|
+
models
|
|
3069
3100
|
}) {
|
|
3070
3101
|
if (!apiKey || apiKey === "") {
|
|
3071
3102
|
throw new Error("HuggingFace API key not set");
|
|
@@ -3080,10 +3111,10 @@ var AxAIHuggingFace = class extends AxBaseAI {
|
|
|
3080
3111
|
apiURL: "https://api-inference.huggingface.co",
|
|
3081
3112
|
headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
|
|
3082
3113
|
modelInfo: axModelInfoHuggingFace,
|
|
3083
|
-
|
|
3114
|
+
defaults: { model: _config.model },
|
|
3084
3115
|
options,
|
|
3085
3116
|
supportFor: { functions: false, streaming: false },
|
|
3086
|
-
|
|
3117
|
+
models
|
|
3087
3118
|
});
|
|
3088
3119
|
}
|
|
3089
3120
|
};
|
|
@@ -3167,7 +3198,7 @@ var AxAIMistral = class extends AxAIOpenAI {
|
|
|
3167
3198
|
apiKey,
|
|
3168
3199
|
config,
|
|
3169
3200
|
options,
|
|
3170
|
-
|
|
3201
|
+
models
|
|
3171
3202
|
}) {
|
|
3172
3203
|
if (!apiKey || apiKey === "") {
|
|
3173
3204
|
throw new Error("Mistral API key not set");
|
|
@@ -3182,7 +3213,7 @@ var AxAIMistral = class extends AxAIOpenAI {
|
|
|
3182
3213
|
options,
|
|
3183
3214
|
apiURL: "https://api.mistral.ai/v1",
|
|
3184
3215
|
modelInfo: axModelInfoMistral,
|
|
3185
|
-
|
|
3216
|
+
models
|
|
3186
3217
|
});
|
|
3187
3218
|
super.setName("Mistral");
|
|
3188
3219
|
}
|
|
@@ -3200,7 +3231,7 @@ var AxAIOllama = class extends AxAIOpenAI {
|
|
|
3200
3231
|
url = "http://localhost:11434/v1",
|
|
3201
3232
|
config,
|
|
3202
3233
|
options,
|
|
3203
|
-
|
|
3234
|
+
models
|
|
3204
3235
|
}) {
|
|
3205
3236
|
const _config = {
|
|
3206
3237
|
...axAIOllamaDefaultConfig(),
|
|
@@ -3211,7 +3242,7 @@ var AxAIOllama = class extends AxAIOpenAI {
|
|
|
3211
3242
|
options,
|
|
3212
3243
|
config: _config,
|
|
3213
3244
|
apiURL: url,
|
|
3214
|
-
|
|
3245
|
+
models
|
|
3215
3246
|
});
|
|
3216
3247
|
super.setName("Ollama");
|
|
3217
3248
|
}
|
|
@@ -3414,7 +3445,7 @@ var AxAIReka = class extends AxBaseAI {
|
|
|
3414
3445
|
options,
|
|
3415
3446
|
apiURL,
|
|
3416
3447
|
modelInfo = axModelInfoReka,
|
|
3417
|
-
|
|
3448
|
+
models
|
|
3418
3449
|
}) {
|
|
3419
3450
|
if (!apiKey || apiKey === "") {
|
|
3420
3451
|
throw new Error("Reka API key not set");
|
|
@@ -3429,12 +3460,12 @@ var AxAIReka = class extends AxBaseAI {
|
|
|
3429
3460
|
apiURL: apiURL ? apiURL : "https://api.reka.ai/v1/chat",
|
|
3430
3461
|
headers: async () => ({ "X-Api-Key": apiKey }),
|
|
3431
3462
|
modelInfo,
|
|
3432
|
-
|
|
3463
|
+
defaults: {
|
|
3433
3464
|
model: _config.model
|
|
3434
3465
|
},
|
|
3435
3466
|
options,
|
|
3436
3467
|
supportFor: { functions: true, streaming: true },
|
|
3437
|
-
|
|
3468
|
+
models
|
|
3438
3469
|
});
|
|
3439
3470
|
}
|
|
3440
3471
|
};
|
|
@@ -3453,7 +3484,7 @@ var AxAITogether = class extends AxAIOpenAI {
|
|
|
3453
3484
|
apiKey,
|
|
3454
3485
|
config,
|
|
3455
3486
|
options,
|
|
3456
|
-
|
|
3487
|
+
models
|
|
3457
3488
|
}) {
|
|
3458
3489
|
if (!apiKey || apiKey === "") {
|
|
3459
3490
|
throw new Error("Together API key not set");
|
|
@@ -3468,7 +3499,7 @@ var AxAITogether = class extends AxAIOpenAI {
|
|
|
3468
3499
|
options,
|
|
3469
3500
|
apiURL: "https://api.together.xyz/v1",
|
|
3470
3501
|
modelInfo: axModelInfoTogether,
|
|
3471
|
-
|
|
3502
|
+
models
|
|
3472
3503
|
});
|
|
3473
3504
|
super.setName("Together");
|
|
3474
3505
|
}
|
|
@@ -3531,8 +3562,8 @@ var AxAI = class {
|
|
|
3531
3562
|
getFeatures(model) {
|
|
3532
3563
|
return this.ai.getFeatures(model);
|
|
3533
3564
|
}
|
|
3534
|
-
|
|
3535
|
-
return this.ai.
|
|
3565
|
+
getModelList() {
|
|
3566
|
+
return this.ai.getModelList();
|
|
3536
3567
|
}
|
|
3537
3568
|
getMetrics() {
|
|
3538
3569
|
return this.ai.getMetrics();
|
|
@@ -5665,7 +5696,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5665
5696
|
traceId,
|
|
5666
5697
|
functions
|
|
5667
5698
|
}) {
|
|
5668
|
-
const streamingValidation =
|
|
5699
|
+
const streamingValidation = ai.getFeatures().functionCot !== true;
|
|
5669
5700
|
const functionCalls = [];
|
|
5670
5701
|
const values = {};
|
|
5671
5702
|
const xstate = {
|
|
@@ -5926,6 +5957,7 @@ var AxAgent = class {
|
|
|
5926
5957
|
ai;
|
|
5927
5958
|
signature;
|
|
5928
5959
|
program;
|
|
5960
|
+
functions;
|
|
5929
5961
|
agents;
|
|
5930
5962
|
name;
|
|
5931
5963
|
description;
|
|
@@ -5941,14 +5973,9 @@ var AxAgent = class {
|
|
|
5941
5973
|
}, options) {
|
|
5942
5974
|
this.ai = ai;
|
|
5943
5975
|
this.agents = agents;
|
|
5976
|
+
this.functions = functions;
|
|
5944
5977
|
this.signature = new AxSignature(signature);
|
|
5945
5978
|
this.signature.setDescription(description);
|
|
5946
|
-
const funcs = [
|
|
5947
|
-
...functions ?? [],
|
|
5948
|
-
...agents?.map((a) => a.getFunction()) ?? []
|
|
5949
|
-
];
|
|
5950
|
-
const opt = { ...options, functions: funcs };
|
|
5951
|
-
this.program = new AxGen(this.signature, opt);
|
|
5952
5979
|
if (!name || name.length < 5) {
|
|
5953
5980
|
throw new Error(
|
|
5954
5981
|
`Agent name must be at least 10 characters (more descriptive): ${name}`
|
|
@@ -5959,6 +5986,10 @@ var AxAgent = class {
|
|
|
5959
5986
|
`Agent description must be at least 20 characters (explain in detail what the agent does): ${description}`
|
|
5960
5987
|
);
|
|
5961
5988
|
}
|
|
5989
|
+
this.program = new AxGen(this.signature, options);
|
|
5990
|
+
for (const agent of agents ?? []) {
|
|
5991
|
+
this.program.register(agent);
|
|
5992
|
+
}
|
|
5962
5993
|
this.name = name;
|
|
5963
5994
|
this.description = description;
|
|
5964
5995
|
this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
|
|
@@ -5968,8 +5999,9 @@ var AxAgent = class {
|
|
|
5968
5999
|
parameters: this.signature.toJSONSchema(),
|
|
5969
6000
|
func: () => this.forward
|
|
5970
6001
|
};
|
|
5971
|
-
|
|
5972
|
-
|
|
6002
|
+
const mm = ai?.getModelList();
|
|
6003
|
+
if (mm) {
|
|
6004
|
+
this.func.parameters = addModelParameter(this.func.parameters, mm);
|
|
5973
6005
|
}
|
|
5974
6006
|
}
|
|
5975
6007
|
setExamples(examples) {
|
|
@@ -5995,38 +6027,41 @@ var AxAgent = class {
|
|
|
5995
6027
|
}
|
|
5996
6028
|
getFunction() {
|
|
5997
6029
|
const boundFunc = this.forward.bind(this);
|
|
5998
|
-
const wrappedFunc = (
|
|
6030
|
+
const wrappedFunc = (valuesAndModel, options) => {
|
|
6031
|
+
const { model, ...values } = valuesAndModel;
|
|
5999
6032
|
const ai = this.ai ?? options?.ai;
|
|
6000
6033
|
if (!ai) {
|
|
6001
6034
|
throw new Error("AI service is required to run the agent");
|
|
6002
6035
|
}
|
|
6003
|
-
return boundFunc(ai, values, options);
|
|
6036
|
+
return boundFunc(ai, values, { ...options, model });
|
|
6004
6037
|
};
|
|
6005
6038
|
return {
|
|
6006
6039
|
...this.func,
|
|
6007
6040
|
func: wrappedFunc
|
|
6008
6041
|
};
|
|
6009
6042
|
}
|
|
6010
|
-
init(
|
|
6011
|
-
const
|
|
6012
|
-
const
|
|
6013
|
-
|
|
6014
|
-
|
|
6043
|
+
init(parentAi, options) {
|
|
6044
|
+
const ai = this.ai ?? parentAi;
|
|
6045
|
+
const mm = ai?.getModelList();
|
|
6046
|
+
const agentFuncs = this.agents?.map((a) => a.getFunction())?.map(
|
|
6047
|
+
(f) => mm ? { ...f, parameters: addModelParameter(f.parameters, mm) } : f
|
|
6048
|
+
);
|
|
6049
|
+
const functions = [
|
|
6050
|
+
...options?.functions ?? this.functions ?? [],
|
|
6051
|
+
...agentFuncs ?? []
|
|
6015
6052
|
];
|
|
6016
|
-
|
|
6017
|
-
if (funcs.length > 0) {
|
|
6018
|
-
const opt2 = { ...options, functions: funcs };
|
|
6019
|
-
this.program = new AxGen(this.signature, opt2);
|
|
6020
|
-
}
|
|
6021
|
-
return { _ai, opt };
|
|
6053
|
+
return { ai, functions };
|
|
6022
6054
|
}
|
|
6023
|
-
async forward(
|
|
6024
|
-
const {
|
|
6025
|
-
return await this.program.forward(
|
|
6055
|
+
async forward(parentAi, values, options) {
|
|
6056
|
+
const { ai, functions } = this.init(parentAi, options);
|
|
6057
|
+
return await this.program.forward(ai, values, { ...options, functions });
|
|
6026
6058
|
}
|
|
6027
|
-
async *streamingForward(
|
|
6028
|
-
const {
|
|
6029
|
-
return yield* this.program.streamingForward(
|
|
6059
|
+
async *streamingForward(parentAi, values, options) {
|
|
6060
|
+
const { ai, functions } = this.init(parentAi, options);
|
|
6061
|
+
return yield* this.program.streamingForward(ai, values, {
|
|
6062
|
+
...options,
|
|
6063
|
+
functions
|
|
6064
|
+
});
|
|
6030
6065
|
}
|
|
6031
6066
|
};
|
|
6032
6067
|
function toCamelCase(inputString) {
|
|
@@ -6040,6 +6075,31 @@ function toCamelCase(inputString) {
|
|
|
6040
6075
|
}).join("");
|
|
6041
6076
|
return camelCaseString;
|
|
6042
6077
|
}
|
|
6078
|
+
function addModelParameter(parameters, models) {
|
|
6079
|
+
const baseSchema = parameters ? structuredClone(parameters) : {
|
|
6080
|
+
type: "object",
|
|
6081
|
+
properties: {},
|
|
6082
|
+
required: []
|
|
6083
|
+
};
|
|
6084
|
+
if (baseSchema.properties?.model) {
|
|
6085
|
+
return baseSchema;
|
|
6086
|
+
}
|
|
6087
|
+
const modelProperty = {
|
|
6088
|
+
type: "string",
|
|
6089
|
+
enum: models.map((m) => m.key),
|
|
6090
|
+
description: `The AI model to use for this function call. Available options: ${models.map((m) => `${m.key}: ${m.description}`).join(" | ")}`
|
|
6091
|
+
};
|
|
6092
|
+
const newProperties = {
|
|
6093
|
+
...baseSchema.properties ?? {},
|
|
6094
|
+
model: modelProperty
|
|
6095
|
+
};
|
|
6096
|
+
const newRequired = [...baseSchema.required ?? [], "model"];
|
|
6097
|
+
return {
|
|
6098
|
+
...baseSchema,
|
|
6099
|
+
properties: newProperties,
|
|
6100
|
+
required: newRequired
|
|
6101
|
+
};
|
|
6102
|
+
}
|
|
6043
6103
|
|
|
6044
6104
|
// docs/tika.ts
|
|
6045
6105
|
import { createReadStream } from "node:fs";
|
|
@@ -6122,7 +6182,7 @@ var AxBalancer = class _AxBalancer {
|
|
|
6122
6182
|
const bTotalCost = (bInfo.promptTokenCostPer1M || Infinity) + (bInfo.completionTokenCostPer1M || Infinity);
|
|
6123
6183
|
return aTotalCost - bTotalCost;
|
|
6124
6184
|
};
|
|
6125
|
-
|
|
6185
|
+
getModelList() {
|
|
6126
6186
|
throw new Error("Method not implemented.");
|
|
6127
6187
|
}
|
|
6128
6188
|
getNextService() {
|
|
@@ -7739,8 +7799,8 @@ var AxMockAIService = class {
|
|
|
7739
7799
|
streaming: this.config.features?.streaming ?? false
|
|
7740
7800
|
};
|
|
7741
7801
|
}
|
|
7742
|
-
|
|
7743
|
-
return this.config.
|
|
7802
|
+
getModelList() {
|
|
7803
|
+
return this.config.models;
|
|
7744
7804
|
}
|
|
7745
7805
|
getMetrics() {
|
|
7746
7806
|
return this.metrics;
|