qianfan.resources.images package
Submodules
qianfan.resources.images.image2text module
- class qianfan.resources.images.image2text.Image2Text(model: Optional[str] = None, endpoint: Optional[str] = None, **kwargs: Any)[source]
Bases:
BaseResourceQianFan Image2Text API Resource
- async abatch_do(input_list: List[Tuple[str, str]], worker_num: Optional[int] = None, **kwargs: Any) List[Union[QfResponse, AsyncIterator[QfResponse]]][source]
Async batch generate execute a image2text action on the provided inputs and generate responses.
- Parameters:
- input_list (Tuple(str, str)):
The list user input prompt and base64 encoded image data for which a response is generated.
- worker_num (Optional[int]):
The number of prompts to process at the same time, default to None, which means this number will be decided dynamically.
- kwargs (Any):
Please refer to Plugin.ado for other parameters such as model, endpoint, retry_count, etc.
``` response_list = await Image2Text(endpoint=””).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, image: str, model: Optional[str] = None, endpoint: Optional[str] = None, stream: bool = False, retry_count: int = 1, request_timeout: float = 60, request_id: Optional[str] = None, backoff_factor: float = 0, **kwargs: Any) Union[QfResponse, AsyncIterator[QfResponse]][source]
Async execute a image2text action on the provided input prompt and generate responses.
- Parameters:
- prompt (str):
The user input or prompt for which a response is generated.
- image (str):
The user input base64 encoded image data for which a response is generated.
- model (Optional[str]):
The name or identifier of the language model to use.
- endpoint (Optional[str]):
The endpoint for making API requests. If not provided, the default endpoint is used.
- stream (bool):
Whether to stream responses or not.
- 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:
` Image2Text(endpoint="").ado(prompt="", image="", xx=vv) `
- batch_do(input_list: List[Tuple[str, str]], worker_num: Optional[int] = None, **kwargs: Any) BatchRequestFuture[source]
Batch generate execute a image2text action on the provided inputs and generate responses.
- Parameters:
- input_list (Tuple(str, str)):
The list user input prompt and base64 encoded image data for which a response is generated.
- worker_num (Optional[int]):
The number of prompts to process at the same time, default to None, which means this number will be decided dynamically.
- kwargs (Any):
Please refer to Plugin.do for other parameters such as model, endpoint, retry_count, etc.
``` response_list = Image2Text(endpoint=””).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, image: str, model: Optional[str] = None, endpoint: Optional[str] = None, stream: bool = False, retry_count: int = 1, request_timeout: float = 60, request_id: Optional[str] = None, backoff_factor: float = 0, **kwargs: Any) Union[QfResponse, Iterator[QfResponse]][source]
Execute a image2text action on the provided input prompt and generate responses.
- Parameters:
- prompt (str):
The user input or prompt for which a response is generated.
- image (str):
The user input base64 encoded image data for which a response is generated.
- model (Optional[str]):
The name or identifier of the language model to use.
- endpoint (Optional[str]):
The endpoint for making API requests. If not provided, the default endpoint is used.
- stream (bool):
Whether to stream responses or not.
- 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:
` Image2Text(endpoint="").do(prompt="", image="", xxx=vvv) `
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: Optional[int] = None, **kwargs: Any) List[Union[QfResponse, AsyncIterator[QfResponse]]][source]
Async batch execute a text2image 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 (Optional[int]):
The number of prompts to process at the same time, default to None, which means this number will be decided dynamically.
- kwargs (Any):
Please refer to Text2Image.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, request_id: Optional[str] = None, 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(Stable-Diffusion-XL).
- 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: Optional[int] = None, **kwargs: Any) BatchRequestFuture[source]
Batch generate execute a text2image 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 (Optional[int]):
The number of prompts to process at the same time, default to None, which means this number will be decided dynamically.
- kwargs (Any):
Please refer to Text2Image.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, request_id: Optional[str] = None, 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(Stable-Diffusion-XL).
- 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) `