赞
踩
- from http import HTTPStatus
- import dashscope
- dashscope.api_key='你的key'
-
- def call_with_messages():
- messages = [{'role': 'system', 'content': 'You are a helpful assistant.'},
- {'role': 'user', 'content': '如何做炒西红柿鸡蛋?'}]
-
- response = dashscope.Generation.call(
- dashscope.Generation.Models.qwen_max,
- messages=messages,
- result_format='message', # set the result to be "message" format.
- )
- if response.status_code == HTTPStatus.OK:
- print(response.output.choices[0]['message']['role'])
- print(response.output.choices[0]['message']['content'])
- else:
- print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
- response.request_id, response.status_code,
- response.code, response.message
- ))
-
-
- if __name__ == '__main__':
- call_with_messages()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。