qianfan.resources.console package

Submodules

qianfan.resources.console.consts module

User constants when using resources

class qianfan.resources.console.consts.DataExportDestinationType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

PlatformBos: int = 0

导出到平台 Bos

PrivateBos: int = 1

导出到私有 Bos

class qianfan.resources.console.consts.DataExportStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

Failed: int = 3

导出失败

Finished: int = 2

导出完成

Initialized: int = 0

导出初始化

NotStarted: int = -1

未发起导出

Running: int = 1

导出进行中

class qianfan.resources.console.consts.DataImportStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

Failed: int = 3

导入失败

Finished: int = 2

导入完成

Initialized: int = 0

导入初始化

NotStarted: int = -1

未发起导入

Running: int = 1

导入进行中

Terminated: int = 4

导入终止

class qianfan.resources.console.consts.DataProjectType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

Project type used by Qianfan Data

Conversation: int = 20

对话类

GenericText: int = 401

返文本类

QuerySet: int = 402

Query 查询类

Text2Image: int = 705

文生图类

class qianfan.resources.console.consts.DataReleaseStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

Failed: int = 3

发布失败

Finished: int = 2

发布完成

NotStarted: int = 0

未发起发布

Running: int = 1

发布进行中

class qianfan.resources.console.consts.DataSetType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

MultiModel: int = 7

多模态数据集

TextOnly: int = 4

文本类数据集

class qianfan.resources.console.consts.DataSourceType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

PrivateBos: int = 1

私有 Bos

SharedZipUrl: int = 2

包含 zip 压缩包的分享链接

class qianfan.resources.console.consts.DataStorageType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

PrivateBos: str = 'usrBos'

用户私有 Bos

PublicBos: str = 'sysBos'

平台公共 Bos

class qianfan.resources.console.consts.DataTemplateType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

Template type used by Qianfan Data

GenericText: int = 40100

泛文本

NonSortedConversation: int = 2000

非排序对话

QuerySet: int = 40200

Query 查询

SortedConversation: int = 2001

含排序对话

Text2Image: int = 70500

文生图

class qianfan.resources.console.consts.DeployPoolType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

PrivateResource = 2
PublicResource = 1
class qianfan.resources.console.consts.ETLTaskStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

Failed: int = 4

清洗失败

Finished: int = 2

清洗完成

Interrupted: int = 3

清洗被终止

NoTask: int = 0

没有任务

Paused: int = 5

清洗暂停

Running: int = 1

清洗中

class qianfan.resources.console.consts.EntityListingType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

All: int = 0

展示全部

AnnotatedOnly: int = 1

只展示已标注的

NotAnnotatedOnly: int = 2

只展示未标注的

class qianfan.resources.console.consts.EvaluationResultExportDestinationType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

PrivateBos: str = 'storage'

导出到用户 Bos

PublicBos: str = 'local'

导出到平台 Bos

class qianfan.resources.console.consts.EvaluationResultExportField(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Completion: str = 'completion'

预期回答

Metrics: str = 'metrics'

评估指标

Prediction: str = 'prediction'

模型回答

Prompt: str = 'prompt'

提示词

class qianfan.resources.console.consts.EvaluationResultExportRange(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Part: str = 'part'

导出指定部分

Total: str = 'total'

导出全部

class qianfan.resources.console.consts.EvaluationResultExportTaskStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Done: str = 'Done'

导出成功

Fail: str = 'Fail'

导出失败

Pending: str = 'Pending'

任务待执行

Uploading: str = 'Uploading'

进行中

class qianfan.resources.console.consts.EvaluationTaskStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Doing: str = 'Doing'

任务已调度,执行中

DoingWithManualBegin: str = 'DoingWithManualBegin'

运行中(可人工标注)

Done: str = 'Done'

评估任务全部评估成功

Failed: str = 'Failed'

评估任务全部失败

PartlyDone: str = 'PartlyDone'

评估任务部分评估成功

Pending: str = 'Pending'

任务已提交,待调度

Stopped: str = 'Stopped'

任务已全部停止

Stopping: str = 'Stopping'

任务停止中

class qianfan.resources.console.consts.ModelState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Creating = 'Creating'

创建中

Fail = 'Fail'

创建失败

Ready = 'Ready'

已就绪

class qianfan.resources.console.consts.ServiceStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Deploying = 'Deploying'

服务部署中

Done = 'Done'

服务就绪

Failed = 'Failed'

服务部署失败

New = 'New'

服务新建

Stopped = 'Stopped'

服务下线

class qianfan.resources.console.consts.ServiceType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Chat: str = 'chat'

ChatCompletion Service

Completions: str = 'completions'

Completion Service

Embeddings: str = 'embeddings'

Embeddings Service

Image2text: str = 'image2text'

Image2text Service

Text2image: str = 'text2image'

Text2image Service

class qianfan.resources.console.consts.TrainDatasetSourceType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Platform = 'Platform'
PrivateBos = 'Bos'
class qianfan.resources.console.consts.TrainDatasetType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

Platform = 1

平台数据集

PrivateBos = 2

私有Bos数据集

class qianfan.resources.console.consts.TrainMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

PostPretrain = 'PostPretrain'

PostPretrain

SFT = 'SFT'

对应 LLMFinetune

class qianfan.resources.console.consts.TrainParameterScale(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

FullFineTuning = 'FullFineTuning'
LoRA = 'LoRA'
PromptTuning = 'PromptTuning'
class qianfan.resources.console.consts.TrainStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Fail = 'Fail'

训练失败

Finish = 'Done'

训练完成

Running = 'Running'

训练进行中

Stop = 'Stopped'

训练停止

qianfan.resources.console.data module

Data API

class qianfan.resources.console.data.Data[source]

Bases: object

Class for Data API

classmethod annotate_an_entity(entity_id: str, dataset_id: str, content: Optional[List[Dict[str, Any]]] = None, labels: Optional[List[Dict[str, Any]]] = None, **kwargs: Any) QfRequest[source]

annotate an entity within a dataset

Parameters:
entity_id (str):

entity id to be annotating

dataset_id (str):

dataset id to do annotate

content (Optional[Dict[str, Any]]):

the prompt and LLM responses on a conversation

labels (Optional[Dict[str, Any]]):

description of an image

**kwargs (Any):

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/mlp6izcqr

classmethod create_bare_dataset(name: str, data_set_type: DataSetType, project_type: DataProjectType, template_type: DataTemplateType, storage_type: DataStorageType = DataStorageType.PublicBos, storage_id: Optional[str] = None, storage_path: Optional[str] = None, **kwargs: Any) QfRequest[source]

create a bare dataset。

Parameters:
name (str):

the name of the dataset.

data_set_type (DataSetType):

the type of the dataset.

project_type (DataProjectType):

the project type.

template_type (DataTemplateType):

the template type.

storage_type (DataStorageType):

the type of data storage.

storage_id (Optional[str]):

the storage ID when the storage type is PrivateBos.

storage_path (Optional[str]):

the storage path when the storage type is PrivateBos.

**kwargs:

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/qloic44vr

classmethod create_data_import_task(dataset_id: str, is_annotated: bool, import_source: DataSourceType, file_url: str, **kwargs: Any) QfRequest[source]

create data import task

Parameters:
dataset_id (str):

dataset id

is_annotated (bool):

has dataset been annotated

import_source (DataSourceType):

the source for importing dataset

file_url (str):

file url

**kwargs:

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Yloic82qy

classmethod create_dataset_augmenting_task(name: str, source_dataset_id: str, destination_dataset_id: str, service_name: str, service_url: str, app_id: int, num_seed_fewshot: int, num_instances_to_generate: int, similarity_threshold: float, **kwargs: Any) QfRequest[source]

create a data augmenting task

Parameters:
name (str):

name of augment task

source_dataset_id (str):

dataset id need to be augmented.

destination_dataset_id (str):

where dataset should be stored after augmentation

service_name (str):

which LLM should be used for augmenting task

service_url (str):

service url related to service_name

app_id (int):

app id

num_seed_fewshot (int):

the number of sample used for augmenting each data

num_instances_to_generate (int):

the number of instance to generate

similarity_threshold (float):

similarity threshold

**kwargs (Any):

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Dlp6iv0zw

classmethod create_dataset_etl_task(source_dataset_id: str, destination_dataset_id: str, operations: Dict[str, List[Dict[str, Any]]], **kwargs: Any) QfRequest[source]

create a post-pretrain dataset etl task

Parameters:
source_dataset_id (str):

dataset id need to be processed.

destination_dataset_id (str):

where dataset should be stored after etl

operations (Dict[str, List[Dict[str, Any]]]),

etl operator settings.

**kwargs (Any):

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/8lp6irqen

classmethod create_dataset_export_task(dataset_id: str, export_destination_type: DataExportDestinationType, storage_id: Optional[str] = None, is_export_with_annotation: bool = True, **kwargs: Any) QfRequest[source]

create dataset export task

Args:
dataset_id (str):

dataset id

export_destination_type (DataExportDestinationType):

export destination type

storage_id (Optional[str]):

storage id of user’s BOS, needed when export_destination_type is PrivateBos, Default to None.

is_export_with_annotation (Optional[bool]):

is export dataset with annotation, Defaults to True.

**kwargs:

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/bloicnydp

classmethod delete_an_entity(entity_ids: List[str], dataset_id: str, **kwargs: Any) QfRequest[source]

delete an entity from dataset

Parameters:
entity_ids (List[str]):

entity id list

dataset_id (str):

dataset id to do delete

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/ilp6j1rse

classmethod delete_dataset(dataset_id: str, **kwargs: Any) QfRequest[source]

delete dataset

Parameters:
dataset_id (str):

dataset id.

**kwargs:

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Oloicp6fk

classmethod delete_dataset_augmenting_task(task_ids: List[str], **kwargs: Any) QfRequest[source]

delete dataset augmenting task

Parameters:
task_ids (List[str]):

dataset augmenting task id list.

**kwargs (Any):

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/glp6iy6h3

classmethod delete_dataset_etl_task(etl_ids: List[str], **kwargs: Any) QfRequest[source]

delete post-pretrain dataset etl task

Parameters:
etl_ids (List[str]):

dataset etl task id list.

**kwargs (Any):

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Glp6iu8ny

classmethod get_dataset_aug_task_list(keyword: Optional[str] = None, sorted_by_start_time_asc: Optional[bool] = None, page_size: int = 10, offset: int = 0, **kwargs: Any) QfRequest[source]

get a post-pretrain dataset etl task info

Parameters:
keyword: (Optional[str]):

optional keyword to search augmentation task, default to None.

sorted_by_start_time_asc (Optional[bool]):

is result list sorted by starting time in ascending order if True, sorted by starting time in descending order if False, sorted by id in ascending order if None. default to None

page_size (int):

the length of etl list showing, default to 10.

offset (int):

where to start list etl task, default to 0.

**kwargs (Any):

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Flp7n9xmp

classmethod get_dataset_augmenting_task_info(task_id: str, **kwargs: Any) QfRequest[source]

get a data augmenting task info

Parameters:
task_id (str):

dataset augmenting task id.

**kwargs (Any):

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Clp6iwiy9

classmethod get_dataset_etl_task_info(etl_id: str, **kwargs: Any) QfRequest[source]

get a post-pretrain dataset etl task info

Parameters:
etl_id (str):

dataset etl task id.

**kwargs (Any):

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/mlp6it4vd

classmethod get_dataset_etl_task_list(page_size: int = 10, offset: int = 0, **kwargs: Any) QfRequest[source]

get a post-pretrain dataset etl task info

Parameters:
page_size (int):

the length of etl list showing, default to 10.

offset (int):

where to start list etl task, default to 0.

**kwargs (Any):

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/elp7myxvp

classmethod get_dataset_export_records(dataset_id: str, **kwargs: Any) QfRequest[source]

get dataset export records

Parameters:
dataset_id (str):

dataset id.

**kwargs:

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Zlonqgtw0

classmethod get_dataset_import_error_detail(dataset_id: str, error_code: int, **kwargs: Any) QfRequest[source]

get dataset status in dataset id list

Parameters:
dataset_id (str):

dataset id.

error_code (int):

error code used to query

**kwargs:

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/hlonqulbq

classmethod get_dataset_info(dataset_id: str, **kwargs: Any) QfRequest[source]

get dataset info

Parameters:
dataset_id (str):

dataset id.

**kwargs:

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Xloick80a

classmethod get_dataset_status_in_batch(dataset_id_list: List[str], **kwargs: Any) QfRequest[source]

get dataset status in dataset id list

Parameters:
dataset_id_list (List[str]):

dataset id list.

**kwargs:

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Sloicm9qz

classmethod list_all_entity_in_dataset(dataset_id: str, offset: int = 0, page_size: int = 20, import_time_closure: Optional[List[int]] = None, annotating_time_closure: Optional[List[int]] = None, listing_type: EntityListingType = EntityListingType.All, label_id_str: Optional[str] = None, **kwargs: Any) QfRequest[source]

delete an entity from dataset

Parameters:
dataset_id (str):

dataset id

offset (int):

offset of dataset where the list start, default to 0

page_size (int):

window size of the list, default to 20, the maximum value is 30 and the minimum is 1

import_time_closure (Optional[List[int]]):

a list containing start timestamp and end timestamp of importing time, default to None

annotating_time_closure (Optional[List[int]]):

a list containing start timestamp and end timestamp of annotating time, default to None

listing_type (EntityListingType):

type of listing, default to EntityListingType.All

label_id_str (Optional[str]):

label id of text2image, default to None

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Ulp6j2yep

classmethod release_dataset(dataset_id: str, **kwargs: Any) QfRequest[source]

release dataset

Parameters:
dataset_id (str):

dataset id.

**kwargs:

any other parameters.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Uloic6krs

qianfan.resources.console.finetune module

FineTune API

class qianfan.resources.console.finetune.FineTune[source]

Bases: object

Class for FineTune API

class V2[source]

Bases: object

this class provides methods to interact with the fine-tuning V2 API.

classmethod base_api_route() str[source]

base api url route for fine-tuning V2.

Returns:

str: base api url route

classmethod create_job(name: str, model: str, train_mode: Union[str, TrainMode], description: Optional[str] = None, **kwargs: Any) QfRequest[source]

create a fine-tuning job.

This function create a fine-tuning job. job may be associated with many tasks.

Parameters: name (str):

The name of job.

model (str):

The identifier of the fine-tuning job to be stopped. e.g. “ERNIE-Speed”

train_mode (Union[str, console_consts.TrainMode]):

The train mode of the fine-tuning job, including “SFT” and “PostPreTrain” and so on.

description (Optional[str]):

The description of the fine-tuning job.

kwargs:

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

classmethod create_task(job_id: str, params_scale: Union[str, TrainParameterScale], hyper_params: Dict[str, Any], dataset_config: Dict[str, Any], incrementTaskId: Optional[str] = None, **kwargs: Any) QfRequest[source]

create a fine-tuning task.

This function create a fine-tuning task associated with a specific job.

Parameters: name (str):

The name of job.

model (str):

The identifier of the fine-tuning job to be stopped. e.g. “ERNIE-Speed”

train_mode (Union[str, console_consts.TrainMode]):

The train mode of the fine-tuning job, including “SFT”, “PostPreTrain” and so on.

description (Optional[str]):

The description of the fine-tuning job.

kwargs:

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

classmethod job_list(train_model: Optional[Union[str, TrainMode]] = None, marker: Optional[str] = None, max_keys: Optional[int] = None, page_reverse: Optional[bool] = None, **kwargs: Any) QfRequest[source]
classmethod task_detail(task_id: str, **kwargs: Any) QfRequest[source]
classmethod task_list(job_id: str, marker: Optional[str] = None, max_keys: Optional[int] = None, page_reverse: Optional[bool] = None, **kwargs: Any) QfRequest[source]
classmethod create_job(job: Dict[str, Any], **kwargs: Any) QfRequest[source]

Create a job for fine-tuning a model.

This function creates a job for fine-tuning a model.

Parameters:
job (Dict[str, Any]):

A dictionary containing job details and configurations. The fields are same with the API doc.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/mlmrgo4yx

classmethod create_task(name: str, base_train_type: str, train_type: str, description: Optional[str] = None, **kwargs: Any) QfRequest[source]

Create a model fine-tuning task.

This function is used to create a model fine-tuning task. The task can be customized with a name and description.

Parameters:
name (str):

The name of the fine-tuning task.

base_train_type (str):

The base training type of the fine-tuning task. e.g. “ERNIE-Bot-turbo”

train_type (str):

The training type of the fine-tuning task. e.g. “ERNIE-Bot-turbo-0922

description (Optional[str]):

An optional description for the fine-tuning task.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/almrgn397

classmethod get_job(task_id: int, job_id: int, **kwargs: Any) QfRequest[source]

Retrieves a job for model fine-tuning.

This method is responsible for retrieving a job for the specified fine-tuning task and job IDs.

Parameters:
task_id (int):

The ID of the task associated with the fine-tuning job.

job_id (int):

The ID of the fine-tuning job to retrieve.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/wlmrgowee

classmethod stop_job(task_id: str, job_id: str, **kwargs: Any) QfRequest[source]

Stop a fine-tuning job.

This function allows the stopping of a fine-tuning job associated with a specific task.

Parameters:
task_id (str):

The identifier of the task associated with the fine-tuning job.

job_id (str):

The identifier of the fine-tuning job to be stopped.

kwargs:

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/2lnlebz15

qianfan.resources.console.model module

Model API

class qianfan.resources.console.model.Model[source]

Bases: object

Class for Model Management API

classmethod batch_delete_model(model_ids: List[Any], **kwargs: Any) QfRequest[source]

batch delete model by ids

Parameters:
model_ids (List[Any]):

model ids to delete

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

classmethod batch_delete_model_version(model_version_ids: List[Any], **kwargs: Any) QfRequest[source]

batch delete model version by ids

Parameters:
model_version_ids (List[Any]):

model version ids to delete

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

classmethod create_evaluation_result_export_task(eval_id: Union[str, int], export_destination_type: Optional[EvaluationResultExportDestinationType] = None, export_range: EvaluationResultExportRange = EvaluationResultExportRange.Total, export_field: Optional[List[EvaluationResultExportField]] = None, bos_bucket_id: Optional[str] = None, result_ids: Optional[List[str]] = None, **kwargs: Any) QfRequest[source]

Create evaluation result export task

Parameters:
eval_id (Union[str, int]):

the id of evaluation you want to export

export_destination_type (Optional[EvaluationResultExportDestinationType]):

where to export evaluation result, default to EvaluationResultExportDestinationType.PublicBos

export_range (EvaluationResultExportRange):

which part of evaluation result should be exported, default to EvaluationResultExportRange.Total

export_field (Optional[List[EvaluationResultExportField]]):

which field should be contained in exported data, default to all.

bos_bucket_id (Optional[str]):

bucket id of your private bos, used when export_destination_type is EvaluationResultExportDestinationType.PrivateBos. Default to None

result_ids (Optional[List[str]]):

which results you want to export, used when export_range is EvaluationResultExportRange.Part. Default to None

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

Not available currently

classmethod create_evaluation_task(name: str, version_info: List[Dict[str, Any]], dataset_id: str, eval_config: Dict[str, Any], description: Optional[str] = None, pending_eval_id: Optional[int] = None, result_dataset_storage_type: DataStorageType = DataStorageType.PublicBos, result_dataset_storage_id: Optional[str] = None, result_dataset_raw_path: Optional[str] = None, **kwargs: Any) QfRequest[source]

Create an evaluation task on model(s) with dataset

Parameters:
name (str):

the evaluation name you want to use

version_info (List[Dict[str, Any]]):

a list of model info which will be evaluated

dataset_id (str):

dataset’s id for evaluation

eval_config (Dict[str, Any]):

the detail info about how to conduct this evaluation

description (Optional[str]):

description about evaluation, default to None.

pending_eval_id (Optional[int]):

the id of evaluation which doesn’t start yet, you can set this parameter to modify the spec of specific evaluation and start it. Default to None

result_dataset_storage_type (DataStorageType):

where to place evaluation result dataset, default to DataStorageType.PublicBos

result_dataset_storage_id (Optional[str]):

user bos id, only used when result_dataset_storage_type is DataStorageType.PrivateBos, default to None.

result_dataset_raw_path (Optional[str]):

bos path, only used when result_dataset_storage_type is DataStorageType.PrivateBos, default to None.

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Hlpbyhl9o

classmethod detail(model_version_id: str, **kwargs: Any) QfRequest[source]

Retrieve detailed information for a specific model version.

This method is used to fetch detailed information about a particular model version identified by the model_version_id parameter. The information includes various attributes and properties associated with the specified model version.

Parameters:
model_version_id (str):

The unique identifier for the model version whose details are to be retrieved.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/ylnljj3ku

classmethod evaluable_model_list(**kwargs: Any) QfRequest[source]

get all evaluable model list

Parameters:
**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

classmethod get_evaluation_info(eval_id: str, **kwargs: Any) QfRequest[source]

Get an evaluation task info

Parameters:
eval_id (str):

the id of evaluation you want to check

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/wlpbyj1dn

classmethod get_evaluation_result(eval_id: str, **kwargs: Any) QfRequest[source]

Get the result of an evaluation

Parameters:
eval_id (str):

the id of evaluation you want to check

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/7lpbyk8fj

classmethod get_evaluation_result_export_task_status(export_task_id: Union[str, int], **kwargs: Any) QfRequest[source]

Get evaluation result export task status

Parameters:
export_task_id (Union[str, int]):

export task id

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

Not available currently

classmethod list(model_id: str, **kwargs: Any) QfRequest[source]

List all versions and source information of a model.

This class method is used to retrieve information about all versions of a specific model, along with their source details.

Parameters:
model_id (str):

The unique identifier of the model for which you want to list versions.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clnlizwcs

classmethod preset_list(name_filter: Optional[str] = None, model_type: Optional[str] = None, model_version_vendor: Optional[List[str]] = None, model_advantage: Optional[List[str]] = None, page_no: int = 1, page_size: int = 20, **kwargs: Any) QfRequest[source]

Get the list of preset models

Parameters:
name_filter (Optional[str]):

name filter to filter preset models

model_type (Optional[str]):

model type to filter preset models

model_version_vendor (Optional[List[str]]):

model version vendor to filter preset models

model_advantage (Optional[List[str]]):

model advantage to filter preset models

page_no (int):

page number default is 1, start from 1

page_size (int):

page size default is 20

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

classmethod publish(is_new: bool, version_meta: Dict[str, Any], model_name: Optional[str] = None, model_id: Optional[str] = None, tags: Optional[List[str]] = None, **kwargs: Any) QfRequest[source]

Publishes a trained model to the model repository.

This function allows for the publishing of a trained model to a model repository.

Parameters:
is_new (bool):

A boolean indicating whether this is a new model to be published.

version_meta (Dict[str, Any]):

Metadata for the model being published.

model_name (Optional[str]):

The name of the model to be published (required when is_new is True).

model_id (Optional[str]):

The ID of the model to be published (required when is_new is False).

tags (Optional[List[str]]):

A list of tags associated with the model (optional).

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Jlnlm0rdx

classmethod stop_evaluation_task(eval_id: str, **kwargs: Any) QfRequest[source]

Stop an evaluation task

Parameters:
eval_id (str):

the id of evaluation you want to stop

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/klpbyl1ea

classmethod user_list(name_filter: Optional[str] = None, model_type: Optional[str] = None, order_by: Optional[str] = None, order: Optional[str] = None, page_no: int = 1, page_size: int = 20, **kwargs: Any) QfRequest[source]

Get the list of user models

Parameters:
name_filter (Optional[str]):

name filter to filter preset models

model_type (Optional[str]):

model type to filter preset models

order_by (Optional[str]):

order condition, such as create_time

order (Optional[str]):

order type, including: asc and desc

page_no (int):

page number default is 1, start from 1

page_size (int):

page size default is 20

**kwargs (Any):

arbitrary arguments

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

qianfan.resources.console.prompt module

Prompt API

class qianfan.resources.console.prompt.Prompt[source]

Bases: object

Class for Prompt API

classmethod create(name: str, template: str, identifier: Literal['{}', '{{}}', '[]', '[[]]', '()', '(())'] = '{}', scene: PromptSceneType = PromptSceneType.Text2Text, framework: PromptFrameworkType = PromptFrameworkType.NotUse, variables: Optional[List[str]] = None, label_ids: Optional[List[int]] = None, negative_template: Optional[str] = None, negative_variables: Optional[List[str]] = None, **kwargs: Any) QfRequest[source]

Creates a prompt template.

Parameters:
name (str):

A descriptive name for the prompt template.

template (str):

The main text of the prompt template.

identifier (Literal[“{}”, “{{}}”, “[]”, “[[]]”, “()”, “(())”]):

The identifier pattern to be used for variable replacement in the template.

scene (PromptSceneType):

The type of prompt scene, e.g., Text2Text/Text2Image.

framework (PromptFrameworkType):

The framework to be used for prompt generation.

variables (Optional[List[str]]):

List of variables used in the template. If not provided, sdk will automatically find variables in the template. The variables only support English, numbers, and underscores (_), and cannot start with a number. They must be between 2 and 30 characters in length.

label_ids (Optional[List[int]]):

List of label IDs associated with the prompt.

negative_template (Optional[str]):

An optional negative example template. Only available when scene is Text2Image.

negative_variables (Optional[List[str]]):

List of variables for the negative example. Only available when scene is Text2Image.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Returns:

QfRequest: An object representing the prompt request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

Usage: ```python prompt_request = Prompt.create(

name=”MyPrompt”, template=”Generate a sentence with {object}.”, identifier=”{}”, scene=PromptSceneType.Text2Text, framework=PromptFrameworkType.NotUse, variables=[“object”], label_ids=[1, 2], negative_template=”Avoid using {profanity} in the sentence.”, negative_variables=[“profanity”], custom_arg=”value” # Additional keyword arguments can be included.

)

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Hlp7waib4

classmethod create_optimiztion_task(content: str, operations: List[Any], app_id: Optional[int] = None, service_name: Optional[str] = None, **kwargs: Any) QfRequest[source]

Creates an optimization task for prompts.

This method is responsible for creating an optimization task for prompts, where a content string is optimized based on a series of operations. These operations define the transformation steps to enhance or modify the given content.

Parameters:
content (str):

The original content of prompt that needs to be optimized.

operations (List[Any]):

A list of operations specifying the transformations to be applied to the content. The detail can be found in the api document.

app_id (Optional[int]):

The ID of the application associated with the optimization task.

service_name (Optional[str]):

The name of the service related to the optimization task.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Returns:
QfRequest:

An instance of the QfRequest class representing the API request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/olr8svd33

classmethod delete(id: str, **kwargs: Any) QfRequest[source]

Deletes a prompt template.

This method is responsible for deleting a prompt template based on the specified template ID.

Parameters:
id (str):

The ID of the prompt template to delete.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Returns:
QfRequest:

An instance of the QfRequest class representing the API request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Hlp7tri81

classmethod evaluation_score(type: int, data: List[Any]) QfRequest[source]

Evaluates the performance of a prompt template.

This method is responsible for assessing the performance of a given prompt template based on the specified type and data. The type parameter indicates the evaluation criteria or metric to be used, while the data parameter contains the input data required for the evaluation.

Parameters:
type (int):

An integer representing the evaluation standard.

data (List[Any]):

A list of input data necessary for evaluating the prompt template. The detail of the parameter can be found in the API documentation.

Returns:
QfRequest:

An instance of the QfRequest class representing the API request for prompt evaluation.

Note: The @console_api_request decorator is applied to this method, allowing it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/ulr8sx5jk

classmethod evaluation_summary(data: List[Any]) QfRequest[source]

Retrieves an evaluation summary for a given set of prompt.

This method is responsible for evaluating the quality of prompts and generating a summary based on the provided data. The evaluation considers various factors to determine the effectiveness of the prompts in generating desired responses.

Parameters:
data (List[Any]):

A list of prompt data to be evaluated. The detail of the parameter can be found in the API documentation.

Returns:
QfRequest:

An instance of the QfRequest class representing the API request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/nlr8tnlm9

classmethod get_optimization_task(task_id: str, **kwargs: Any) QfRequest[source]

Retrieves details for an optimization prompt task.

This method is responsible for fetching detailed information about a specific optimization prompt task identified by the provided task_id.

Parameters:
task_id (int):

The unique identifier for the optimization prompt task.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Returns:
QfRequest:

An instance of the QfRequest class representing the API request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Clr8svx5q

classmethod info(id: str, **kwargs: Any) QfRequest[source]

Renders a prompt template and retrieves template details.

This method is responsible for rendering a prompt template and obtaining details about the template.

Parameters:
id (str):

The ID of the prompt template to render.

kwargs (Any):

The value of the variables to be used for variable replacement in the template.

Returns:
QfRequest:

An object representing the request for rendering the prompt template.

Note:

The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Olp7ysef9

classmethod list(offset: int = 0, page_size: int = 10, name: Optional[str] = None, label_ids: List[int] = [], type: Optional[PromptType] = None, **kwargs: Any) QfRequest[source]

Retrieves a list of prompt templates.

This method is responsible for retrieving a list of prompt templates based on the specified parameters.

Parameters:
offset (int):

The index from which to start retrieving prompt templates. Default is 0.

page_size (int):

The number of prompt templates to retrieve per page. Default is 10.

name (Optional[str]):

A filter for prompt templates by name.

label_ids (List[int]):

A list of label IDs to filter prompt templates.

type (Optional[PromptType]):

A filter for prompt templates by type.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Returns:
QfRequest:

An object representing the request to retrieve prompt templates.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/ulp7tycbq

classmethod list_labels(offset: int = 0, page_size: int = 10, **kwargs: Any) QfRequest[source]

Retrieves a list of labels for prompt templates.

This method is responsible for retrieving a list of labels. Labels provide information about the categories or attributes associated with each template.

Parameters:
offset (int):

The offset for paginating through the list of labels. Default is 0.

page_size (int):

The number of labels to include in each page. Default is 10.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Returns:
QfRequest:

An instance of the QfRequest class representing the API request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/zlp7u6inp

classmethod update(id: str, name: Optional[str] = None, label_ids: Optional[List[int]] = None, template: Optional[str] = None, identifier: Optional[Literal['{}', '{{}}', '[]', '[[]]', '()', '(())']] = None, negative_template: Optional[str] = None, **kwargs: Any) QfRequest[source]

Update information for a prompt template.

This method is responsible for updating various attributes of a prompt template identified by the provided ID.

Parameters:
id (str):

The ID of the prompt template to update.

name (Optional[str]):

The new name for the prompt template.

label_ids (Optional[List[int]]):

The updated list of label IDs associated with the prompt template.

template (Optional[str]):

The modified template for the prompt.

identifier (Optional[Literal[“{}”, “{{}}”, “[]”, “[[]]”, “()”, “(())”]]):

The updated identifier format for the prompt.

negative_template (Optional[str]):

The revised negative template for the prompt.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Returns:
QfRequest:

An instance of QfRequest representing the update request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/plp7tp3kx

qianfan.resources.console.service module

Service API

class qianfan.resources.console.service.Service[source]

Bases: object

Class for Service API

classmethod create(model_id: str, model_version_id: str, name: str, uri: str, replicas: int, pool_type: DeployPoolType = DeployPoolType.PrivateResource, description: Optional[str] = None, **kwargs: Any) QfRequest[source]

Create a service for the given model.

This function creates a service associated with the specified model and iteration.

Parameters:
model_id (int):

The ID of the model for which the service is to be created.

model_version_id (int):

The ID of the version of the model.

name (str):

The name for the created service.

uri (str):

The URI (Uniform Resource Identifier) for accessing the service.

replicas (int):

The number of replicas for the service.

pool_type (int):

The type of pooling for the service (1 for public and 2 for private).

description (Optional[str], optional):

An optional description for the service.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Plnlmxdgy

classmethod get(id: int, **kwargs: Any) QfRequest[source]

Retrieve information for a specific service.

This method allows retrieval of information pertaining to a specific service based on its unique identifier.

Parameters:
id (int):

The unique identifier for the service.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/llnlmyp8o

classmethod list(api_type_filter: Optional[List[Union[str, ServiceType]]] = None, **kwargs: Any) QfRequest[source]

list all services.

This method allows calling list API to get all services, including common: preset model services. custom user-deployed model services.

Parameters:
api_type_filter (Optional[List[str]]):
Optional, filter the services by ServiceType.
Concretely, the value of this parameter can be one or more of:

‘chat’, ‘completions’, ‘embeddings’, ‘text2image’, ‘image2text’

If the value is None, all services will be returned.

kwargs (Any):

Additional keyword arguments that can be passed to customize the request.

Note: The @console_api_request decorator is applied to this method, enabling it to send the generated QfRequest and return a QfResponse to the user.

API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/4lqoklvr1

qianfan.resources.console.utils module

Utils for console api

qianfan.resources.console.utils.async_console_api_request(func: Callable[[P], Awaitable[QfRequest]]) Callable[[P], Awaitable[QfResponse]][source]

wrapper for all functions in sdk for console api, so that the function only needs to provide the request this decorator will: 1. extract ak and sk from kwargs 2. extract retry config from kwargs 3. use the requestor to send request 4. return the response to the user

qianfan.resources.console.utils.console_api_request(func: Callable[[P], QfRequest]) Callable[[P], QfResponse][source]

wrapper for all functions in sdk for console api, so that the function only needs to provide the request this decorator will: 1. extract ak and sk from kwargs 2. extract retry config from kwargs 3. use the requestor to send request 4. return the response to the user