Skip to content

opto.optimizers.opro_v2

OPROPromptSymbolSet

Bases: OptimizerPromptSymbolSet

problem_context_section_title class-attribute instance-attribute

problem_context_section_title = '# Problem Context'

variable_section_title class-attribute instance-attribute

variable_section_title = '# Solution'

feedback_section_title class-attribute instance-attribute

feedback_section_title = '# Feedback'

node_tag class-attribute instance-attribute

node_tag = 'node'

variable_tag class-attribute instance-attribute

variable_tag = 'solution'

value_tag class-attribute instance-attribute

value_tag = 'value'

constraint_tag class-attribute instance-attribute

constraint_tag = 'constraint'

reasoning_tag class-attribute instance-attribute

reasoning_tag = 'reasoning'

improved_variable_tag class-attribute instance-attribute

improved_variable_tag = 'variable'

name_tag class-attribute instance-attribute

name_tag = 'name'

expect_json class-attribute instance-attribute

expect_json = False

default_prompt_symbols property

default_prompt_symbols: Dict[str, str]

ProblemInstance dataclass

ProblemInstance(
    instruction: str,
    variables: str,
    feedback: str,
    optimizer_prompt_symbol_set: OPROPromptSymbolSet,
)

instruction instance-attribute

instruction: str

variables instance-attribute

variables: str

feedback instance-attribute

feedback: str

optimizer_prompt_symbol_set instance-attribute

optimizer_prompt_symbol_set: OPROPromptSymbolSet

problem_template class-attribute instance-attribute

problem_template = dedent(
    "\n        # Problem Context\n        {instruction}\n\n        # Solution\n        {variables}\n\n        # Feedback\n        {feedback}\n        "
)

OPROv2

OPROv2(
    *args,
    optimizer_prompt_symbol_set: OptimizerPromptSymbolSet = None,
    include_example=False,
    memory_size=5,
    **kwargs
)

Bases: OptoPrimeV2

representation_prompt class-attribute instance-attribute

representation_prompt = dedent(
    "\n        You're tasked to change the proposed solution according to feedback.\n\n        Specifically, a problem will be composed of the following parts:\n        - {instruction_section_title}: the instruction which describes the things you need to do or the question you should answer.\n        - {variables_section_title}: the proposed solution that you can change/tweak (trainable).\n        - {feedback_section_title}: the feedback about the solution.\n\n        If `data_type` is `code`, it means `{value_tag}` is the source code of a python code, which may include docstring and definitions.\n        "
)

output_format_prompt_template class-attribute instance-attribute

output_format_prompt_template = dedent(
    "\n        Output_format: Your output should be in the following XML/HTML format:\n\n        ```\n        {output_format}\n        ```\n\n        In <{reasoning_tag}>, explain the problem: 1. what the {instruction_section_title} means 2. what the {feedback_section_title} means to {variables_section_title} considering how {variables_section_title} follow {instruction_section_title}. 3. Reasoning about the suggested changes in {variables_section_title} (if needed) and the expected result.\n\n        If you need to suggest a change in the values of {variables_section_title}, write down the suggested values in <{improved_variable_tag}>. Remember you can change only the values in {variables_section_title}, not others. When `type` of a variable is `code`, you should write the new definition in the format of python code without syntax errors, and you should not change the function name or the function signature.\n\n        If no changes are needed, just output TERMINATE.\n        "
)

user_prompt_template class-attribute instance-attribute

user_prompt_template = dedent(
    "\n        Now you see problem instance:\n\n        ================================\n        {problem_instance}\n        ================================\n\n        "
)

final_prompt class-attribute instance-attribute

final_prompt = dedent(
    "\n        What are your revised solutions on {names}?\n\n        Your response:\n        "
)

default_objective class-attribute instance-attribute

default_objective = "Propose a new solution that will incorporate the feedback."

problem_instance

problem_instance(summary, mask=None)

initialize_prompt

initialize_prompt()