gepa-spo
Version:
Genetic-Pareto prompt optimizer to evolve system prompts from a few rollouts with modular support and intelligent crossover
76 lines (75 loc) • 2.86 kB
TypeScript
import type { Candidate, Module } from './types.js';
/**
* Utility functions for handling modular candidates
*/
/**
* Check if a candidate is modular (has modules array)
*/
export declare function isModular(candidate: Candidate): candidate is Candidate & {
modules: Module[];
};
/**
* Check if a candidate is single-system (has system string)
*/
export declare function isSingleSystem(candidate: Candidate): candidate is Candidate & {
system: string;
};
/**
* Get the number of modules in a candidate
*/
export declare function getModuleCount(candidate: Candidate): number;
/**
* Get a specific module by index
*/
export declare function getModule(candidate: Candidate, index: number): Module | null;
/**
* Set a specific module by index
*/
export declare function setModule(candidate: Candidate, index: number, module: Module): Candidate;
/**
* Concatenate modules into a single system prompt for backward compatibility
*/
export declare function concatenateModules(candidate: Candidate): string;
/**
* Serialize a candidate to a string representation for storage
*/
export declare function serializeCandidate(candidate: Candidate): string;
/**
* Deserialize a candidate from a string representation
*/
export declare function deserializeCandidate(serialized: string): Candidate;
/**
* Create a deep copy of a candidate
*/
export declare function cloneCandidate(candidate: Candidate): Candidate;
/**
* Validate that a candidate has the expected structure
*/
export declare function validateCandidate(candidate: Candidate): void;
/**
* Merge two parent candidates to create a child candidate
* Uses module-level ancestry and scores to determine which modules to take from each parent
*/
export declare function mergeCandidates(parentA: Candidate, parentB: Candidate, lineageA: number[], lineageB: number[], scoreA: number, scoreB: number): Candidate;
/**
* Check if two candidates are direct ancestors/descendants
*/
export declare function areDirectRelatives(candidateIndexA: number, candidateIndexB: number, lineage: Array<{
candidateIndex: number;
parentIndex?: number;
}>): boolean;
/**
* Check if a merge triplet (parentA, parentB, ancestor) has been tried before
*/
export declare function hasBeenTriedBefore(parentAIndex: number, parentBIndex: number, ancestorIndex: number, triedTriplets: Array<[number, number, number]>): boolean;
/**
* Find a shared ancestor between two candidates
*/
export declare function findSharedAncestor(candidateIndexA: number, candidateIndexB: number, lineage: Array<{
candidateIndex: number;
parentIndex?: number;
}>): number | null;
/**
* Check if a merged candidate introduces module-level novelty
*/
export declare function hasModuleNovelty(mergedCandidate: Candidate, parentA: Candidate, parentB: Candidate, lineageA: number[], lineageB: number[]): boolean;