当前位置:   article > 正文

api调用阿里云的千问大模型_open api调用千问模型

open api调用千问模型
  1. from http import HTTPStatus
  2. import dashscope
  3. dashscope.api_key='你的key'
  4. def call_with_messages():
  5. messages = [{'role': 'system', 'content': 'You are a helpful assistant.'},
  6. {'role': 'user', 'content': '如何做炒西红柿鸡蛋?'}]
  7. response = dashscope.Generation.call(
  8. dashscope.Generation.Models.qwen_max,
  9. messages=messages,
  10. result_format='message', # set the result to be "message" format.
  11. )
  12. if response.status_code == HTTPStatus.OK:
  13. print(response.output.choices[0]['message']['role'])
  14. print(response.output.choices[0]['message']['content'])
  15. else:
  16. print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
  17. response.request_id, response.status_code,
  18. response.code, response.message
  19. ))
  20. if __name__ == '__main__':
  21. call_with_messages()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/615104
推荐阅读
相关标签
  

闽ICP备14008679号