@ax-llm/ax 11.0.63 → 11.0.65

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 CHANGED
@@ -124,6 +124,7 @@ __export(index_exports, {
124
124
  AxSpanKindValues: () => AxSpanKindValues,
125
125
  AxStringUtil: () => AxStringUtil,
126
126
  AxTestPrompt: () => AxTestPrompt,
127
+ ax: () => ax,
127
128
  axAIAnthropicDefaultConfig: () => axAIAnthropicDefaultConfig,
128
129
  axAIAnthropicVertexDefaultConfig: () => axAIAnthropicVertexDefaultConfig,
129
130
  axAIAzureOpenAIBestConfig: () => axAIAzureOpenAIBestConfig,
@@ -158,6 +159,7 @@ __export(index_exports, {
158
159
  axAITogetherDefaultConfig: () => axAITogetherDefaultConfig,
159
160
  axBaseAIDefaultConfig: () => axBaseAIDefaultConfig,
160
161
  axBaseAIDefaultCreativeConfig: () => axBaseAIDefaultCreativeConfig,
162
+ axField: () => axField,
161
163
  axModelInfoAnthropic: () => axModelInfoAnthropic,
162
164
  axModelInfoCohere: () => axModelInfoCohere,
163
165
  axModelInfoDeepSeek: () => axModelInfoDeepSeek,
@@ -6506,7 +6508,17 @@ var renderOutputFields = (fields) => {
6506
6508
  const name = field.title;
6507
6509
  const type = field.type?.name ? toFieldType(field.type) : "string";
6508
6510
  const requiredMsg = field.isOptional ? `Only include this ${type} field if its value is available` : `This ${type} field must be included`;
6509
- const description = field.description ? ` ${formatDescription(field.description)}` : "";
6511
+ let description = "";
6512
+ if (field.description && field.description.length > 0) {
6513
+ const value = field.type?.name === "class" ? field.description : formatDescription(field.description);
6514
+ description = ` ${value}`;
6515
+ }
6516
+ if (field.type?.options && field.type.options.length > 0) {
6517
+ if (description.length > 0) {
6518
+ description += `. `;
6519
+ }
6520
+ description += `Allowed values: ${field.type.options.join(", ")}`;
6521
+ }
6510
6522
  return `${name}: (${requiredMsg})${description}`.trim();
6511
6523
  });
6512
6524
  return rows.join("\n");
@@ -6546,7 +6558,7 @@ var toFieldType = (type) => {
6546
6558
  case "json":
6547
6559
  return "JSON object";
6548
6560
  case "class":
6549
- return `list of classes (match case): ${type.classes?.join(", ")})`;
6561
+ return "classification class";
6550
6562
  case "code":
6551
6563
  return "code";
6552
6564
  default:
@@ -6833,12 +6845,12 @@ var convertValueToType = (field, val, required = false) => {
6833
6845
  return parseLLMFriendlyDateTime(field, val, required);
6834
6846
  case "class":
6835
6847
  const className = val;
6836
- if (field.type.classes && !field.type.classes.includes(className)) {
6848
+ if (field.type.options && !field.type.options.includes(className)) {
6837
6849
  if (field.isOptional) {
6838
6850
  return;
6839
6851
  }
6840
6852
  throw new Error(
6841
- `Invalid class '${val}', expected one of the following: ${field.type.classes.join(", ")}`
6853
+ `Invalid class '${val}', expected one of the following: ${field.type.options.join(", ")}`
6842
6854
  );
6843
6855
  }
6844
6856
  return className;
@@ -7617,13 +7629,13 @@ ${pointer}`;
7617
7629
  `Output field "${name}": Expected class names in quotes after "class" type. Example: class "MyClass1, MyClass2"`
7618
7630
  );
7619
7631
  }
7620
- const classes = classNamesString.split(/[,\s]+/).map((s) => s.trim()).filter((s) => s.length > 0);
7621
- if (classes.length === 0) {
7632
+ const options = classNamesString.split(/[,\s]+/).map((s) => s.trim()).filter((s) => s.length > 0);
7633
+ if (options.length === 0) {
7622
7634
  throw new Error(
7623
7635
  `Output field "${name}": Empty class list provided. At least one class name is required`
7624
7636
  );
7625
7637
  }
7626
- type = { name: "class", isArray, classes };
7638
+ type = { name: "class", isArray, options };
7627
7639
  } else {
7628
7640
  try {
7629
7641
  const typeName = this.parseTypeNotClass();
@@ -11921,6 +11933,147 @@ var AxTestPrompt = class {
11921
11933
  }
11922
11934
  };
11923
11935
 
11936
+ // dsp/template.ts
11937
+ function ax(strings, ...values) {
11938
+ let result = "";
11939
+ for (let i = 0; i < strings.length; i++) {
11940
+ result += strings[i] ?? "";
11941
+ if (i < values.length) {
11942
+ const val = values[i];
11943
+ if (isAxFieldType(val)) {
11944
+ const fieldNameMatch = result.match(/(\w+)\s*:\s*$/);
11945
+ if (fieldNameMatch && (val.isOptional || val.isInternal)) {
11946
+ const fieldName = fieldNameMatch[1];
11947
+ let modifiedFieldName = fieldName;
11948
+ if (val.isOptional) modifiedFieldName += "?";
11949
+ if (val.isInternal) modifiedFieldName += "!";
11950
+ result = result.replace(/(\w+)(\s*:\s*)$/, `${modifiedFieldName}$2`);
11951
+ }
11952
+ const { isOptional: _o, isInternal: _i, ...typeNoFlags } = val;
11953
+ result += convertFieldTypeToString(typeNoFlags);
11954
+ } else if (isAxFieldDescriptor(val)) {
11955
+ result += convertFieldDescriptorToString(val);
11956
+ } else if (typeof val === "string" || val instanceof AxSignature) {
11957
+ result += convertValueToSignatureString(val);
11958
+ } else {
11959
+ throw new Error("Unsupported template interpolation value");
11960
+ }
11961
+ }
11962
+ }
11963
+ return new AxSignature(result);
11964
+ }
11965
+ function convertValueToSignatureString(value) {
11966
+ if (typeof value === "string") {
11967
+ return value;
11968
+ }
11969
+ if (isAxFieldType(value)) {
11970
+ return convertFieldTypeToString(value);
11971
+ }
11972
+ if (isAxFieldDescriptor(value)) {
11973
+ return convertFieldDescriptorToString(value);
11974
+ }
11975
+ if (value instanceof AxSignature) {
11976
+ const sigString = value.toString();
11977
+ const arrowIndex = sigString.indexOf(" -> ");
11978
+ if (arrowIndex !== -1) {
11979
+ return sigString.substring(arrowIndex + 4);
11980
+ }
11981
+ return sigString;
11982
+ }
11983
+ throw new Error(`Unsupported template value type: ${typeof value}`);
11984
+ }
11985
+ function convertFieldTypeToString(fieldType) {
11986
+ let result = fieldType.type;
11987
+ if (fieldType.isArray) {
11988
+ result += "[]";
11989
+ }
11990
+ if (fieldType.options && fieldType.options.length > 0 && fieldType.type === "class") {
11991
+ result += ` "${fieldType.options.join(", ")}"`;
11992
+ }
11993
+ if (fieldType.description) {
11994
+ result += ` "${fieldType.description}"`;
11995
+ }
11996
+ return result;
11997
+ }
11998
+ function convertFieldDescriptorToString(descriptor) {
11999
+ let result = descriptor.name;
12000
+ if (descriptor.isOptional) {
12001
+ result += "?";
12002
+ }
12003
+ if (descriptor.isInternal) {
12004
+ result += "!";
12005
+ }
12006
+ if (descriptor.type) {
12007
+ result += ":" + convertFieldTypeToString(descriptor.type);
12008
+ }
12009
+ if (descriptor.description && !descriptor.type?.description) {
12010
+ result += ` "${descriptor.description}"`;
12011
+ }
12012
+ return result;
12013
+ }
12014
+ function isAxFieldType(value) {
12015
+ return value !== null && typeof value === "object" && value !== void 0 && "type" in value && typeof value.type === "string";
12016
+ }
12017
+ function isAxFieldDescriptor(value) {
12018
+ return value !== null && typeof value === "object" && value !== void 0 && "name" in value && typeof value.name === "string";
12019
+ }
12020
+ var axField = {
12021
+ string: (desc) => ({
12022
+ type: "string",
12023
+ description: desc
12024
+ }),
12025
+ number: (desc) => ({
12026
+ type: "number",
12027
+ description: desc
12028
+ }),
12029
+ boolean: (desc) => ({
12030
+ type: "boolean",
12031
+ description: desc
12032
+ }),
12033
+ date: (desc) => ({
12034
+ type: "date",
12035
+ description: desc
12036
+ }),
12037
+ datetime: (desc) => ({
12038
+ type: "datetime",
12039
+ description: desc
12040
+ }),
12041
+ json: (desc) => ({
12042
+ type: "json",
12043
+ description: desc
12044
+ }),
12045
+ image: (desc) => ({
12046
+ type: "image",
12047
+ description: desc
12048
+ }),
12049
+ audio: (desc) => ({
12050
+ type: "audio",
12051
+ description: desc
12052
+ }),
12053
+ class: (options, desc) => ({
12054
+ type: "class",
12055
+ options,
12056
+ description: desc
12057
+ }),
12058
+ code: (language, desc) => ({
12059
+ type: "code",
12060
+ options: [language],
12061
+ description: desc
12062
+ }),
12063
+ array: (baseType) => ({
12064
+ ...baseType,
12065
+ isArray: true
12066
+ }),
12067
+ optional: (baseType) => ({
12068
+ ...baseType,
12069
+ isOptional: true
12070
+ }),
12071
+ internal: (baseType) => ({
12072
+ ...baseType,
12073
+ isInternal: true
12074
+ })
12075
+ };
12076
+
11924
12077
  // prompts/cot.ts
11925
12078
  var AxChainOfThought = class extends AxGen {
11926
12079
  constructor(signature, options) {
@@ -13889,6 +14042,7 @@ var AxRAG = class extends AxChainOfThought {
13889
14042
  AxSpanKindValues,
13890
14043
  AxStringUtil,
13891
14044
  AxTestPrompt,
14045
+ ax,
13892
14046
  axAIAnthropicDefaultConfig,
13893
14047
  axAIAnthropicVertexDefaultConfig,
13894
14048
  axAIAzureOpenAIBestConfig,
@@ -13923,6 +14077,7 @@ var AxRAG = class extends AxChainOfThought {
13923
14077
  axAITogetherDefaultConfig,
13924
14078
  axBaseAIDefaultConfig,
13925
14079
  axBaseAIDefaultCreativeConfig,
14080
+ axField,
13926
14081
  axModelInfoAnthropic,
13927
14082
  axModelInfoCohere,
13928
14083
  axModelInfoDeepSeek,