千问开源大模型
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
546 B

  1. # coding=utf-8
  2. import requests
  3. import json
  4. url = "https://api.openai.com/v1/chat/completions"
  5. payload = json.dumps({
  6. "model": "gpt-3.5-turbo",
  7. "messages": [
  8. {
  9. "role": "user",
  10. "content": "你好!"
  11. }
  12. ]
  13. })
  14. headers = {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': 'Bearer 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'
  17. }
  18. response = requests.request("POST", url, headers=headers, data=payload)
  19. # print(response.text)
  20. r=json.loads(response.text)
  21. # r=response.text
  22. print(r['choices'][0]['message']['content'])