chore: 添加虚拟环境到仓库
- 添加 backend_service/venv 虚拟环境 - 包含所有Python依赖包 - 注意:虚拟环境约393MB,包含12655个文件
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
|
||||
# yapf: disable
|
||||
|
||||
from dashscope.assistants.assistant_types import (Assistant, AssistantFile,
|
||||
AssistantList,
|
||||
DeleteResponse)
|
||||
from dashscope.assistants.assistants import Assistants
|
||||
|
||||
__all__ = [
|
||||
Assistant,
|
||||
Assistants,
|
||||
AssistantList,
|
||||
AssistantFile,
|
||||
DeleteResponse,
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,175 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
|
||||
# adapter from openai sdk
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Optional, Union
|
||||
|
||||
from dashscope.common.base_type import BaseList, BaseObjectMixin
|
||||
|
||||
__all__ = [
|
||||
'Assistant', 'AssistantFile', 'ToolCodeInterpreter', 'ToolSearch',
|
||||
'ToolWanX', 'FunctionDefinition', 'ToolFunction', 'AssistantFileList',
|
||||
'AssistantList', 'DeleteResponse'
|
||||
]
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class AssistantFile(BaseObjectMixin):
|
||||
id: str
|
||||
assistant_id: str
|
||||
created_at: int
|
||||
object: str
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class ToolCodeInterpreter(BaseObjectMixin):
|
||||
type: str = 'code_interpreter'
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class ToolSearch(BaseObjectMixin):
|
||||
type: str = 'search'
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class ToolWanX(BaseObjectMixin):
|
||||
type: str = 'wanx'
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class FunctionDefinition(BaseObjectMixin):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
parameters: Optional[Dict[str, object]] = None
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class ToolFunction(BaseObjectMixin):
|
||||
function: FunctionDefinition
|
||||
type: str = 'function'
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.function = FunctionDefinition(**kwargs.pop('function', {}))
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
Tool = Union[ToolCodeInterpreter, ToolSearch, ToolFunction, ToolWanX]
|
||||
ASSISTANT_SUPPORT_TOOL = {
|
||||
'code_interpreter': ToolCodeInterpreter,
|
||||
'search': ToolSearch,
|
||||
'wanx': ToolWanX,
|
||||
'function': ToolFunction
|
||||
}
|
||||
|
||||
|
||||
def convert_tools_dict_to_objects(tools):
|
||||
tools_object = []
|
||||
for tool in tools:
|
||||
if 'type' in tool:
|
||||
tool_type = ASSISTANT_SUPPORT_TOOL.get(tool['type'], None)
|
||||
if tool_type:
|
||||
tools_object.append(tool_type(**tool))
|
||||
else:
|
||||
tools_object.append(tool)
|
||||
else:
|
||||
tools_object.append(tool)
|
||||
return tools_object
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class Assistant(BaseObjectMixin):
|
||||
status_code: int
|
||||
"""The call response status_code, 200 indicate create success.
|
||||
"""
|
||||
code: str
|
||||
"""The request failed, this is the error code.
|
||||
"""
|
||||
message: str
|
||||
"""The request failed, this is the error message.
|
||||
"""
|
||||
id: str
|
||||
"""ID of the assistant.
|
||||
"""
|
||||
model: str
|
||||
name: Optional[str] = None
|
||||
created_at: int
|
||||
"""The Unix timestamp (in seconds) for when the assistant was created.
|
||||
"""
|
||||
description: Optional[str] = None
|
||||
|
||||
file_ids: List[str]
|
||||
|
||||
instructions: Optional[str] = None
|
||||
metadata: Optional[object] = None
|
||||
tools: List[Tool]
|
||||
|
||||
object: Optional[str] = None
|
||||
|
||||
top_p: Optional[float] = None
|
||||
top_k: Optional[int] = None
|
||||
temperature: Optional[float] = None
|
||||
max_tokens: Optional[int] = None
|
||||
|
||||
request_id: Optional[str] = None
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.tools = convert_tools_dict_to_objects(kwargs.pop('tools', []))
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class AssistantList(BaseList):
|
||||
data: List[Assistant]
|
||||
|
||||
def __init__(self,
|
||||
has_more: bool = None,
|
||||
last_id: Optional[str] = None,
|
||||
first_id: Optional[str] = None,
|
||||
data: List[Assistant] = [],
|
||||
**kwargs):
|
||||
super().__init__(has_more=has_more,
|
||||
last_id=last_id,
|
||||
first_id=first_id,
|
||||
data=data,
|
||||
**kwargs)
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class AssistantFileList(BaseList):
|
||||
data: List[AssistantFile]
|
||||
|
||||
def __init__(self,
|
||||
has_more: bool = None,
|
||||
last_id: Optional[str] = None,
|
||||
first_id: Optional[str] = None,
|
||||
data: List[AssistantFile] = [],
|
||||
**kwargs):
|
||||
super().__init__(has_more=has_more,
|
||||
last_id=last_id,
|
||||
first_id=first_id,
|
||||
data=data,
|
||||
**kwargs)
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class DeleteResponse(BaseObjectMixin):
|
||||
id: str
|
||||
deleted: bool
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@@ -0,0 +1,311 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from dashscope.assistants.assistant_types import (Assistant, AssistantList,
|
||||
DeleteResponse)
|
||||
from dashscope.client.base_api import (CancelMixin, CreateMixin, DeleteMixin,
|
||||
GetStatusMixin, ListObjectMixin,
|
||||
UpdateMixin)
|
||||
from dashscope.common.error import ModelRequired
|
||||
|
||||
__all__ = ['Assistants']
|
||||
|
||||
|
||||
class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
||||
GetStatusMixin, UpdateMixin):
|
||||
SUB_PATH = 'assistants'
|
||||
|
||||
@classmethod
|
||||
def _create_assistant_object(
|
||||
cls,
|
||||
model: str = None,
|
||||
name: str = None,
|
||||
description: str = None,
|
||||
instructions: str = None,
|
||||
tools: Optional[List[Dict]] = None,
|
||||
file_ids: Optional[List[str]] = [],
|
||||
metadata: Dict = {},
|
||||
top_p: Optional[float] = None,
|
||||
top_k: Optional[int] = None,
|
||||
temperature: Optional[float] = None,
|
||||
max_tokens: Optional[int] = None,
|
||||
):
|
||||
obj = {}
|
||||
if model:
|
||||
obj['model'] = model
|
||||
if name:
|
||||
obj['name'] = name
|
||||
if description:
|
||||
obj['description'] = description
|
||||
if instructions:
|
||||
obj['instructions'] = instructions
|
||||
if tools is not None:
|
||||
obj['tools'] = tools
|
||||
obj['file_ids'] = file_ids
|
||||
obj['metadata'] = metadata
|
||||
|
||||
if top_p is not None:
|
||||
obj['top_p'] = top_p
|
||||
if top_k is not None:
|
||||
obj['top_k'] = top_k
|
||||
if temperature is not None:
|
||||
obj['temperature'] = temperature
|
||||
if max_tokens is not None:
|
||||
obj['max_tokens'] = max_tokens
|
||||
|
||||
return obj
|
||||
|
||||
@classmethod
|
||||
def call(cls,
|
||||
*,
|
||||
model: str,
|
||||
name: str = None,
|
||||
description: str = None,
|
||||
instructions: str = None,
|
||||
tools: Optional[List[Dict]] = None,
|
||||
file_ids: Optional[List[str]] = [],
|
||||
metadata: Dict = None,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> Assistant:
|
||||
"""Create Assistant.
|
||||
|
||||
Args:
|
||||
model (str): The model to use.
|
||||
name (str, optional): The assistant name. Defaults to None.
|
||||
description (str, optional): The assistant description. Defaults to None.
|
||||
instructions (str, optional): The system instructions this assistant uses. Defaults to None.
|
||||
tools (Optional[List[Dict]], optional): List of tools to use. Defaults to [].
|
||||
file_ids (Optional[List[str]], optional): : The files to use. Defaults to [].
|
||||
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
||||
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
||||
api_key (str, optional): The DashScope api key. Defaults to None.
|
||||
|
||||
Raises:
|
||||
ModelRequired: The model is required.
|
||||
|
||||
Returns:
|
||||
Assistant: The `Assistant` object.
|
||||
"""
|
||||
return cls.create(model=model,
|
||||
name=name,
|
||||
description=description,
|
||||
instructions=instructions,
|
||||
tools=tools,
|
||||
file_ids=file_ids,
|
||||
metadata=metadata,
|
||||
workspace=workspace,
|
||||
api_key=api_key,
|
||||
**kwargs)
|
||||
|
||||
@classmethod
|
||||
def create(cls,
|
||||
*,
|
||||
model: str,
|
||||
name: str = None,
|
||||
description: str = None,
|
||||
instructions: str = None,
|
||||
tools: Optional[List[Dict]] = None,
|
||||
file_ids: Optional[List[str]] = [],
|
||||
metadata: Dict = None,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
top_p: Optional[float] = None,
|
||||
top_k: Optional[int] = None,
|
||||
temperature: Optional[float] = None,
|
||||
max_tokens: Optional[int] = None,
|
||||
**kwargs) -> Assistant:
|
||||
"""Create Assistant.
|
||||
|
||||
Args:
|
||||
model (str): The model to use.
|
||||
name (str, optional): The assistant name. Defaults to None.
|
||||
description (str, optional): The assistant description. Defaults to None.
|
||||
instructions (str, optional): The system instructions this assistant uses. Defaults to None.
|
||||
tools (Optional[List[Dict]], optional): List of tools to use. Defaults to [].
|
||||
file_ids (Optional[List[str]], optional): : The files to use. Defaults to [].
|
||||
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
||||
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
||||
api_key (str, optional): The DashScope api key. Defaults to None.
|
||||
top_p (float, optional): top_p parameter for model. Defaults to None.
|
||||
top_k (int, optional): top_p parameter for model. Defaults to None.
|
||||
temperature (float, optional): temperature parameter for model. Defaults to None.
|
||||
max_tokens (int, optional): max_tokens parameter for model. Defaults to None.
|
||||
|
||||
Raises:
|
||||
ModelRequired: The model is required.
|
||||
|
||||
Returns:
|
||||
Assistant: The `Assistant` object.
|
||||
"""
|
||||
if not model:
|
||||
raise ModelRequired('Model is required!')
|
||||
data = cls._create_assistant_object(model, name, description,
|
||||
instructions, tools, file_ids,
|
||||
metadata, top_p, top_k, temperature, max_tokens)
|
||||
response = super().call(data=data,
|
||||
api_key=api_key,
|
||||
flattened_output=True,
|
||||
workspace=workspace,
|
||||
**kwargs)
|
||||
return Assistant(**response)
|
||||
|
||||
@classmethod
|
||||
def retrieve(cls,
|
||||
assistant_id: str,
|
||||
*,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> Assistant:
|
||||
"""Get the `Assistant`.
|
||||
|
||||
Args:
|
||||
assistant_id (str): The assistant id.
|
||||
workspace (str): The dashscope workspace id.
|
||||
api_key (str, optional): The api key. Defaults to None.
|
||||
|
||||
Returns:
|
||||
Assistant: The `Assistant` object.
|
||||
"""
|
||||
return cls.get(assistant_id,
|
||||
workspace=workspace,
|
||||
api_key=api_key,
|
||||
**kwargs)
|
||||
|
||||
@classmethod
|
||||
def get(cls,
|
||||
assistant_id: str,
|
||||
*,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> Assistant:
|
||||
"""Get the `Assistant`.
|
||||
|
||||
Args:
|
||||
assistant_id (str): The assistant id.
|
||||
workspace (str): The dashscope workspace id.
|
||||
api_key (str, optional): The api key. Defaults to None.
|
||||
|
||||
Returns:
|
||||
Assistant: The `Assistant` object.
|
||||
"""
|
||||
if not assistant_id:
|
||||
raise ModelRequired('assistant_id is required!')
|
||||
response = super().get(assistant_id,
|
||||
workspace=workspace,
|
||||
api_key=api_key,
|
||||
flattened_output=True,
|
||||
**kwargs)
|
||||
return Assistant(**response)
|
||||
|
||||
@classmethod
|
||||
def list(cls,
|
||||
*,
|
||||
limit: int = None,
|
||||
order: str = None,
|
||||
after: str = None,
|
||||
before: str = None,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> AssistantList:
|
||||
"""List assistants
|
||||
|
||||
Args:
|
||||
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:
|
||||
AssistantList: The list of assistants.
|
||||
"""
|
||||
response = super().list(limit=limit,
|
||||
order=order,
|
||||
after=after,
|
||||
before=before,
|
||||
workspace=workspace,
|
||||
api_key=api_key,
|
||||
flattened_output=True,
|
||||
**kwargs)
|
||||
return AssistantList(**response)
|
||||
|
||||
@classmethod
|
||||
def update(cls,
|
||||
assistant_id: str,
|
||||
*,
|
||||
model: str = None,
|
||||
name: str = None,
|
||||
description: str = None,
|
||||
instructions: str = None,
|
||||
tools: Optional[List[Dict]] = None,
|
||||
file_ids: Optional[List[str]] = [],
|
||||
metadata: Dict = None,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
top_p: Optional[float] = None,
|
||||
top_k: Optional[int] = None,
|
||||
temperature: Optional[float] = None,
|
||||
max_tokens: Optional[int] = None,
|
||||
**kwargs) -> Assistant:
|
||||
"""Update an exist assistants
|
||||
|
||||
Args:
|
||||
assistant_id (str): The target assistant id.
|
||||
model (str): The model to use.
|
||||
name (str, optional): The assistant name. Defaults to None.
|
||||
description (str, optional): The assistant description . Defaults to None.
|
||||
instructions (str, optional): The system instructions this assistant uses.. Defaults to None.
|
||||
tools (Optional[str], optional): List of tools to use.. Defaults to [].
|
||||
file_ids (Optional[str], optional): The files to use in assistants.. Defaults to [].
|
||||
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
||||
workspace (str): The DashScope workspace id.
|
||||
api_key (str, optional): The DashScope workspace id. Defaults to None.
|
||||
top_p (float, optional): top_p parameter for model. Defaults to None.
|
||||
top_k (int, optional): top_p parameter for model. Defaults to None.
|
||||
temperature (float, optional): temperature parameter for model. Defaults to None.
|
||||
max_tokens (int, optional): max_tokens parameter for model. Defaults to None.
|
||||
|
||||
Returns:
|
||||
Assistant: The updated assistant.
|
||||
"""
|
||||
if not assistant_id:
|
||||
raise ModelRequired('assistant_id is required!')
|
||||
response = super().update(assistant_id,
|
||||
cls._create_assistant_object(
|
||||
model, name, description, instructions,
|
||||
tools, file_ids, metadata, top_p, top_k, temperature, max_tokens),
|
||||
api_key=api_key,
|
||||
workspace=workspace,
|
||||
flattened_output=True,
|
||||
method='post',
|
||||
**kwargs)
|
||||
return Assistant(**response)
|
||||
|
||||
@classmethod
|
||||
def delete(cls,
|
||||
assistant_id: str,
|
||||
*,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> DeleteResponse:
|
||||
"""Delete uploaded file.
|
||||
|
||||
Args:
|
||||
assistant_id (str): The assistant id want to delete.
|
||||
workspace (str): The DashScope workspace id.
|
||||
api_key (str, optional): The api key. Defaults to None.
|
||||
|
||||
Returns:
|
||||
AssistantsDeleteResponse: Delete result.
|
||||
"""
|
||||
if not assistant_id:
|
||||
raise ModelRequired('assistant_id is required!')
|
||||
response = super().delete(assistant_id,
|
||||
api_key=api_key,
|
||||
workspace=workspace,
|
||||
flattened_output=True,
|
||||
**kwargs)
|
||||
return DeleteResponse(**response)
|
||||
@@ -0,0 +1,197 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
from typing import Optional
|
||||
|
||||
from dashscope.assistants.assistant_types import (AssistantFile,
|
||||
AssistantFileList,
|
||||
DeleteResponse)
|
||||
from dashscope.client.base_api import (CreateMixin, DeleteMixin,
|
||||
GetStatusMixin, ListObjectMixin)
|
||||
from dashscope.common.error import InputRequired
|
||||
|
||||
__all__ = ['Files']
|
||||
|
||||
|
||||
class Files(CreateMixin, DeleteMixin, ListObjectMixin, GetStatusMixin):
|
||||
SUB_PATH = 'assistants'
|
||||
|
||||
@classmethod
|
||||
def call(cls,
|
||||
assistant_id: str,
|
||||
*,
|
||||
file_id: str,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> AssistantFile:
|
||||
"""Create assistant file.
|
||||
|
||||
Args:
|
||||
assistant_id (str): The target assistant id.
|
||||
file_id (str): The file id.
|
||||
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
||||
api_key (str, optional): The DashScope api key. Defaults to None.
|
||||
|
||||
Raises:
|
||||
InputRequired: The assistant id and file id are required.
|
||||
|
||||
Returns:
|
||||
AssistantFile: The assistant file object.
|
||||
"""
|
||||
return cls.create(assistant_id,
|
||||
file_id=file_id,
|
||||
workspace=workspace,
|
||||
api_key=api_key,
|
||||
**kwargs)
|
||||
|
||||
@classmethod
|
||||
def create(cls,
|
||||
assistant_id: str,
|
||||
*,
|
||||
file_id: str,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> AssistantFile:
|
||||
"""Create assistant file.
|
||||
|
||||
Args:
|
||||
assistant_id (str): The target assistant id.
|
||||
file_id (str): The file id.
|
||||
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
||||
api_key (str, optional): The DashScope api key. Defaults to None.
|
||||
|
||||
Raises:
|
||||
InputRequired: The assistant id and file id is required.
|
||||
|
||||
Returns:
|
||||
AssistantFile: _description_
|
||||
"""
|
||||
if not file_id or not assistant_id:
|
||||
raise InputRequired('input file_id and assistant_id is required!')
|
||||
|
||||
response = super().call(data={'file_id': file_id},
|
||||
path=f'assistants/{assistant_id}/files',
|
||||
api_key=api_key,
|
||||
flattened_output=True,
|
||||
workspace=workspace,
|
||||
**kwargs)
|
||||
return AssistantFile(**response)
|
||||
|
||||
@classmethod
|
||||
def list(cls,
|
||||
assistant_id: str,
|
||||
*,
|
||||
limit: int = None,
|
||||
order: str = None,
|
||||
after: str = None,
|
||||
before: str = None,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> AssistantFileList:
|
||||
"""List assistant files.
|
||||
|
||||
Args:
|
||||
assistant_id (str): The assistant 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:
|
||||
ListAssistantFile: The list of file objects.
|
||||
"""
|
||||
|
||||
response = super().list(limit=limit,
|
||||
order=order,
|
||||
after=after,
|
||||
before=before,
|
||||
path=f'assistants/{assistant_id}/files',
|
||||
api_key=api_key,
|
||||
flattened_output=True,
|
||||
workspace=workspace,
|
||||
**kwargs)
|
||||
return AssistantFileList(**response)
|
||||
|
||||
@classmethod
|
||||
def retrieve(cls,
|
||||
file_id: str,
|
||||
*,
|
||||
assistant_id: str,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> AssistantFile:
|
||||
"""Retrieve file information.
|
||||
|
||||
Args:
|
||||
file_id (str): The file if.
|
||||
assistant_id (str): The assistant id of the file.
|
||||
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
||||
api_key (str, optional): Your DashScope api key. Defaults to None.
|
||||
|
||||
Returns:
|
||||
AssistantFile: The `AssistantFile` object.
|
||||
"""
|
||||
if not assistant_id or not file_id:
|
||||
raise InputRequired('assistant id and file id are required!')
|
||||
response = super().get(
|
||||
file_id,
|
||||
path=f'assistants/{assistant_id}/files/{file_id}',
|
||||
api_key=api_key,
|
||||
flattened_output=True,
|
||||
workspace=workspace,
|
||||
**kwargs)
|
||||
return AssistantFile(**response)
|
||||
|
||||
@classmethod
|
||||
def get(cls,
|
||||
file_id: str,
|
||||
*,
|
||||
assistant_id: str,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> Optional[AssistantFile]:
|
||||
"""Retrieve file information.
|
||||
|
||||
Args:
|
||||
file_id (str): The file if.
|
||||
assistant_id (str): The assistant id of the file.
|
||||
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
||||
api_key (str, optional): Your DashScope api key. Defaults to None.
|
||||
|
||||
Returns:
|
||||
AssistantFile: The `AssistantFile` object.
|
||||
"""
|
||||
response = super().get(target=assistant_id + '/files/' + file_id, api_key=api_key, workspace=workspace, **kwargs)
|
||||
if response.status_code == 200 and response.output:
|
||||
return AssistantFile(**response.output)
|
||||
else:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def delete(cls,
|
||||
file_id: str,
|
||||
*,
|
||||
assistant_id: str,
|
||||
workspace: str = None,
|
||||
api_key: str = None,
|
||||
**kwargs) -> DeleteResponse:
|
||||
"""Delete the `file_id`.
|
||||
|
||||
Args:
|
||||
file_id (str): The file to be deleted.
|
||||
assistant_id (str): The assistant id of the file.
|
||||
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
||||
api_key (str, optional): Your DashScope api key. Defaults to None.
|
||||
|
||||
Returns:
|
||||
AssistantsDeleteResponse: _description_
|
||||
"""
|
||||
|
||||
response = super().delete(
|
||||
file_id,
|
||||
path=f'assistants/{assistant_id}/files/{file_id}',
|
||||
api_key=api_key,
|
||||
flattened_output=True,
|
||||
workspace=workspace,
|
||||
**kwargs)
|
||||
return DeleteResponse(**response)
|
||||
Reference in New Issue
Block a user