12345678910111213141516 |
- import os
- from http import HTTPStatus
- from dashscope import Application
- response = Application.call(
- # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
- api_key="sk-f49eecdb8e50462aa5cdc4f6f1c27446",
- app_id='b2fc1c44f28647f3ab2fbe283d7e4102',# 替换为实际的应用 ID
- prompt='你是谁?')
- if response.status_code != HTTPStatus.OK:
- print(f'request_id={response.request_id}')
- print(f'code={response.status_code}')
- print(f'message={response.message}')
- print(f'请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code')
- else:
- print(response.output.text)
|