opto.optimizers.textgrad#

Module Contents#

Classes#

GradientInfo

TextGrad

Functions#

construct_tgd_prompt

construct_reduce_prompt

rm_node_attrs

get_short_value

Data#

GLOSSARY_TEXT

OPTIMIZER_SYSTEM_PROMPT

TGD_PROMPT_PREFIX

TGD_MULTIPART_PROMPT_INIT

TGD_MULTIPART_PROMPT_PREFIX

TGD_PROMPT_SUFFIX

MOMENTUM_PROMPT_ADDITION

CONSTRAINT_PROMPT_ADDITION

IN_CONTEXT_EXAMPLE_PROMPT_ADDITION

GRADIENT_TEMPLATE

GRADIENT_MULTIPART_TEMPLATE

GLOSSARY_TEXT_BACKWARD

BACKWARD_SYSTEM_PROMPT

CONVERSATION_TEMPLATE

CONVERSATION_START_INSTRUCTION_CHAIN

OBJECTIVE_INSTRUCTION_CHAIN

CONVERSATION_START_INSTRUCTION_BASE

OBJECTIVE_INSTRUCTION_BASE

EVALUATE_VARIABLE_INSTRUCTION

SEARCH_QUERY_BACKWARD_INSTRUCTION

GRADIENT_OF_RESULTS_INSTRUCTION

REDUCE_MEAN_SYSTEM_PROMPT

API#

GLOSSARY_TEXT = <Multiline-String>#
OPTIMIZER_SYSTEM_PROMPT = None#
TGD_PROMPT_PREFIX = <Multiline-String>#
TGD_MULTIPART_PROMPT_INIT = <Multiline-String>#
TGD_MULTIPART_PROMPT_PREFIX = 'Improve the variable ({variable_desc}) using the feedback provided in <FEEDBACK> tags.\n'#
TGD_PROMPT_SUFFIX = <Multiline-String>#
MOMENTUM_PROMPT_ADDITION = <Multiline-String>#
CONSTRAINT_PROMPT_ADDITION = <Multiline-String>#
IN_CONTEXT_EXAMPLE_PROMPT_ADDITION = <Multiline-String>#
construct_tgd_prompt(do_momentum: bool = False, do_constrained: bool = False, do_in_context_examples: bool = False, **optimizer_kwargs)[source]#
GRADIENT_TEMPLATE = <Multiline-String>#
GRADIENT_MULTIPART_TEMPLATE = <Multiline-String>#
GLOSSARY_TEXT_BACKWARD = <Multiline-String>#
BACKWARD_SYSTEM_PROMPT = None#
CONVERSATION_TEMPLATE = <Multiline-String>#
CONVERSATION_START_INSTRUCTION_CHAIN = <Multiline-String>#
OBJECTIVE_INSTRUCTION_CHAIN = <Multiline-String>#
CONVERSATION_START_INSTRUCTION_BASE = <Multiline-String>#
OBJECTIVE_INSTRUCTION_BASE = <Multiline-String>#
EVALUATE_VARIABLE_INSTRUCTION = <Multiline-String>#
SEARCH_QUERY_BACKWARD_INSTRUCTION = <Multiline-String>#
GRADIENT_OF_RESULTS_INSTRUCTION = <Multiline-String>#
REDUCE_MEAN_SYSTEM_PROMPT = 'You are part of an optimization system that improves a given text (i.e. the variable). Your only res...'#
class GradientInfo[source]#
gradient: str = None#
gradient_context: Optional[Dict[str, str]] = None#
construct_reduce_prompt(gradients: List[opto.optimizers.textgrad.GradientInfo])[source]#
rm_node_attrs(text: str) str[source]#
get_short_value(text, n_words_offset: int = 10) str[source]#
class TextGrad(parameters: List[opto.trace.nodes.ParameterNode], config_list: List = None, *args, propagator: opto.trace.propagators.Propagator = None, objective: Union[None, str] = None, max_tokens=4096, log=False, **kwargs)[source]#

Bases: opto.optimizers.optimizer.Optimizer

call_llm(system_prompt: str, user_prompt: str, verbose: Union[bool, str] = False)[source]#