Skip to content

dspy.streaming.StatusMessageProvider

dspy.streaming.StatusMessageProvider

为DSPy程序提供可自定义的状态消息流。

该类作为创建自定义状态消息提供者的基础。用户可以继承子类并重写其方法,为程序执行的不同阶段定义特定的状态消息,每个方法必须返回一个字符串。

示例:

class MyStatusMessageProvider(StatusMessageProvider):
    def lm_start_status_message(self, instance, inputs):
        return f"正在调用语言模型,输入参数为 {inputs}..."

    def module_end_status_message(self, outputs):
        return f"模块执行完成,输出结果为: {outputs}!"

program = dspy.streamify(dspy.Predict("q->a"), status_message_provider=MyStatusMessageProvider())

函数

lm_end_status_message(outputs: Any)

调用 dspy.LM 后的状态消息。

Source code in dspy/streaming/messages.py
def lm_end_status_message(self, outputs: Any):
    """Status message after a `dspy.LM` is called."""
    pass

lm_start_status_message(instance: Any, inputs: dict[str, Any])

在调用dspy.LM之前的状态消息。

Source code in dspy/streaming/messages.py
def lm_start_status_message(self, instance: Any, inputs: dict[str, Any]):
    """Status message before a `dspy.LM` is called."""
    pass

module_end_status_message(outputs: Any)

在调用 dspy.Moduledspy.Predict 之后的状态消息。

Source code in dspy/streaming/messages.py
def module_end_status_message(self, outputs: Any):
    """Status message after a `dspy.Module` or `dspy.Predict` is called."""
    pass

module_start_status_message(instance: Any, inputs: dict[str, Any])

在调用dspy.Moduledspy.Predict之前的状态消息。

Source code in dspy/streaming/messages.py
def module_start_status_message(self, instance: Any, inputs: dict[str, Any]):
    """Status message before a `dspy.Module` or `dspy.Predict` is called."""
    pass

tool_end_status_message(outputs: Any)

调用dspy.Tool后的状态消息。

Source code in dspy/streaming/messages.py
def tool_end_status_message(self, outputs: Any):
    """Status message after a `dspy.Tool` is called."""
    return "Tool calling finished! Querying the LLM with tool calling results..."

tool_start_status_message(instance: Any, inputs: dict[str, Any])

在调用dspy.Tool之前的状态消息。

Source code in dspy/streaming/messages.py
def tool_start_status_message(self, instance: Any, inputs: dict[str, Any]):
    """Status message before a `dspy.Tool` is called."""
    return f"Calling tool {instance.name}..."

:::

优云智算