test_all.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 4K Context
  34. g4f.models.gpt_35_turbo,
  35. g4f.models.gpt_35_turbo_0613,
  36. # GPT-3.5 16K Context
  37. g4f.models.gpt_35_turbo_16k,
  38. g4f.models.gpt_35_turbo_16k_0613,
  39. # GPT-4 8K Context
  40. g4f.models.gpt_4,
  41. g4f.models.gpt_4_0613,
  42. # GPT-4 32K Context
  43. g4f.models.gpt_4_32k,
  44. g4f.models.gpt_4_32k_0613,
  45. ]
  46. models_working = []
  47. for model in models_to_test:
  48. if await test(model):
  49. models_working.append(model.name)
  50. print("working models:", models_working)
  51. asyncio.run(start_test())