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

Bases: object

Client object for the chat command

END_PROMPT = '/exit'
HELP_MESSAGES = {'/exit': 'End the conversation', '/help': 'Print help message', '/reset': 'Reset the conversation'}
HELP_PROMPT = '/help'
RESET_PROMPT = '/reset'
chat_in_terminal() None[source]

Chat in terminal

input_completer = <prompt_toolkit.completion.word_completer.WordCompleter object>
print_help_message() None[source]

Print command introduction

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>, debug: 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>, extra_parameters: ~typing.Optional[str] = <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, debug: bool, **kwargs: Any)[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>, debug: 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]

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[str][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.evaluation module

qianfan.common.client.evaluation.list_evaluable_models(ctx: Context, param: CallbackParam, value: bool) None[source]

Print models of ChatCompletion and exit.

qianfan.common.client.evaluation.run(models: ~typing.List[str] = <typer.models.ArgumentInfo object>, dataset_id: str = <typer.models.OptionInfo object>, enable_rule_evaluator: bool = <typer.models.OptionInfo object>, using_similarity: bool = <typer.models.OptionInfo object>, using_accuracy: bool = <typer.models.OptionInfo object>, stop_words: ~typing.Optional[str] = <typer.models.OptionInfo object>, enable_referee_evaluator: bool = <typer.models.OptionInfo object>, app_id: ~typing.Optional[int] = <typer.models.OptionInfo object>, prompt_metrics: str = <typer.models.OptionInfo object>, prompt_steps: str = <typer.models.OptionInfo object>, prompt_max_score: int = <typer.models.OptionInfo object>, enable_manual_evaluator: bool = <typer.models.OptionInfo object>, dimensions: ~typing.Optional[str] = <typer.models.OptionInfo object>, list_evaluable_models: ~typing.Optional[bool] = <typer.models.OptionInfo object>) None[source]

Run evaluation task.

At least one evaluator should be enabled. Manual evaluator may not be mixed with other evaluators.

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.plugin module

class qianfan.common.client.plugin.PluginClient(model: Optional[str], endpoint: Optional[str], multi_line: bool, debug: bool, plugins: List[str], bos_path: Optional[str], **kwargs: Any)[source]

Bases: object

Client object for the chat command

END_PROMPT = '/exit'
HELP_MESSAGES = {'/exit': 'End the conversation', '/help': 'Print help message', '/image': 'Attach a local image to the conversation (e.g. /image car.jpg)', '/reset': 'Reset the conversation'}
HELP_PROMPT = '/help'
IMAGE_PROMPT = '/image'
RESET_PROMPT = '/reset'
chat_in_terminal() None[source]

Chat in terminal

get_bos_path() str[source]

Get bos path. If bos_path is not provided, prompt user to input

input_completer = <prompt_toolkit.completion.word_completer.WordCompleter object>
print_help_message() None[source]

Print command introduction

print_hint_msg() None[source]

Print hint message when startup

upload_file_to_bos(filepath: str) Tuple[str, str][source]

Upload file to bos and get bos_url and http_url

class qianfan.common.client.plugin.PluginInputValidator[source]

Bases: InputEmptyValidator

Validator for input in plugin

validate(document: Document) None[source]

validate input: - input must not be empty - if input is /image, file path must be provided

qianfan.common.client.plugin.plugin_entry(endpoint: ~typing.Optional[str] = <typer.models.OptionInfo object>, multi_line: bool = <typer.models.OptionInfo object>, debug: bool = <typer.models.OptionInfo object>, plugins: str = <typer.models.OptionInfo object>, bos_path: ~typing.Optional[str] = <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>) None[source]

Chat with the LLM with plugins in the terminal.

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.list_train_type(ctx: Context, param: CallbackParam, value: bool) None[source]

list all the supported train types

qianfan.common.client.trainer.print_trainer_config(config: ModelInfo) None[source]

Print trainer config

qianfan.common.client.trainer.run(dataset_id: ~typing.Optional[str] = <typer.models.OptionInfo object>, dataset_bos_path: ~typing.Optional[str] = <typer.models.OptionInfo object>, train_type: str = <typer.models.OptionInfo object>, list_train_type: ~typing.Optional[bool] = <typer.models.OptionInfo object>, show_config_limit: ~typing.Optional[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.trainer.show_config_limit(ctx: Context, param: CallbackParam, value: str) None[source]

show config limit for specified train type

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: ~pathlib.Path = <typer.models.OptionInfo object>, plain: bool = <typer.models.OptionInfo object>, list_model: bool = <typer.models.OptionInfo object>, debug: bool = <typer.models.OptionInfo object>) None[source]

Generate images based on the provided prompt.

qianfan.common.client.utils module

class qianfan.common.client.utils.BosPathValidator[source]

Bases: Validator

validate(document: Document) None[source]

Validate the input. If invalid, this should raise a ValidationError.

Parameters:

documentDocument instance.

class qianfan.common.client.utils.InputEmptyValidator[source]

Bases: Validator

validate(document: Document) None[source]

Validate the input. If invalid, this should raise a ValidationError.

Parameters:

documentDocument instance.

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.check_credential() None[source]
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.credential_required(func: Callable) Callable[source]

Check the credential is provided.

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.render_response_debug_info(response: QfResponse) Group[source]
qianfan.common.client.utils.replace_logger_handler() Console[source]
qianfan.common.client.utils.timestamp(time: datetime = datetime.datetime(2024, 2, 5, 2, 30, 42, 523193)) str[source]

Return a timestamp string used in the client.