qianfan.resources.images package
Submodules
qianfan.resources.images.text2image module
- class qianfan.resources.images.text2image.Text2Image(model: Optional[str] = None, endpoint: Optional[str] = None, **kwargs: Any)[source]
Bases:
BaseResourceQianFan Text2Image API Resource
- async abatch_do(prompt_list: List[str], worker_num: int = 1, **kwargs: Any) List[Union[QfResponse, AsyncIterator[QfResponse]]][source]
Async batch execute a plugin action on the provided input prompt and generate responses.
- Parameters:
- prompt_list (List[str]):
The list user input or prompt for which a response is generated.
- worker_num (int):
The number of prompts to process at the same time.
- kwargs (Any):
Please refer to Plugin.ado for other parameters such as model, endpoint, retry_count, etc.
``` response_list = await Text2Image().abatch_do([…], worker_num = 10) for response in response_list:
# response is QfResponse if succeed, or response will be exception print(response)
- async ado(prompt: str, model: Optional[str] = None, endpoint: Optional[str] = None, with_decode: Optional[str] = None, retry_count: int = 1, request_timeout: float = 60, backoff_factor: float = 0, **kwargs: Any) Union[QfResponse, AsyncIterator[QfResponse]][source]
Async execute a text2image action on the provided input prompt and generate responses.
- Parameters:
- prompt (str):
The user input or prompt for which a response is generated.
- model (Optional[str]):
The name or identifier of the language model to use. If not specified, the default model is used(ERNIE-Bot-turbo).
- endpoint (Optional[str]):
The endpoint for making API requests. If not provided, the default endpoint is used.
- with_decode(Optional[str]):
The way to decode data. If not provided, the decode is not used. use “base64” to auto decode from data.
- retry_count (int):
The number of times to retry the request in case of failure.
- request_timeout (float):
The maximum time (in seconds) to wait for a response from the model.
- backoff_factor (float):
A factor to increase the waiting time between retry attempts.
- kwargs (Any):
Additional keyword arguments that can be passed to customize the request.
Additional parameters like temperature will vary depending on the model, please refer to the API documentation. The additional parameters can be passed as follows:
` Text2Image().do(prompt = ..., steps=20) `
- batch_do(prompt_list: List[str], worker_num: int = 1, **kwargs: Any) BatchRequestFuture[source]
Batch generate execute a plugin action on the provided input prompt and generate responses.
- Parameters:
- prompt_list (List[str]):
The list user input or prompt for which a response is generated.
- worker_num (int):
The number of prompts to process at the same time.
- kwargs (Any):
Please refer to Plugin.do for other parameters such as model, endpoint, retry_count, etc.
``` response_list = Text2Image().batch_do([”…”, “…”], worker_num = 10) for response in response_list:
# return QfResponse if succeed, or exception will be raised print(response.result())
# or while response_list.finished_count() != response_list.task_count():
time.sleep(1)
- do(prompt: str, model: Optional[str] = None, endpoint: Optional[str] = None, with_decode: Optional[str] = None, retry_count: int = 1, request_timeout: float = 60, backoff_factor: float = 0, **kwargs: Any) Union[QfResponse, Iterator[QfResponse]][source]
Execute a text2image action on the provided input prompt and generate responses.
- Parameters:
- prompt (str):
The user input or prompt for which a response is generated.
- model (Optional[str]):
The name or identifier of the language model to use. If not specified, the default model is used(ERNIE-Bot-turbo).
- endpoint (Optional[str]):
The endpoint for making API requests. If not provided, the default endpoint is used.
- with_decode(Optional[str]):
The way to decode data. If not provided, the decode is not used. use “base64” to auto decode from data.
- retry_count (int):
The number of times to retry the request in case of failure.
- request_timeout (float):
The maximum time (in seconds) to wait for a response from the model.
- backoff_factor (float):
A factor to increase the waiting time between retry attempts.
- kwargs (Any):
Additional keyword arguments that can be passed to customize the request.
Additional parameters like temperature will vary depending on the model, please refer to the API documentation. The additional parameters can be passed as follows:
` Text2Image().do(prompt = ..., steps=20) `