example_server.py 547 B

123456789101112131415161718
  1. import openai
  2. import sys
  3. openai.api_key = ""
  4. openai.api_base = "http://127.0.0.1:1337"
  5. chat_completion = openai.ChatCompletion.create(stream=True,
  6. model="gpt-3.5-turbo",
  7. messages=[{"role": "user",
  8. "content": "Write a poem about a tree."}])
  9. for token in chat_completion:
  10. content = token["choices"][0]["delta"].get("content")
  11. if content is not None:
  12. print(content, end="")
  13. sys.stdout.flush()