@ax-llm/ax 11.0.44 → 11.0.45
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 +138 -22
- package/index.cjs.map +1 -1
- package/index.d.cts +33 -9
- package/index.d.ts +33 -9
- package/index.js +126 -16
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -46,6 +46,9 @@ __export(index_exports, {
|
|
|
46
46
|
AxAIGoogleGeminiModel: () => AxAIGoogleGeminiModel,
|
|
47
47
|
AxAIGoogleGeminiSafetyCategory: () => AxAIGoogleGeminiSafetyCategory,
|
|
48
48
|
AxAIGoogleGeminiSafetyThreshold: () => AxAIGoogleGeminiSafetyThreshold,
|
|
49
|
+
AxAIGrok: () => AxAIGrok,
|
|
50
|
+
AxAIGrokEmbedModels: () => AxAIGrokEmbedModels,
|
|
51
|
+
AxAIGrokModel: () => AxAIGrokModel,
|
|
49
52
|
AxAIGroq: () => AxAIGroq,
|
|
50
53
|
AxAIGroqModel: () => AxAIGroqModel,
|
|
51
54
|
AxAIHuggingFace: () => AxAIHuggingFace,
|
|
@@ -126,6 +129,8 @@ __export(index_exports, {
|
|
|
126
129
|
axAIDeepSeekDefaultConfig: () => axAIDeepSeekDefaultConfig,
|
|
127
130
|
axAIGoogleGeminiDefaultConfig: () => axAIGoogleGeminiDefaultConfig,
|
|
128
131
|
axAIGoogleGeminiDefaultCreativeConfig: () => axAIGoogleGeminiDefaultCreativeConfig,
|
|
132
|
+
axAIGrokBestConfig: () => axAIGrokBestConfig,
|
|
133
|
+
axAIGrokDefaultConfig: () => axAIGrokDefaultConfig,
|
|
129
134
|
axAIHuggingFaceCreativeConfig: () => axAIHuggingFaceCreativeConfig,
|
|
130
135
|
axAIHuggingFaceDefaultConfig: () => axAIHuggingFaceDefaultConfig,
|
|
131
136
|
axAIMistralBestConfig: () => axAIMistralBestConfig,
|
|
@@ -147,6 +152,7 @@ __export(index_exports, {
|
|
|
147
152
|
axModelInfoCohere: () => axModelInfoCohere,
|
|
148
153
|
axModelInfoDeepSeek: () => axModelInfoDeepSeek,
|
|
149
154
|
axModelInfoGoogleGemini: () => axModelInfoGoogleGemini,
|
|
155
|
+
axModelInfoGrok: () => axModelInfoGrok,
|
|
150
156
|
axModelInfoGroq: () => axModelInfoGroq,
|
|
151
157
|
axModelInfoHuggingFace: () => axModelInfoHuggingFace,
|
|
152
158
|
axModelInfoMistral: () => axModelInfoMistral,
|
|
@@ -1073,10 +1079,6 @@ var AxBaseAI = class {
|
|
|
1073
1079
|
if (!canStream) {
|
|
1074
1080
|
modelConfig.stream = false;
|
|
1075
1081
|
}
|
|
1076
|
-
const canSetThinkingTokenBudget = this.getFeatures(model).thinkingTokenBudget;
|
|
1077
|
-
if (!canSetThinkingTokenBudget && options?.thinkingTokenBudget) {
|
|
1078
|
-
throw new Error("Thinking token budget is not supported for this model");
|
|
1079
|
-
}
|
|
1080
1082
|
if (this.tracer) {
|
|
1081
1083
|
return await this.tracer?.startActiveSpan(
|
|
1082
1084
|
"AI Chat Request",
|
|
@@ -2106,9 +2108,10 @@ var axAIOpenAIFastConfig = () => ({
|
|
|
2106
2108
|
model: "gpt-4.1-mini" /* GPT41Mini */
|
|
2107
2109
|
});
|
|
2108
2110
|
var AxAIOpenAIImpl = class {
|
|
2109
|
-
constructor(config, streamingUsage) {
|
|
2111
|
+
constructor(config, streamingUsage, chatReqUpdater) {
|
|
2110
2112
|
this.config = config;
|
|
2111
2113
|
this.streamingUsage = streamingUsage;
|
|
2114
|
+
this.chatReqUpdater = chatReqUpdater;
|
|
2112
2115
|
}
|
|
2113
2116
|
tokensUsed;
|
|
2114
2117
|
getTokenUsage() {
|
|
@@ -2128,7 +2131,7 @@ var AxAIOpenAIImpl = class {
|
|
|
2128
2131
|
stream: config.stream
|
|
2129
2132
|
};
|
|
2130
2133
|
}
|
|
2131
|
-
createChatReq(req,
|
|
2134
|
+
createChatReq(req, config) {
|
|
2132
2135
|
const model = req.model;
|
|
2133
2136
|
if (!req.chatPrompt || req.chatPrompt.length === 0) {
|
|
2134
2137
|
throw new Error("Chat prompt is empty");
|
|
@@ -2148,12 +2151,11 @@ var AxAIOpenAIImpl = class {
|
|
|
2148
2151
|
const messages = createMessages2(req);
|
|
2149
2152
|
const frequencyPenalty = req.modelConfig?.frequencyPenalty ?? this.config.frequencyPenalty;
|
|
2150
2153
|
const stream = req.modelConfig?.stream ?? this.config.stream;
|
|
2151
|
-
const reasoningEffort = isReasoningModel(model) ? this.config.reasoningEffort : void 0;
|
|
2152
2154
|
const store = this.config.store;
|
|
2153
|
-
|
|
2155
|
+
let reqValue = {
|
|
2154
2156
|
model,
|
|
2155
2157
|
messages,
|
|
2156
|
-
response_format: this.config?.responseFormat ? { type: this.config
|
|
2158
|
+
response_format: this.config?.responseFormat ? { type: this.config.responseFormat } : void 0,
|
|
2157
2159
|
tools,
|
|
2158
2160
|
tool_choice: toolsChoice,
|
|
2159
2161
|
max_completion_tokens: req.modelConfig?.maxTokens ?? this.config.maxTokens ?? 500,
|
|
@@ -2165,9 +2167,29 @@ var AxAIOpenAIImpl = class {
|
|
|
2165
2167
|
logit_bias: this.config.logitBias,
|
|
2166
2168
|
...frequencyPenalty ? { frequency_penalty: frequencyPenalty } : {},
|
|
2167
2169
|
...stream && this.streamingUsage ? { stream: true, stream_options: { include_usage: true } } : {},
|
|
2168
|
-
...reasoningEffort ? { reasoning_effort: reasoningEffort } : {},
|
|
2169
2170
|
...store ? { store } : {}
|
|
2170
2171
|
};
|
|
2172
|
+
if (this.config.reasoningEffort) {
|
|
2173
|
+
reqValue.reasoning_effort = this.config.reasoningEffort;
|
|
2174
|
+
}
|
|
2175
|
+
if (config.thinkingTokenBudget) {
|
|
2176
|
+
switch (config.thinkingTokenBudget) {
|
|
2177
|
+
case "minimal":
|
|
2178
|
+
reqValue.reasoning_effort = "low";
|
|
2179
|
+
break;
|
|
2180
|
+
case "low":
|
|
2181
|
+
reqValue.reasoning_effort = "medium";
|
|
2182
|
+
break;
|
|
2183
|
+
case "medium":
|
|
2184
|
+
reqValue.reasoning_effort = "high";
|
|
2185
|
+
break;
|
|
2186
|
+
case "high":
|
|
2187
|
+
reqValue.reasoning_effort = "high";
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
if (this.chatReqUpdater) {
|
|
2191
|
+
reqValue = this.chatReqUpdater(reqValue);
|
|
2192
|
+
}
|
|
2171
2193
|
return [apiConfig, reqValue];
|
|
2172
2194
|
}
|
|
2173
2195
|
createEmbedReq(req) {
|
|
@@ -2350,14 +2372,16 @@ var AxAIOpenAIBase = class extends AxBaseAI {
|
|
|
2350
2372
|
options,
|
|
2351
2373
|
apiURL,
|
|
2352
2374
|
modelInfo,
|
|
2353
|
-
models
|
|
2375
|
+
models,
|
|
2376
|
+
chatReqUpdater
|
|
2354
2377
|
}) {
|
|
2355
2378
|
if (!apiKey || apiKey === "") {
|
|
2356
2379
|
throw new Error("OpenAI API key not set");
|
|
2357
2380
|
}
|
|
2358
2381
|
const aiImpl = new AxAIOpenAIImpl(
|
|
2359
2382
|
config,
|
|
2360
|
-
options?.streamingUsage ?? true
|
|
2383
|
+
options?.streamingUsage ?? true,
|
|
2384
|
+
chatReqUpdater
|
|
2361
2385
|
);
|
|
2362
2386
|
super(aiImpl, {
|
|
2363
2387
|
name: "OpenAI",
|
|
@@ -2376,9 +2400,6 @@ var AxAIOpenAIBase = class extends AxBaseAI {
|
|
|
2376
2400
|
});
|
|
2377
2401
|
}
|
|
2378
2402
|
};
|
|
2379
|
-
var isReasoningModel = (model) => ["o1-mini" /* O1Mini */, "o1" /* O1 */, "o3-mini" /* O3Mini */].includes(
|
|
2380
|
-
model
|
|
2381
|
-
);
|
|
2382
2403
|
var AxAIOpenAI = class extends AxAIOpenAIBase {
|
|
2383
2404
|
constructor({
|
|
2384
2405
|
apiKey,
|
|
@@ -3163,7 +3184,20 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
3163
3184
|
thinkingConfig.thinkingBudget = this.config.thinking.thinkingTokenBudget;
|
|
3164
3185
|
}
|
|
3165
3186
|
if (config.thinkingTokenBudget) {
|
|
3166
|
-
|
|
3187
|
+
switch (config.thinkingTokenBudget) {
|
|
3188
|
+
case "minimal":
|
|
3189
|
+
thinkingConfig.thinkingBudget = 0;
|
|
3190
|
+
break;
|
|
3191
|
+
case "low":
|
|
3192
|
+
thinkingConfig.thinkingBudget = 1024;
|
|
3193
|
+
break;
|
|
3194
|
+
case "medium":
|
|
3195
|
+
thinkingConfig.thinkingBudget = 4096;
|
|
3196
|
+
break;
|
|
3197
|
+
case "high":
|
|
3198
|
+
thinkingConfig.thinkingBudget = 8192;
|
|
3199
|
+
break;
|
|
3200
|
+
}
|
|
3167
3201
|
}
|
|
3168
3202
|
const generationConfig = {
|
|
3169
3203
|
maxOutputTokens: req.modelConfig?.maxTokens ?? this.config.maxTokens,
|
|
@@ -4129,9 +4163,85 @@ var AxAI = class {
|
|
|
4129
4163
|
}
|
|
4130
4164
|
};
|
|
4131
4165
|
|
|
4166
|
+
// ai/x-grok/types.ts
|
|
4167
|
+
var AxAIGrokModel = /* @__PURE__ */ ((AxAIGrokModel2) => {
|
|
4168
|
+
AxAIGrokModel2["Grok3"] = "grok-3";
|
|
4169
|
+
AxAIGrokModel2["Grok3Mini"] = "grok-3-mini";
|
|
4170
|
+
AxAIGrokModel2["Grok3Fast"] = "grok-3-fast";
|
|
4171
|
+
AxAIGrokModel2["Grok3MiniFast"] = "grok-3-mini-fast";
|
|
4172
|
+
return AxAIGrokModel2;
|
|
4173
|
+
})(AxAIGrokModel || {});
|
|
4174
|
+
var AxAIGrokEmbedModels = /* @__PURE__ */ ((AxAIGrokEmbedModels3) => {
|
|
4175
|
+
AxAIGrokEmbedModels3["GrokEmbedSmall"] = "grok-embed-small";
|
|
4176
|
+
return AxAIGrokEmbedModels3;
|
|
4177
|
+
})(AxAIGrokEmbedModels || {});
|
|
4178
|
+
|
|
4179
|
+
// ai/x-grok/info.ts
|
|
4180
|
+
var axModelInfoGrok = [
|
|
4181
|
+
{
|
|
4182
|
+
name: "grok-3" /* Grok3 */,
|
|
4183
|
+
currency: "USD",
|
|
4184
|
+
promptTokenCostPer1M: 3,
|
|
4185
|
+
completionTokenCostPer1M: 15
|
|
4186
|
+
},
|
|
4187
|
+
{
|
|
4188
|
+
name: "grok-3-mini" /* Grok3Mini */,
|
|
4189
|
+
currency: "USD",
|
|
4190
|
+
promptTokenCostPer1M: 0.3,
|
|
4191
|
+
completionTokenCostPer1M: 0.5
|
|
4192
|
+
},
|
|
4193
|
+
{
|
|
4194
|
+
name: "grok-3-fast" /* Grok3Fast */,
|
|
4195
|
+
currency: "USD",
|
|
4196
|
+
promptTokenCostPer1M: 5,
|
|
4197
|
+
completionTokenCostPer1M: 25
|
|
4198
|
+
},
|
|
4199
|
+
{
|
|
4200
|
+
name: "grok-3-mini-fast" /* Grok3MiniFast */,
|
|
4201
|
+
currency: "USD",
|
|
4202
|
+
promptTokenCostPer1M: 0.6,
|
|
4203
|
+
completionTokenCostPer1M: 4
|
|
4204
|
+
}
|
|
4205
|
+
];
|
|
4206
|
+
|
|
4207
|
+
// ai/x-grok/api.ts
|
|
4208
|
+
var axAIGrokDefaultConfig = () => structuredClone({
|
|
4209
|
+
model: "grok-3-mini" /* Grok3Mini */,
|
|
4210
|
+
...axBaseAIDefaultConfig()
|
|
4211
|
+
});
|
|
4212
|
+
var axAIGrokBestConfig = () => structuredClone({
|
|
4213
|
+
...axAIGrokDefaultConfig(),
|
|
4214
|
+
model: "grok-3" /* Grok3 */
|
|
4215
|
+
});
|
|
4216
|
+
var AxAIGrok = class extends AxAIOpenAIBase {
|
|
4217
|
+
constructor({
|
|
4218
|
+
apiKey,
|
|
4219
|
+
config,
|
|
4220
|
+
options,
|
|
4221
|
+
models
|
|
4222
|
+
}) {
|
|
4223
|
+
if (!apiKey || apiKey === "") {
|
|
4224
|
+
throw new Error("Grok API key not set");
|
|
4225
|
+
}
|
|
4226
|
+
const _config = {
|
|
4227
|
+
...axAIGrokDefaultConfig(),
|
|
4228
|
+
...config
|
|
4229
|
+
};
|
|
4230
|
+
super({
|
|
4231
|
+
apiKey,
|
|
4232
|
+
config: _config,
|
|
4233
|
+
options,
|
|
4234
|
+
apiURL: "https://api.x.ai/v1",
|
|
4235
|
+
modelInfo: axModelInfoGrok,
|
|
4236
|
+
models
|
|
4237
|
+
});
|
|
4238
|
+
super.setName("Grok");
|
|
4239
|
+
}
|
|
4240
|
+
};
|
|
4241
|
+
|
|
4132
4242
|
// dsp/generate.ts
|
|
4133
4243
|
var import_web5 = require("stream/web");
|
|
4134
|
-
var
|
|
4244
|
+
var import_api22 = require("@opentelemetry/api");
|
|
4135
4245
|
|
|
4136
4246
|
// ai/util.ts
|
|
4137
4247
|
function mergeFunctionCalls(functionCalls, functionCallDeltas) {
|
|
@@ -6986,7 +7096,7 @@ Content: ${result.content}`
|
|
|
6986
7096
|
const traceLabel = options.traceLabel ?? this.options?.traceLabel;
|
|
6987
7097
|
const spanName = traceLabel ? `${traceLabel} (AxGen)` : "AxGen";
|
|
6988
7098
|
const span = tracer.startSpan(spanName, {
|
|
6989
|
-
kind:
|
|
7099
|
+
kind: import_api22.SpanKind.SERVER,
|
|
6990
7100
|
attributes
|
|
6991
7101
|
});
|
|
6992
7102
|
try {
|
|
@@ -7861,7 +7971,7 @@ var randomSample = (array, n) => {
|
|
|
7861
7971
|
};
|
|
7862
7972
|
|
|
7863
7973
|
// db/base.ts
|
|
7864
|
-
var
|
|
7974
|
+
var import_api23 = require("@opentelemetry/api");
|
|
7865
7975
|
var AxDBBase = class {
|
|
7866
7976
|
name;
|
|
7867
7977
|
fetch;
|
|
@@ -7888,7 +7998,7 @@ var AxDBBase = class {
|
|
|
7888
7998
|
return await this.tracer?.startActiveSpan(
|
|
7889
7999
|
"DB Upsert Request",
|
|
7890
8000
|
{
|
|
7891
|
-
kind:
|
|
8001
|
+
kind: import_api23.SpanKind.SERVER,
|
|
7892
8002
|
attributes: {
|
|
7893
8003
|
[axSpanAttributes.DB_SYSTEM]: this.name,
|
|
7894
8004
|
[axSpanAttributes.DB_OPERATION_NAME]: "upsert",
|
|
@@ -7922,7 +8032,7 @@ var AxDBBase = class {
|
|
|
7922
8032
|
return await this.tracer?.startActiveSpan(
|
|
7923
8033
|
"DB Batch Upsert Request",
|
|
7924
8034
|
{
|
|
7925
|
-
kind:
|
|
8035
|
+
kind: import_api23.SpanKind.SERVER,
|
|
7926
8036
|
attributes: {
|
|
7927
8037
|
[axSpanAttributes.DB_SYSTEM]: this.name,
|
|
7928
8038
|
[axSpanAttributes.DB_OPERATION_NAME]: "upsert",
|
|
@@ -7950,7 +8060,7 @@ var AxDBBase = class {
|
|
|
7950
8060
|
return await this.tracer?.startActiveSpan(
|
|
7951
8061
|
"DB Query Request",
|
|
7952
8062
|
{
|
|
7953
|
-
kind:
|
|
8063
|
+
kind: import_api23.SpanKind.SERVER,
|
|
7954
8064
|
attributes: {
|
|
7955
8065
|
[axSpanAttributes.DB_SYSTEM]: this.name,
|
|
7956
8066
|
[axSpanAttributes.DB_OPERATION_NAME]: "upsert",
|
|
@@ -11764,6 +11874,9 @@ var AxRAG = class extends AxChainOfThought {
|
|
|
11764
11874
|
AxAIGoogleGeminiModel,
|
|
11765
11875
|
AxAIGoogleGeminiSafetyCategory,
|
|
11766
11876
|
AxAIGoogleGeminiSafetyThreshold,
|
|
11877
|
+
AxAIGrok,
|
|
11878
|
+
AxAIGrokEmbedModels,
|
|
11879
|
+
AxAIGrokModel,
|
|
11767
11880
|
AxAIGroq,
|
|
11768
11881
|
AxAIGroqModel,
|
|
11769
11882
|
AxAIHuggingFace,
|
|
@@ -11844,6 +11957,8 @@ var AxRAG = class extends AxChainOfThought {
|
|
|
11844
11957
|
axAIDeepSeekDefaultConfig,
|
|
11845
11958
|
axAIGoogleGeminiDefaultConfig,
|
|
11846
11959
|
axAIGoogleGeminiDefaultCreativeConfig,
|
|
11960
|
+
axAIGrokBestConfig,
|
|
11961
|
+
axAIGrokDefaultConfig,
|
|
11847
11962
|
axAIHuggingFaceCreativeConfig,
|
|
11848
11963
|
axAIHuggingFaceDefaultConfig,
|
|
11849
11964
|
axAIMistralBestConfig,
|
|
@@ -11865,6 +11980,7 @@ var AxRAG = class extends AxChainOfThought {
|
|
|
11865
11980
|
axModelInfoCohere,
|
|
11866
11981
|
axModelInfoDeepSeek,
|
|
11867
11982
|
axModelInfoGoogleGemini,
|
|
11983
|
+
axModelInfoGrok,
|
|
11868
11984
|
axModelInfoGroq,
|
|
11869
11985
|
axModelInfoHuggingFace,
|
|
11870
11986
|
axModelInfoMistral,
|