model.py 915 B

123456789101112131415161718192021222324252627
  1. import unittest
  2. import g4f
  3. from g4f import ChatCompletion
  4. from .mocks import ModelProviderMock
  5. DEFAULT_MESSAGES = [{'role': 'user', 'content': 'Hello'}]
  6. test_model = g4f.models.Model(
  7. name = "test/test_model",
  8. base_provider = "",
  9. best_provider = ModelProviderMock
  10. )
  11. g4f.models.ModelUtils.convert["test_model"] = test_model
  12. class TestPassModel(unittest.TestCase):
  13. def test_model_instance(self):
  14. response = ChatCompletion.create(test_model, DEFAULT_MESSAGES)
  15. self.assertEqual(test_model.name, response)
  16. def test_model_name(self):
  17. response = ChatCompletion.create("test_model", DEFAULT_MESSAGES)
  18. self.assertEqual(test_model.name, response)
  19. def test_model_pass(self):
  20. response = ChatCompletion.create("test/test_model", DEFAULT_MESSAGES, ModelProviderMock)
  21. self.assertEqual(test_model.name, response)