Skip to content

Commit d25b9da

Browse files
committed
Clarify __call__
1 parent c1b2ec1 commit d25b9da

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

docs/docs/api/optimizers/GEPA.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,25 @@ We invite community contributions of new instruction proposers for specialized d
149149

150150
### How to Implement Custom Instruction Proposers
151151

152-
Custom instruction proposers must implement the `ProposalFn` protocol:
152+
Custom instruction proposers must implement the `ProposalFn` protocol by defining a callable class or function. GEPA will call your proposer during optimization:
153153

154154
```python
155155
from dspy.teleprompt.gepa.gepa_utils import ReflectiveExample
156156

157-
def __call__(
158-
self,
159-
candidate: dict[str, str], # Candidate component name -> instruction mapping to be updated in this round
160-
reflective_dataset: dict[str, list[ReflectiveExample]], # Component -> examples with structure: {"Inputs": ..., "Generated Outputs": ..., "Feedback": ...}
161-
components_to_update: list[str] # Which components to improve
162-
) -> dict[str, str]: # Return new instruction mapping only for components being updated
157+
class CustomInstructionProposer:
158+
def __call__(
159+
self,
160+
candidate: dict[str, str], # Candidate component name -> instruction mapping to be updated in this round
161+
reflective_dataset: dict[str, list[ReflectiveExample]], # Component -> examples with structure: {"Inputs": ..., "Generated Outputs": ..., "Feedback": ...}
162+
components_to_update: list[str] # Which components to improve
163+
) -> dict[str, str]: # Return new instruction mapping only for components being updated
164+
# Your custom instruction generation logic here
165+
return updated_instructions
166+
167+
# Or as a function:
168+
def custom_instruction_proposer(candidate, reflective_dataset, components_to_update):
169+
# Your custom instruction generation logic here
170+
return updated_instructions
163171
```
164172

165173
**Reflective Dataset Structure:**

0 commit comments

Comments
 (0)