接口文档
请求
import random
from http import HTTPStatus
from dashscope import Generation # 建议dashscope SDK 的版本 >= 1.14.0def call_with_messages():messages = [{'role': 'system', 'content': 'You are a helpful assistant.'},{'role': 'user', 'content': '如何做西红柿炒鸡蛋?'}]response = Generation.call(model="qwen-turbo",messages=messages,# 设置随机数种子seed,如果没有设置,则随机数种子默认为1234seed=random.randint(1, 10000),# 将输出设置为"message"格式result_format='message')if response.status_code == HTTPStatus.OK:print(response)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()
返回
{"status_code": 200,"request_id": "5d768057-2820-91ba-8c99-31cd520e7628","code": "","message": "","output": {"text": null,"finish_reason": null,"choices": [{"finish_reason": "stop","message": {"role": "assistant","content": "材料:\n西红柿2个,鸡蛋3个,油适量,盐适量,糖适量,葱花适量。\n\n步骤:\n\n1. 鸡蛋打入碗中,加入少许盐,用筷子搅拌均匀,放置一会儿让蛋白和蛋黄充分融合。\n\n2. 西红柿洗净,切成小块。如果喜欢口感更沙一些,可以切得稍微大一些;如果喜欢口感细腻,可以切得小一些。\n\n3. 热锅凉油,油热后倒入打好的鸡蛋液,用铲子快速搅拌,炒至鸡蛋凝固并变成金黄色,盛出备用。\n\n4. 锅中再加一点油,放入切好的西红柿,用中小火慢慢翻煮,让西红柿出汁,这样炒出来的西红柿才会更甜。\n\n5. 西红柿出汁后,加入适量的糖,继续翻煮,直到西红柿变得软烂。\n\n6. 将炒好的鸡蛋倒回锅中,与西红柿一起翻煮均匀,让鸡蛋充分吸收西红柿的汁水。\n\n7. 最后,根据个人口味加入适量的盐调味,撒上葱花进行提香,翻炒均匀即可出锅。\n\n8. 如果喜欢汤汁多一些,可以适当加点水,调整一下浓稠度。\n\n西红柿炒鸡蛋就做好了,简单易做,营养美味,是一道家常菜的经典之作。"}}]},"usage": {"input_tokens": 25,"output_tokens": 289,"total_tokens": 314}
}