test_chat_completion.py 722 B

12345678910111213141516171819202122232425262728
  1. import sys
  2. from pathlib import Path
  3. sys.path.append(str(Path(__file__).parent.parent.parent))
  4. import g4f, asyncio
  5. print("create:", end=" ", flush=True)
  6. for response in g4f.ChatCompletion.create(
  7. model=g4f.models.gpt_4_32k_0613,
  8. provider=g4f.Provider.Aivvm,
  9. messages=[{"role": "user", "content": "write a poem about a tree"}],
  10. temperature=0.1,
  11. stream=True
  12. ):
  13. print(response, end="", flush=True)
  14. print()
  15. async def run_async():
  16. response = await g4f.ChatCompletion.create_async(
  17. model=g4f.models.gpt_35_turbo_16k_0613,
  18. provider=g4f.Provider.GptGod,
  19. messages=[{"role": "user", "content": "hello!"}],
  20. )
  21. print("create_async:", response)
  22. # asyncio.run(run_async())