dspy.ReAct
dspy.ReAct(signature, tools: list[Callable], max_iters=5)
Bases: Module
tools
is either a list of functions, callable classes, or dspy.Tool
instances.
Source code in dspy/predict/react.py
Functions
__call__(*args, **kwargs)
Source code in dspy/primitives/program.py
batch(examples, num_threads: Optional[int] = None, max_errors: int = 10, return_failed_examples: bool = False, provide_traceback: Optional[bool] = None, disable_progress_bar: bool = False)
Processes a list of dspy.Example instances in parallel using the Parallel module.
:param examples: List of dspy.Example instances to process. :param num_threads: Number of threads to use for parallel processing. :param max_errors: Maximum number of errors allowed before stopping execution. :param return_failed_examples: Whether to return failed examples and exceptions. :param provide_traceback: Whether to include traceback information in error logs. :return: List of results, and optionally failed examples and exceptions.
Source code in dspy/primitives/program.py
deepcopy()
Deep copy the module.
This is a tweak to the default python deepcopy that only deep copies self.parameters()
, and for other
attributes, we just do the shallow copy.
Source code in dspy/primitives/module.py
dump_state()
forward(**input_args)
Source code in dspy/predict/react.py
get_lm()
load(path)
Load the saved module. You may also want to check out dspy.load, if you want to load an entire program, not just the state for an existing program.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Path to the saved state file, which should be a .json or a .pkl file |
required |
Source code in dspy/primitives/module.py
load_state(state)
map_named_predictors(func)
named_parameters()
Unlike PyTorch, handles (non-recursive) lists of parameters too.
Source code in dspy/primitives/module.py
named_predictors()
named_sub_modules(type_=None, skip_compiled=False) -> Generator[tuple[str, BaseModule], None, None]
Find all sub-modules in the module, as well as their names.
Say self.children[4]['key'].sub_module is a sub-module. Then the name will be 'children[4][key].sub_module'. But if the sub-module is accessible at different paths, only one of the paths will be returned.
Source code in dspy/primitives/module.py
parameters()
predictors()
reset_copy()
save(path, save_program=False)
Save the module.
Save the module to a directory or a file. There are two modes:
- save_program=False
: Save only the state of the module to a json or pickle file, based on the value of
the file extension.
- save_program=True
: Save the whole module to a directory via cloudpickle, which contains both the state and
architecture of the model.
We also save the dependency versions, so that the loaded model can check if there is a version mismatch on critical dependencies or DSPy version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Path to the saved state file, which should be a .json or .pkl file when |
required |
save_program
|
bool
|
If True, save the whole module to a directory via cloudpickle, otherwise only save the state. |
False
|
Source code in dspy/primitives/module.py
set_lm(lm)
truncate_trajectory(trajectory)
Truncates the trajectory so that it fits in the context window.
Users can override this method to implement their own truncation logic.