-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_chat.py
37 lines (28 loc) · 954 Bytes
/
test_chat.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
# Chat test program
# Date: 2024/10/04, 2025/01/26
# Author: [email protected]
import sys
sys.path.append("../..")
from cx.rag import chat
import unittest
def callback(chunk):
print(chunk, end="")
class TestChat(unittest.TestCase):
"""Test chat package
"""
def test_chat(self):
result = chat.invoke("Please explain Einstein's theory of relativity in 300 characters.")
print(result)
self.assertTrue("relativity" in result.lower())
def test_chat_streaming(self):
print("---streaming---")
self.result = ""
def _callback(text):
self.result += text
print(text, end="")
# Note: this is a synchronous method
chat.invoke("Please explain Einstein's theory of relativity in 800 characters.", callback=_callback)
print()
self.assertTrue("relativity" in self.result.lower())
if __name__ == "__main__":
unittest.main()