Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add num_retries to signature_opt_typed #1568

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dspy/teleprompt/signature_opt_typed.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def optimize_signature(
prompt_model=None,
initial_prompts=2,
verbose=False,
max_retries: int = 3,
) -> dspy.Program:
"""Create a new program that is optimized for the given task.

Expand Down Expand Up @@ -177,6 +178,8 @@ def optimize_signature(
Note that we also use the "plain" signature as a prompt, so the total number of prompts is initial_prompts + 1.
verbose : bool, optional
Whether to print debug information, by default False
max_retries : int
The number of retries to use when generating new signatures, by default 3.

Notes:
-----
Expand Down Expand Up @@ -216,7 +219,7 @@ def optimize_signature(
if verbose:
print(f"Generating {initial_prompts} initial signatures for {name}...")
info = candidates[name][0] # Use initial info, to make sure types are identical
generator = TypedChainOfThought(MyGenerateInstructionInitial[type(info)])
generator = TypedChainOfThought(MyGenerateInstructionInitial[type(info)], max_retries=max_retries)
candidates[name] += generator(
basic_signature=info,
).proposed_signatures
Expand Down Expand Up @@ -267,7 +270,7 @@ def optimize_signature(

# We can only tell the LM to avoid the signatures we are actually giving it as demos.
avoid = [ex.proposed_signature for ex in demos]
generator = TypedPredictor(generate_with_avoidance(avoid)[SignatureInfo])
generator = TypedPredictor(generate_with_avoidance(avoid)[SignatureInfo], max_retries=max_retries)
generator.predictor.demos = demos

if verbose:
Expand Down
Loading