From fe9b082c896beab2b0888415e7edc66bbfe2f168 Mon Sep 17 00:00:00 2001 From: Zack Date: Fri, 20 Oct 2023 17:09:03 -0500 Subject: [PATCH] feat: Test revgptV1.py Former-commit-id: 18fd62f36ec71fb3156b3172f4a0281758d64f29 --- swarms/models/revgptV1.py | 2 +- tests/models/revgpt.py | 82 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tests/models/revgpt.py diff --git a/swarms/models/revgptV1.py b/swarms/models/revgptV1.py index a3a4e878..4aaf2cf3 100644 --- a/swarms/models/revgptV1.py +++ b/swarms/models/revgptV1.py @@ -40,7 +40,7 @@ from swarms.utils.revutils import create_completer from swarms.utils.revutils import create_session from swarms.utils.revutils import get_input -BASE_URL = environ.get("CHATGPT_BASE_URL", "http://192.168.250.249:9898/api/") +# BASE_URL = environ.get("CHATGPT_BASE_URL", "http://192.168.250.249:9898/api/") # BASE_URL = os.environ.get("CHATGPT_BASE_URL", "https://ai.fakeopen.com/api/") # BASE_URL = environ.get("CHATGPT_BASE_URL", "https://bypass.churchless.tech/") diff --git a/tests/models/revgpt.py b/tests/models/revgpt.py new file mode 100644 index 00000000..8f372282 --- /dev/null +++ b/tests/models/revgpt.py @@ -0,0 +1,82 @@ +import unittest +from unittest.mock import patch +from Sswarms.models.revgptv1 import RevChatGPTModelv1 + +class TestRevChatGPT(unittest.TestCase): + + def setUp(self): + self.access_token = "" + self.model = RevChatGPTModelv1(access_token=self.access_token) + + def test_run(self): + prompt = "What is the capital of France?" + response = self.model.run(prompt) + self.assertEqual(response, "The capital of France is Paris.") + + def test_run_time(self): + prompt = "Generate a 300 word essay about technology." + response = self.model.run(prompt) + self.assertLess(self.model.end_time - self.model.start_time, 60) + + def test_generate_summary(self): + text = "This is a sample text to summarize. It has multiple sentences and details. The summary should be concise." + summary = self.model.generate_summary(text) + self.assertLess(len(summary), len(text)/2) + + def test_enable_plugin(self): + plugin_id = "some_plugin_id" + self.model.enable_plugin(plugin_id) + self.assertIn(plugin_id, self.model.config["plugin_ids"]) + + def test_list_plugins(self): + plugins = self.model.list_plugins() + self.assertGreater(len(plugins), 0) + self.assertIsInstance(plugins[0], dict) + self.assertIn("id", plugins[0]) + self.assertIn("name", plugins[0]) + + def test_get_conversations(self): + conversations = self.model.chatbot.get_conversations() + self.assertIsInstance(conversations, list) + + @patch("RevChatGPTModelv1.Chatbot.get_msg_history") + def test_get_msg_history(self, mock_get_msg_history): + conversation_id = "convo_id" + self.model.chatbot.get_msg_history(conversation_id) + mock_get_msg_history.assert_called_with(conversation_id) + + @patch("RevChatGPTModelv1.Chatbot.share_conversation") + def test_share_conversation(self, mock_share_conversation): + self.model.chatbot.share_conversation() + mock_share_conversation.assert_called() + + def test_gen_title(self): + convo_id = "123" + message_id = "456" + title = self.model.chatbot.gen_title(convo_id, message_id) + self.assertIsInstance(title, str) + + def test_change_title(self): + convo_id = "123" + title = "New Title" + self.model.chatbot.change_title(convo_id, title) + self.assertEqual(self.model.chatbot.get_msg_history(convo_id)["title"], title) + + def test_delete_conversation(self): + convo_id = "123" + self.model.chatbot.delete_conversation(convo_id) + with self.assertRaises(Exception): + self.model.chatbot.get_msg_history(convo_id) + + def test_clear_conversations(self): + self.model.chatbot.clear_conversations() + conversations = self.model.chatbot.get_conversations() + self.assertEqual(len(conversations), 0) + + def test_rollback_conversation(self): + original_convo_id = self.model.chatbot.conversation_id + self.model.chatbot.rollback_conversation(1) + self.assertNotEqual(original_convo_id, self.model.chatbot.conversation_id) + +if __name__ == "__main__": + unittest.main()