test_all.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import asyncio
  2. import sys
  3. from pathlib import Path
  4. sys.path.append(str(Path(__file__).parent.parent.parent))
  5. import g4f
  6. async def test(model: g4f.Model):
  7. try:
  8. try:
  9. for response in g4f.ChatCompletion.create(
  10. model=model,
  11. messages=[{"role": "user", "content": "write a poem about a tree"}],
  12. temperature=0.1,
  13. stream=True
  14. ):
  15. print(response, end="")
  16. print()
  17. except:
  18. for response in await g4f.ChatCompletion.create_async(
  19. model=model,
  20. messages=[{"role": "user", "content": "write a poem about a tree"}],
  21. temperature=0.1,
  22. stream=True
  23. ):
  24. print(response, end="")
  25. print()
  26. return True
  27. except Exception as e:
  28. print(model.name, "not working:", e)
  29. print(e.__traceback__.tb_next)
  30. return False
  31. async def start_test():
  32. models_to_test = [
  33. # GPT-3.5
  34. g4f.models.gpt_35_turbo,
  35. # GPT-4
  36. g4f.models.gpt_4,
  37. ]
  38. models_working = []
  39. for model in models_to_test:
  40. if await test(model):
  41. models_working.append(model.name)
  42. print("working models:", models_working)
  43. asyncio.run(start_test())