如何使用程序调用通义千问
安装
支持两种方式,python和java
python 导入依赖
pip install dashscope
java安装:安装DashScope SDK_模型服务灵积(DashScope)-阿里云帮助中心
获取API-KEY
如何开通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()
原文地址:https://blog.csdn.net/star1210644725/article/details/136483837
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!