dolly.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # For prerequisites running the following sample, visit https://help.aliyun.com/document_detail/611472.html
  2. import dashscope
  3. from dashscope import Generation
  4. from http import HTTPStatus
  5. import api
  6. dashscope.api_key=api.api_key
  7. response = Generation.call(
  8. model='dolly-12b-v2',
  9. prompt='翻一下:今天星期几拉拉。'
  10. )
  11. # The response status_code is HTTPStatus.OK indicate success,
  12. # otherwise indicate request is failed, you can get error code
  13. # and message from code and message.
  14. if response.status_code == HTTPStatus.OK:
  15. print(response.output) # The output text
  16. print(response.usage) # The usage information
  17. else:
  18. print(response.code) # The error code.
  19. print(response.message) # The error message.
  20. # {
  21. # "status_code": 200,
  22. # "request_id": "39a41abe-1bed-430a-b9b5-277130c7eb82",
  23. # "code": "",
  24. # "message": "",
  25. # "output": {
  26. # "text": "Spring has come, flowers blossomed."
  27. # },
  28. # "usage": {
  29. # "input_tokens": 0,
  30. # "output_tokens": 0
  31. # }
  32. # }