赞
踩
支持两种方式,python和java
python 导入依赖
pip install dashscope
java安装:安装DashScope SDK_模型服务灵积(DashScope)-阿里云帮助中心
如何开通DashScope并创建API-KEY_模型服务灵积(DashScope)-阿里云帮助中心
python代码
- import dashscope
- import time
- from http import HTTPStatus
- # 替换api key
- dashscope.api_key="sk-f7a06881b8814bdebd19252d47ccc6f1"
-
- def sample_sync_call():
- start_time = time.time() # 记录开始时间
- prompt_text = '用土豆可以做什么饭'
- resp = dashscope.Generation.call(
- model='qwen-max',
- prompt=prompt_text
- )
- end_time = time.time() # 记录结束时间
- # The response status_code is HTTPStatus.OK indicate success,
- # otherwise indicate request is failed, you can get error code
- # and message from code and message.
- if resp.status_code == HTTPStatus.OK:
- print(resp.output) # The output text
- print(resp.usage) # The usage information
- else:
- print(resp.code) # The error code.
- print(resp.message) # The error message.
-
- # 计算并打印调用时间
- print("调用时间:", end_time - start_time, "秒")
-
-
- sample_sync_call()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。