Documentation

Build LLM-powered agents
with production-ready TypeScript

DSPy for TypeScript. Working with LLMs is complex—they don't always do what you want. DSPy makes it easier to build amazing things with LLMs. Just define your inputs and outputs (signature) and an efficient prompt is auto-generated and used. Connect together various signatures to build complex systems and workflows using LLMs.

15+ LLM Providers
End-to-end Streaming
Auto Prompt Tuning

AxBalancer

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L56

Balancer that rotates through services.

Type Parameters

Type ParameterDefault type
TServices extends readonly AxAIService<any, any, any>[]readonly AxAIService[]
TModelKeyExtractAllModelKeys<TServices>

Implements

Constructors

Constructor

new AxBalancer<TServices, TModelKey>(services: TServices, options?: AxBalancerOptions<TModelKey>): AxBalancer<TServices, TModelKey>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L77

Parameters

ParameterType
servicesTServices
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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L238

Parameters

ParameterType
reqReadonly<AxChatRequest<TModelKey>>
options?Readonly<AxAIServiceOptions>

Returns

Promise< | AxChatResponse | ReadableStream<AxChatResponse>>

Implementation of

AxAIService.chat


embed()

embed(req: Readonly<AxEmbedRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L298

Parameters

ParameterType
reqReadonly<AxEmbedRequest<TModelKey>>
options?Readonly<AxAIServiceOptions>

Returns

Promise<AxEmbedResponse>

Implementation of

AxAIService.embed


getFeatures()

getFeatures(model?: string): AxAIFeatures;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L184

Parameters

ParameterType
model?string

Returns

AxAIFeatures

Implementation of

AxAIService.getFeatures


getId()

getId(): string;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L180

Returns

string

Implementation of

AxAIService.getId


getLastUsedChatModel()

getLastUsedChatModel(): unknown;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L110

Returns

unknown

Implementation of

AxAIService.getLastUsedChatModel


getLastUsedEmbedModel()

getLastUsedEmbedModel(): unknown;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L332

Returns

AxLoggerFunction

Implementation of

AxAIService.getLogger


getMetrics()

getMetrics(): AxAIServiceMetrics;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L188

Returns

AxAIServiceMetrics

Implementation of

AxAIService.getMetrics


getModelList()

getModelList(): 
  | undefined
| AxAIModelList<TModelKey>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L154

Returns

| undefined | AxAIModelList<TModelKey>

Implementation of

AxAIService.getModelList


getName()

getName(): string;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L176

Returns

string

Implementation of

AxAIService.getName


getOptions()

getOptions(): Readonly<AxAIServiceOptions>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L328

Returns

Readonly<AxAIServiceOptions>

Implementation of

AxAIService.getOptions


setOptions()

setOptions(options: Readonly<AxAIServiceOptions>): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L324

Parameters

ParameterType
optionsReadonly<AxAIServiceOptions>

Returns

void

Implementation of

AxAIService.setOptions


create()

static create<TServices>(services: TServices, options?: AxBalancerOptions<ExtractAllModelKeys<TServices>>): AxBalancer<TServices, ExtractAllModelKeys<TServices>>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/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

ParameterType
servicesTServices
options?AxBalancerOptions<ExtractAllModelKeys<TServices>>

Returns

AxBalancer<TServices, ExtractAllModelKeys<TServices>>


inputOrderComparator()

static inputOrderComparator(): number;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/balance.ts#L144

Service comparator that sorts services by cost.

Type Parameters

Type ParameterDefault type
TModelKeystring

Parameters

ParameterType
aAxAIService<unknown, unknown, TModelKey>
bAxAIService<unknown, unknown, TModelKey>

Returns

number