pi-para 0.5.5 → 0.6.1
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/ARCHITECTURE.md +0 -9
- package/CHANGELOG.md +35 -0
- package/CONFIGURATION.md +0 -23
- package/README.md +1 -29
- package/SETUP.md +1 -1
- package/STRUCTURE.md +0 -9
- package/dist/cli.js +0 -84
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +0 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -14
- package/dist/config.js.map +1 -1
- package/dist/doctor.js +5 -0
- package/dist/doctor.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -18
- package/dist/index.js.map +1 -1
- package/dist/templates/prompts.d.ts +0 -12
- package/dist/templates/prompts.d.ts.map +1 -1
- package/dist/templates/prompts.js +0 -57
- package/dist/templates/prompts.js.map +1 -1
- package/package.json +9 -5
- package/scripts/build-assets.mjs +17 -0
- package/scripts/install.ps1 +27 -16
- package/scripts/install.sh +3 -2
- package/scripts/smoke-install.mjs +5 -3
- package/skills/setup/SKILL.md +1 -1
- package/src/cli.ts +0 -70
- package/src/config.ts +0 -25
- package/src/doctor.ts +5 -0
- package/src/index.ts +1 -38
- package/src/templates/prompts.ts +0 -56
- package/dist/gepa/dataset.d.ts +0 -36
- package/dist/gepa/dataset.d.ts.map +0 -1
- package/dist/gepa/dataset.js +0 -148
- package/dist/gepa/dataset.js.map +0 -1
- package/dist/gepa/evaluator.d.ts +0 -51
- package/dist/gepa/evaluator.d.ts.map +0 -1
- package/dist/gepa/evaluator.js +0 -317
- package/dist/gepa/evaluator.js.map +0 -1
- package/dist/gepa/index.d.ts +0 -66
- package/dist/gepa/index.d.ts.map +0 -1
- package/dist/gepa/index.js +0 -240
- package/dist/gepa/index.js.map +0 -1
- package/dist/gepa/llm.d.ts +0 -35
- package/dist/gepa/llm.d.ts.map +0 -1
- package/dist/gepa/llm.js +0 -268
- package/dist/gepa/llm.js.map +0 -1
- package/dist/gepa/optimized/capture-prompt.txt +0 -65
- package/dist/gepa/optimizer.d.ts +0 -29
- package/dist/gepa/optimizer.d.ts.map +0 -1
- package/dist/gepa/optimizer.js +0 -249
- package/dist/gepa/optimizer.js.map +0 -1
- package/dist/gepa/targets.d.ts +0 -39
- package/dist/gepa/targets.d.ts.map +0 -1
- package/dist/gepa/targets.js +0 -326
- package/dist/gepa/targets.js.map +0 -1
- package/dist/gepa/types.d.ts +0 -168
- package/dist/gepa/types.d.ts.map +0 -1
- package/dist/gepa/types.js +0 -124
- package/dist/gepa/types.js.map +0 -1
- package/scripts/gepa/__pycache__/dataset.cpython-313.pyc +0 -0
- package/scripts/gepa/__pycache__/lm_providers.cpython-313.pyc +0 -0
- package/scripts/gepa/__pycache__/metric.cpython-313.pyc +0 -0
- package/scripts/gepa/__pycache__/program.cpython-313.pyc +0 -0
- package/scripts/gepa/__pycache__/wiki_reader.cpython-313.pyc +0 -0
- package/scripts/gepa/dataset.py +0 -192
- package/scripts/gepa/lm_providers.py +0 -472
- package/scripts/gepa/metric.py +0 -279
- package/scripts/gepa/optimize.py +0 -367
- package/scripts/gepa/program.py +0 -99
- package/scripts/gepa/pyproject.toml +0 -19
- package/scripts/gepa/run-all.sh +0 -53
- package/scripts/gepa/uv.lock +0 -2241
- package/scripts/gepa/wiki_reader.py +0 -113
- package/src/gepa/index.ts +0 -287
- package/src/gepa/optimized/capture-prompt.txt +0 -65
package/dist/gepa/targets.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"targets.js","sourceRoot":"","sources":["../../src/gepa/targets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAA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CAAC,IAAI;QACd,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,UAAU,EAAE,GAAG,CAAC,QAAQ;QACxB,WAAW,EAAE,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC;QAChD,iBAAiB,EAAE,GAAG,CAAC,UAAU;QACjC,QAAQ,EAAE,GAAG,CAAC,QAAQ;KACvB,CAAC;AACJ,CAAC;AAED,wBAAwB;AACxB,MAAM,UAAU,WAAW;IACzB,OAAO,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAClC,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,UAAU,EAAE,GAAG,CAAC,QAAQ;QACxB,WAAW,EAAE,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC;QAChD,iBAAiB,EAAE,GAAG,CAAC,UAAU;QACjC,QAAQ,EAAE,GAAG,CAAC,QAAQ;KACvB,CAAC,CAAC,CAAC;AACN,CAAC;AAED,4BAA4B;AAC5B,MAAM,UAAU,eAAe;IAC7B,OAAO,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/gepa/types.d.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GEPA (Genetic-Evolutionary Prompt Adaptation) — shared types.
|
|
3
|
-
*
|
|
4
|
-
* All types used across the GEPA optimizer pipeline:
|
|
5
|
-
* config, targets, candidates, evaluation, Pareto frontier, and deployment.
|
|
6
|
-
*/
|
|
7
|
-
/** GEPA optimizer configuration (stored in config.json under "gepa" key). */
|
|
8
|
-
export interface GEPAConfig {
|
|
9
|
-
/** Model for reflection/mutation. Format: "provider/model-id".
|
|
10
|
-
* Resolution: this → daemonModel → AuthStorage auto-detect → qmd config. */
|
|
11
|
-
reflectionModel: string | null;
|
|
12
|
-
/** Maximum optimization iterations per target. */
|
|
13
|
-
maxIterations: number;
|
|
14
|
-
/** Maximum number of candidates retained on the Pareto frontier. */
|
|
15
|
-
paretoSize: number;
|
|
16
|
-
/** When true, optimized prompts are loaded at runtime instead of originals. */
|
|
17
|
-
useOptimized: boolean;
|
|
18
|
-
}
|
|
19
|
-
/** Default GEPA config values. */
|
|
20
|
-
export declare const DEFAULT_GEPA_CONFIG: GEPAConfig;
|
|
21
|
-
/** The kind of content being optimized. */
|
|
22
|
-
export type TargetType = "prompt" | "skill";
|
|
23
|
-
/** An optimization target — a prompt template or skill document to improve. */
|
|
24
|
-
export interface Target {
|
|
25
|
-
/** Unique identifier (e.g. "wiki-system-prompt", "para-skill"). */
|
|
26
|
-
name: string;
|
|
27
|
-
/** Whether this is a prompt template or a skill document. */
|
|
28
|
-
type: TargetType;
|
|
29
|
-
/** Retrieve the current (original) content of this target. */
|
|
30
|
-
getCurrentContent: () => Promise<string>;
|
|
31
|
-
/** Constraints the optimizer must respect (e.g. "must include PARA categories"). */
|
|
32
|
-
constraints: string[];
|
|
33
|
-
/** Optional description of what this target does (used in reflection). */
|
|
34
|
-
description?: string;
|
|
35
|
-
/** File path where the original content lives (for reference/logging). */
|
|
36
|
-
sourcePath?: string;
|
|
37
|
-
}
|
|
38
|
-
/** A unique identifier for a candidate in the optimization run. */
|
|
39
|
-
export type CandidateId = string;
|
|
40
|
-
/** A mutated version of a target's content, with evaluation scores. */
|
|
41
|
-
export interface Candidate {
|
|
42
|
-
/** Unique identifier for this candidate. */
|
|
43
|
-
id: CandidateId;
|
|
44
|
-
/** The mutated prompt/skill content. */
|
|
45
|
-
content: string;
|
|
46
|
-
/** Composite score (0-1), computed from dimension scores. */
|
|
47
|
-
score: number;
|
|
48
|
-
/** Per-dimension evaluation results. */
|
|
49
|
-
dimensions: EvalDimension[];
|
|
50
|
-
/** Which iteration produced this candidate. */
|
|
51
|
-
iteration: number;
|
|
52
|
-
/** ID of the parent candidate this was mutated from (null for the original). */
|
|
53
|
-
parentId: CandidateId | null;
|
|
54
|
-
/** The mutation description applied to produce this candidate. */
|
|
55
|
-
mutationDescription?: string;
|
|
56
|
-
}
|
|
57
|
-
/** A single scored dimension from the LLM judge. */
|
|
58
|
-
export interface EvalDimension {
|
|
59
|
-
/** Dimension name (e.g. "clarity", "actionability"). */
|
|
60
|
-
name: string;
|
|
61
|
-
/** Score from 0 (worst) to 1 (best). */
|
|
62
|
-
score: number;
|
|
63
|
-
/** Brief textual feedback from the judge for this dimension. */
|
|
64
|
-
feedback: string;
|
|
65
|
-
/** Weight of this dimension in the composite score (0-1, should sum to 1). */
|
|
66
|
-
weight: number;
|
|
67
|
-
}
|
|
68
|
-
/** Full evaluation result returned by the LLM judge. */
|
|
69
|
-
export interface EvalResult {
|
|
70
|
-
/** Composite score (0-1), weighted average of dimension scores. */
|
|
71
|
-
score: number;
|
|
72
|
-
/** Per-dimension scores and feedback. */
|
|
73
|
-
dimensions: EvalDimension[];
|
|
74
|
-
/** Overall textual feedback from the judge. */
|
|
75
|
-
overallFeedback: string;
|
|
76
|
-
}
|
|
77
|
-
/** Standard evaluation dimensions used across all targets. */
|
|
78
|
-
export declare const STANDARD_DIMENSIONS: ReadonlyArray<{
|
|
79
|
-
name: string;
|
|
80
|
-
weight: number;
|
|
81
|
-
}>;
|
|
82
|
-
/**
|
|
83
|
-
* Pareto frontier — maintains the best non-dominated candidates.
|
|
84
|
-
*
|
|
85
|
-
* A candidate dominates another if it scores >= on ALL dimensions
|
|
86
|
-
* and strictly > on at least one. The frontier keeps only non-dominated
|
|
87
|
-
* candidates, capped at `maxSize`.
|
|
88
|
-
*/
|
|
89
|
-
export declare class ParetoFrontier {
|
|
90
|
-
private _candidates;
|
|
91
|
-
private readonly maxSize;
|
|
92
|
-
constructor(maxSize?: number);
|
|
93
|
-
/** Current candidates on the frontier. */
|
|
94
|
-
get candidates(): ReadonlyArray<Candidate>;
|
|
95
|
-
/** Number of candidates on the frontier. */
|
|
96
|
-
get size(): number;
|
|
97
|
-
/**
|
|
98
|
-
* Attempt to add a candidate to the frontier.
|
|
99
|
-
* Returns true if the candidate was added (i.e., it is non-dominated).
|
|
100
|
-
*/
|
|
101
|
-
add(candidate: Candidate): boolean;
|
|
102
|
-
/**
|
|
103
|
-
* Get the best candidate by composite score.
|
|
104
|
-
* Returns undefined if the frontier is empty.
|
|
105
|
-
*/
|
|
106
|
-
best(): Candidate | undefined;
|
|
107
|
-
/**
|
|
108
|
-
* Get the top N candidates by composite score.
|
|
109
|
-
*/
|
|
110
|
-
topN(n: number): Candidate[];
|
|
111
|
-
/** Serialize the frontier for persistence. */
|
|
112
|
-
toJSON(): CandidateJSON[];
|
|
113
|
-
/** Restore the frontier from persisted data. */
|
|
114
|
-
static fromJSON(data: CandidateJSON[], maxSize: number): ParetoFrontier;
|
|
115
|
-
}
|
|
116
|
-
/** JSON-serializable candidate shape (same as Candidate). */
|
|
117
|
-
type CandidateJSON = Omit<Candidate, never>;
|
|
118
|
-
/** A saved optimized prompt, ready for deployment. */
|
|
119
|
-
export interface OptimizedPrompt {
|
|
120
|
-
/** Target name this optimized prompt belongs to. */
|
|
121
|
-
targetName: string;
|
|
122
|
-
/** The optimized content. */
|
|
123
|
-
content: string;
|
|
124
|
-
/** Composite score achieved. */
|
|
125
|
-
score: number;
|
|
126
|
-
/** ISO timestamp when optimization completed. */
|
|
127
|
-
optimizedAt: string;
|
|
128
|
-
/** Number of iterations run. */
|
|
129
|
-
iterationsRun: number;
|
|
130
|
-
/** Model used for optimization (e.g. "anthropic/claude-opus-4-6"). */
|
|
131
|
-
modelUsed: string;
|
|
132
|
-
/** Original score before optimization (for comparison). */
|
|
133
|
-
originalScore?: number;
|
|
134
|
-
/** The dimensions breakdown. */
|
|
135
|
-
dimensions?: EvalDimension[];
|
|
136
|
-
}
|
|
137
|
-
/** Summary of a complete optimization run. */
|
|
138
|
-
export interface OptimizationRunSummary {
|
|
139
|
-
/** Target that was optimized. */
|
|
140
|
-
targetName: string;
|
|
141
|
-
/** Total iterations executed. */
|
|
142
|
-
iterations: number;
|
|
143
|
-
/** Original (baseline) score. */
|
|
144
|
-
originalScore: number;
|
|
145
|
-
/** Best score achieved. */
|
|
146
|
-
bestScore: number;
|
|
147
|
-
/** Score improvement (best - original). */
|
|
148
|
-
improvement: number;
|
|
149
|
-
/** Model used. */
|
|
150
|
-
model: string;
|
|
151
|
-
/** ISO timestamp when the run started. */
|
|
152
|
-
startedAt: string;
|
|
153
|
-
/** ISO timestamp when the run completed. */
|
|
154
|
-
completedAt: string;
|
|
155
|
-
/** Duration in seconds. */
|
|
156
|
-
durationSeconds: number;
|
|
157
|
-
/** Number of candidates that made it to the Pareto frontier. */
|
|
158
|
-
frontierSize: number;
|
|
159
|
-
}
|
|
160
|
-
/** Minimal LLM completion client interface used by the optimizer. */
|
|
161
|
-
export interface LLMClient {
|
|
162
|
-
/** Send a prompt to the LLM and get a text response. */
|
|
163
|
-
complete(prompt: string, system?: string): Promise<string>;
|
|
164
|
-
/** The model identifier being used (e.g. "anthropic/claude-opus-4-6"). */
|
|
165
|
-
modelId: string;
|
|
166
|
-
}
|
|
167
|
-
export {};
|
|
168
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/gepa/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/gepa/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,6EAA6E;AAC7E,MAAM,WAAW,UAAU;IACzB;iFAC6E;IAC7E,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B,kDAAkD;IAClD,aAAa,EAAE,MAAM,CAAC;IAEtB,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IAEnB,+EAA+E;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a,EAAE,MAAM,CAAC;IAEtB,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAElB,2DAA2D;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,gCAAgC;IAChC,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;CAC9B;AAID,8CAA8C;AAC9C,MAAM,WAAW,sBAAsB;IACrC,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IAEnB,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IAEnB,iCAAiC;IACjC,aAAa,EAAE,MAAM,CAAC;IAEtB,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;IAElB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IAEpB,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IAEd,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAElB,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IAEpB,2BAA2B;IAC3B,eAAe,EAAE,MAAM,CAAC;IAExB,gEAAgE;IAChE,YAAY,EAAE,MAAM,CAAC;CACtB;AAID,qEAAqE;AACrE,MAAM,WAAW,SAAS;IACxB,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3D,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
package/dist/gepa/types.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GEPA (Genetic-Evolutionary Prompt Adaptation) — shared types.
|
|
3
|
-
*
|
|
4
|
-
* All types used across the GEPA optimizer pipeline:
|
|
5
|
-
* config, targets, candidates, evaluation, Pareto frontier, and deployment.
|
|
6
|
-
*/
|
|
7
|
-
/** Default GEPA config values. */
|
|
8
|
-
export const DEFAULT_GEPA_CONFIG = {
|
|
9
|
-
reflectionModel: null,
|
|
10
|
-
maxIterations: 50,
|
|
11
|
-
paretoSize: 10,
|
|
12
|
-
useOptimized: false,
|
|
13
|
-
};
|
|
14
|
-
/** Standard evaluation dimensions used across all targets. */
|
|
15
|
-
export const STANDARD_DIMENSIONS = [
|
|
16
|
-
{ name: "structure", weight: 0.15 },
|
|
17
|
-
{ name: "clarity", weight: 0.25 },
|
|
18
|
-
{ name: "actionability", weight: 0.25 },
|
|
19
|
-
{ name: "completeness", weight: 0.20 },
|
|
20
|
-
{ name: "error-prevention", weight: 0.15 },
|
|
21
|
-
];
|
|
22
|
-
// -- Pareto Frontier ---------------------------------------------------------
|
|
23
|
-
/**
|
|
24
|
-
* Pareto frontier — maintains the best non-dominated candidates.
|
|
25
|
-
*
|
|
26
|
-
* A candidate dominates another if it scores >= on ALL dimensions
|
|
27
|
-
* and strictly > on at least one. The frontier keeps only non-dominated
|
|
28
|
-
* candidates, capped at `maxSize`.
|
|
29
|
-
*/
|
|
30
|
-
export class ParetoFrontier {
|
|
31
|
-
_candidates = [];
|
|
32
|
-
maxSize;
|
|
33
|
-
constructor(maxSize = 10) {
|
|
34
|
-
this.maxSize = maxSize;
|
|
35
|
-
}
|
|
36
|
-
/** Current candidates on the frontier. */
|
|
37
|
-
get candidates() {
|
|
38
|
-
return this._candidates;
|
|
39
|
-
}
|
|
40
|
-
/** Number of candidates on the frontier. */
|
|
41
|
-
get size() {
|
|
42
|
-
return this._candidates.length;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Attempt to add a candidate to the frontier.
|
|
46
|
-
* Returns true if the candidate was added (i.e., it is non-dominated).
|
|
47
|
-
*/
|
|
48
|
-
add(candidate) {
|
|
49
|
-
// Check if the new candidate is dominated by any existing candidate
|
|
50
|
-
for (const existing of this._candidates) {
|
|
51
|
-
if (dominates(existing, candidate)) {
|
|
52
|
-
return false; // dominated — don't add
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// Remove any existing candidates that are dominated by the new one
|
|
56
|
-
this._candidates = this._candidates.filter((existing) => !dominates(candidate, existing));
|
|
57
|
-
// Add the new candidate
|
|
58
|
-
this._candidates.push(candidate);
|
|
59
|
-
// If over capacity, remove the lowest-scoring candidate
|
|
60
|
-
if (this._candidates.length > this.maxSize) {
|
|
61
|
-
this._candidates.sort((a, b) => b.score - a.score);
|
|
62
|
-
this._candidates = this._candidates.slice(0, this.maxSize);
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Get the best candidate by composite score.
|
|
68
|
-
* Returns undefined if the frontier is empty.
|
|
69
|
-
*/
|
|
70
|
-
best() {
|
|
71
|
-
if (this._candidates.length === 0)
|
|
72
|
-
return undefined;
|
|
73
|
-
return this._candidates.reduce((best, c) => (c.score > best.score ? c : best));
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Get the top N candidates by composite score.
|
|
77
|
-
*/
|
|
78
|
-
topN(n) {
|
|
79
|
-
return [...this._candidates]
|
|
80
|
-
.sort((a, b) => b.score - a.score)
|
|
81
|
-
.slice(0, n);
|
|
82
|
-
}
|
|
83
|
-
/** Serialize the frontier for persistence. */
|
|
84
|
-
toJSON() {
|
|
85
|
-
return this._candidates.map((c) => ({
|
|
86
|
-
id: c.id,
|
|
87
|
-
content: c.content,
|
|
88
|
-
score: c.score,
|
|
89
|
-
dimensions: c.dimensions,
|
|
90
|
-
iteration: c.iteration,
|
|
91
|
-
parentId: c.parentId,
|
|
92
|
-
mutationDescription: c.mutationDescription,
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
/** Restore the frontier from persisted data. */
|
|
96
|
-
static fromJSON(data, maxSize) {
|
|
97
|
-
const frontier = new ParetoFrontier(maxSize);
|
|
98
|
-
for (const c of data) {
|
|
99
|
-
frontier._candidates.push(c);
|
|
100
|
-
}
|
|
101
|
-
return frontier;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Check if candidate `a` dominates candidate `b`.
|
|
106
|
-
* `a` dominates `b` if a.score >= b.score on ALL dimensions
|
|
107
|
-
* and strictly > on at least one.
|
|
108
|
-
*/
|
|
109
|
-
function dominates(a, b) {
|
|
110
|
-
if (a.dimensions.length !== b.dimensions.length)
|
|
111
|
-
return false;
|
|
112
|
-
let strictlyBetterOnAtLeastOne = false;
|
|
113
|
-
for (let i = 0; i < a.dimensions.length; i++) {
|
|
114
|
-
const aDim = a.dimensions.find((d) => d.name === b.dimensions[i].name);
|
|
115
|
-
if (!aDim)
|
|
116
|
-
return false; // different dimension sets — can't compare
|
|
117
|
-
if (aDim.score < b.dimensions[i].score)
|
|
118
|
-
return false; // a is worse on this dim
|
|
119
|
-
if (aDim.score > b.dimensions[i].score)
|
|
120
|
-
strictlyBetterOnAtLeastOne = true;
|
|
121
|
-
}
|
|
122
|
-
return strictlyBetterOnAtLeastOne;
|
|
123
|
-
}
|
|
124
|
-
//# sourceMappingURL=types.js.map
|
package/dist/gepa/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/gepa/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH,kCAAkC;AAClC,MAAM,CAAC,MAAM,mBAAmB,GAAe;IAC7C,eAAe,EAAE,IAAI;IACrB,aAAa,EAAE,EAAE;IACjB,UAAU,EAAE,EAAE;IACd,YAAY,EAAE,KAAK;CACpB,CAAC;AAsFF,8DAA8D;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAoD;IAClF,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE;IACnC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE;IACjC,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE;IACvC,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE;IACtC,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,E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AC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAKD;;;;GAIG;AACH,SAAS,SAAS,CAAC,CAAY,EAAE,CAAY;IAC3C,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,UAAU,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAE9D,IAAI,0BAA0B,GAAG,KAAK,CAAC;IAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC,CAAC,2CAA2C;QAEpE,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC,CAAC,yBAAyB;QAC/E,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK;YAAE,0BAA0B,GAAG,IAAI,CAAC;IAC5E,CAAC;IAED,OAAO,0BAA0B,CAAC;AACpC,CAAC"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/scripts/gepa/dataset.py
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"""Build trainset/valset from real wiki pages.
|
|
2
|
-
|
|
3
|
-
Each example pairs a synthetic task context (derived from the page topic)
|
|
4
|
-
with the actual page body as expected output. The proxy module runs the
|
|
5
|
-
instruction on the task context; the metric scores how well the output
|
|
6
|
-
matches the gold page.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
|
|
11
|
-
import random
|
|
12
|
-
from typing import Any
|
|
13
|
-
|
|
14
|
-
import dspy
|
|
15
|
-
|
|
16
|
-
from wiki_reader import WikiPage, load_all_pages, get_wiki_stats
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# -- Task context generators --------------------------------------------------
|
|
20
|
-
|
|
21
|
-
def _capture_context(page: WikiPage) -> str:
|
|
22
|
-
"""Generate a synthetic capture-style task context from a wiki page."""
|
|
23
|
-
scope_str = ", ".join(page.scope) if page.scope else "unknown"
|
|
24
|
-
tags_str = ", ".join(page.tags[:5]) if page.tags else ""
|
|
25
|
-
# Simulate what a session about this topic would look like
|
|
26
|
-
return (
|
|
27
|
-
f"A coding session about '{page.title}' in the {scope_str} project. "
|
|
28
|
-
f"Topics covered: {tags_str}. "
|
|
29
|
-
f"Extract and organize the key knowledge from this session into a wiki page."
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def _ingest_context(page: WikiPage) -> str:
|
|
34
|
-
"""Generate a synthetic ingest-style task context."""
|
|
35
|
-
return (
|
|
36
|
-
f"Ingest the following source material about '{page.title}' "
|
|
37
|
-
f"into the PARA wiki. Organize into a structured page with "
|
|
38
|
-
f"proper frontmatter, sections, and cross-references."
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def _query_context(page: WikiPage) -> str:
|
|
43
|
-
"""Generate a synthetic query-style task context."""
|
|
44
|
-
return (
|
|
45
|
-
f"The user asked about '{page.title}'. "
|
|
46
|
-
f"Search results returned pages related to: {', '.join(page.scope)}. "
|
|
47
|
-
f"Synthesize a helpful answer citing specific wiki pages."
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def _maintenance_context(page: WikiPage) -> str:
|
|
52
|
-
"""Generate a synthetic maintenance-style task context."""
|
|
53
|
-
link_count = len(page.links)
|
|
54
|
-
return (
|
|
55
|
-
f"Review the wiki page '{page.title}' ({page.category}/{page.slug}). "
|
|
56
|
-
f"It has {link_count} outgoing links, scope [{', '.join(page.scope)}], "
|
|
57
|
-
f"tags [{', '.join(page.tags[:5])}]. "
|
|
58
|
-
f"Check for correct categorization, missing links, and content quality."
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def _tool_context(page: WikiPage) -> str:
|
|
63
|
-
"""Generate a task context for tool instruction optimization."""
|
|
64
|
-
return (
|
|
65
|
-
f"A user wants to work with the wiki page '{page.title}' "
|
|
66
|
-
f"in category '{page.category}', scope [{', '.join(page.scope)}]. "
|
|
67
|
-
f"Guide them on how to use wiki tools effectively."
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def _skill_context(page: WikiPage) -> str:
|
|
72
|
-
"""Generate a task context for skill optimization."""
|
|
73
|
-
return (
|
|
74
|
-
f"Working on a task related to '{page.title}' in the {', '.join(page.scope)} project. "
|
|
75
|
-
f"Apply the PARA knowledge management methodology to this work."
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
# Target type → context generator
|
|
80
|
-
CONTEXT_GENERATORS = {
|
|
81
|
-
"capture": _capture_context,
|
|
82
|
-
"ingest": _ingest_context,
|
|
83
|
-
"query": _query_context,
|
|
84
|
-
"maintenance": _maintenance_context,
|
|
85
|
-
"tool": _tool_context,
|
|
86
|
-
"skill": _skill_context,
|
|
87
|
-
"system": _capture_context, # system prompts use capture-style context
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
# -- Dataset builder -----------------------------------------------------------
|
|
92
|
-
|
|
93
|
-
def build_dataset(
|
|
94
|
-
wiki_dir: str,
|
|
95
|
-
target_type: str = "capture",
|
|
96
|
-
max_examples: int = 50,
|
|
97
|
-
val_ratio: float = 0.4,
|
|
98
|
-
seed: int = 42,
|
|
99
|
-
) -> tuple[list[dspy.Example], list[dspy.Example]]:
|
|
100
|
-
"""Build train/val datasets from real wiki pages.
|
|
101
|
-
|
|
102
|
-
Args:
|
|
103
|
-
wiki_dir: Path to wiki directory (e.g. ~/.pi/wiki)
|
|
104
|
-
target_type: Type of target being optimized (capture, ingest, query, etc.)
|
|
105
|
-
max_examples: Maximum total examples
|
|
106
|
-
val_ratio: Fraction of examples for validation
|
|
107
|
-
seed: Random seed for reproducible splits
|
|
108
|
-
|
|
109
|
-
Returns:
|
|
110
|
-
(trainset, valset) — lists of dspy.Example
|
|
111
|
-
"""
|
|
112
|
-
pages = load_all_pages(wiki_dir)
|
|
113
|
-
|
|
114
|
-
if not pages:
|
|
115
|
-
raise ValueError(f"No wiki pages found in {wiki_dir}")
|
|
116
|
-
|
|
117
|
-
# Filter to pages with substantial content (at least 200 chars body)
|
|
118
|
-
good_pages = [p for p in pages if len(p.body) >= 200]
|
|
119
|
-
|
|
120
|
-
if len(good_pages) < 4:
|
|
121
|
-
raise ValueError(f"Need at least 4 pages with content, found {len(good_pages)}")
|
|
122
|
-
|
|
123
|
-
# Shuffle deterministically
|
|
124
|
-
rng = random.Random(seed)
|
|
125
|
-
rng.shuffle(good_pages)
|
|
126
|
-
|
|
127
|
-
# Limit to max_examples
|
|
128
|
-
good_pages = good_pages[:max_examples]
|
|
129
|
-
|
|
130
|
-
# Get context generator for this target type
|
|
131
|
-
gen_context = CONTEXT_GENERATORS.get(target_type, _capture_context)
|
|
132
|
-
|
|
133
|
-
# Build examples
|
|
134
|
-
examples = []
|
|
135
|
-
for page in good_pages:
|
|
136
|
-
task_context = gen_context(page)
|
|
137
|
-
|
|
138
|
-
# Gold output: the actual page body (truncated to keep examples manageable)
|
|
139
|
-
expected_output = page.body[:3000] if len(page.body) > 3000 else page.body
|
|
140
|
-
|
|
141
|
-
example = dspy.Example(
|
|
142
|
-
task_context=task_context,
|
|
143
|
-
expected_output=expected_output,
|
|
144
|
-
# Metadata for the metric
|
|
145
|
-
expected_category=page.category,
|
|
146
|
-
expected_scope=",".join(page.scope),
|
|
147
|
-
expected_slug=page.slug,
|
|
148
|
-
expected_title=page.title,
|
|
149
|
-
page_link_count=str(len(page.links)),
|
|
150
|
-
).with_inputs("task_context")
|
|
151
|
-
|
|
152
|
-
examples.append(example)
|
|
153
|
-
|
|
154
|
-
# Split into train/val
|
|
155
|
-
split_idx = max(1, int(len(examples) * (1 - val_ratio)))
|
|
156
|
-
trainset = examples[:split_idx]
|
|
157
|
-
valset = examples[split_idx:]
|
|
158
|
-
|
|
159
|
-
# Ensure minimum sizes
|
|
160
|
-
if len(trainset) < 2:
|
|
161
|
-
trainset = examples[:max(2, len(examples) // 2)]
|
|
162
|
-
valset = examples[len(trainset):]
|
|
163
|
-
if len(valset) < 2:
|
|
164
|
-
valset = trainset[-2:] # share a few from train if needed
|
|
165
|
-
|
|
166
|
-
return trainset, valset
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
def get_wiki_context(wiki_dir: str) -> str:
|
|
170
|
-
"""Build a wiki context string for the metric/evaluator."""
|
|
171
|
-
stats = get_wiki_stats(wiki_dir)
|
|
172
|
-
pages = load_all_pages(wiki_dir)
|
|
173
|
-
|
|
174
|
-
# Build a brief summary of existing pages for context
|
|
175
|
-
page_summaries = []
|
|
176
|
-
for p in pages[:30]: # Top 30 pages
|
|
177
|
-
first_line = ""
|
|
178
|
-
for line in p.body.split("\n"):
|
|
179
|
-
line = line.strip()
|
|
180
|
-
if line and not line.startswith("#"):
|
|
181
|
-
first_line = line[:100]
|
|
182
|
-
break
|
|
183
|
-
page_summaries.append(f" - [[{p.slug}]] ({p.category}): {p.title}")
|
|
184
|
-
|
|
185
|
-
context = f"""Wiki has {stats['total_pages']} pages across categories: {stats['categories']}.
|
|
186
|
-
Scopes: {', '.join(stats['unique_scopes'][:10])}.
|
|
187
|
-
Avg links/page: {stats['avg_links_per_page']}.
|
|
188
|
-
|
|
189
|
-
Existing pages:
|
|
190
|
-
{chr(10).join(page_summaries)}"""
|
|
191
|
-
|
|
192
|
-
return context
|