python实现调用通义千问API,实现对话

我的微信小程序上线了,AI识图生诗词文案,识别图片生成古诗词,欢迎大家使用。

(用户日访问量太少了,大家帮我踩一下,谢谢!)

以下是我在开发中的一些经验和心得。

下面是一个简单的调用通义千问大模型api,实现问答的功能,因为我做的是生成文案的小程序,所以user_prompt是输入,result是大模型的输出。

# 先pip安装dashscope
import dashscope

# 你的通义千问API key,可以在https://www.aliyun.com/阿里云官网注册并申请
dashscope.api_key='sk-****************************'

from http import HTTPStatus
def call_with_prompt(prompt):
    response = dashscope.Generation.call(
        model=dashscope.Generation.Models.qwen_max,
        prompt=prompt
    )
    if response.status_code == HTTPStatus.OK:
        #print(response.output.text)  # The output text
        #print(response.usage)  # The usage information
        return response.output.text
    else:
        #print(response.code)  # The error code.
        #print(response.message)  # The error message.
        return None


theme = '您过奖了'
user_prompt = '将我的回答:' + theme +',改写为高情商、幽默、机智的回答'
result = call_with_prompt(user_prompt)
print(result)

  • 10
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值