-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathstatus.py
More file actions
65 lines (49 loc) · 1.84 KB
/
status.py
File metadata and controls
65 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# pylint: disable=no-name-in-module
from __future__ import annotations
from enum import IntEnum
from yandex.cloud.ai.assistants.v1.runs.run_pb2 import RunState as ProtoRunState
from yandex.cloud.ai.assistants.v1.runs.run_service_pb2 import StreamEvent as ProtoStreamEvent
from yandex_cloud_ml_sdk._types.operation import BaseOperationStatus
from yandex_cloud_ml_sdk._utils.proto import ProtoEnumBase
# pylint: disable=abstract-method
class BaseRunStatus(BaseOperationStatus):
pass
class RunStatus(BaseRunStatus, ProtoEnumBase, IntEnum):
UNKNOWN = -1
RUN_STATUS_UNSPECIFIED = ProtoRunState.RUN_STATUS_UNSPECIFIED
PENDING = ProtoRunState.PENDING
IN_PROGRESS = ProtoRunState.IN_PROGRESS
FAILED = ProtoRunState.FAILED
COMPLETED = ProtoRunState.COMPLETED
TOOL_CALLS = ProtoRunState.TOOL_CALLS
@property
def is_running(self) -> bool:
return self in (self.IN_PROGRESS, self.PENDING)
@property
def is_succeeded(self) -> bool:
return self in (self.COMPLETED, self.TOOL_CALLS)
@property
def is_failed(self) -> bool:
return self is self.FAILED
class StreamEvent(BaseRunStatus, ProtoEnumBase, IntEnum):
UNKNOWN = -1
EVENT_TYPE_UNSPECIFIED = ProtoStreamEvent.EVENT_TYPE_UNSPECIFIED
PARTIAL_MESSAGE = ProtoStreamEvent.PARTIAL_MESSAGE
ERROR = ProtoStreamEvent.ERROR
DONE = ProtoStreamEvent.DONE
TOOL_CALLS = ProtoStreamEvent.TOOL_CALLS
@property
def is_running(self) -> bool:
return self is self.PARTIAL_MESSAGE
@property
def is_succeeded(self) -> bool:
return self in (self.DONE, self.TOOL_CALLS)
@property
def is_failed(self) -> bool:
return self is self.ERROR
@classmethod
def _from_proto(cls, proto: int) -> StreamEvent:
try:
return cls(proto)
except ValueError:
return cls(-1)