@mzhub/promptc 0.1.0 → 0.1.2

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.
Files changed (144) hide show
  1. package/README.md +6 -5
  2. package/dist/examples/load-compiled.d.ts +7 -0
  3. package/dist/examples/load-compiled.d.ts.map +1 -0
  4. package/dist/examples/load-compiled.js +44 -0
  5. package/dist/examples/load-compiled.js.map +1 -0
  6. package/dist/examples/multi-provider.d.ts +7 -0
  7. package/dist/examples/multi-provider.d.ts.map +1 -0
  8. package/dist/examples/multi-provider.js +63 -0
  9. package/dist/examples/multi-provider.js.map +1 -0
  10. package/dist/examples/name-extractor.d.ts +11 -0
  11. package/dist/examples/name-extractor.d.ts.map +1 -0
  12. package/dist/examples/name-extractor.js +85 -0
  13. package/dist/examples/name-extractor.js.map +1 -0
  14. package/dist/examples/qa-system.d.ts +8 -0
  15. package/dist/examples/qa-system.d.ts.map +1 -0
  16. package/dist/examples/qa-system.js +73 -0
  17. package/dist/examples/qa-system.js.map +1 -0
  18. package/dist/src/cli.d.ts +3 -0
  19. package/dist/src/cli.d.ts.map +1 -0
  20. package/dist/src/cli.js +111 -0
  21. package/dist/src/cli.js.map +1 -0
  22. package/dist/src/compiler/BootstrapFewShot.d.ts +13 -0
  23. package/dist/src/compiler/BootstrapFewShot.d.ts.map +1 -0
  24. package/dist/src/compiler/BootstrapFewShot.js +93 -0
  25. package/dist/src/compiler/BootstrapFewShot.js.map +1 -0
  26. package/dist/src/compiler/CandidatePool.d.ts +10 -0
  27. package/dist/src/compiler/CandidatePool.d.ts.map +1 -0
  28. package/dist/src/compiler/CandidatePool.js +29 -0
  29. package/dist/src/compiler/CandidatePool.js.map +1 -0
  30. package/dist/src/compiler/CompiledProgram.d.ts +43 -0
  31. package/dist/src/compiler/CompiledProgram.d.ts.map +1 -0
  32. package/dist/src/compiler/CompiledProgram.js +41 -0
  33. package/dist/src/compiler/CompiledProgram.js.map +1 -0
  34. package/dist/src/compiler/InstructionRewrite.d.ts +19 -0
  35. package/dist/src/compiler/InstructionRewrite.d.ts.map +1 -0
  36. package/dist/src/compiler/InstructionRewrite.js +117 -0
  37. package/dist/src/compiler/InstructionRewrite.js.map +1 -0
  38. package/dist/src/compiler/index.d.ts +8 -0
  39. package/dist/src/compiler/index.d.ts.map +1 -0
  40. package/dist/src/compiler/index.js +5 -0
  41. package/dist/src/compiler/index.js.map +1 -0
  42. package/dist/src/compiler/types.d.ts +41 -0
  43. package/dist/src/compiler/types.d.ts.map +1 -0
  44. package/dist/src/compiler/types.js +2 -0
  45. package/dist/src/compiler/types.js.map +1 -0
  46. package/dist/src/eval/exactMatch.d.ts +5 -0
  47. package/dist/src/eval/exactMatch.d.ts.map +1 -0
  48. package/dist/src/eval/exactMatch.js +58 -0
  49. package/dist/src/eval/exactMatch.js.map +1 -0
  50. package/dist/src/eval/index.d.ts +5 -0
  51. package/dist/src/eval/index.d.ts.map +1 -0
  52. package/dist/src/eval/index.js +3 -0
  53. package/dist/src/eval/index.js.map +1 -0
  54. package/dist/src/eval/llmJudge.d.ts +9 -0
  55. package/dist/src/eval/llmJudge.d.ts.map +1 -0
  56. package/dist/src/eval/llmJudge.js +33 -0
  57. package/dist/src/eval/llmJudge.js.map +1 -0
  58. package/dist/src/eval/types.d.ts +2 -0
  59. package/dist/src/eval/types.d.ts.map +1 -0
  60. package/dist/src/eval/types.js +2 -0
  61. package/dist/src/eval/types.js.map +1 -0
  62. package/dist/src/index.d.ts +14 -0
  63. package/dist/src/index.d.ts.map +1 -0
  64. package/dist/src/index.js +8 -0
  65. package/dist/src/index.js.map +1 -0
  66. package/dist/src/program/ChainOfThought.d.ts +6 -0
  67. package/dist/src/program/ChainOfThought.d.ts.map +1 -0
  68. package/dist/src/program/ChainOfThought.js +44 -0
  69. package/dist/src/program/ChainOfThought.js.map +1 -0
  70. package/dist/src/program/Predict.d.ts +6 -0
  71. package/dist/src/program/Predict.d.ts.map +1 -0
  72. package/dist/src/program/Predict.js +33 -0
  73. package/dist/src/program/Predict.js.map +1 -0
  74. package/dist/src/program/Program.d.ts +33 -0
  75. package/dist/src/program/Program.d.ts.map +1 -0
  76. package/dist/src/program/Program.js +28 -0
  77. package/dist/src/program/Program.js.map +1 -0
  78. package/dist/src/program/index.d.ts +5 -0
  79. package/dist/src/program/index.d.ts.map +1 -0
  80. package/dist/src/program/index.js +4 -0
  81. package/dist/src/program/index.js.map +1 -0
  82. package/dist/src/providers/anthropic.d.ts +10 -0
  83. package/dist/src/providers/anthropic.d.ts.map +1 -0
  84. package/dist/src/providers/anthropic.js +40 -0
  85. package/dist/src/providers/anthropic.js.map +1 -0
  86. package/dist/src/providers/cerebras.d.ts +10 -0
  87. package/dist/src/providers/cerebras.d.ts.map +1 -0
  88. package/dist/src/providers/cerebras.js +39 -0
  89. package/dist/src/providers/cerebras.js.map +1 -0
  90. package/dist/src/providers/google.d.ts +10 -0
  91. package/dist/src/providers/google.d.ts.map +1 -0
  92. package/dist/src/providers/google.js +42 -0
  93. package/dist/src/providers/google.js.map +1 -0
  94. package/dist/src/providers/groq.d.ts +10 -0
  95. package/dist/src/providers/groq.d.ts.map +1 -0
  96. package/dist/src/providers/groq.js +42 -0
  97. package/dist/src/providers/groq.js.map +1 -0
  98. package/dist/src/providers/index.d.ts +11 -0
  99. package/dist/src/providers/index.d.ts.map +1 -0
  100. package/dist/src/providers/index.js +31 -0
  101. package/dist/src/providers/index.js.map +1 -0
  102. package/dist/src/providers/ollama.d.ts +9 -0
  103. package/dist/src/providers/ollama.d.ts.map +1 -0
  104. package/dist/src/providers/ollama.js +39 -0
  105. package/dist/src/providers/ollama.js.map +1 -0
  106. package/dist/src/providers/openai.d.ts +10 -0
  107. package/dist/src/providers/openai.d.ts.map +1 -0
  108. package/dist/src/providers/openai.js +42 -0
  109. package/dist/src/providers/openai.js.map +1 -0
  110. package/dist/src/providers/types.d.ts +25 -0
  111. package/dist/src/providers/types.d.ts.map +1 -0
  112. package/dist/src/providers/types.js +2 -0
  113. package/dist/src/providers/types.js.map +1 -0
  114. package/dist/src/runtime/cache.d.ts +18 -0
  115. package/dist/src/runtime/cache.d.ts.map +1 -0
  116. package/dist/src/runtime/cache.js +45 -0
  117. package/dist/src/runtime/cache.js.map +1 -0
  118. package/dist/src/runtime/concurrency.d.ts +7 -0
  119. package/dist/src/runtime/concurrency.d.ts.map +1 -0
  120. package/dist/src/runtime/concurrency.js +14 -0
  121. package/dist/src/runtime/concurrency.js.map +1 -0
  122. package/dist/src/runtime/costTracker.d.ts +24 -0
  123. package/dist/src/runtime/costTracker.d.ts.map +1 -0
  124. package/dist/src/runtime/costTracker.js +37 -0
  125. package/dist/src/runtime/costTracker.js.map +1 -0
  126. package/dist/src/runtime/index.d.ts +9 -0
  127. package/dist/src/runtime/index.d.ts.map +1 -0
  128. package/dist/src/runtime/index.js +5 -0
  129. package/dist/src/runtime/index.js.map +1 -0
  130. package/dist/src/runtime/retry.d.ts +10 -0
  131. package/dist/src/runtime/retry.d.ts.map +1 -0
  132. package/dist/src/runtime/retry.js +39 -0
  133. package/dist/src/runtime/retry.js.map +1 -0
  134. package/dist/src/schema/defineSchema.d.ts +18 -0
  135. package/dist/src/schema/defineSchema.d.ts.map +1 -0
  136. package/dist/src/schema/defineSchema.js +27 -0
  137. package/dist/src/schema/defineSchema.js.map +1 -0
  138. package/dist/src/schema/index.d.ts +3 -0
  139. package/dist/src/schema/index.d.ts.map +1 -0
  140. package/dist/src/schema/index.js +2 -0
  141. package/dist/src/schema/index.js.map +1 -0
  142. package/examples/README.md +1 -1
  143. package/package.json +3 -3
  144. package/src/cli.ts +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CandidatePool.d.ts","sourceRoot":"","sources":["../../../src/compiler/CandidatePool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,qBAAa,aAAa,CAAC,CAAC,EAAE,CAAC;IAGjB,OAAO,CAAC,QAAQ;IAF5B,OAAO,CAAC,GAAG,CAAe;gBAEN,QAAQ,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM;IAI5D,yBAAyB,CACvB,KAAK,EAAE,MAAM,EACb,oBAAoB,EAAE,MAAM,GAC3B,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAazB,gBAAgB,CAAC,UAAU,GAAE,MAAY,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;IAM3D,OAAO,CAAC,YAAY;CAOrB"}
@@ -0,0 +1,29 @@
1
+ export class CandidatePool {
2
+ trainset;
3
+ rng;
4
+ constructor(trainset, seed) {
5
+ this.trainset = trainset;
6
+ this.rng = seed !== undefined ? this.seededRandom(seed) : Math.random;
7
+ }
8
+ generateFewShotCandidates(count, examplesPerCandidate) {
9
+ const candidates = [];
10
+ for (let i = 0; i < count; i++) {
11
+ const shuffled = [...this.trainset].sort(() => this.rng() - 0.5);
12
+ candidates.push(shuffled.slice(0, Math.min(examplesPerCandidate, shuffled.length)));
13
+ }
14
+ return candidates;
15
+ }
16
+ getValidationSet(splitRatio = 0.3) {
17
+ const count = Math.max(1, Math.floor(this.trainset.length * splitRatio));
18
+ const shuffled = [...this.trainset].sort(() => this.rng() - 0.5);
19
+ return shuffled.slice(0, count);
20
+ }
21
+ seededRandom(seed) {
22
+ let s = seed;
23
+ return () => {
24
+ s = Math.sin(s) * 10000;
25
+ return s - Math.floor(s);
26
+ };
27
+ }
28
+ }
29
+ //# sourceMappingURL=CandidatePool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CandidatePool.js","sourceRoot":"","sources":["../../../src/compiler/CandidatePool.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,aAAa;IAGJ;IAFZ,GAAG,CAAe;IAE1B,YAAoB,QAAyB,EAAE,IAAa;QAAxC,aAAQ,GAAR,QAAQ,CAAiB;QAC3C,IAAI,CAAC,GAAG,GAAG,IA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AAK,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,43 @@
1
+ import { ZodRawShape } from "zod";
2
+ import type { ProgramConfig, ProgramOutput } from "../program/Program.js";
3
+ import type { Example } from "./types.js";
4
+ export interface CompiledProgramMeta {
5
+ score: number;
6
+ compiledAt: string;
7
+ strategy: string;
8
+ tokenUsage: {
9
+ inputTokens: number;
10
+ outputTokens: number;
11
+ totalTokens: number;
12
+ calls: number;
13
+ };
14
+ }
15
+ export interface CompiledProgram<I, O> {
16
+ run(input: I, overrides?: Partial<ProgramConfig>): Promise<ProgramOutput<O>>;
17
+ meta: CompiledProgramMeta;
18
+ config: {
19
+ instructions: string;
20
+ fewShotExamples: Array<Example<unknown, unknown>>;
21
+ };
22
+ toJSON(): string;
23
+ }
24
+ export declare function createCompiledProgram<I extends ZodRawShape, O extends ZodRawShape, InputType = unknown, OutputType = unknown>(originalProgram: {
25
+ run(input: InputType, config?: ProgramConfig): Promise<ProgramOutput<OutputType>>;
26
+ }, compilationResult: {
27
+ meta: CompiledProgramMeta;
28
+ config: {
29
+ instructions: string;
30
+ fewShotExamples: Array<Example<unknown, unknown>>;
31
+ };
32
+ }): CompiledProgram<InputType, OutputType>;
33
+ export interface SerializedCompiledProgram {
34
+ meta: CompiledProgramMeta;
35
+ config: {
36
+ instructions: string;
37
+ fewShotExamples: Array<Example<unknown, unknown>>;
38
+ };
39
+ }
40
+ export declare function loadCompiledProgram<InputType = unknown, OutputType = unknown>(jsonOrPath: string | SerializedCompiledProgram, program: {
41
+ run(input: InputType, config?: ProgramConfig): Promise<ProgramOutput<OutputType>>;
42
+ }): CompiledProgram<InputType, OutputType>;
43
+ //# sourceMappingURL=CompiledProgram.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompiledProgram.d.ts","sourceRoot":"","sources":["../../../src/compiler/CompiledProgram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,K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CAAC;KACnD,CAAC;CACH,GACA,eAAe,CAAC,SAAS,EAAE,UAAU,CAAC,CA8BxC;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,MAAM,EAAE;QACN,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;KACnD,CAAC;CACH;AAED,wBAAgB,mBAAmB,CAAC,SAAS,GAAG,OAAO,EAAE,UAAU,GAAG,OAAO,EAC3E,UAAU,EAAE,MAAM,GAAG,yBAAyB,EAC9C,OAAO,EAAE;IACP,GAAG,CACD,KAAK,EAAE,SAAS,EAChB,MAAM,CAAC,EAAE,aAAa,GACrB,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;CACvC,GACA,eAAe,CAAC,SAAS,EAAE,UAAU,CAAC,CAkBxC"}
@@ -0,0 +1,41 @@
1
+ export function createCompiledProgram(originalProgram, compilationResult) {
2
+ return {
3
+ async run(input, overrides) {
4
+ return originalProgram.run(input, {
5
+ instructions: overrides?.instructions ?? compilationResult.config.instructions,
6
+ fewShotExamples: overrides?.fewShotExamples ??
7
+ compilationResult.config.fewShotExamples.map((ex) => ({
8
+ input: ex.input,
9
+ output: ex.output,
10
+ })),
11
+ });
12
+ },
13
+ meta: compilationResult.meta,
14
+ config: compilationResult.config,
15
+ toJSON() {
16
+ return JSON.stringify({
17
+ meta: compilationResult.meta,
18
+ config: compilationResult.config,
19
+ }, null, 2);
20
+ },
21
+ };
22
+ }
23
+ export function loadCompiledProgram(jsonOrPath, program) {
24
+ let data;
25
+ if (typeof jsonOrPath === "string") {
26
+ try {
27
+ data = JSON.parse(jsonOrPath);
28
+ }
29
+ catch {
30
+ throw new Error("Invalid JSON string provided to loadCompiledProgram");
31
+ }
32
+ }
33
+ else {
34
+ data = jsonOrPath;
35
+ }
36
+ if (!data.meta || !data.config) {
37
+ throw new Error("Invalid compiled program format: missing meta or config");
38
+ }
39
+ return createCompiledProgram(program, data);
40
+ }
41
+ //# sourceMappingURL=CompiledProgram.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompiledProgram.js","sourceRoot":"","sources":["../../../src/compiler/CompiledProgram.ts"],"names":[],"mappings":"AA0BA,MAAM,UAAU,qBAAqB,CAMnC,eAKC,EACD,iBAMC;IAED,OAAO;QACL,KAAK,CAAC,GAAG,CACP,KAAgB,EAChB,SAAkC;YAElC,OAAO,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE;gBAChC,YAAY,EACV,SAAS,EAAE,YAAY,IAAI,iBAAiB,CAAC,MAAM,CAAC,YAAY;gBAClE,eAAe,EACb,SAAS,EAAE,eAAe;oBAC1B,iBAAiB,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;wBACpD,KAAK,EAAE,EAAE,CAAC,KAAgC;wBAC1C,MAAM,EAAE,EAAE,CAAC,MAAiC;qBAC7C,CAAC,CAAC;aACN,CAAC,CAAC;QACL,CAAC;QACD,IAAI,EAAE,iBAAiB,CAAC,IAAI;QAC5B,MAAM,EAAE,iBAAiB,CAAC,MAAM;QAChC,MAAM;YACJ,OAAO,IAAI,CAAC,SAAS,CACnB;gBACE,IAAI,EAAE,iBAAiB,CAAC,IAAI;gBAC5B,MAAM,EAAE,iBAAiB,CAAC,MAAM;aACjC,EACD,IAAI,EACJ,CAAC,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAUD,MAAM,UAAU,mBAAmB,CACjC,UAA8C,EAC9C,OAKC;IAED,IAAI,IAA+B,CAAC;IAEpC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { ZodRawShape } from "zod";
2
+ import { Program } from "../program/Program.js";
3
+ import type { LLMProvider } from "../providers/types.js";
4
+ import type { Evaluator, Example, CompilationResult, CompileOptions } from "./types.js";
5
+ export interface InstructionRewriteOptions extends CompileOptions {
6
+ instructionVariations?: number;
7
+ provider: LLMProvider;
8
+ }
9
+ export declare class InstructionRewrite<O> {
10
+ private evaluator;
11
+ constructor(evaluator: Evaluator<O>);
12
+ compile<I extends ZodRawShape, OShape extends ZodRawShape>(program: Program<I, OShape>, trainset: Example<unknown, O>[], options: InstructionRewriteOptions): Promise<CompilationResult<unknown, O>>;
13
+ private generateInstructionVariants;
14
+ estimateCost(trainsetSize: number, options?: Partial<InstructionRewriteOptions>): {
15
+ estimatedCalls: number;
16
+ estimatedTokens: number;
17
+ };
18
+ }
19
+ //# sourceMappingURL=InstructionRewrite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstructionRewrite.d.ts","sourceRoot":"","sources":["../../../src/compiler/InstructionRewrite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,EAAE,WAAW,CAAC;CACvB;AAED,qBAAa,kBAAkB,CAAC,CAAC;IACnB,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;IAErC,OAAO,CAAC,CAAC,SAAS,WAAW,EAAE,MAAM,SAAS,WAAW,EAC7D,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,EAC3B,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAC/B,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAiH3B,2BAA2B;IAoCzC,YAAY,CACV,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,OAAO,CAAC,yBAAyB,CAAM,GAC/C;QACD,cAAc,EAAE,MAAM,CAAC;QACvB,eAAe,EAAE,MAAM,CAAC;KACzB;CAmBF"}
@@ -0,0 +1,117 @@
1
+ import { createConcurrencyManager } from "../runtime/concurrency.js";
2
+ import { CostTracker } from "../runtime/costTracker.js";
3
+ import { CandidatePool } from "./CandidatePool.js";
4
+ export class InstructionRewrite {
5
+ evaluator;
6
+ constructor(evaluator) {
7
+ this.evaluator = evaluator;
8
+ }
9
+ async compile(program, trainset, options) {
10
+ const { candidates: candidateCount = 5, instructionVariations = 5, concurrency = 5, examplesPerCandidate = 3, validationSplit = 0.3, seed, budget, provider, } = options;
11
+ const baseDescription = program["schema"].description;
12
+ const pool = new CandidatePool(trainset, seed);
13
+ const validationSet = pool.getValidationSet(validationSplit);
14
+ const limiter = createConcurrencyManager(concurrency);
15
+ const costTracker = new CostTracker();
16
+ const instructionVariants = await this.generateInstructionVariants(provider, baseDescription, instructionVariations);
17
+ const fewShotCandidates = pool.generateFewShotCandidates(candidateCount, examplesPerCandidate);
18
+ const allCandidates = [];
19
+ for (const instruction of instructionVariants) {
20
+ for (const examples of fewShotCandidates) {
21
+ allCandidates.push({ instructions: instruction, examples });
22
+ }
23
+ }
24
+ const results = [];
25
+ const evaluationPromises = allCandidates.map((candidate) => limiter.run(async () => {
26
+ if (budget?.maxTokens && costTracker.exceedsBudget(budget.maxTokens)) {
27
+ budget.onBudgetWarning?.(costTracker.total.totalTokens, budget.maxTokens);
28
+ return { score: -1, ...candidate };
29
+ }
30
+ let totalScore = 0;
31
+ let validCount = 0;
32
+ for (const testCase of validationSet) {
33
+ try {
34
+ const prediction = await program.run(testCase.input, {
35
+ instructions: candidate.instructions,
36
+ fewShotExamples: candidate.examples.map((ex) => ({
37
+ input: ex.input,
38
+ output: ex.output,
39
+ })),
40
+ });
41
+ costTracker.record(prediction.trace.usage);
42
+ const score = await this.evaluator(prediction.result, testCase.output);
43
+ totalScore += score;
44
+ validCount++;
45
+ }
46
+ catch {
47
+ continue;
48
+ }
49
+ }
50
+ return {
51
+ score: validCount > 0 ? totalScore / validCount : 0,
52
+ ...candidate,
53
+ };
54
+ }));
55
+ const candidateResults = await Promise.all(evaluationPromises);
56
+ results.push(...candidateResults.filter((r) => r.score >= 0));
57
+ const winner = results.reduce((best, current) => (current.score > best.score ? current : best), {
58
+ score: -1,
59
+ instructions: baseDescription,
60
+ examples: [],
61
+ });
62
+ return {
63
+ meta: {
64
+ score: winner.score,
65
+ compiledAt: new Date().toISOString(),
66
+ strategy: "InstructionRewrite",
67
+ tokenUsage: costTracker.total,
68
+ },
69
+ config: {
70
+ instructions: winner.instructions,
71
+ fewShotExamples: winner.examples,
72
+ },
73
+ };
74
+ }
75
+ async generateInstructionVariants(provider, baseInstruction, count) {
76
+ const prompt = `You are an expert prompt engineer. Given a base instruction for an LLM task, generate ${count} different variations that might perform better.
77
+
78
+ Base instruction: "${baseInstruction}"
79
+
80
+ Requirements:
81
+ - Each variation should convey the same task but with different wording, tone, or structure
82
+ - Try variations like: more specific, more concise, role-based ("You are an expert..."), step-by-step, formal, casual
83
+ - Output as a JSON array of strings
84
+
85
+ Respond with ONLY a JSON array, no additional text:
86
+ ["variation 1", "variation 2", ...]`;
87
+ const response = await provider.complete({
88
+ prompt,
89
+ temperature: 0.8,
90
+ maxTokens: 1024,
91
+ responseFormat: "json",
92
+ });
93
+ try {
94
+ const jsonMatch = response.content.match(/\[[\s\S]*\]/);
95
+ if (!jsonMatch) {
96
+ return [baseInstruction];
97
+ }
98
+ const variations = JSON.parse(jsonMatch[0]);
99
+ return [baseInstruction, ...variations.slice(0, count)];
100
+ }
101
+ catch {
102
+ return [baseInstruction];
103
+ }
104
+ }
105
+ estimateCost(trainsetSize, options = {}) {
106
+ const { candidates = 5, instructionVariations = 5, validationSplit = 0.3, } = options;
107
+ const validationSize = Math.max(1, Math.floor(trainsetSize * validationSplit));
108
+ const totalCandidates = candidates * instructionVariations;
109
+ const estimatedCalls = totalCandidates * validationSize + 1;
110
+ const avgTokensPerCall = 500;
111
+ return {
112
+ estimatedCalls,
113
+ estimatedTokens: estimatedCalls * avgTokensPerCall,
114
+ };
115
+ }
116
+ }
117
+ //# sourceMappingURL=InstructionRewrite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstructionRewrite.js","sourceRoot":"","sources":["../../../src/compiler/InstructionRewrite.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAcnD,MAAM,OAAO,kBAAkB;IACT;IAApB,YAAoB,SAAuB;QAAvB,cAAS,GAAT,SAAS,CAAc;IAAG,CAAC;IAE/C,KAAK,CAAC,OAAO,CACX,OAA2B,EAC3B,QAA+B,EAC/B,OAAkC;QAElC,MAAM,EACJ,UAAU,EAAE,cAAc,GAAG,CAAC,EAC9B,qBAAqB,GAAG,CAAC,EACzB,WAAW,GAAG,CAAC,EACf,oBAAoB,GAAG,CAAC,EACxB,eAAe,G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CAAC;QAC1D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,eAAe,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,YAAY,CACV,YAAoB,EACpB,UAA8C,EAAE;QAKhD,MAAM,EACJ,UAAU,GAAG,CAAC,EACd,qBAAqB,GAAG,CAAC,EACzB,eAAe,GAAG,GAAG,GACtB,GAAG,OAAO,CAAC;QACZ,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAC7B,CAAC,EACD,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,eAAe,CAAC,CAC3C,CAAC;QACF,MAAM,eAAe,GAAG,UAAU,GAAG,qBAAqB,CAAC;QAC3D,MAAM,cAAc,GAAG,eAAe,GAAG,cAAc,GAAG,CAAC,CAAC;QAC5D,MAAM,gBAAgB,GAAG,GAAG,CAAC;QAE7B,OAAO;YACL,cAAc;YACd,eAAe,EAAE,cAAc,GAAG,gBAAgB;SACnD,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ export { BootstrapFewShot } from "./BootstrapFewShot.js";
2
+ export { InstructionRewrite } from "./InstructionRewrite.js";
3
+ export type { InstructionRewriteOptions } from "./InstructionRewrite.js";
4
+ export { CandidatePool } from "./CandidatePool.js";
5
+ export { createCompiledProgram, loadCompiledProgram, } from "./CompiledProgram.js";
6
+ export type { CompiledProgram, CompiledProgramMeta, SerializedCompiledProgram, } from "./CompiledProgram.js";
7
+ export type { Evaluator, Example, CompilationResult, CompileOptions, } from "./types.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,SAAS,EACT,OAAO,EACP,iBAAiB,EACjB,cAAc,GACf,MAAM,YAAY,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { BootstrapFewShot } from "./BootstrapFewShot.js";
2
+ export { InstructionRewrite } from "./InstructionRewrite.js";
3
+ export { CandidatePool } from "./CandidatePool.js";
4
+ export { createCompiledProgram, loadCompiledProgram, } from "./CompiledProgram.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,41 @@
1
+ export type Evaluator<O> = (prediction: O, groundTruth: O) => number | Promise<number>;
2
+ export interface Example<I, O> {
3
+ input: I;
4
+ output: O;
5
+ }
6
+ export interface CompilationResult<I, O> {
7
+ meta: {
8
+ score: number;
9
+ compiledAt: string;
10
+ strategy: string;
11
+ tokenUsage: {
12
+ inputTokens: number;
13
+ outputTokens: number;
14
+ totalTokens: number;
15
+ calls: number;
16
+ };
17
+ };
18
+ config: {
19
+ instructions: string;
20
+ fewShotExamples: Array<Example<I, O>>;
21
+ };
22
+ }
23
+ export interface CompileOptions {
24
+ candidates?: number;
25
+ concurrency?: number;
26
+ examplesPerCandidate?: number;
27
+ validationSplit?: number;
28
+ seed?: number;
29
+ earlyStopThreshold?: number;
30
+ budget?: {
31
+ maxTokens?: number;
32
+ onBudgetWarning?: (used: number, max: number) => void;
33
+ };
34
+ onProgress?: (progress: {
35
+ candidatesEvaluated: number;
36
+ totalCandidates: number;
37
+ currentBestScore: number;
38
+ tokensUsed: number;
39
+ }) => void;
40
+ }
41
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/compiler/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CACzB,UAAU,EAAE,CAAC,EACb,WAAW,EAAE,CAAC,KACX,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9B,MAAM,WAAW,OAAO,CAAC,CAAC,EAAE,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,CAAC,CAAC;CACX;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,EAAE,CAAC;IACrC,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE;YACV,WAAW,EAAE,MAAM,CAAC;YACpB,YAAY,EAAE,MAAM,CAAC;YACrB,WAAW,EAAE,MAAM,CAAC;YACpB,KAAK,EAAE,MAAM,CAAC;SACf,CAAC;KACH,CAAC;IACF,MAAM,EAAE;QACN,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KACvC,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE;QACP,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;KACvD,CAAC;IACF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE;QACtB,mBAAmB,EAAE,MAAM,CAAC;QAC5B,eAAe,EAAE,MAAM,CAAC;QACxB,gBAAgB,EAAE,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,IAAI,CAAC;CACZ"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/compiler/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { Evaluator } from "./types.js";
2
+ export declare function exactMatch<O>(): Evaluator<O>;
3
+ export declare function partialMatch<O extends Record<string, unknown>>(): Evaluator<O>;
4
+ export declare function arrayOverlap<T>(): Evaluator<T[]>;
5
+ //# sourceMappingURL=exactMatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exactMatch.d.ts","sourceRoot":"","sources":["../../../src/eval/exactMatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAyB5C,wBAAgB,UAAU,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAI5C;AAED,wBAAgB,YAAY,CAC1B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,SAAS,CAAC,CAAC,CAAC,CAchB;AAED,wBAAgB,YAAY,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC,CAehD"}
@@ -0,0 +1,58 @@
1
+ function deepEqual(a, b) {
2
+ if (a === b)
3
+ return true;
4
+ if (typeof a !== typeof b)
5
+ return false;
6
+ if (a === null || b === null)
7
+ return a === b;
8
+ if (Array.isArray(a) && Array.isArray(b)) {
9
+ if (a.length !== b.length)
10
+ return false;
11
+ return a.every((item, i) => deepEqual(item, b[i]));
12
+ }
13
+ if (typeof a === "object" && typeof b === "object") {
14
+ const aObj = a;
15
+ const bObj = b;
16
+ const aKeys = Object.keys(aObj);
17
+ const bKeys = Object.keys(bObj);
18
+ if (aKeys.length !== bKeys.length)
19
+ return false;
20
+ return aKeys.every((key) => deepEqual(aObj[key], bObj[key]));
21
+ }
22
+ return false;
23
+ }
24
+ export function exactMatch() {
25
+ return (prediction, groundTruth) => {
26
+ return deepEqual(prediction, groundTruth) ? 1.0 : 0.0;
27
+ };
28
+ }
29
+ export function partialMatch() {
30
+ return (prediction, groundTruth) => {
31
+ const keys = Object.keys(groundTruth);
32
+ if (keys.length === 0)
33
+ return 1.0;
34
+ let matchCount = 0;
35
+ for (const key of keys) {
36
+ if (deepEqual(prediction[key], groundTruth[key])) {
37
+ matchCount++;
38
+ }
39
+ }
40
+ return matchCount / keys.length;
41
+ };
42
+ }
43
+ export function arrayOverlap() {
44
+ return (prediction, groundTruth) => {
45
+ if (groundTruth.length === 0)
46
+ return prediction.length === 0 ? 1.0 : 0.0;
47
+ const predSet = new Set(prediction.map((x) => JSON.stringify(x)));
48
+ const truthSet = new Set(groundTruth.map((x) => JSON.stringify(x)));
49
+ let intersection = 0;
50
+ for (const item of predSet) {
51
+ if (truthSet.has(item))
52
+ intersection++;
53
+ }
54
+ const union = new Set([...predSet, ...truthSet]).size;
55
+ return union > 0 ? intersection / union : 0;
56
+ };
57
+ }
58
+ //# sourceMappingURL=exactMatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exactMatch.js","sourceRoot":"","sources":["../../../src/eval/exactMatch.ts"],"names":[],"mappings":"AAEA,SAAS,SAAS,CAAC,CAAU,EAAE,CAAU;IACvC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,IAA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KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QACtD,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type { Evaluator } from "./types.js";
2
+ export { exactMatch, partialMatch, arrayOverlap } from "./exactMatch.js";
3
+ export { llmJudge } from "./llmJudge.js";
4
+ export type { LLMJudgeConfig } from "./llmJudge.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/eval/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { exactMatch, partialMatch, arrayOverlap } from "./exactMatch.js";
2
+ export { llmJudge } from "./llmJudge.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/eval/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { LLMProvider } from "../providers/types.js";
2
+ import type { Evaluator } from "./types.js";
3
+ export interface LLMJudgeConfig {
4
+ provider: LLMProvider;
5
+ criteria?: string;
6
+ model?: string;
7
+ }
8
+ export declare function llmJudge<O>(config: LLMJudgeConfig): Evaluator<O>;
9
+ //# sourceMappingURL=llmJudge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llmJudge.d.ts","sourceRoot":"","sources":["../../../src/eval/llmJudge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,WAAW,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,CAmChE"}
@@ -0,0 +1,33 @@
1
+ export function llmJudge(config) {
2
+ const { provider, criteria = "accuracy and completeness", model } = config;
3
+ return async (prediction, groundTruth) => {
4
+ const prompt = `You are evaluating the quality of an AI response.
5
+
6
+ EXPECTED OUTPUT:
7
+ ${JSON.stringify(groundTruth, null, 2)}
8
+
9
+ ACTUAL OUTPUT:
10
+ ${JSON.stringify(prediction, null, 2)}
11
+
12
+ EVALUATION CRITERIA: ${criteria}
13
+
14
+ Rate the actual output on a scale from 0.0 to 1.0, where:
15
+ - 1.0 = Perfect match or equivalent
16
+ - 0.5 = Partially correct
17
+ - 0.0 = Completely wrong
18
+
19
+ Respond with ONLY a number between 0.0 and 1.0, nothing else.`;
20
+ const response = await provider.complete({
21
+ prompt,
22
+ model,
23
+ temperature: 0,
24
+ maxTokens: 10,
25
+ });
26
+ const score = parseFloat(response.content.trim());
27
+ if (isNaN(score) || score < 0 || score > 1) {
28
+ return 0;
29
+ }
30
+ return score;
31
+ };
32
+ }
33
+ //# sourceMappingURL=llmJudge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llmJudge.js","sourceRoot":"","sources":["../../../src/eval/llmJudge.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,QAAQ,CAAI,MAAsB;IAChD,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,2BAA2B,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAE3E,OAAO,KAAK,EAAE,UAAa,EAAE,WAAc,EAAmB,EAAE;QAC9D,MAAM,MAAM,GAAG;;;EAGjB,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;;;EAGpC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;;uBAEd,QAAQ;;;;;;;8DAO+B,CAAC;QAE3D,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC;YACvC,MAAM;YACN,KAAK;YACL,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,EAAE;SACd,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAClD,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YAC3C,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type Evaluator<O> = (prediction: O, groundTruth: O) => number | Promise<number>;
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/eval/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CACzB,UAAU,EAAE,CAAC,EACb,WAAW,EAAE,CAAC,KACX,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/eval/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ export { z } from "zod";
2
+ export { Schema, defineSchema } from "./schema/index.js";
3
+ export type { SchemaDefinition } from "./schema/index.js";
4
+ export { createProvider, OpenAIProvider, AnthropicProvider, GoogleProvider, OllamaProvider, GroqProvider, CerebrasProvider, } from "./providers/index.js";
5
+ export type { LLMProvider, CompletionParams, CompletionResult, ProviderConfig, ProviderName, } from "./providers/index.js";
6
+ export { Program, Predict, ChainOfThought } from "./program/index.js";
7
+ export type { ProgramConfig, ProgramOutput, ProgramTrace, } from "./program/index.js";
8
+ export { BootstrapFewShot, InstructionRewrite, CandidatePool, createCompiledProgram, loadCompiledProgram, } from "./compiler/index.js";
9
+ export type { Evaluator, Example, CompilationResult, CompileOptions, CompiledProgram, CompiledProgramMeta, SerializedCompiledProgram, InstructionRewriteOptions, } from "./compiler/index.js";
10
+ export { exactMatch, partialMatch, arrayOverlap, llmJudge, } from "./eval/index.js";
11
+ export type { LLMJudgeConfig } from "./eval/index.js";
12
+ export { createConcurrencyManager, CostTracker, estimateCost, withRetry, createRetryWrapper, PromptCache, createCache, } from "./runtime/index.js";
13
+ export type { ConcurrencyManager, TokenUsage, CostEstimate, RetryOptions, CacheOptions, } from "./runtime/index.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EACL,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACtE,YAAY,EACV,aAAa,EACb,aAAa,EACb,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,SAAS,EACT,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,GACT,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EACL,wBAAwB,EACxB,WAAW,EACX,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { z } from "zod";
2
+ export { Schema, defineSchema } from "./schema/index.js";
3
+ export { createProvider, OpenAIProvider, AnthropicProvider, GoogleProvider, OllamaProvider, GroqProvider, CerebrasProvider, } from "./providers/index.js";
4
+ export { Program, Predict, ChainOfThought } from "./program/index.js";
5
+ export { BootstrapFewShot, InstructionRewrite, CandidatePool, createCompiledProgram, loadCompiledProgram, } from "./compiler/index.js";
6
+ export { exactMatch, partialMatch, arrayOverlap, llmJudge, } from "./eval/index.js";
7
+ export { createConcurrencyManager, CostTracker, estimateCost, withRetry, createRetryWrapper, PromptCache, createCache, } from "./runtime/index.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EACL,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAS9B,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAOtE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAY7B,OAAO,EACL,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,GACT,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,wBAAwB,EACxB,WAAW,EACX,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,WAAW,GACZ,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { z, ZodRawShape, ZodObject } from "zod";
2
+ import { Program, ProgramConfig, ProgramOutput } from "./Program.js";
3
+ export declare class ChainOfThought<I extends ZodRawShape, O extends ZodRawShape> extends Program<I, O> {
4
+ run(input: z.infer<ZodObject<I>>, config?: ProgramConfig): Promise<ProgramOutput<z.infer<ZodObject<O>>>>;
5
+ }
6
+ //# sourceMappingURL=ChainOfThought.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChainOfThought.d.ts","sourceRoot":"","sources":["../../../src/program/ChainOfThought.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAErE,qBAAa,cAAc,CACzB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,WAAW,CACrB,SAAQ,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IACf,GAAG,CACP,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAC5B,MAAM,GAAE,aAAkB,GACzB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAgDjD"}
@@ -0,0 +1,44 @@
1
+ import { Program } from "./Program.js";
2
+ export class ChainOfThought extends Program {
3
+ async run(input, config = {}) {
4
+ const startTime = Date.now();
5
+ const validatedInput = this.schema.validateInput(input);
6
+ const instructions = config.instructions || this.schema.description;
7
+ const fewShotSection = this.buildFewShotString(config.fewShotExamples);
8
+ const outputKeys = this.schema.getOutputKeys();
9
+ const outputFormat = outputKeys
10
+ .map((k) => `"${k}": <value>`)
11
+ .join(",\n ");
12
+ const prompt = `${instructions}
13
+
14
+ ${fewShotSection ? `Here are some examples:\n\n${fewShotSection}\n\n` : ""}Think through this step-by-step before providing your answer.
15
+
16
+ Input: ${JSON.stringify(validatedInput)}
17
+
18
+ Respond with valid JSON in this exact format:
19
+ {
20
+ "reasoning": "Your step-by-step thinking process...",
21
+ ${outputFormat}
22
+ }
23
+
24
+ Respond ONLY with valid JSON, no additional text.`;
25
+ const response = await this.provider.complete({
26
+ prompt,
27
+ responseFormat: "json",
28
+ });
29
+ const parsed = this.parseJsonResponse(response.content);
30
+ const reasoning = parsed.reasoning;
31
+ delete parsed.reasoning;
32
+ const result = this.schema.validateOutput(parsed);
33
+ return {
34
+ result,
35
+ trace: {
36
+ promptUsed: prompt,
37
+ reasoning,
38
+ usage: response.usage,
39
+ latencyMs: Date.now() - startTime,
40
+ },
41
+ };
42
+ }
43
+ }
44
+ //# sourceMappingURL=ChainOfThought.js.map