-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_llm.py
38 lines (28 loc) · 1.33 KB
/
test_llm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import unittest
from llm_engines import LLM, LLMApi, ChatgptLLM
class TestLLM(unittest.TestCase):
def setUp(self):
self.llm = LLM()
def test_set_system_prompt(self):
self.llm.set_system_prompt('test prompt')
self.assertEqual(self.llm.get_system_prompt(), 'test prompt')
def test_set_history(self):
self.llm.set_history([{'role': 'system', 'content': 'test history'}])
self.assertEqual(self.llm.get_history(), [{'role': 'system', 'content': 'test history'}])
class TestLLMApi(unittest.TestCase):
def setUp(self):
self.llmapi = LLMApi()
def test_generate_response(self):
self.assertTrue(self.llmapi.generate_response('test prompt'))
# check that history was updated by comparing length of history before and after
class TestChatgptLLM(unittest.TestCase):
def setUp(self):
self.chatgpt_llm = ChatgptLLM()
def test_set_system_prompt(self):
self.chatgpt_llm.set_system_prompt('test user prompt')
self.assertEqual(self.chatgpt_llm.get_system_prompt(), 'test user prompt')
def test_generate_response(self):
self.assertTrue(self.chatgpt_llm.generate_response('test prompt'))
# check that history was updated by comparing length of history before and after
if __name__ == '__main__':
unittest.main()