diff --git a/unstract/sdk1/src/unstract/sdk1/tool/stream.py b/unstract/sdk1/src/unstract/sdk1/tool/stream.py index 0fde90efa..92e3b6735 100644 --- a/unstract/sdk1/src/unstract/sdk1/tool/stream.py +++ b/unstract/sdk1/src/unstract/sdk1/tool/stream.py @@ -4,6 +4,7 @@ import os from typing import Any +from deprecated import deprecated from unstract.sdk1.constants import Command, LogLevel, LogStage, ToolEnv from unstract.sdk1.exceptions import SdkError from unstract.sdk1.utils.common import Utils @@ -234,3 +235,24 @@ def stream_update(message: str, state: str, **kwargs: dict[str, Any]) -> None: **kwargs, } print(json.dumps(record)) + + @staticmethod + @deprecated(version="0.4.4", reason="Use `BaseTool.write_to_result()` instead") + def stream_result(result: dict[Any, Any], **kwargs: dict[str, Any]) -> None: + """Streams tool result (review if required). + + Args: + result (dict): The result of the tool. Refer to the + Unstract protocol for the format of the result. + **kwargs: Additional keyword arguments to include in the record. + + Returns: + None + """ + record = { + "type": "RESULT", + "result": result, + "emitted_at": datetime.datetime.now().isoformat(), + **kwargs, + } + print(json.dumps(record))