Skip to content

Commit a086646

Browse files
committed
refactor(gepa): unify config extraction patterns
- Use isinstance(v, str) for predictor filtering (type-based) - Use .get("tools", {}) for tools extraction (more Pythonic) Both changes make the code more consistent and resilient to config structure changes.
1 parent d3693c9 commit a086646

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

dspy/teleprompt/gepa/gepa_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ def build_program(self, candidate: dict[str, str]):
217217
if isinstance(instruction, str):
218218
improved_predictors[pred_name] = instruction
219219

220-
if "tools" in config:
221-
improved_tools.update(config["tools"])
220+
improved_tools.update(config.get("tools", {}))
222221

223222
# Update predictor instructions
224223
for name, pred in new_prog.named_predictors():

dspy/teleprompt/gepa/instruction_proposal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ def __call__(
385385
# Deserialize module config
386386
current_module_config = json.loads(candidate[module_key])
387387

388-
# Extract predictor keys (all keys except "tools")
388+
# Extract predictor keys (strings are predictor instructions)
389389
# Predictor keys are expected to be 1 for tool modules and 2 for ReAct modules (extra extract predictor)
390-
predictor_keys = [k for k in current_module_config if k != "tools"]
390+
predictor_keys = [k for k, v in current_module_config.items() if isinstance(v, str)]
391391
logger.debug(f"Predictor keys: {predictor_keys}")
392392
primary_predictor_key = predictor_keys[0]
393393
extract_predictor_key = predictor_keys[1] if module_key.startswith(REACT_MODULE_PREFIX) else None

0 commit comments

Comments
 (0)