Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions unstract/sdk1/src/unstract/sdk1/tool/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))