文档

Runs

更新时间:
一键部署

Create

from dashscope import Runs
run = Runs.create('thread_id',
                  assistant_id='assistant_id',
                  model='the_model_to_use',
                  instructions='Instructions',
                  additional_instructions='additional_instructions',
                  tools=['list_of_tool_to_use'],
                  metadata={'key': 'value'})

返回结果

结果为Run对象,json化内容为:

{
    "account_id": "sk-450bfd9582664946b8c42244fce43fcc",
    "assistant_id": "asst_8eeaedde-3f8b-41d2-9433-0e88a6042ecb",
    "created_at": 1711347311426,
    "file_ids": [],
    "id": "run_f2c663e6-69f9-4494-9017-acf788db5a17",
    "instructions": "You are a helpful assistant. When asked a question, use tools wherever possible.",
    "metadata": {},
    "model": "qwen-max-allinone",
    "object": "thread.run",
    "request_id": "53561cd0-350c-918d-b3f7-716a0e41bcfd",
    "status": "in_progress",
    "status_code": 200,
    "thread_id": "thread_45ca9a78-2b1f-4172-b4cf-cf8c748c1c32",
    "tools": [
        {
            "type": "search"
        },
        {
            "function": {
                "description": "Add to number",
                "name": "big_add",
                "parameters": {
                    "properties": {
                        "left": {
                            "description": "The left operator",
                            "type": "integer"
                        },
                        "right": {
                            "description": "The right operator.",
                            "type": "integer"
                        }
                    },
                    "required": [
                        "left",
                        "right"
                    ],
                    "type": "object"
                }
            },
            "type": "function"
        }
    ]
}

输入参数配置

参数

类型

默认值

说明

thread_id

str

-

期望在那个Thread run

assistant_id

str

-

assistant id

model

str

-

指定使用的模型

instructions

str

None

指定本次run所用的指令

additional_instructions

str

None

指定附加的指令

tools

List[Dict]

[]

assistant使用的tools

metadata

Dict

None

assistant关联信息

workspace

str

None

DashScope workspace id

api_key

str

None

DashScope api key,可以通过环境变量等方法设置。

输出Run对象字段说明

字段名

字段类型

字段描述

status_code

int

为调用http status code,200表示调用成功,其他表示调用出错

id

str

Run id,为uuid字符串

model

str

Run 使用的模型名称

instructions

str

assistant instruction信息,指定assisiant功能信息。

metadata

object

key,value对对象信息,描述assistant信息

status

str

Run的状态,包含'in_progress, 等

thread_id

str

Run所属Thread id

tools

List[Tool]

Run使用的tool列表

file_ids

List[str]

Run 关联file id 列表

created_at

timestamp

assistant创建时间

gmt_created

datatime

2024-03-22 17:12:31

gmt_modified

datatime

2024-03-22 17:12:31

code

str

表示请求失败,表示错误码,成功忽略。

python only

message

str

失败,表示失败详细信息,成功忽略。

python only

retrieve

调用方法

from dashscope import Runs
run = Runs.retrieve('run_id',
                    thread_id='thread_id')

输入参数

参数

类型

默认值

说明

run_id

str

-

指定要查询的Run id

thread_id

str

-

指定Run所属Thread id

workspace

str

None

DashScope workspace id

api_key

str

None

DashScope api key,可以通过环境变量等方法设置。

输出参数

参考create结果

list

from dashscope import Runs
runs = Runs.list('thread_id',
                 limit=1,
                 order='desc',
                 after='',
                 before='')

请求参数

参数

类型

默认值

说明

thread_id

str

-

指定要list的Thread id

limit

str

-

order

after

before

workspace

str

None

DashScope workspace id

api_key

str

None

DashScope API key,可以通过环境变量等方法设置。

返回参数

输出RunList对象字段说明

字段名

字段类型

字段描述

his_more

bool

last_id

str

first_id

str

data

list[Run]

Run对象列表

update

from dashscope import Runs
run = Runs.update('run_id',
                  thread_id='thread_id',
                  metadata={'newkey': 'newvalue'})

请求参数

参数

类型

默认值

说明

run_id

str

-

要更新的Run id

thread_id

str

-

Run所属的Thread id

metadata

Dict

None

assistant关联信息

workspace

str

None

DashScope workspace id

api_key

str

None

DashScope api key,可以通过环境变量等方法设置。

返回参数

同create,参考create

Wait

等待run执行,run为终态返回,终止状态包含['cancelled', 'failed', 'completed', 'expired',

'requires_action']

from dashscope import Runs
run = Runs.wait('run_id',
                thread_id='thread_id')

请求参数

参数

类型

默认值

说明

run_id

str

-

指定要取消的Run id

thread_id

str

-

Run所属Thread id

workspace

str

None

DashScope workspace id

api_key

str

None

DashScope api key,可以通过环境变量等方法设置。

返回参数

同Create

  • 本页导读 (1)
文档反馈