qianfan.common.client package

Submodules

qianfan.common.client.chat module

class qianfan.common.client.chat.ChatClient(model: Optional[str], endpoint: Optional[str], multi_line: bool, **kwargs: Any)[source]

Bases: object

Client object for the chat command

chat_in_terminal() None[source]

Chat in terminal

print_hint_msg() None[source]

Print hint message when startup

render_model_response(msg_list: List[Tuple[str, bool, Optional[QfResponse]]]) Union[ConsoleRenderable, RichCast, str][source]

Render responses from multiple models

single_model_response(msg: Tuple[str, bool, Optional[QfResponse]]) Union[ConsoleRenderable, RichCast, str][source]

Renders response of one model

qianfan.common.client.chat.chat_entry(model: ~typing.Optional[str] = <typer.models.OptionInfo object>, endpoint: ~typing.Optional[str] = <typer.models.OptionInfo object>, multi_line: bool = <typer.models.OptionInfo object>, list_model: ~typing.Optional[bool] = <typer.models.OptionInfo object>, temperature: ~typing.Optional[float] = <typer.models.OptionInfo object>, top_p: ~typing.Optional[float] = <typer.models.OptionInfo object>, penalty_score: ~typing.Optional[float] = <typer.models.OptionInfo object>, system: ~typing.Optional[str] = <typer.models.OptionInfo object>, stop: ~typing.Optional[str] = <typer.models.OptionInfo object>, disable_search: ~typing.Optional[bool] = <typer.models.OptionInfo object>, enable_citation: ~typing.Optional[bool] = <typer.models.OptionInfo object>) None[source]

Chat with the LLM in the terminal.

qianfan.common.client.completion module

class qianfan.common.client.completion.CompletionClient(model: str, endpoint: Optional[str], plain: bool)[source]

Bases: object

Client class for completion command.

completion_multi(messages: List[str]) None[source]

Use ChatCompletion to complete the given messages.

completion_single(message: str) None[source]

Use Completion to complete the given message.

qianfan.common.client.completion.completion_entry(prompts: ~typing.Optional[~typing.List[str]] = <typer.models.ArgumentInfo object>, model: str = <typer.models.OptionInfo object>, endpoint: ~typing.Optional[str] = <typer.models.OptionInfo object>, plain: bool = <typer.models.OptionInfo object>, list_model: bool = <typer.models.OptionInfo object>, multi_line: bool = <typer.models.OptionInfo object>) None[source]

Complete the provided prompt or messages.

qianfan.common.client.dataset module

qianfan.common.client.dataset.download(dataset_id: str = <typer.models.ArgumentInfo object>, output: ~pathlib.Path = <typer.models.OptionInfo object>) None[source]

Download dataset to local file.

qianfan.common.client.dataset.extract_id_from_path(path: str) Optional[int][source]

Extract dataset id from path. Return 0 if path is not a qianfan dataset.

qianfan.common.client.dataset.load_dataset(path: str, **kwargs: Any) Dataset[source]

Load dataset from platform or local file based on the format of path.

qianfan.common.client.dataset.predict(dataset: str = <typer.models.ArgumentInfo object>, model: str = <typer.models.OptionInfo object>, endpoint: ~typing.Optional[str] = <typer.models.OptionInfo object>, output: ~pathlib.Path = <typer.models.OptionInfo object>, input_columns: str = <typer.models.OptionInfo object>, reference_column: ~typing.Optional[str] = <typer.models.OptionInfo object>) None[source]

Predict the dataset using a model and save to local file.

qianfan.common.client.dataset.save(src: str = <typer.models.ArgumentInfo object>, dst: ~typing.Optional[str] = <typer.models.ArgumentInfo object>, dataset_name: ~typing.Optional[str] = <typer.models.OptionInfo object>, dataset_template_type: str = <typer.models.OptionInfo object>, dataset_storage_type: str = <typer.models.OptionInfo object>, bos_path: str = <typer.models.OptionInfo object>) None[source]

Save dataset to platform or local file.

qianfan.common.client.dataset.upload(path: ~pathlib.Path = <typer.models.ArgumentInfo object>, dst: ~typing.Optional[str] = <typer.models.ArgumentInfo object>, dataset_name: ~typing.Optional[str] = <typer.models.OptionInfo object>, bos_path: str = <typer.models.OptionInfo object>, dataset_template_type: str = <typer.models.OptionInfo object>, dataset_storage_type: str = <typer.models.OptionInfo object>) None[source]

Upload dataset to platform.

qianfan.common.client.dataset.view(dataset: str = <typer.models.ArgumentInfo object>, row: ~typing.Optional[str] = <typer.models.OptionInfo object>, column: ~typing.Optional[str] = <typer.models.OptionInfo object>, raw: bool = <typer.models.OptionInfo object>) None[source]

View the content of the dataset.

qianfan.common.client.embedding module

qianfan.common.client.embedding.embedding_entry(list_model: bool = <typer.models.OptionInfo object>) None[source]

Embedding utils.

qianfan.common.client.main module

qianfan.common.client.main.entry(access_key: ~typing.Optional[str] = <typer.models.OptionInfo object>, secret_key: ~typing.Optional[str] = <typer.models.OptionInfo object>, ak: ~typing.Optional[str] = <typer.models.OptionInfo object>, sk: ~typing.Optional[str] = <typer.models.OptionInfo object>, version: ~typing.Optional[bool] = <typer.models.OptionInfo object>, enable_traceback: bool = <typer.models.OptionInfo object>, install_completion: bool = <typer.models.OptionInfo object>, show_completion: bool = <typer.models.OptionInfo object>) None[source]

Qianfan CLI which provides access to various Qianfan services.

qianfan.common.client.main.main() None[source]

Main function of qianfan client.

qianfan.common.client.main.qianfan_config_callback(ctx: Context, param: CallbackParam, value: str) None[source]

update qianfan config

qianfan.common.client.main.version_callback(value: bool) None[source]

Print qianfan sdk version

qianfan.common.client.trainer module

class qianfan.common.client.trainer.MyEventHandler(console: Console)[source]

Bases: EventHandler

dispatch(event: Event) None[source]

_summary_

Parameters:
event (Event):

event to dispatch to user custom handler

handle_deploy(event: Event) None[source]
handle_evaluate(event: Event) None[source]
handle_load_data(event: Event) None[source]
handle_pipeline(event: Event) None[source]
handle_publish(event: Event) None[source]
handle_train(event: Event) None[source]
qianfan.common.client.trainer.run(dataset_id: int = <typer.models.OptionInfo object>, train_type: str = <typer.models.OptionInfo object>, train_config_file: ~typing.Optional[str] = <typer.models.OptionInfo object>, train_epoch: ~typing.Optional[int] = <typer.models.OptionInfo object>, train_batch_size: ~typing.Optional[int] = <typer.models.OptionInfo object>, train_learning_rate: ~typing.Optional[float] = <typer.models.OptionInfo object>, train_max_seq_len: ~typing.Optional[int] = <typer.models.OptionInfo object>, train_peft_type: ~typing.Optional[~qianfan.trainer.consts.PeftType] = <typer.models.OptionInfo object>, trainset_rate: int = <typer.models.OptionInfo object>, train_logging_steps: ~typing.Optional[int] = <typer.models.OptionInfo object>, train_warmup_ratio: ~typing.Optional[float] = <typer.models.OptionInfo object>, train_weight_decay: ~typing.Optional[float] = <typer.models.OptionInfo object>, train_lora_rank: ~typing.Optional[int] = <typer.models.OptionInfo object>, train_lora_all_linear: ~typing.Optional[str] = <typer.models.OptionInfo object>, deploy_name: ~typing.Optional[str] = <typer.models.OptionInfo object>, deploy_endpoint_prefix: ~typing.Optional[str] = <typer.models.OptionInfo object>, deploy_description: str = <typer.models.OptionInfo object>, deploy_replicas: int = <typer.models.OptionInfo object>, deploy_pool_type: str = <typer.models.OptionInfo object>, deploy_service_type: str = <typer.models.OptionInfo object>) None[source]

Run a trainer job.

qianfan.common.client.txt2img module

qianfan.common.client.txt2img.txt2img_entry(prompt: str = <typer.models.ArgumentInfo object>, negative_prompt: str = <typer.models.OptionInfo object>, model: str = <typer.models.OptionInfo object>, endpoint: ~typing.Optional[str] = <typer.models.OptionInfo object>, output: ~typing.Optional[~pathlib.Path] = <typer.models.OptionInfo object>, plain: bool = <typer.models.OptionInfo object>, list_model: bool = <typer.models.OptionInfo object>) None[source]

Generate images based on the provided prompt.

qianfan.common.client.utils module

qianfan.common.client.utils.assert_not_none(value: Any, var_name: str) None[source]

Assert the value is not none.

qianfan.common.client.utils.bos_bucket_region(bucket: str) str[source]

Get the bos bucket location.

qianfan.common.client.utils.create_client(type: Type[BaseResourceType], model: str, endpoint: Optional[str], **kwargs: Any) BaseResourceType[source]

Create the client according to the type, model and endpoint.

qianfan.common.client.utils.enum_callback(ctx: Context, param: CallbackParam, value: str) Any[source]

update qianfan config

qianfan.common.client.utils.enum_list(enum_type: Type[Enum]) list[source]

Return a list of the enum values.

qianfan.common.client.utils.enum_typer(enum_type: Type[Enum]) Dict[str, Any][source]
qianfan.common.client.utils.list_model_callback(ctx: Context, param: CallbackParam, value: bool) None[source]

Print models of ChatCompletion and exit.

qianfan.common.client.utils.print_error_msg(msg: str, exit: bool = False) None[source]

Print an error message in the console.

qianfan.common.client.utils.print_info_msg(msg: str) None[source]

Print an info message in the console.

qianfan.common.client.utils.print_success_msg(msg: str) None[source]

Print a success message in the console.

qianfan.common.client.utils.print_warn_msg(msg: str) None[source]

Print a warning message in the console.

qianfan.common.client.utils.replace_logger_handler() Console[source]
qianfan.common.client.utils.timestamp(time: datetime = datetime.datetime(2024, 1, 11, 15, 34, 46, 422478)) str[source]

Return a timestamp string used in the client.