From e4f743881c915ba250b859d01ef78c7b90a96bf5 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 23 Jan 2024 12:17:16 +0100 Subject: Fix: Model sometimes not converted #1507 --- etc/unittest/model.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 etc/unittest/model.py (limited to 'etc/unittest/model.py') diff --git a/etc/unittest/model.py b/etc/unittest/model.py new file mode 100644 index 00000000..0d318e7a --- /dev/null +++ b/etc/unittest/model.py @@ -0,0 +1,27 @@ +import unittest +import g4f +from g4f import ChatCompletion +from .mocks import ModelProviderMock + +DEFAULT_MESSAGES = [{'role': 'user', 'content': 'Hello'}] + +test_model = g4f.models.Model( + name = "test/test_model", + base_provider = "", + best_provider = ModelProviderMock +) +g4f.models.ModelUtils.convert["test_model"] = test_model + +class TestPassModel(unittest.TestCase): + + def test_model_instance(self): + response = ChatCompletion.create(test_model, DEFAULT_MESSAGES) + self.assertEqual(test_model.name, response) + + def test_model_name(self): + response = ChatCompletion.create("test_model", DEFAULT_MESSAGES) + self.assertEqual(test_model.name, response) + + def test_model_pass(self): + response = ChatCompletion.create("test/test_model", DEFAULT_MESSAGES, ModelProviderMock) + self.assertEqual(test_model.name, response) \ No newline at end of file -- cgit v1.2.3