File size: 3,735 Bytes
cbc00ce | 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | # -*- coding: utf-8 -*-
# Copyright (c) Alibaba, Inc. and its affiliates.
from dashscope.client.base_api import GetStatusMixin, ListObjectMixin
from dashscope.common.error import InputRequired
from dashscope.threads.thread_types import RunStep, RunStepList
__all__ = ["Steps"]
class Steps(ListObjectMixin, GetStatusMixin):
SUB_PATH = "RUNS" # useless
@classmethod
def list( # type: ignore[override]
cls,
run_id: str,
*,
thread_id: str,
limit: int = None,
order: str = None,
after: str = None,
before: str = None,
workspace: str = None,
api_key: str = None,
**kwargs,
) -> RunStepList:
"""List `RunStep` of `Run`.
Args:
thread_id (str): The thread id.
run_id (str): The run id.
limit (int, optional):
How many assistant to retrieve. Defaults to None.
order (str, optional): Sort order by created_at. Defaults to None.
after (str, optional): Assistant id after. Defaults to None.
before (str, optional): Assistant id before. Defaults to None.
workspace (str, optional):
The DashScope workspace id. Defaults to None.
api_key (str, optional): Your DashScope api key. Defaults to None.
Returns:
RunList: The list of runs.
"""
if not run_id:
raise InputRequired("run_id is required!")
response = super().list(
limit=limit,
order=order,
after=after,
before=before,
path=f"threads/{thread_id}/runs/{run_id}/steps",
workspace=workspace,
api_key=api_key,
flattened_output=True,
**kwargs,
)
return RunStepList(**response)
@classmethod
def retrieve(
cls,
step_id: str,
*,
thread_id: str,
run_id: str,
workspace: str = None,
api_key: str = None,
**kwargs,
) -> RunStep:
"""Retrieve the `RunStep`.
Args:
thread_id (str): The thread id.
run_id (str): The run id.
step_id (str): The step id.
workspace (str): The dashscope workspace id.
api_key (str, optional): The api key. Defaults to None.
Returns:
RunStep: The `RunStep` object.
"""
if not thread_id or not run_id or not step_id:
raise InputRequired("thread_id, run_id and step_id are required!")
response = super().get(
run_id,
path=f"threads/{thread_id}/runs/{run_id}/steps/{step_id}",
workspace=workspace,
api_key=api_key,
flattened_output=True,
**kwargs,
)
return RunStep(**response)
@classmethod
def get( # type: ignore[override]
cls,
step_id: str,
*,
thread_id: str,
run_id: str,
workspace: str = None,
api_key: str = None,
**kwargs,
) -> RunStep:
"""Retrieve the `RunStep`.
Args:
thread_id (str): The thread id.
run_id (str): The run id.
step_id (str): The step id.
workspace (str): The dashscope workspace id.
api_key (str, optional): The api key. Defaults to None.
Returns:
RunStep: The `RunStep` object.
"""
# pylint: disable=too-many-function-args
return cls.retrieve( # type: ignore[misc]
thread_id,
run_id,
step_id,
workspace=workspace,
api_key=api_key,
**kwargs,
)
|