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

WIP feature(dspy): add the ability to pass feedback to mipro #1597

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions dspy/propose/grounded_proposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def generate_instruction_class(
use_task_demos=True,
use_instruct_history=True,
use_tip=True,
use_feedback=False,
):
class GenerateSingleModuleInstruction(dspy.Signature):
(
Expand Down Expand Up @@ -117,6 +118,12 @@ class GenerateSingleModuleInstruction(dspy.Signature):
desc="A suggestion for how to go about generating the new instruction.",
prefix="TIP:",
)
if use_feedback:
feedback = dspy.InputField(
format=str,
desc="Feedback from the user on previous model outputs. This informs us about what failures to avoid and what success factors to focus on.",
prefix="FEEDBACK:",
)
proposed_instruction = dspy.OutputField(
desc="Propose an instruction that will be used to prompt a Language Model to perform this task.",
prefix="PROPOSED INSTRUCTION:",
Expand All @@ -135,6 +142,7 @@ def __init__(
use_task_demos=True,
use_instruct_history=True,
use_tip=True,
use_feedback=False,
verbose=False,
):
super().__init__()
Expand All @@ -143,6 +151,7 @@ def __init__(
self.use_task_demos = use_task_demos
self.use_instruct_history = use_instruct_history
self.use_tip = use_tip
self.use_feedback = use_feedback
self.verbose = verbose

self.program_code_string = program_code_string
Expand All @@ -154,6 +163,7 @@ def __init__(
use_task_demos=use_task_demos,
use_instruct_history=use_instruct_history,
use_tip=use_tip,
use_feedback=use_feedback,
)

def forward(
Expand All @@ -166,6 +176,7 @@ def forward(
data_summary,
max_demos=3,
tip=None,
feedback=None,
):
# Construct full program demo or single module demo depending on whether or not we're using the full program
task_demos = ""
Expand Down Expand Up @@ -230,6 +241,7 @@ def forward(
module=module_code,
task_demos=task_demos,
tip=tip,
feedback=feedback,
basic_instruction=basic_instruction,
previous_instructions=previous_instructions,
module_description=module_description,
Expand All @@ -256,6 +268,8 @@ def __init__(
use_instruct_history=True,
use_tip=True,
set_tip_randomly=True,
use_feedback=False,
feedback=None,
set_history_randomly=True,
verbose=False,
):
Expand All @@ -266,6 +280,8 @@ def __init__(
self.use_instruct_history = use_instruct_history
self.use_tip = use_tip
self.set_tip_randomly=set_tip_randomly
self.use_feedback = use_feedback
self.feedback = feedback
self.set_history_randomly=set_history_randomly
self.verbose = verbose

Expand Down Expand Up @@ -337,6 +353,7 @@ def propose_instructions_for_program(
demo_set_i=demo_set_i,
trial_logs=trial_logs,
tip=selected_tip,
feedback=self.feedback,
),
)

Expand All @@ -353,6 +370,7 @@ def propose_instruction_for_predictor(
demo_set_i,
trial_logs,
tip=None,
feedback=None,
):
"""This method is responsible for returning a single instruction for a given predictor, using the specified criteria."""

Expand All @@ -369,6 +387,7 @@ def propose_instruction_for_predictor(
use_task_demos=self.use_task_demos,
use_instruct_history=self.use_instruct_history and instruction_history,
use_tip=self.use_tip,
use_feedback=self.use_feedback,
verbose=self.verbose
)

Expand All @@ -385,6 +404,7 @@ def propose_instruction_for_predictor(
data_summary=self.data_summary,
previous_instructions=instruction_history,
tip=tip,
feedback=feedback,
).proposed_instruction
self.prompt_model.kwargs["temperature"] = original_temp

Expand Down
4 changes: 4 additions & 0 deletions dspy/teleprompt/mipro_optimizer_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def compile(
data_aware_proposer=True,
view_data_batch_size=10,
tip_aware_proposer=True,
feedback_aware_proposer=False,
feedback=None,
fewshot_aware_proposer=True,
requires_permission_to_run=True,
):
Expand Down Expand Up @@ -274,6 +276,8 @@ def compile(
use_task_demos=fewshot_aware_proposer,
use_tip=tip_aware_proposer,
set_tip_randomly=tip_aware_proposer,
use_feedback=feedback_aware_proposer,
feedback=feedback,
use_instruct_history=False,
set_history_randomly=False,
verbose = self.verbose,
Expand Down
Loading