@ax-llm/ax 10.0.37 → 10.0.39
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 +143 -39
- package/index.cjs.map +1 -1
- package/index.d.cts +36 -8
- package/index.d.ts +36 -8
- package/index.js +143 -39
- package/index.js.map +1 -1
- package/package.json +4 -3
package/index.d.cts
CHANGED
|
@@ -226,7 +226,7 @@ interface AxBaseAIFeatures {
|
|
|
226
226
|
interface AxBaseAIArgs {
|
|
227
227
|
name: string;
|
|
228
228
|
apiURL: string;
|
|
229
|
-
headers: Record<string, string
|
|
229
|
+
headers: () => Promise<Record<string, string>>;
|
|
230
230
|
modelInfo: Readonly<AxModelInfo[]>;
|
|
231
231
|
models: Readonly<{
|
|
232
232
|
model: string;
|
|
@@ -249,13 +249,13 @@ declare class AxBaseAI<TChatRequest, TEmbedRequest, TChatResponse, TChatResponse
|
|
|
249
249
|
private models;
|
|
250
250
|
protected apiURL: string;
|
|
251
251
|
protected name: string;
|
|
252
|
-
protected headers: Record<string, string
|
|
252
|
+
protected headers: () => Promise<Record<string, string>>;
|
|
253
253
|
protected supportFor: AxBaseAIFeatures | ((model: string) => AxBaseAIFeatures);
|
|
254
254
|
private metrics;
|
|
255
255
|
constructor(aiImpl: Readonly<AxAIServiceImpl<TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse>>, { name, apiURL, headers, modelInfo, models, options, supportFor, modelMap, }: Readonly<AxBaseAIArgs>);
|
|
256
256
|
setName(name: string): void;
|
|
257
257
|
setAPIURL(apiURL: string): void;
|
|
258
|
-
setHeaders(headers: Record<string, string
|
|
258
|
+
setHeaders(headers: () => Promise<Record<string, string>>): void;
|
|
259
259
|
setOptions(options: Readonly<AxAIServiceOptions>): void;
|
|
260
260
|
getOptions(): Readonly<AxAIServiceOptions>;
|
|
261
261
|
getModelInfo(): Readonly<AxModelInfoWithProvider>;
|
|
@@ -813,7 +813,8 @@ declare enum AxAIGoogleGeminiModel {
|
|
|
813
813
|
AQA = "aqa"
|
|
814
814
|
}
|
|
815
815
|
declare enum AxAIGoogleGeminiEmbedModel {
|
|
816
|
-
TextEmbedding004 = "text-embedding-004"
|
|
816
|
+
TextEmbedding004 = "text-embedding-004",
|
|
817
|
+
TextEmbedding005 = "text-embedding-005"
|
|
817
818
|
}
|
|
818
819
|
declare enum AxAIGoogleGeminiSafetyCategory {
|
|
819
820
|
HarmCategoryHarassment = "HARM_CATEGORY_HARASSMENT",
|
|
@@ -959,6 +960,24 @@ type AxAIGoogleGeminiBatchEmbedResponse = {
|
|
|
959
960
|
values: number[];
|
|
960
961
|
}[];
|
|
961
962
|
};
|
|
963
|
+
/**
|
|
964
|
+
* AxAIGoogleVertexBatchEmbedRequest: Structure for making an embedding request to the Google Vertex API.
|
|
965
|
+
*/
|
|
966
|
+
type AxAIGoogleVertexBatchEmbedRequest = {
|
|
967
|
+
instances: {
|
|
968
|
+
content: string;
|
|
969
|
+
}[];
|
|
970
|
+
};
|
|
971
|
+
/**
|
|
972
|
+
* AxAIGoogleVertexBatchEmbedResponse: Structure for handling responses from the Google Vertex API embedding requests.
|
|
973
|
+
*/
|
|
974
|
+
type AxAIGoogleVertexBatchEmbedResponse = {
|
|
975
|
+
predictions: {
|
|
976
|
+
embeddings: {
|
|
977
|
+
values: number[];
|
|
978
|
+
};
|
|
979
|
+
}[];
|
|
980
|
+
};
|
|
962
981
|
|
|
963
982
|
interface AxAIGoogleGeminiOptionsTools {
|
|
964
983
|
codeExecution?: boolean;
|
|
@@ -969,9 +988,10 @@ interface AxAIGoogleGeminiOptionsTools {
|
|
|
969
988
|
}
|
|
970
989
|
interface AxAIGoogleGeminiArgs {
|
|
971
990
|
name: 'google-gemini';
|
|
972
|
-
apiKey
|
|
991
|
+
apiKey?: string;
|
|
973
992
|
projectId?: string;
|
|
974
993
|
region?: string;
|
|
994
|
+
keyFile?: string;
|
|
975
995
|
config?: Readonly<Partial<AxAIGoogleGeminiConfig>>;
|
|
976
996
|
options?: Readonly<AxAIServiceOptions & AxAIGoogleGeminiOptionsTools>;
|
|
977
997
|
modelMap?: Record<string, AxAIGoogleGeminiModel | AxAIGoogleGeminiEmbedModel | string>;
|
|
@@ -979,8 +999,8 @@ interface AxAIGoogleGeminiArgs {
|
|
|
979
999
|
/**
|
|
980
1000
|
* AxAIGoogleGemini: AI Service
|
|
981
1001
|
*/
|
|
982
|
-
declare class AxAIGoogleGemini extends AxBaseAI<AxAIGoogleGeminiChatRequest, AxAIGoogleGeminiBatchEmbedRequest, AxAIGoogleGeminiChatResponse, AxAIGoogleGeminiChatResponseDelta, AxAIGoogleGeminiBatchEmbedResponse> {
|
|
983
|
-
constructor({ apiKey, projectId, region, config, options, modelMap, }: Readonly<Omit<AxAIGoogleGeminiArgs, 'name'>>);
|
|
1002
|
+
declare class AxAIGoogleGemini extends AxBaseAI<AxAIGoogleGeminiChatRequest, AxAIGoogleGeminiBatchEmbedRequest | AxAIGoogleVertexBatchEmbedRequest, AxAIGoogleGeminiChatResponse, AxAIGoogleGeminiChatResponseDelta, AxAIGoogleGeminiBatchEmbedResponse | AxAIGoogleVertexBatchEmbedResponse> {
|
|
1003
|
+
constructor({ apiKey, projectId, region, keyFile, config, options, modelMap, }: Readonly<Omit<AxAIGoogleGeminiArgs, 'name'>>);
|
|
984
1004
|
}
|
|
985
1005
|
|
|
986
1006
|
declare enum AxAIGroqModel {
|
|
@@ -1582,6 +1602,14 @@ declare class AxBalancer implements AxAIService {
|
|
|
1582
1602
|
private currentServiceIndex;
|
|
1583
1603
|
private currentService;
|
|
1584
1604
|
constructor(services: readonly AxAIService[], options?: AxBalancerOptions);
|
|
1605
|
+
/**
|
|
1606
|
+
* Service comparator that respects the input order of services.
|
|
1607
|
+
*/
|
|
1608
|
+
static inputOrderComparator: () => number;
|
|
1609
|
+
/**
|
|
1610
|
+
* Service comparator that sorts services by cost.
|
|
1611
|
+
*/
|
|
1612
|
+
static costComparator: (a: AxAIService, b: AxAIService) => number;
|
|
1585
1613
|
getModelMap(): AxAIModelMap | undefined;
|
|
1586
1614
|
private getNextService;
|
|
1587
1615
|
private reset;
|
|
@@ -2088,4 +2116,4 @@ declare class AxRAG extends AxChainOfThought<{
|
|
|
2088
2116
|
}>;
|
|
2089
2117
|
}
|
|
2090
2118
|
|
|
2091
|
-
export { AxAI, AxAIAnthropic, type AxAIAnthropicArgs, type AxAIAnthropicChatError, type AxAIAnthropicChatRequest, type AxAIAnthropicChatRequestCacheParam, type AxAIAnthropicChatResponse, type AxAIAnthropicChatResponseDelta, type AxAIAnthropicConfig, type AxAIAnthropicContentBlockDeltaEvent, type AxAIAnthropicContentBlockStartEvent, type AxAIAnthropicContentBlockStopEvent, type AxAIAnthropicErrorEvent, type AxAIAnthropicMessageDeltaEvent, type AxAIAnthropicMessageStartEvent, type AxAIAnthropicMessageStopEvent, AxAIAnthropicModel, type AxAIAnthropicPingEvent, type AxAIArgs, AxAIAzureOpenAI, type AxAIAzureOpenAIArgs, AxAICohere, type AxAICohereArgs, type AxAICohereChatRequest, type AxAICohereChatRequestToolResults, type AxAICohereChatResponse, type AxAICohereChatResponseDelta, type AxAICohereChatResponseToolCalls, type AxAICohereConfig, AxAICohereEmbedModel, type AxAICohereEmbedRequest, type AxAICohereEmbedResponse, AxAICohereModel, AxAIDeepSeek, type AxAIDeepSeekArgs, AxAIDeepSeekModel, type AxAIEmbedModels, AxAIGoogleGemini, type AxAIGoogleGeminiArgs, type AxAIGoogleGeminiBatchEmbedRequest, type AxAIGoogleGeminiBatchEmbedResponse, type AxAIGoogleGeminiChatRequest, type AxAIGoogleGeminiChatResponse, type AxAIGoogleGeminiChatResponseDelta, type AxAIGoogleGeminiConfig, type AxAIGoogleGeminiContent, AxAIGoogleGeminiEmbedModel, type AxAIGoogleGeminiGenerationConfig, AxAIGoogleGeminiModel, type AxAIGoogleGeminiOptionsTools, AxAIGoogleGeminiSafetyCategory, type AxAIGoogleGeminiSafetySettings, AxAIGoogleGeminiSafetyThreshold, type AxAIGoogleGeminiTool, type AxAIGoogleGeminiToolConfig, type AxAIGoogleGeminiToolFunctionDeclaration, type AxAIGoogleGeminiToolGoogleSearchRetrieval, AxAIGroq, type AxAIGroqArgs, AxAIGroqModel, AxAIHuggingFace, type AxAIHuggingFaceArgs, type AxAIHuggingFaceConfig, AxAIHuggingFaceModel, type AxAIHuggingFaceRequest, type AxAIHuggingFaceResponse, type AxAIMemory, AxAIMistral, type AxAIMistralArgs, AxAIMistralEmbedModels, AxAIMistralModel, type AxAIModelMap, type AxAIModels, AxAIOllama, type AxAIOllamaAIConfig, type AxAIOllamaArgs, AxAIOpenAI, type AxAIOpenAIArgs, type AxAIOpenAIChatRequest, type AxAIOpenAIChatResponse, type AxAIOpenAIChatResponseDelta, type AxAIOpenAIConfig, AxAIOpenAIEmbedModel, type AxAIOpenAIEmbedRequest, type AxAIOpenAIEmbedResponse, type AxAIOpenAILogprob, AxAIOpenAIModel, type AxAIOpenAIResponseDelta, type AxAIOpenAIUsage, type AxAIPromptConfig, AxAIReka, type AxAIRekaArgs, type AxAIRekaChatRequest, type AxAIRekaChatResponse, type AxAIRekaChatResponseDelta, type AxAIRekaConfig, AxAIRekaModel, type AxAIRekaUsage, type AxAIService, type AxAIServiceActionOptions, type AxAIServiceImpl, type AxAIServiceMetrics, type AxAIServiceOptions, AxAITogether, type AxAITogetherArgs, type AxAPI, AxAgent, type AxAgentOptions, type AxAgentic, AxApacheTika, type AxApacheTikaArgs, type AxApacheTikaConvertOptions, type AxAssertion, AxAssertionError, AxBalancer, type AxBalancerOptions, AxBaseAI, type AxBaseAIArgs, type AxBaseAIFeatures, AxBootstrapFewShot, AxChainOfThought, type AxChatRequest, type AxChatResponse, type AxChatResponseFunctionCall, type AxChatResponseResult, AxDB, type AxDBArgs, AxDBBase, type AxDBBaseArgs, type AxDBBaseOpOptions, AxDBCloudflare, type AxDBCloudflareArgs, type AxDBCloudflareOpOptions, type AxDBLoaderOptions, AxDBManager, type AxDBManagerArgs, type AxDBMatch, AxDBMemory, type AxDBMemoryArgs, type AxDBMemoryOpOptions, AxDBPinecone, type AxDBPineconeArgs, type AxDBPineconeOpOptions, type AxDBQueryRequest, type AxDBQueryResponse, type AxDBQueryService, type AxDBService, type AxDBState, type AxDBUpsertRequest, type AxDBUpsertResponse, AxDBWeaviate, type AxDBWeaviateArgs, type AxDBWeaviateOpOptions, type AxDataRow, AxDefaultQueryRewriter, AxDefaultResultReranker, type AxDockerContainer, AxDockerSession, type AxEmbedRequest, type AxEmbedResponse, AxEmbeddingAdapter, type AxEvaluateArgs, type AxExample, type AxField, type AxFieldTemplateFn, type AxFieldValue, type AxFunction, type AxFunctionExec, type AxFunctionHandler, type AxFunctionJSONSchema, AxFunctionProcessor, AxGen, type AxGenIn, type AxGenOptions, type AxGenOut, type AxGenerateResult, AxHFDataLoader, type AxIField, type AxInputFunctionType, AxInstanceRegistry, type AxInternalChatRequest, type AxInternalEmbedRequest, AxJSInterpreter, AxJSInterpreterPermission, AxLLMRequestTypeValues, AxMemory, type AxMetricFn, type AxMetricFnArgs, type AxModelConfig, type AxModelInfo, type AxModelInfoWithProvider, type AxOptimizerArgs, AxProgram, type AxProgramDemos, type AxProgramExamples, type AxProgramForwardOptions, type AxProgramTrace, type AxProgramUsage, AxProgramWithSignature, type AxProgramWithSignatureOptions, AxPromptTemplate, AxRAG, type AxRateLimiterFunction, AxRateLimiterTokenUsage, type AxRateLimiterTokenUsageOptions, type AxRerankerIn, type AxRerankerOut, type AxResponseHandlerArgs, type AxRewriteIn, type AxRewriteOut, AxRoute, AxRouter, type AxRouterForwardOptions, AxSignature, AxSpanKindValues, type AxStreamingAssertion, AxTestPrompt, type AxTokenUsage, type AxTunable, type AxUsable };
|
|
2119
|
+
export { AxAI, AxAIAnthropic, type AxAIAnthropicArgs, type AxAIAnthropicChatError, type AxAIAnthropicChatRequest, type AxAIAnthropicChatRequestCacheParam, type AxAIAnthropicChatResponse, type AxAIAnthropicChatResponseDelta, type AxAIAnthropicConfig, type AxAIAnthropicContentBlockDeltaEvent, type AxAIAnthropicContentBlockStartEvent, type AxAIAnthropicContentBlockStopEvent, type AxAIAnthropicErrorEvent, type AxAIAnthropicMessageDeltaEvent, type AxAIAnthropicMessageStartEvent, type AxAIAnthropicMessageStopEvent, AxAIAnthropicModel, type AxAIAnthropicPingEvent, type AxAIArgs, AxAIAzureOpenAI, type AxAIAzureOpenAIArgs, AxAICohere, type AxAICohereArgs, type AxAICohereChatRequest, type AxAICohereChatRequestToolResults, type AxAICohereChatResponse, type AxAICohereChatResponseDelta, type AxAICohereChatResponseToolCalls, type AxAICohereConfig, AxAICohereEmbedModel, type AxAICohereEmbedRequest, type AxAICohereEmbedResponse, AxAICohereModel, AxAIDeepSeek, type AxAIDeepSeekArgs, AxAIDeepSeekModel, type AxAIEmbedModels, AxAIGoogleGemini, type AxAIGoogleGeminiArgs, type AxAIGoogleGeminiBatchEmbedRequest, type AxAIGoogleGeminiBatchEmbedResponse, type AxAIGoogleGeminiChatRequest, type AxAIGoogleGeminiChatResponse, type AxAIGoogleGeminiChatResponseDelta, type AxAIGoogleGeminiConfig, type AxAIGoogleGeminiContent, AxAIGoogleGeminiEmbedModel, type AxAIGoogleGeminiGenerationConfig, AxAIGoogleGeminiModel, type AxAIGoogleGeminiOptionsTools, AxAIGoogleGeminiSafetyCategory, type AxAIGoogleGeminiSafetySettings, AxAIGoogleGeminiSafetyThreshold, type AxAIGoogleGeminiTool, type AxAIGoogleGeminiToolConfig, type AxAIGoogleGeminiToolFunctionDeclaration, type AxAIGoogleGeminiToolGoogleSearchRetrieval, type AxAIGoogleVertexBatchEmbedRequest, type AxAIGoogleVertexBatchEmbedResponse, AxAIGroq, type AxAIGroqArgs, AxAIGroqModel, AxAIHuggingFace, type AxAIHuggingFaceArgs, type AxAIHuggingFaceConfig, AxAIHuggingFaceModel, type AxAIHuggingFaceRequest, type AxAIHuggingFaceResponse, type AxAIMemory, AxAIMistral, type AxAIMistralArgs, AxAIMistralEmbedModels, AxAIMistralModel, type AxAIModelMap, type AxAIModels, AxAIOllama, type AxAIOllamaAIConfig, type AxAIOllamaArgs, AxAIOpenAI, type AxAIOpenAIArgs, type AxAIOpenAIChatRequest, type AxAIOpenAIChatResponse, type AxAIOpenAIChatResponseDelta, type AxAIOpenAIConfig, AxAIOpenAIEmbedModel, type AxAIOpenAIEmbedRequest, type AxAIOpenAIEmbedResponse, type AxAIOpenAILogprob, AxAIOpenAIModel, type AxAIOpenAIResponseDelta, type AxAIOpenAIUsage, type AxAIPromptConfig, AxAIReka, type AxAIRekaArgs, type AxAIRekaChatRequest, type AxAIRekaChatResponse, type AxAIRekaChatResponseDelta, type AxAIRekaConfig, AxAIRekaModel, type AxAIRekaUsage, type AxAIService, type AxAIServiceActionOptions, type AxAIServiceImpl, type AxAIServiceMetrics, type AxAIServiceOptions, AxAITogether, type AxAITogetherArgs, type AxAPI, AxAgent, type AxAgentOptions, type AxAgentic, AxApacheTika, type AxApacheTikaArgs, type AxApacheTikaConvertOptions, type AxAssertion, AxAssertionError, AxBalancer, type AxBalancerOptions, AxBaseAI, type AxBaseAIArgs, type AxBaseAIFeatures, AxBootstrapFewShot, AxChainOfThought, type AxChatRequest, type AxChatResponse, type AxChatResponseFunctionCall, type AxChatResponseResult, AxDB, type AxDBArgs, AxDBBase, type AxDBBaseArgs, type AxDBBaseOpOptions, AxDBCloudflare, type AxDBCloudflareArgs, type AxDBCloudflareOpOptions, type AxDBLoaderOptions, AxDBManager, type AxDBManagerArgs, type AxDBMatch, AxDBMemory, type AxDBMemoryArgs, type AxDBMemoryOpOptions, AxDBPinecone, type AxDBPineconeArgs, type AxDBPineconeOpOptions, type AxDBQueryRequest, type AxDBQueryResponse, type AxDBQueryService, type AxDBService, type AxDBState, type AxDBUpsertRequest, type AxDBUpsertResponse, AxDBWeaviate, type AxDBWeaviateArgs, type AxDBWeaviateOpOptions, type AxDataRow, AxDefaultQueryRewriter, AxDefaultResultReranker, type AxDockerContainer, AxDockerSession, type AxEmbedRequest, type AxEmbedResponse, AxEmbeddingAdapter, type AxEvaluateArgs, type AxExample, type AxField, type AxFieldTemplateFn, type AxFieldValue, type AxFunction, type AxFunctionExec, type AxFunctionHandler, type AxFunctionJSONSchema, AxFunctionProcessor, AxGen, type AxGenIn, type AxGenOptions, type AxGenOut, type AxGenerateResult, AxHFDataLoader, type AxIField, type AxInputFunctionType, AxInstanceRegistry, type AxInternalChatRequest, type AxInternalEmbedRequest, AxJSInterpreter, AxJSInterpreterPermission, AxLLMRequestTypeValues, AxMemory, type AxMetricFn, type AxMetricFnArgs, type AxModelConfig, type AxModelInfo, type AxModelInfoWithProvider, type AxOptimizerArgs, AxProgram, type AxProgramDemos, type AxProgramExamples, type AxProgramForwardOptions, type AxProgramTrace, type AxProgramUsage, AxProgramWithSignature, type AxProgramWithSignatureOptions, AxPromptTemplate, AxRAG, type AxRateLimiterFunction, AxRateLimiterTokenUsage, type AxRateLimiterTokenUsageOptions, type AxRerankerIn, type AxRerankerOut, type AxResponseHandlerArgs, type AxRewriteIn, type AxRewriteOut, AxRoute, AxRouter, type AxRouterForwardOptions, AxSignature, AxSpanKindValues, type AxStreamingAssertion, AxTestPrompt, type AxTokenUsage, type AxTunable, type AxUsable };
|
package/index.d.ts
CHANGED
|
@@ -226,7 +226,7 @@ interface AxBaseAIFeatures {
|
|
|
226
226
|
interface AxBaseAIArgs {
|
|
227
227
|
name: string;
|
|
228
228
|
apiURL: string;
|
|
229
|
-
headers: Record<string, string
|
|
229
|
+
headers: () => Promise<Record<string, string>>;
|
|
230
230
|
modelInfo: Readonly<AxModelInfo[]>;
|
|
231
231
|
models: Readonly<{
|
|
232
232
|
model: string;
|
|
@@ -249,13 +249,13 @@ declare class AxBaseAI<TChatRequest, TEmbedRequest, TChatResponse, TChatResponse
|
|
|
249
249
|
private models;
|
|
250
250
|
protected apiURL: string;
|
|
251
251
|
protected name: string;
|
|
252
|
-
protected headers: Record<string, string
|
|
252
|
+
protected headers: () => Promise<Record<string, string>>;
|
|
253
253
|
protected supportFor: AxBaseAIFeatures | ((model: string) => AxBaseAIFeatures);
|
|
254
254
|
private metrics;
|
|
255
255
|
constructor(aiImpl: Readonly<AxAIServiceImpl<TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse>>, { name, apiURL, headers, modelInfo, models, options, supportFor, modelMap, }: Readonly<AxBaseAIArgs>);
|
|
256
256
|
setName(name: string): void;
|
|
257
257
|
setAPIURL(apiURL: string): void;
|
|
258
|
-
setHeaders(headers: Record<string, string
|
|
258
|
+
setHeaders(headers: () => Promise<Record<string, string>>): void;
|
|
259
259
|
setOptions(options: Readonly<AxAIServiceOptions>): void;
|
|
260
260
|
getOptions(): Readonly<AxAIServiceOptions>;
|
|
261
261
|
getModelInfo(): Readonly<AxModelInfoWithProvider>;
|
|
@@ -813,7 +813,8 @@ declare enum AxAIGoogleGeminiModel {
|
|
|
813
813
|
AQA = "aqa"
|
|
814
814
|
}
|
|
815
815
|
declare enum AxAIGoogleGeminiEmbedModel {
|
|
816
|
-
TextEmbedding004 = "text-embedding-004"
|
|
816
|
+
TextEmbedding004 = "text-embedding-004",
|
|
817
|
+
TextEmbedding005 = "text-embedding-005"
|
|
817
818
|
}
|
|
818
819
|
declare enum AxAIGoogleGeminiSafetyCategory {
|
|
819
820
|
HarmCategoryHarassment = "HARM_CATEGORY_HARASSMENT",
|
|
@@ -959,6 +960,24 @@ type AxAIGoogleGeminiBatchEmbedResponse = {
|
|
|
959
960
|
values: number[];
|
|
960
961
|
}[];
|
|
961
962
|
};
|
|
963
|
+
/**
|
|
964
|
+
* AxAIGoogleVertexBatchEmbedRequest: Structure for making an embedding request to the Google Vertex API.
|
|
965
|
+
*/
|
|
966
|
+
type AxAIGoogleVertexBatchEmbedRequest = {
|
|
967
|
+
instances: {
|
|
968
|
+
content: string;
|
|
969
|
+
}[];
|
|
970
|
+
};
|
|
971
|
+
/**
|
|
972
|
+
* AxAIGoogleVertexBatchEmbedResponse: Structure for handling responses from the Google Vertex API embedding requests.
|
|
973
|
+
*/
|
|
974
|
+
type AxAIGoogleVertexBatchEmbedResponse = {
|
|
975
|
+
predictions: {
|
|
976
|
+
embeddings: {
|
|
977
|
+
values: number[];
|
|
978
|
+
};
|
|
979
|
+
}[];
|
|
980
|
+
};
|
|
962
981
|
|
|
963
982
|
interface AxAIGoogleGeminiOptionsTools {
|
|
964
983
|
codeExecution?: boolean;
|
|
@@ -969,9 +988,10 @@ interface AxAIGoogleGeminiOptionsTools {
|
|
|
969
988
|
}
|
|
970
989
|
interface AxAIGoogleGeminiArgs {
|
|
971
990
|
name: 'google-gemini';
|
|
972
|
-
apiKey
|
|
991
|
+
apiKey?: string;
|
|
973
992
|
projectId?: string;
|
|
974
993
|
region?: string;
|
|
994
|
+
keyFile?: string;
|
|
975
995
|
config?: Readonly<Partial<AxAIGoogleGeminiConfig>>;
|
|
976
996
|
options?: Readonly<AxAIServiceOptions & AxAIGoogleGeminiOptionsTools>;
|
|
977
997
|
modelMap?: Record<string, AxAIGoogleGeminiModel | AxAIGoogleGeminiEmbedModel | string>;
|
|
@@ -979,8 +999,8 @@ interface AxAIGoogleGeminiArgs {
|
|
|
979
999
|
/**
|
|
980
1000
|
* AxAIGoogleGemini: AI Service
|
|
981
1001
|
*/
|
|
982
|
-
declare class AxAIGoogleGemini extends AxBaseAI<AxAIGoogleGeminiChatRequest, AxAIGoogleGeminiBatchEmbedRequest, AxAIGoogleGeminiChatResponse, AxAIGoogleGeminiChatResponseDelta, AxAIGoogleGeminiBatchEmbedResponse> {
|
|
983
|
-
constructor({ apiKey, projectId, region, config, options, modelMap, }: Readonly<Omit<AxAIGoogleGeminiArgs, 'name'>>);
|
|
1002
|
+
declare class AxAIGoogleGemini extends AxBaseAI<AxAIGoogleGeminiChatRequest, AxAIGoogleGeminiBatchEmbedRequest | AxAIGoogleVertexBatchEmbedRequest, AxAIGoogleGeminiChatResponse, AxAIGoogleGeminiChatResponseDelta, AxAIGoogleGeminiBatchEmbedResponse | AxAIGoogleVertexBatchEmbedResponse> {
|
|
1003
|
+
constructor({ apiKey, projectId, region, keyFile, config, options, modelMap, }: Readonly<Omit<AxAIGoogleGeminiArgs, 'name'>>);
|
|
984
1004
|
}
|
|
985
1005
|
|
|
986
1006
|
declare enum AxAIGroqModel {
|
|
@@ -1582,6 +1602,14 @@ declare class AxBalancer implements AxAIService {
|
|
|
1582
1602
|
private currentServiceIndex;
|
|
1583
1603
|
private currentService;
|
|
1584
1604
|
constructor(services: readonly AxAIService[], options?: AxBalancerOptions);
|
|
1605
|
+
/**
|
|
1606
|
+
* Service comparator that respects the input order of services.
|
|
1607
|
+
*/
|
|
1608
|
+
static inputOrderComparator: () => number;
|
|
1609
|
+
/**
|
|
1610
|
+
* Service comparator that sorts services by cost.
|
|
1611
|
+
*/
|
|
1612
|
+
static costComparator: (a: AxAIService, b: AxAIService) => number;
|
|
1585
1613
|
getModelMap(): AxAIModelMap | undefined;
|
|
1586
1614
|
private getNextService;
|
|
1587
1615
|
private reset;
|
|
@@ -2088,4 +2116,4 @@ declare class AxRAG extends AxChainOfThought<{
|
|
|
2088
2116
|
}>;
|
|
2089
2117
|
}
|
|
2090
2118
|
|
|
2091
|
-
export { AxAI, AxAIAnthropic, type AxAIAnthropicArgs, type AxAIAnthropicChatError, type AxAIAnthropicChatRequest, type AxAIAnthropicChatRequestCacheParam, type AxAIAnthropicChatResponse, type AxAIAnthropicChatResponseDelta, type AxAIAnthropicConfig, type AxAIAnthropicContentBlockDeltaEvent, type AxAIAnthropicContentBlockStartEvent, type AxAIAnthropicContentBlockStopEvent, type AxAIAnthropicErrorEvent, type AxAIAnthropicMessageDeltaEvent, type AxAIAnthropicMessageStartEvent, type AxAIAnthropicMessageStopEvent, AxAIAnthropicModel, type AxAIAnthropicPingEvent, type AxAIArgs, AxAIAzureOpenAI, type AxAIAzureOpenAIArgs, AxAICohere, type AxAICohereArgs, type AxAICohereChatRequest, type AxAICohereChatRequestToolResults, type AxAICohereChatResponse, type AxAICohereChatResponseDelta, type AxAICohereChatResponseToolCalls, type AxAICohereConfig, AxAICohereEmbedModel, type AxAICohereEmbedRequest, type AxAICohereEmbedResponse, AxAICohereModel, AxAIDeepSeek, type AxAIDeepSeekArgs, AxAIDeepSeekModel, type AxAIEmbedModels, AxAIGoogleGemini, type AxAIGoogleGeminiArgs, type AxAIGoogleGeminiBatchEmbedRequest, type AxAIGoogleGeminiBatchEmbedResponse, type AxAIGoogleGeminiChatRequest, type AxAIGoogleGeminiChatResponse, type AxAIGoogleGeminiChatResponseDelta, type AxAIGoogleGeminiConfig, type AxAIGoogleGeminiContent, AxAIGoogleGeminiEmbedModel, type AxAIGoogleGeminiGenerationConfig, AxAIGoogleGeminiModel, type AxAIGoogleGeminiOptionsTools, AxAIGoogleGeminiSafetyCategory, type AxAIGoogleGeminiSafetySettings, AxAIGoogleGeminiSafetyThreshold, type AxAIGoogleGeminiTool, type AxAIGoogleGeminiToolConfig, type AxAIGoogleGeminiToolFunctionDeclaration, type AxAIGoogleGeminiToolGoogleSearchRetrieval, AxAIGroq, type AxAIGroqArgs, AxAIGroqModel, AxAIHuggingFace, type AxAIHuggingFaceArgs, type AxAIHuggingFaceConfig, AxAIHuggingFaceModel, type AxAIHuggingFaceRequest, type AxAIHuggingFaceResponse, type AxAIMemory, AxAIMistral, type AxAIMistralArgs, AxAIMistralEmbedModels, AxAIMistralModel, type AxAIModelMap, type AxAIModels, AxAIOllama, type AxAIOllamaAIConfig, type AxAIOllamaArgs, AxAIOpenAI, type AxAIOpenAIArgs, type AxAIOpenAIChatRequest, type AxAIOpenAIChatResponse, type AxAIOpenAIChatResponseDelta, type AxAIOpenAIConfig, AxAIOpenAIEmbedModel, type AxAIOpenAIEmbedRequest, type AxAIOpenAIEmbedResponse, type AxAIOpenAILogprob, AxAIOpenAIModel, type AxAIOpenAIResponseDelta, type AxAIOpenAIUsage, type AxAIPromptConfig, AxAIReka, type AxAIRekaArgs, type AxAIRekaChatRequest, type AxAIRekaChatResponse, type AxAIRekaChatResponseDelta, type AxAIRekaConfig, AxAIRekaModel, type AxAIRekaUsage, type AxAIService, type AxAIServiceActionOptions, type AxAIServiceImpl, type AxAIServiceMetrics, type AxAIServiceOptions, AxAITogether, type AxAITogetherArgs, type AxAPI, AxAgent, type AxAgentOptions, type AxAgentic, AxApacheTika, type AxApacheTikaArgs, type AxApacheTikaConvertOptions, type AxAssertion, AxAssertionError, AxBalancer, type AxBalancerOptions, AxBaseAI, type AxBaseAIArgs, type AxBaseAIFeatures, AxBootstrapFewShot, AxChainOfThought, type AxChatRequest, type AxChatResponse, type AxChatResponseFunctionCall, type AxChatResponseResult, AxDB, type AxDBArgs, AxDBBase, type AxDBBaseArgs, type AxDBBaseOpOptions, AxDBCloudflare, type AxDBCloudflareArgs, type AxDBCloudflareOpOptions, type AxDBLoaderOptions, AxDBManager, type AxDBManagerArgs, type AxDBMatch, AxDBMemory, type AxDBMemoryArgs, type AxDBMemoryOpOptions, AxDBPinecone, type AxDBPineconeArgs, type AxDBPineconeOpOptions, type AxDBQueryRequest, type AxDBQueryResponse, type AxDBQueryService, type AxDBService, type AxDBState, type AxDBUpsertRequest, type AxDBUpsertResponse, AxDBWeaviate, type AxDBWeaviateArgs, type AxDBWeaviateOpOptions, type AxDataRow, AxDefaultQueryRewriter, AxDefaultResultReranker, type AxDockerContainer, AxDockerSession, type AxEmbedRequest, type AxEmbedResponse, AxEmbeddingAdapter, type AxEvaluateArgs, type AxExample, type AxField, type AxFieldTemplateFn, type AxFieldValue, type AxFunction, type AxFunctionExec, type AxFunctionHandler, type AxFunctionJSONSchema, AxFunctionProcessor, AxGen, type AxGenIn, type AxGenOptions, type AxGenOut, type AxGenerateResult, AxHFDataLoader, type AxIField, type AxInputFunctionType, AxInstanceRegistry, type AxInternalChatRequest, type AxInternalEmbedRequest, AxJSInterpreter, AxJSInterpreterPermission, AxLLMRequestTypeValues, AxMemory, type AxMetricFn, type AxMetricFnArgs, type AxModelConfig, type AxModelInfo, type AxModelInfoWithProvider, type AxOptimizerArgs, AxProgram, type AxProgramDemos, type AxProgramExamples, type AxProgramForwardOptions, type AxProgramTrace, type AxProgramUsage, AxProgramWithSignature, type AxProgramWithSignatureOptions, AxPromptTemplate, AxRAG, type AxRateLimiterFunction, AxRateLimiterTokenUsage, type AxRateLimiterTokenUsageOptions, type AxRerankerIn, type AxRerankerOut, type AxResponseHandlerArgs, type AxRewriteIn, type AxRewriteOut, AxRoute, AxRouter, type AxRouterForwardOptions, AxSignature, AxSpanKindValues, type AxStreamingAssertion, AxTestPrompt, type AxTokenUsage, type AxTunable, type AxUsable };
|
|
2119
|
+
export { AxAI, AxAIAnthropic, type AxAIAnthropicArgs, type AxAIAnthropicChatError, type AxAIAnthropicChatRequest, type AxAIAnthropicChatRequestCacheParam, type AxAIAnthropicChatResponse, type AxAIAnthropicChatResponseDelta, type AxAIAnthropicConfig, type AxAIAnthropicContentBlockDeltaEvent, type AxAIAnthropicContentBlockStartEvent, type AxAIAnthropicContentBlockStopEvent, type AxAIAnthropicErrorEvent, type AxAIAnthropicMessageDeltaEvent, type AxAIAnthropicMessageStartEvent, type AxAIAnthropicMessageStopEvent, AxAIAnthropicModel, type AxAIAnthropicPingEvent, type AxAIArgs, AxAIAzureOpenAI, type AxAIAzureOpenAIArgs, AxAICohere, type AxAICohereArgs, type AxAICohereChatRequest, type AxAICohereChatRequestToolResults, type AxAICohereChatResponse, type AxAICohereChatResponseDelta, type AxAICohereChatResponseToolCalls, type AxAICohereConfig, AxAICohereEmbedModel, type AxAICohereEmbedRequest, type AxAICohereEmbedResponse, AxAICohereModel, AxAIDeepSeek, type AxAIDeepSeekArgs, AxAIDeepSeekModel, type AxAIEmbedModels, AxAIGoogleGemini, type AxAIGoogleGeminiArgs, type AxAIGoogleGeminiBatchEmbedRequest, type AxAIGoogleGeminiBatchEmbedResponse, type AxAIGoogleGeminiChatRequest, type AxAIGoogleGeminiChatResponse, type AxAIGoogleGeminiChatResponseDelta, type AxAIGoogleGeminiConfig, type AxAIGoogleGeminiContent, AxAIGoogleGeminiEmbedModel, type AxAIGoogleGeminiGenerationConfig, AxAIGoogleGeminiModel, type AxAIGoogleGeminiOptionsTools, AxAIGoogleGeminiSafetyCategory, type AxAIGoogleGeminiSafetySettings, AxAIGoogleGeminiSafetyThreshold, type AxAIGoogleGeminiTool, type AxAIGoogleGeminiToolConfig, type AxAIGoogleGeminiToolFunctionDeclaration, type AxAIGoogleGeminiToolGoogleSearchRetrieval, type AxAIGoogleVertexBatchEmbedRequest, type AxAIGoogleVertexBatchEmbedResponse, AxAIGroq, type AxAIGroqArgs, AxAIGroqModel, AxAIHuggingFace, type AxAIHuggingFaceArgs, type AxAIHuggingFaceConfig, AxAIHuggingFaceModel, type AxAIHuggingFaceRequest, type AxAIHuggingFaceResponse, type AxAIMemory, AxAIMistral, type AxAIMistralArgs, AxAIMistralEmbedModels, AxAIMistralModel, type AxAIModelMap, type AxAIModels, AxAIOllama, type AxAIOllamaAIConfig, type AxAIOllamaArgs, AxAIOpenAI, type AxAIOpenAIArgs, type AxAIOpenAIChatRequest, type AxAIOpenAIChatResponse, type AxAIOpenAIChatResponseDelta, type AxAIOpenAIConfig, AxAIOpenAIEmbedModel, type AxAIOpenAIEmbedRequest, type AxAIOpenAIEmbedResponse, type AxAIOpenAILogprob, AxAIOpenAIModel, type AxAIOpenAIResponseDelta, type AxAIOpenAIUsage, type AxAIPromptConfig, AxAIReka, type AxAIRekaArgs, type AxAIRekaChatRequest, type AxAIRekaChatResponse, type AxAIRekaChatResponseDelta, type AxAIRekaConfig, AxAIRekaModel, type AxAIRekaUsage, type AxAIService, type AxAIServiceActionOptions, type AxAIServiceImpl, type AxAIServiceMetrics, type AxAIServiceOptions, AxAITogether, type AxAITogetherArgs, type AxAPI, AxAgent, type AxAgentOptions, type AxAgentic, AxApacheTika, type AxApacheTikaArgs, type AxApacheTikaConvertOptions, type AxAssertion, AxAssertionError, AxBalancer, type AxBalancerOptions, AxBaseAI, type AxBaseAIArgs, type AxBaseAIFeatures, AxBootstrapFewShot, AxChainOfThought, type AxChatRequest, type AxChatResponse, type AxChatResponseFunctionCall, type AxChatResponseResult, AxDB, type AxDBArgs, AxDBBase, type AxDBBaseArgs, type AxDBBaseOpOptions, AxDBCloudflare, type AxDBCloudflareArgs, type AxDBCloudflareOpOptions, type AxDBLoaderOptions, AxDBManager, type AxDBManagerArgs, type AxDBMatch, AxDBMemory, type AxDBMemoryArgs, type AxDBMemoryOpOptions, AxDBPinecone, type AxDBPineconeArgs, type AxDBPineconeOpOptions, type AxDBQueryRequest, type AxDBQueryResponse, type AxDBQueryService, type AxDBService, type AxDBState, type AxDBUpsertRequest, type AxDBUpsertResponse, AxDBWeaviate, type AxDBWeaviateArgs, type AxDBWeaviateOpOptions, type AxDataRow, AxDefaultQueryRewriter, AxDefaultResultReranker, type AxDockerContainer, AxDockerSession, type AxEmbedRequest, type AxEmbedResponse, AxEmbeddingAdapter, type AxEvaluateArgs, type AxExample, type AxField, type AxFieldTemplateFn, type AxFieldValue, type AxFunction, type AxFunctionExec, type AxFunctionHandler, type AxFunctionJSONSchema, AxFunctionProcessor, AxGen, type AxGenIn, type AxGenOptions, type AxGenOut, type AxGenerateResult, AxHFDataLoader, type AxIField, type AxInputFunctionType, AxInstanceRegistry, type AxInternalChatRequest, type AxInternalEmbedRequest, AxJSInterpreter, AxJSInterpreterPermission, AxLLMRequestTypeValues, AxMemory, type AxMetricFn, type AxMetricFnArgs, type AxModelConfig, type AxModelInfo, type AxModelInfoWithProvider, type AxOptimizerArgs, AxProgram, type AxProgramDemos, type AxProgramExamples, type AxProgramForwardOptions, type AxProgramTrace, type AxProgramUsage, AxProgramWithSignature, type AxProgramWithSignatureOptions, AxPromptTemplate, AxRAG, type AxRateLimiterFunction, AxRateLimiterTokenUsage, type AxRateLimiterTokenUsageOptions, type AxRerankerIn, type AxRerankerOut, type AxResponseHandlerArgs, type AxRewriteIn, type AxRewriteOut, AxRoute, AxRouter, type AxRouterForwardOptions, AxSignature, AxSpanKindValues, type AxStreamingAssertion, AxTestPrompt, type AxTokenUsage, type AxTunable, type AxUsable };
|
package/index.js
CHANGED
|
@@ -556,7 +556,7 @@ var AxBaseAI = class {
|
|
|
556
556
|
{
|
|
557
557
|
name: apiConfig.name,
|
|
558
558
|
url: this.apiURL,
|
|
559
|
-
headers: this.buildHeaders(apiConfig.headers),
|
|
559
|
+
headers: await this.buildHeaders(apiConfig.headers),
|
|
560
560
|
stream: modelConfig.stream,
|
|
561
561
|
debug: this.debug,
|
|
562
562
|
fetch: this.fetch,
|
|
@@ -675,7 +675,7 @@ var AxBaseAI = class {
|
|
|
675
675
|
{
|
|
676
676
|
name: apiConfig.name,
|
|
677
677
|
url: this.apiURL,
|
|
678
|
-
headers: this.buildHeaders(apiConfig.headers),
|
|
678
|
+
headers: await this.buildHeaders(apiConfig.headers),
|
|
679
679
|
debug: this.debug,
|
|
680
680
|
fetch: this.fetch,
|
|
681
681
|
span
|
|
@@ -699,8 +699,8 @@ var AxBaseAI = class {
|
|
|
699
699
|
span?.end();
|
|
700
700
|
return res;
|
|
701
701
|
}
|
|
702
|
-
buildHeaders(headers = {}) {
|
|
703
|
-
return { ...headers, ...this.headers };
|
|
702
|
+
async buildHeaders(headers = {}) {
|
|
703
|
+
return { ...headers, ...await this.headers() };
|
|
704
704
|
}
|
|
705
705
|
};
|
|
706
706
|
var logChatRequest = (req) => {
|
|
@@ -1060,11 +1060,11 @@ var AxAIAnthropic = class extends AxBaseAI {
|
|
|
1060
1060
|
super(aiImpl, {
|
|
1061
1061
|
name: "Anthropic",
|
|
1062
1062
|
apiURL: "https://api.anthropic.com/v1",
|
|
1063
|
-
headers: {
|
|
1063
|
+
headers: async () => ({
|
|
1064
1064
|
"anthropic-version": "2023-06-01",
|
|
1065
1065
|
"anthropic-beta": "prompt-caching-2024-07-31",
|
|
1066
1066
|
"x-api-key": apiKey
|
|
1067
|
-
},
|
|
1067
|
+
}),
|
|
1068
1068
|
modelInfo: axModelInfoAnthropic,
|
|
1069
1069
|
models: { model: _config.model },
|
|
1070
1070
|
options,
|
|
@@ -1569,7 +1569,7 @@ var AxAIOpenAI = class extends AxBaseAI {
|
|
|
1569
1569
|
super(aiImpl, {
|
|
1570
1570
|
name: "OpenAI",
|
|
1571
1571
|
apiURL: apiURL ? apiURL : "https://api.openai.com/v1",
|
|
1572
|
-
headers: { Authorization: `Bearer ${apiKey}` },
|
|
1572
|
+
headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
|
|
1573
1573
|
modelInfo,
|
|
1574
1574
|
models: {
|
|
1575
1575
|
model: _config.model,
|
|
@@ -1621,7 +1621,7 @@ var AxAIAzureOpenAI = class extends AxAIOpenAI {
|
|
|
1621
1621
|
host
|
|
1622
1622
|
).href
|
|
1623
1623
|
);
|
|
1624
|
-
super.setHeaders({ "api-key": apiKey });
|
|
1624
|
+
super.setHeaders(async () => ({ "api-key": apiKey }));
|
|
1625
1625
|
}
|
|
1626
1626
|
};
|
|
1627
1627
|
|
|
@@ -1881,7 +1881,7 @@ var AxAICohere = class extends AxBaseAI {
|
|
|
1881
1881
|
super(aiImpl, {
|
|
1882
1882
|
name: "Cohere",
|
|
1883
1883
|
apiURL: "https://api.cohere.ai/v1",
|
|
1884
|
-
headers: { Authorization: `Bearer ${apiKey}` },
|
|
1884
|
+
headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
|
|
1885
1885
|
modelInfo: axModelInfoCohere,
|
|
1886
1886
|
models: { model: _config.model },
|
|
1887
1887
|
supportFor: { functions: true, streaming: true },
|
|
@@ -2001,6 +2001,61 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
|
|
|
2001
2001
|
}
|
|
2002
2002
|
};
|
|
2003
2003
|
|
|
2004
|
+
// ai/google-gemini/auth.ts
|
|
2005
|
+
import { GoogleAuth } from "google-auth-library";
|
|
2006
|
+
var GoogleVertexAuth = class {
|
|
2007
|
+
auth;
|
|
2008
|
+
client;
|
|
2009
|
+
currentToken;
|
|
2010
|
+
tokenExpiry;
|
|
2011
|
+
constructor(config = {}) {
|
|
2012
|
+
this.auth = new GoogleAuth({
|
|
2013
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
2014
|
+
...config
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
async getAuthenticatedClient() {
|
|
2018
|
+
if (!this.client) {
|
|
2019
|
+
this.client = await this.auth.getClient();
|
|
2020
|
+
}
|
|
2021
|
+
return this.client;
|
|
2022
|
+
}
|
|
2023
|
+
async getAccessToken() {
|
|
2024
|
+
if (this.currentToken && this.tokenExpiry && Date.now() < this.tokenExpiry) {
|
|
2025
|
+
return this.currentToken;
|
|
2026
|
+
}
|
|
2027
|
+
const client = await this.getAuthenticatedClient();
|
|
2028
|
+
const tokenResponse = await client.getAccessToken();
|
|
2029
|
+
this.currentToken = tokenResponse.token ?? void 0;
|
|
2030
|
+
const expiry = this.getExpiry(tokenResponse);
|
|
2031
|
+
const fiveMinutes = 5 * 60 * 1e3;
|
|
2032
|
+
this.tokenExpiry = expiry - fiveMinutes;
|
|
2033
|
+
return this.currentToken;
|
|
2034
|
+
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Get the expiry date from the token response.
|
|
2037
|
+
*/
|
|
2038
|
+
getExpiry(tokenResponse) {
|
|
2039
|
+
const oneHour = 3600 * 1e3;
|
|
2040
|
+
let expiry = Date.now() + oneHour;
|
|
2041
|
+
let responseExpiry = tokenResponse.res?.data?.expiry_date;
|
|
2042
|
+
if (responseExpiry) {
|
|
2043
|
+
if (typeof responseExpiry === "number") {
|
|
2044
|
+
expiry = responseExpiry;
|
|
2045
|
+
} else if (responseExpiry instanceof Date) {
|
|
2046
|
+
expiry = responseExpiry.getTime();
|
|
2047
|
+
} else if (typeof responseExpiry === "string") {
|
|
2048
|
+
expiry = new Date(responseExpiry).getTime();
|
|
2049
|
+
} else {
|
|
2050
|
+
console.warn("Unknown expiry type", responseExpiry);
|
|
2051
|
+
}
|
|
2052
|
+
} else {
|
|
2053
|
+
console.warn("No expiry date found in response", tokenResponse.res?.data);
|
|
2054
|
+
}
|
|
2055
|
+
return expiry;
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
|
|
2004
2059
|
// ai/google-gemini/types.ts
|
|
2005
2060
|
var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
|
|
2006
2061
|
AxAIGoogleGeminiModel2["Gemini1Pro"] = "gemini-1.0-pro";
|
|
@@ -2013,6 +2068,7 @@ var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
|
|
|
2013
2068
|
})(AxAIGoogleGeminiModel || {});
|
|
2014
2069
|
var AxAIGoogleGeminiEmbedModel = /* @__PURE__ */ ((AxAIGoogleGeminiEmbedModel2) => {
|
|
2015
2070
|
AxAIGoogleGeminiEmbedModel2["TextEmbedding004"] = "text-embedding-004";
|
|
2071
|
+
AxAIGoogleGeminiEmbedModel2["TextEmbedding005"] = "text-embedding-005";
|
|
2016
2072
|
return AxAIGoogleGeminiEmbedModel2;
|
|
2017
2073
|
})(AxAIGoogleGeminiEmbedModel || {});
|
|
2018
2074
|
var AxAIGoogleGeminiSafetyCategory = /* @__PURE__ */ ((AxAIGoogleGeminiSafetyCategory2) => {
|
|
@@ -2089,10 +2145,11 @@ var axAIGoogleGeminiDefaultConfig = () => structuredClone({
|
|
|
2089
2145
|
...axBaseAIDefaultConfig()
|
|
2090
2146
|
});
|
|
2091
2147
|
var AxAIGoogleGeminiImpl = class {
|
|
2092
|
-
constructor(config, apiKey,
|
|
2148
|
+
constructor(config, isVertex, apiKey, keyFile, options) {
|
|
2093
2149
|
this.config = config;
|
|
2094
|
-
this.apiKey = apiKey;
|
|
2095
2150
|
this.isVertex = isVertex;
|
|
2151
|
+
this.apiKey = apiKey;
|
|
2152
|
+
this.keyFile = keyFile;
|
|
2096
2153
|
this.options = options;
|
|
2097
2154
|
}
|
|
2098
2155
|
getModelConfig() {
|
|
@@ -2119,7 +2176,7 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
2119
2176
|
const apiConfig = {
|
|
2120
2177
|
name: stream ? `/models/${model}:streamGenerateContent?alt=sse` : `/models/${model}:generateContent`
|
|
2121
2178
|
};
|
|
2122
|
-
if (this.isVertex
|
|
2179
|
+
if (!this.isVertex) {
|
|
2123
2180
|
const pf = stream ? "&" : "?";
|
|
2124
2181
|
apiConfig.name += `${pf}key=${this.apiKey}`;
|
|
2125
2182
|
}
|
|
@@ -2266,15 +2323,28 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
2266
2323
|
if (!req.texts || req.texts.length === 0) {
|
|
2267
2324
|
throw new Error("Embed texts is empty");
|
|
2268
2325
|
}
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2326
|
+
let apiConfig;
|
|
2327
|
+
let reqValue;
|
|
2328
|
+
if (this.isVertex) {
|
|
2329
|
+
apiConfig = {
|
|
2330
|
+
name: `/models/${model}:predict`
|
|
2331
|
+
};
|
|
2332
|
+
reqValue = {
|
|
2333
|
+
instances: req.texts.map((text) => ({
|
|
2334
|
+
content: text
|
|
2335
|
+
}))
|
|
2336
|
+
};
|
|
2337
|
+
} else {
|
|
2338
|
+
apiConfig = {
|
|
2339
|
+
name: `/models/${model}:batchEmbedContents?key=${this.apiKey}`
|
|
2340
|
+
};
|
|
2341
|
+
reqValue = {
|
|
2342
|
+
requests: req.texts.map((text) => ({
|
|
2343
|
+
model: "models/" + model,
|
|
2344
|
+
content: { parts: [{ text }] }
|
|
2345
|
+
}))
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2278
2348
|
return [apiConfig, reqValue];
|
|
2279
2349
|
};
|
|
2280
2350
|
createChatResp = (resp) => {
|
|
@@ -2336,7 +2406,16 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
2336
2406
|
return this.createChatResp(resp);
|
|
2337
2407
|
};
|
|
2338
2408
|
createEmbedResp = (resp) => {
|
|
2339
|
-
|
|
2409
|
+
let embeddings;
|
|
2410
|
+
if (this.isVertex) {
|
|
2411
|
+
embeddings = resp.predictions.map(
|
|
2412
|
+
(prediction) => prediction.embeddings.values
|
|
2413
|
+
);
|
|
2414
|
+
} else {
|
|
2415
|
+
embeddings = resp.embeddings.map(
|
|
2416
|
+
(embedding) => embedding.values
|
|
2417
|
+
);
|
|
2418
|
+
}
|
|
2340
2419
|
return {
|
|
2341
2420
|
embeddings
|
|
2342
2421
|
};
|
|
@@ -2347,28 +2426,44 @@ var AxAIGoogleGemini = class extends AxBaseAI {
|
|
|
2347
2426
|
apiKey,
|
|
2348
2427
|
projectId,
|
|
2349
2428
|
region,
|
|
2429
|
+
keyFile,
|
|
2350
2430
|
config,
|
|
2351
2431
|
options,
|
|
2352
2432
|
modelMap
|
|
2353
2433
|
}) {
|
|
2354
|
-
if (!apiKey || apiKey === "") {
|
|
2355
|
-
throw new Error("GoogleGemini AI API key not set");
|
|
2356
|
-
}
|
|
2357
2434
|
const isVertex = projectId !== void 0 && region !== void 0;
|
|
2358
2435
|
let apiURL;
|
|
2359
2436
|
let headers;
|
|
2360
2437
|
if (isVertex) {
|
|
2361
2438
|
apiURL = `https://${region}-aiplatform.googleapis.com/v1/projects/${projectId}/locations/${region}/publishers/google/`;
|
|
2362
|
-
|
|
2439
|
+
if (apiKey) {
|
|
2440
|
+
headers = async () => ({ Authorization: `Bearer ${apiKey}` });
|
|
2441
|
+
} else {
|
|
2442
|
+
const vertexAuth = new GoogleVertexAuth({
|
|
2443
|
+
keyFile
|
|
2444
|
+
});
|
|
2445
|
+
headers = async () => ({
|
|
2446
|
+
Authorization: `Bearer ${await vertexAuth.getAccessToken()}`
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2363
2449
|
} else {
|
|
2450
|
+
if (!apiKey) {
|
|
2451
|
+
throw new Error("GoogleGemini AI API key not set");
|
|
2452
|
+
}
|
|
2364
2453
|
apiURL = "https://generativelanguage.googleapis.com/v1beta";
|
|
2365
|
-
headers = {};
|
|
2454
|
+
headers = async () => ({});
|
|
2366
2455
|
}
|
|
2367
2456
|
const _config = {
|
|
2368
2457
|
...axAIGoogleGeminiDefaultConfig(),
|
|
2369
2458
|
...config
|
|
2370
2459
|
};
|
|
2371
|
-
const aiImpl = new AxAIGoogleGeminiImpl(
|
|
2460
|
+
const aiImpl = new AxAIGoogleGeminiImpl(
|
|
2461
|
+
_config,
|
|
2462
|
+
isVertex,
|
|
2463
|
+
apiKey,
|
|
2464
|
+
keyFile,
|
|
2465
|
+
options
|
|
2466
|
+
);
|
|
2372
2467
|
super(aiImpl, {
|
|
2373
2468
|
name: "GoogleGeminiAI",
|
|
2374
2469
|
apiURL,
|
|
@@ -2638,7 +2733,7 @@ var AxAIHuggingFace = class extends AxBaseAI {
|
|
|
2638
2733
|
super(aiImpl, {
|
|
2639
2734
|
name: "HuggingFace",
|
|
2640
2735
|
apiURL: "https://api-inference.huggingface.co",
|
|
2641
|
-
headers: { Authorization: `Bearer ${apiKey}` },
|
|
2736
|
+
headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
|
|
2642
2737
|
modelInfo: axModelInfoHuggingFace,
|
|
2643
2738
|
models: { model: _config.model },
|
|
2644
2739
|
options,
|
|
@@ -2987,7 +3082,7 @@ var AxAIReka = class extends AxBaseAI {
|
|
|
2987
3082
|
super(aiImpl, {
|
|
2988
3083
|
name: "Reka",
|
|
2989
3084
|
apiURL: apiURL ? apiURL : "https://api.reka.ai/v1/chat",
|
|
2990
|
-
headers: { "X-Api-Key": apiKey },
|
|
3085
|
+
headers: async () => ({ "X-Api-Key": apiKey }),
|
|
2991
3086
|
modelInfo,
|
|
2992
3087
|
models: {
|
|
2993
3088
|
model: _config.model
|
|
@@ -5323,14 +5418,7 @@ var AxApacheTika = class {
|
|
|
5323
5418
|
};
|
|
5324
5419
|
|
|
5325
5420
|
// ai/balance.ts
|
|
5326
|
-
var
|
|
5327
|
-
const aInfo = a.getModelInfo();
|
|
5328
|
-
const bInfo = b.getModelInfo();
|
|
5329
|
-
const aTotalCost = (aInfo.promptTokenCostPer1M || Infinity) + (aInfo.completionTokenCostPer1M || Infinity);
|
|
5330
|
-
const bTotalCost = (bInfo.promptTokenCostPer1M || Infinity) + (bInfo.completionTokenCostPer1M || Infinity);
|
|
5331
|
-
return aTotalCost - bTotalCost;
|
|
5332
|
-
};
|
|
5333
|
-
var AxBalancer = class {
|
|
5421
|
+
var AxBalancer = class _AxBalancer {
|
|
5334
5422
|
services;
|
|
5335
5423
|
currentServiceIndex = 0;
|
|
5336
5424
|
currentService;
|
|
@@ -5338,13 +5426,29 @@ var AxBalancer = class {
|
|
|
5338
5426
|
if (services.length === 0) {
|
|
5339
5427
|
throw new Error("No AI services provided.");
|
|
5340
5428
|
}
|
|
5341
|
-
this.services = [...services].sort(
|
|
5429
|
+
this.services = [...services].sort(
|
|
5430
|
+
options?.comparator ?? _AxBalancer.costComparator
|
|
5431
|
+
);
|
|
5342
5432
|
const cs = this.services[this.currentServiceIndex];
|
|
5343
5433
|
if (cs === void 0) {
|
|
5344
5434
|
throw new Error("Error initializing the AI services.");
|
|
5345
5435
|
}
|
|
5346
5436
|
this.currentService = cs;
|
|
5347
5437
|
}
|
|
5438
|
+
/**
|
|
5439
|
+
* Service comparator that respects the input order of services.
|
|
5440
|
+
*/
|
|
5441
|
+
static inputOrderComparator = () => 0;
|
|
5442
|
+
/**
|
|
5443
|
+
* Service comparator that sorts services by cost.
|
|
5444
|
+
*/
|
|
5445
|
+
static costComparator = (a, b) => {
|
|
5446
|
+
const aInfo = a.getModelInfo();
|
|
5447
|
+
const bInfo = b.getModelInfo();
|
|
5448
|
+
const aTotalCost = (aInfo.promptTokenCostPer1M || Infinity) + (aInfo.completionTokenCostPer1M || Infinity);
|
|
5449
|
+
const bTotalCost = (bInfo.promptTokenCostPer1M || Infinity) + (bInfo.completionTokenCostPer1M || Infinity);
|
|
5450
|
+
return aTotalCost - bTotalCost;
|
|
5451
|
+
};
|
|
5348
5452
|
getModelMap() {
|
|
5349
5453
|
throw new Error("Method not implemented.");
|
|
5350
5454
|
}
|