AxBalancer
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L56
Balancer that rotates through services.
Type Parameters
| Type Parameter | Default type |
|---|---|
TServices extends readonly AxAIService<any, any, any>[] | readonly AxAIService[] |
TModelKey | ExtractAllModelKeys<TServices> |
Implements
AxAIService<unknown,unknown,TModelKey>
Constructors
Constructor
new AxBalancer<TServices, TModelKey>(services: TServices, options?: AxBalancerOptions<TModelKey>): AxBalancer<TServices, TModelKey>;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L77
Parameters
| Parameter | Type |
|---|---|
services | TServices |
options? | AxBalancerOptions<TModelKey> |
Returns
AxBalancer<TServices, TModelKey>
Methods
chat()
chat(req: Readonly<AxChatRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<
| AxChatResponse
| ReadableStream<AxChatResponse>>;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L240
Parameters
| Parameter | Type |
|---|---|
req | Readonly<AxChatRequest<TModelKey>> |
options? | Readonly<AxAIServiceOptions> |
Returns
Promise<
| AxChatResponse
| ReadableStream<AxChatResponse>>
Implementation of
embed()
embed(req: Readonly<AxEmbedRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L300
Parameters
| Parameter | Type |
|---|---|
req | Readonly<AxEmbedRequest<TModelKey>> |
options? | Readonly<AxAIServiceOptions> |
Returns
Promise<AxEmbedResponse>
Implementation of
getFeatures()
getFeatures(model?: string): AxAIFeatures;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L184
Parameters
| Parameter | Type |
|---|---|
model? | string |
Returns
Implementation of
getId()
getId(): string;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L180
Returns
string
Implementation of
getLastUsedChatModel()
getLastUsedChatModel(): unknown;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L110
Returns
unknown
Implementation of
AxAIService.getLastUsedChatModel
getLastUsedEmbedModel()
getLastUsedEmbedModel(): unknown;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L113
Returns
unknown
Implementation of
AxAIService.getLastUsedEmbedModel
getLastUsedModelConfig()
getLastUsedModelConfig(): undefined | AxModelConfig;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L116
Returns
undefined | AxModelConfig
Implementation of
AxAIService.getLastUsedModelConfig
getLogger()
getLogger(): AxLoggerFunction;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L334
Returns
Implementation of
getMetrics()
getMetrics(): AxAIServiceMetrics;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L188
Returns
Implementation of
getModelList()
getModelList():
| undefined
| AxAIModelList<TModelKey>;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L154
Returns
| undefined
| AxAIModelList<TModelKey>
Implementation of
getName()
getName(): string;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L176
Returns
string
Implementation of
getOptions()
getOptions(): Readonly<AxAIServiceOptions>;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L330
Returns
Readonly<AxAIServiceOptions>
Implementation of
setOptions()
setOptions(options: Readonly<AxAIServiceOptions>): void;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L326
Parameters
| Parameter | Type |
|---|---|
options | Readonly<AxAIServiceOptions> |
Returns
void
Implementation of
create()
static create<TServices>(services: TServices, options?: AxBalancerOptions<ExtractAllModelKeys<TServices>>): AxBalancer<TServices, ExtractAllModelKeys<TServices>>;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L104
Static factory method for type-safe balancer creation with automatic model key inference.
Type Parameters
| Type Parameter |
|---|
TServices extends readonly AxAIService<any, any, any>[] |
Parameters
| Parameter | Type |
|---|---|
services | TServices |
options? | AxBalancerOptions<ExtractAllModelKeys<TServices>> |
Returns
AxBalancer<TServices, ExtractAllModelKeys<TServices>>
inputOrderComparator()
static inputOrderComparator(): number;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L123
Service comparator that respects the input order of services.
Returns
number
metricComparator()
static metricComparator<TModelKey>(a: AxAIService<unknown, unknown, TModelKey>, b: AxAIService<unknown, unknown, TModelKey>): number;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/balance.ts#L144
Service comparator that sorts services by cost.
Type Parameters
| Type Parameter | Default type |
|---|---|
TModelKey | string |
Parameters
| Parameter | Type |
|---|---|
a | AxAIService<unknown, unknown, TModelKey> |
b | AxAIService<unknown, unknown, TModelKey> |
Returns
number