qianfan.resources.console package

Submodules

qianfan.resources.console.app module

APP API

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
PrivateBos: int = 1
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
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
SharedZipUrl: int = 2
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'
PublicBos: str = 'sysBos'
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
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.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.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

SFT = 'SFT'

对应 LLMFinetune

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 = 'FINISH'

训练完成

Running = 'RUNNING'

训练进行中

Stop = 'STOP'

训练停止

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: int, 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 (int):

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: int, is_annotated: bool, import_source: DataSourceType, file_url: str, **kwargs: Any) QfRequest[source]

create data import task

Parameters:
dataset_id (int):

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: int, destination_dataset_id: int, 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 (int):

dataset id need to be augmented.

destination_dataset_id (int):

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: int, destination_dataset_id: int, operations: Dict[str, List[Dict[str, Any]]], **kwargs: Any) QfRequest[source]

create a post-pretrain dataset etl task

Parameters:
source_dataset_id (int):

dataset id need to be processed.

destination_dataset_id (int):

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: int, 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 (int):

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: int, **kwargs: Any) QfRequest[source]

delete an entity from dataset

Parameters:
entity_ids (List[str]):

entity id list

dataset_id (int):

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: int, **kwargs: Any) QfRequest[source]

delete dataset

Parameters:
dataset_id (int):

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[int], **kwargs: Any) QfRequest[source]

delete dataset augmenting task

Parameters:
task_ids (List[int]):

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[int], **kwargs: Any) QfRequest[source]

delete post-pretrain dataset etl task

Parameters:
etl_ids (List[int]):

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: int, **kwargs: Any) QfRequest[source]

get a data augmenting task info

Parameters:
task_id (int):

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: int, **kwargs: Any) QfRequest[source]

get a post-pretrain dataset etl task info

Parameters:
etl_id (int):

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: int, **kwargs: Any) QfRequest[source]

get dataset export records

Parameters:
dataset_id (int):

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: int, error_code: int, **kwargs: Any) QfRequest[source]

get dataset status in dataset id list

Parameters:
dataset_id (int):

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: int, **kwargs: Any) QfRequest[source]

get dataset info

Parameters:
dataset_id (int):

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[int], **kwargs: Any) QfRequest[source]

get dataset status in dataset id list

Parameters:
dataset_id_list (List[int]):

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: int, 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 (int):

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: int, **kwargs: Any) QfRequest[source]

release dataset

Parameters:
dataset_id (int):

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

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, 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.

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: int, job_id: int, **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 (int):

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

job_id (int):

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 create_evaluation_task(name: str, version_info: List[Dict[str, Any]], dataset_id: int, eval_config: Dict[str, Any], description: Optional[str] = None, pending_eval_id: Optional[int] = 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 (int):

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

**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: int, **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 (int):

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 get_evaluation_info(eval_id: int, **kwargs: Any) QfRequest[source]

Get an evaluation task info

Parameters:
eval_id (int):

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: int, **kwargs: Any) QfRequest[source]

Get the result of an evaluation

Parameters:
eval_id (int):

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 list(model_id: int, **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 (int):

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 publish(is_new: bool, version_meta: Dict[str, Any], model_name: Optional[str] = None, model_id: Optional[int] = 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[int]):

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: int, **kwargs: Any) QfRequest[source]

Stop an evaluation task

Parameters:
eval_id (int):

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

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 delete(id: int, **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 (int):

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 info(id: int, **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 (int):

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: int, 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 (int):

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: int, model_version_id: int, 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

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