123456789101112131415161718192021 |
- import json
- from http import HTTPStatus
- from dashscope import Application
- with open("output.txt", 'r', encoding="utf8") as f:
- prompt = f.read()
- response = Application.call(
- # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
- api_key="sk-0164613e1a2143fc808fc4cc2451bef0",
- app_id='2f288f146e2d492abb3fe22695e70635', # 替换为实际的应用 ID
- prompt=prompt)
- if response.status_code == HTTPStatus.OK:
- try:
- json_data = json.loads(response.output.text)
- print(json_data)
- except json.JSONDecodeError:
- print("返回内容不是有效的 JSON 格式!")
- else:
- print(f"请求失败: {response.message}")
|