文档

智能体关联文件

更新时间:
一键部署

创建智能体的关联文件

from dashscope.assistants.files import Files as AssistantFiles


assistant_file = AssistantFiles.create('assistant_id', file_id='file_id')
import com.alibaba.dashscope.assistants.AssistantFile;
import com.alibaba.dashscope.assistants.AssistantFileParam;
import com.alibaba.dashscope.assistants.Assistants;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;

public class Main {
    public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
      Assistants assistants = new Assistants();     
      AssistantFileParam assistantFileParam = AssistantFileParam.builder().fileId("file_id").build();
      AssistantFile assistant = assistants.createFile("assistant_id", assistantFileParam);
    }
}

返回结果

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

{
    "account_id": "sk-6bddfc116de744c3aa1d66893cc87b20",
    "assistant_id": "asst_86d4f453-41d7-4354-8048-1953f14fa135",
    "created_at": 1711337516571,
    "gmt_crete": "2024-03-25 11:31:56",
    "gmt_update": "2024-03-25 11:31:56",
    "id": "file_id",
    "is_deleted": false,
    "object": "assistant.file",
    "request_id": "be15d81a-cff9-9999-977e-5ffac765948b",
    "status_code": 200
}

输入参数配置

参数

类型

默认值

说明

assistant_id

str

-

指定file 所属的assistant id

file_id

str

-

指定file id, file 可以通过命令行上传,获取file id。

workspace

str

None

DashScope workspace id

api_key

str

None

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

输出Assistant对象字段说明

字段名

字段类型

字段描述

status_code

int

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

id

str

the assistant 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

检索智能体的关联文件

from dashscope.assistants.files import Files as AssistantFiles

assistant_file = AssistantFiles.retrieve('file_id', assistant_id='assistant_id')
import com.alibaba.dashscope.assistants.AssistantFile;
import com.alibaba.dashscope.assistants.Assistants;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;

public class Main {
    public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
      Assistants assistants = new Assistants();     
      AssistantFile assistant = assistants.retrieveFile("assistant_id", "file_id");
    }
}

输入参数

参数

类型

默认值

说明

file_id

str

-

指定要查询的file id

assistant_id

str

-

指定要查询的assistant id

workspace

str

None

DashScope workspace id

api_key

str

None

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

输出参数

参考create结果

列出智能体的关联文件

from dashscope.assistants.files import Files as AssistantFiles

assistant_files = AssistantFiles.list('assistant_id',
                                      limit=1,
                                      order='desc',
                                      after='',
                                      before='')

import com.alibaba.dashscope.assistants.AssistantFile;
import com.alibaba.dashscope.assistants.Assistants;
import com.alibaba.dashscope.common.GeneralListParam;
import com.alibaba.dashscope.common.ListResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;

public class Main {
    public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
      Assistants assistants = new Assistants();     
      GeneralListParam fileListParam = GeneralListParam.builder().build();
      ListResult<AssistantFile> assistant = assistants.listFiles("assistant_id", fileListParam);
    }
}

请求参数

参数

类型

默认值

说明

assistant_id

str

-

指定要查询的assistant id

limit

order

after

before

workspace

str

None

DashScope workspace id

api_key

str

None

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

返回参数

输出AssistantFileList对象字段说明

字段名

字段类型

字段描述

his_more

bool

last_id

str

first_id

str

data

list[AssistantFile]

删除智能体的关联文件

from dashscope.assistants.files import Files
assistant_file_deleted = Files.delete('file_id_to_delete',
                             assistant_id='the_target_assistant_id')

请求参数

参数

类型

默认值

说明

file_id

str

-

指定要删除的file id

assistant_id

str

-

指定要删除的文件所属的assistant id

workspace

str

None

DashScope workspace id

api_key

str

None

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

返回参数

字段名

字段类型

字段描述

id

str

删除的对象的id

deleted

bool

是否删除