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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// use crate::tests::format_test_block;
// use crate::chat::message::{Messages, Role};
//
// pub async fn test_message() {
// test_message_creation();
// test_add_message();
// test_get_node_by_path();
// test_update_content();
// test_delete_message();
// test_to_api_format();
// }
//
// fn test_message_creation() {
// let msg = Messages::new(Role::User, "Hello".to_string());
// assert_eq!(msg.role, Role::User);
// assert_eq!(msg.content, "Hello");
// assert_eq!(msg.path.len(), 0);
// assert_eq!(msg.child.len(), 0);
// format_test_block("message_creation", || format!("{:?}", msg))
// }
//
// fn test_add_message() {
// let mut root = Messages::new(Role::System, "System prompt".to_string());
//
// // 添加第一级消息
// // Add first level message
// root.add(&[], Role::User, "User message".to_string())
// .unwrap();
// assert_eq!(root.child.len(), 1);
// assert_eq!(root.child[0].role, Role::User);
// assert_eq!(root.child[0].content, "User message");
// assert_eq!(root.child[0].path, vec![0]);
//
// // 添加第二级消息
// // Add second level message
// root.add(&[0], Role::Assistant, "Assistant response".to_string())
// .unwrap();
// assert_eq!(root.child[0].child.len(), 1);
// assert_eq!(root.child[0].child[0].role, Role::Assistant);
// assert_eq!(root.child[0].child[0].content, "Assistant response");
// assert_eq!(root.child[0].child[0].path, vec![0, 0]);
// format_test_block("add_message", || format!("{:?}", root))
// }
//
// fn test_get_node_by_path() {
// let mut root = Messages::new(Role::System, "System prompt".to_string());
// root.add(&[], Role::User, "User message".to_string())
// .unwrap();
// root.add(&[0], Role::Assistant, "Assistant response".to_string())
// .unwrap();
//
// let node = root.get_node_by_path(&[0, 0]).unwrap();
// assert_eq!(node.role, Role::Assistant);
// assert_eq!(node.content, "Assistant response");
// format_test_block("get_node_by_path", || format!("{:?}", node))
// }
//
// fn test_update_content() {
// let mut root = Messages::new(Role::System, "System prompt".to_string());
// root.add(&[], Role::User, "User message".to_string())
// .unwrap();
//
// root.update_content(&[0], "Updated user message".to_string())
// .unwrap();
// assert_eq!(root.child[0].content, "Updated user message");
// format_test_block("update_content", || format!("{:?}", root))
// }
//
// fn test_delete_message() {
// let mut root = Messages::new(Role::System, "System prompt".to_string());
// root.add(&[], Role::User, "User 1".to_string()).unwrap();
// root.add(&[], Role::User, "User 2".to_string()).unwrap();
// root.add(&[], Role::User, "User 3".to_string()).unwrap();
//
// // 删除第二条消息
// // Delete the second message
// root.delete(&[1]).unwrap();
//
// assert_eq!(root.child.len(), 2);
// assert_eq!(root.child[0].content, "User 1");
// assert_eq!(root.child[1].content, "User 3");
// assert_eq!(root.child[1].path, vec![1]);
//
// format_test_block("delete_message", || format!("{:?}", root))
// }
//
// fn test_to_api_format() {
// let msg = Messages::new(Role::User, "Hello".to_string());
// let api_format = msg.to_api_format(&Role::Assistant);
//
// assert_eq!(api_format.get("role").unwrap(), "user");
// assert_eq!(api_format.get("content").unwrap(), "Hello");
//
// let character_msg = Messages::new(Role::Character("Alice".to_string()), "Hi Bob".to_string());
//
// // 当角色不是当前发言者
// // When the role is not the current speaker
// let api_format = character_msg.to_api_format(&Role::Assistant);
// assert_eq!(api_format.get("role").unwrap(), "user");
// assert_eq!(api_format.get("content").unwrap(), "Alice said: Hi Bob");
//
// // 当角色是当前发言者
// // When the role is the current speaker
// let api_format = character_msg.to_api_format(&Role::Character("Alice".to_string()));
// assert_eq!(api_format.get("role").unwrap(), "assistant");
// assert_eq!(api_format.get("content").unwrap(), "Hi Bob");
//
// format_test_block("to_api_format", || format!("{:?}", api_format))
// }