agentscope.service.multi_modality.dashscope_services module
Use DashScope API to generate images, convert text to audio, and convert images to text. Please refer to the official documentation for more details: https://dashscope.aliyun.com/
- agentscope.service.multi_modality.dashscope_services.dashscope_text_to_image(prompt: str, api_key: str, n: int = 1, size: Literal['1024*1024', '720*1280', '1280*720'] = '1024*1024', model: str = 'wanx-v1', save_dir: str | None = None) ServiceResponse [源代码]
Generate image(s) based on the given prompt, and return image url(s).
- 参数:
prompt (str) – The text prompt to generate image.
api_key (str) – The api key for the dashscope api.
n (int, defaults to 1) – The number of images to generate.
(`Literal["1024*1024" (size) –
"720*1280"
"1280*720"]`
to (defaults)
"1024*1024") – Size of the image.
model (str, defaults to ‘“wanx-v1”’) – The model to use.
save_dir (Optional[str], defaults to ‘None’) – The directory to save the generated images. If not specified, will return the web urls.
- 返回:
A dictionary with two variables: status and`content`. If status is ServiceExecStatus.SUCCESS, the content is a dict with key ‘fig_paths” and value is a list of the paths to the generated images.
- 返回类型:
示例
prompt = "A beautiful sunset in the mountains" print(dashscope_text_to_image(prompt, "{api_key}"))
> { > ‘status’: ‘SUCCESS’, > ‘content’: {‘image_urls’: [‘IMAGE_URL1’, ‘IMAGE_URL2’]} > }
- agentscope.service.multi_modality.dashscope_services.dashscope_image_to_text(image_urls: str | Sequence[str], api_key: str, prompt: str = 'Describe the image', model: str = 'qwen-vl-plus') ServiceResponse [源代码]
Generate text based on the given images.
- 参数:
image_urls (Union[str, Sequence[str]]) – The url of single or multiple images.
api_key (str) – The api key for the dashscope api.
prompt (str, defaults to ‘Describe the image’) – The text prompt.
model (str, defaults to ‘qwen-vl-plus’) – The model to use in DashScope MultiModal API.
- 返回:
A dictionary with two variables: status and`content`. If status is ServiceExecStatus.SUCCESS, the content is the generated text.
- 返回类型:
ServiceResponse
示例
image_url = "image.jpg" prompt = "Describe the image" print(image_to_text(image_url, prompt))
> {‘status’: ‘SUCCESS’, ‘content’: ‘A beautiful sunset in the mountains’}
- agentscope.service.multi_modality.dashscope_services.dashscope_text_to_audio(text: str, api_key: str, save_dir: str, model: str = 'sambert-zhichu-v1', sample_rate: int = 48000) ServiceResponse [源代码]
Convert the given text to audio.
- 参数:
text (str) – The text to be converted into audio.
api_key (str) – The api key for the dashscope API.
save_dir (str) – The directory to save the generated audio.
model (str, defaults to ‘sambert-zhichu-v1’) – The model to use. Full model list can be found in https://help.aliyun.com/zh/dashscope/model-list
sample_rate (int, defaults to 48000) – Samplerate of the audio.
- 返回:
A dictionary with two variables: status and`content`. If status is ServiceExecStatus.SUCCESS, the content contains a dictionary with key “audio_path” and value is the path to the generated audio.
- 返回类型:
ServiceResponse
示例
text = "How is the weather today?" print(text_to_audio(text)) gives:
> {‘status’: ‘SUCCESS’, ‘content’: {“audio_path”: “AUDIO_PATH”}}