test_interference.py 668 B

123456789101112131415161718192021222324252627
  1. # type: ignore
  2. import openai
  3. openai.api_key = ""
  4. openai.api_base = "http://localhost:1337"
  5. def main():
  6. chat_completion = openai.ChatCompletion.create(
  7. model="gpt-3.5-turbo",
  8. messages=[{"role": "user", "content": "write a poem about a tree"}],
  9. stream=True,
  10. )
  11. if isinstance(chat_completion, dict):
  12. # not stream
  13. print(chat_completion.choices[0].message.content)
  14. else:
  15. # stream
  16. for token in chat_completion:
  17. content = token["choices"][0]["delta"].get("content")
  18. if content != None:
  19. print(content, end="", flush=True)
  20. if __name__ == "__main__":
  21. main()