example_gpt-3.5-turbo.py 453 B

12345678910111213
  1. import g4f
  2. import sys
  3. # Automatic selection of provider, streamed completion
  4. response = g4f.ChatCompletion.create(model='gpt-3.5-turbo',
  5. messages=[{"role": "user",
  6. "content": "Write a poem about a tree."}],
  7. stream=True)
  8. for message in response:
  9. print(message, end="")
  10. sys.stdout.flush()