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

AxPromptTemplate

Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/prompt.ts#L73

Constructors

Constructor

new AxPromptTemplate(
   sig: Readonly<AxSignature>, 
   options?: Readonly<AxPromptTemplateOptions>, 
   fieldTemplates?: Record<string, AxFieldTemplateFn>): AxPromptTemplate;

Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/prompt.ts#L93

Parameters

ParameterType
sigReadonly<AxSignature>
options?Readonly<AxPromptTemplateOptions>
fieldTemplates?Record<string, AxFieldTemplateFn>

Returns

AxPromptTemplate

Methods

getInstruction()

getInstruction(): undefined | string;

Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/prompt.ts#L84

Returns

undefined | string


render()

render<T>(values: T | readonly AxMessage<T>[], __namedParameters: Readonly<{
  demos?: Record<string, AxFieldValue>[];
  examples?: Record<string, AxFieldValue>[];
  skipSystemPrompt?: boolean;
}>): (
  | {
  cache?: boolean;
  content: string;
  role: "system";
}
  | {
  cache?: boolean;
  content:   | string
     | (
     | {
     cache?: boolean;
     text: string;
     type: "text";
   }
     | {
     altText?: string;
     cache?: boolean;
     details?: "high" | "low" | "auto";
     image: string;
     mimeType: string;
     optimize?: "auto" | "quality" | "size";
     type: "image";
   }
     | {
     cache?: boolean;
     data: string;
     duration?: number;
     format?: "wav" | "mp3" | "ogg";
     transcription?: string;
     type: "audio";
   }
     | {
     cache?: boolean;
     data: string;
     extractedText?: string;
     filename?: string;
     mimeType: string;
     type: "file";
   }
     | {
     cache?: boolean;
     extractedText?: string;
     filename?: string;
     fileUri: string;
     mimeType: string;
     type: "file";
   }
     | {
     cache?: boolean;
     cachedContent?: string;
     description?: string;
     title?: string;
     type: "url";
     url: string;
   })[];
  name?: string;
  role: "user";
}
  | {
  cache?: boolean;
  content?: string;
  functionCalls?: object[];
  name?: string;
  role: "assistant";
  thought?: string;
  thoughtBlocks?: AxThoughtBlockItem[];
})[];

Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/prompt.ts#L381

Type Parameters

Type ParameterDefault type
Tany

Parameters

ParameterType
valuesT | readonly AxMessage<T>[]
__namedParametersReadonly<{ demos?: Record<string, AxFieldValue>[]; examples?: Record<string, AxFieldValue>[]; skipSystemPrompt?: boolean; }>

Returns


renderExtraFields()

renderExtraFields(extraFields: readonly AxIField[]): (
  | {
  cache?: boolean;
  text: string;
  type: "text";
}
  | {
  altText?: string;
  cache?: boolean;
  details?: "high" | "low" | "auto";
  image: string;
  mimeType: string;
  optimize?: "auto" | "quality" | "size";
  type: "image";
}
  | {
  cache?: boolean;
  data: string;
  duration?: number;
  format?: "wav" | "mp3" | "ogg";
  transcription?: string;
  type: "audio";
}
  | {
  cache?: boolean;
  data: string;
  extractedText?: string;
  filename?: string;
  mimeType: string;
  type: "file";
}
  | {
  cache?: boolean;
  extractedText?: string;
  filename?: string;
  fileUri: string;
  mimeType: string;
  type: "file";
}
  | {
  cache?: boolean;
  cachedContent?: string;
  description?: string;
  title?: string;
  type: "url";
  url: string;
})[];

Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/prompt.ts#L733

Parameters

ParameterType
extraFieldsreadonly AxIField[]

Returns


setInstruction()

setInstruction(instruction: string): void;

Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/prompt.ts#L79

Parameters

ParameterType
instructionstring

Returns

void