lionagi 0.0.305__py3-none-any.whl → 0.0.307__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lionagi/__init__.py +2 -5
- lionagi/core/__init__.py +7 -4
- lionagi/core/agent/__init__.py +3 -0
- lionagi/core/agent/base_agent.py +46 -0
- lionagi/core/branch/__init__.py +4 -0
- lionagi/core/branch/base/__init__.py +0 -0
- lionagi/core/branch/base_branch.py +100 -78
- lionagi/core/branch/branch.py +22 -34
- lionagi/core/branch/branch_flow_mixin.py +3 -7
- lionagi/core/branch/executable_branch.py +192 -0
- lionagi/core/branch/util.py +77 -162
- lionagi/core/direct/__init__.py +13 -0
- lionagi/core/direct/parallel_predict.py +127 -0
- lionagi/core/direct/parallel_react.py +0 -0
- lionagi/core/direct/parallel_score.py +0 -0
- lionagi/core/direct/parallel_select.py +0 -0
- lionagi/core/direct/parallel_sentiment.py +0 -0
- lionagi/core/direct/predict.py +174 -0
- lionagi/core/direct/react.py +33 -0
- lionagi/core/direct/score.py +163 -0
- lionagi/core/direct/select.py +144 -0
- lionagi/core/direct/sentiment.py +51 -0
- lionagi/core/direct/utils.py +83 -0
- lionagi/core/flow/__init__.py +0 -3
- lionagi/core/flow/monoflow/{mono_react.py → ReAct.py} +52 -9
- lionagi/core/flow/monoflow/__init__.py +9 -0
- lionagi/core/flow/monoflow/{mono_chat.py → chat.py} +11 -11
- lionagi/core/flow/monoflow/{mono_chat_mixin.py → chat_mixin.py} +33 -27
- lionagi/core/flow/monoflow/{mono_followup.py → followup.py} +7 -6
- lionagi/core/flow/polyflow/__init__.py +1 -0
- lionagi/core/flow/polyflow/{polychat.py → chat.py} +15 -3
- lionagi/core/mail/__init__.py +8 -0
- lionagi/core/mail/mail_manager.py +88 -40
- lionagi/core/mail/schema.py +32 -6
- lionagi/core/messages/__init__.py +3 -0
- lionagi/core/messages/schema.py +56 -25
- lionagi/core/prompt/__init__.py +0 -0
- lionagi/core/prompt/prompt_template.py +0 -0
- lionagi/core/schema/__init__.py +7 -5
- lionagi/core/schema/action_node.py +29 -0
- lionagi/core/schema/base_mixin.py +56 -59
- lionagi/core/schema/base_node.py +35 -38
- lionagi/core/schema/condition.py +24 -0
- lionagi/core/schema/data_logger.py +98 -98
- lionagi/core/schema/data_node.py +19 -19
- lionagi/core/schema/prompt_template.py +0 -0
- lionagi/core/schema/structure.py +293 -190
- lionagi/core/session/__init__.py +1 -3
- lionagi/core/session/session.py +196 -214
- lionagi/core/tool/tool_manager.py +95 -103
- lionagi/integrations/__init__.py +1 -3
- lionagi/integrations/bridge/langchain_/documents.py +17 -18
- lionagi/integrations/bridge/langchain_/langchain_bridge.py +14 -14
- lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +22 -22
- lionagi/integrations/bridge/llamaindex_/node_parser.py +12 -12
- lionagi/integrations/bridge/llamaindex_/reader.py +11 -11
- lionagi/integrations/bridge/llamaindex_/textnode.py +7 -7
- lionagi/integrations/config/openrouter_configs.py +0 -1
- lionagi/integrations/provider/oai.py +26 -26
- lionagi/integrations/provider/services.py +38 -38
- lionagi/libs/__init__.py +34 -1
- lionagi/libs/ln_api.py +211 -221
- lionagi/libs/ln_async.py +53 -60
- lionagi/libs/ln_convert.py +118 -120
- lionagi/libs/ln_dataframe.py +32 -33
- lionagi/libs/ln_func_call.py +334 -342
- lionagi/libs/ln_nested.py +99 -107
- lionagi/libs/ln_parse.py +175 -158
- lionagi/libs/sys_util.py +52 -52
- lionagi/tests/test_core/test_base_branch.py +427 -427
- lionagi/tests/test_core/test_branch.py +292 -292
- lionagi/tests/test_core/test_mail_manager.py +57 -57
- lionagi/tests/test_core/test_session.py +254 -266
- lionagi/tests/test_core/test_session_base_util.py +299 -300
- lionagi/tests/test_core/test_tool_manager.py +70 -74
- lionagi/tests/test_libs/test_nested.py +2 -7
- lionagi/tests/test_libs/test_parse.py +2 -2
- lionagi/version.py +1 -1
- {lionagi-0.0.305.dist-info → lionagi-0.0.307.dist-info}/METADATA +4 -2
- lionagi-0.0.307.dist-info/RECORD +115 -0
- lionagi-0.0.305.dist-info/RECORD +0 -94
- {lionagi-0.0.305.dist-info → lionagi-0.0.307.dist-info}/LICENSE +0 -0
- {lionagi-0.0.305.dist-info → lionagi-0.0.307.dist-info}/WHEEL +0 -0
- {lionagi-0.0.305.dist-info → lionagi-0.0.307.dist-info}/top_level.txt +0 -0
@@ -1,292 +1,292 @@
|
|
1
|
-
from lionagi.core.branch.branch import Branch
|
2
|
-
from lionagi.core.tool.tool_manager import ToolManager, func_to_tool
|
3
|
-
from lionagi.core.schema import DataLogger
|
4
|
-
from lionagi.core.branch.util import MessageUtil
|
5
|
-
|
6
|
-
|
7
|
-
import unittest
|
8
|
-
from unittest.mock import patch, MagicMock
|
9
|
-
import pandas as pd
|
10
|
-
import json
|
11
|
-
from collections import deque
|
12
|
-
|
13
|
-
|
14
|
-
class TestBranch(unittest.TestCase):
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
class TestBranchReceive(unittest.TestCase):
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
# Chatflow: call_chatcompletion, chat, ReAct, auto_followup
|
290
|
-
|
291
|
-
if __name__ == "__main__":
|
292
|
-
|
1
|
+
# from lionagi.core.branch.branch import Branch
|
2
|
+
# from lionagi.core.tool.tool_manager import ToolManager, func_to_tool
|
3
|
+
# from lionagi.core.schema import DataLogger
|
4
|
+
# from lionagi.core.branch.util import MessageUtil
|
5
|
+
|
6
|
+
|
7
|
+
# import unittest
|
8
|
+
# from unittest.mock import patch, MagicMock
|
9
|
+
# import pandas as pd
|
10
|
+
# import json
|
11
|
+
# from collections import deque
|
12
|
+
|
13
|
+
|
14
|
+
# class TestBranch(unittest.TestCase):
|
15
|
+
# def setUp(self):
|
16
|
+
# # Assuming no need for actual files or external services for initialization
|
17
|
+
# self.test_messages = [
|
18
|
+
# {
|
19
|
+
# "node_id": "1",
|
20
|
+
# "timestamp": "2021-01-01 00:00:00",
|
21
|
+
# "role": "system",
|
22
|
+
# "sender": "system",
|
23
|
+
# "content": json.dumps({"system_info": "System message"}),
|
24
|
+
# },
|
25
|
+
# {
|
26
|
+
# "node_id": "2",
|
27
|
+
# "timestamp": "2021-01-01 00:01:00",
|
28
|
+
# "role": "user",
|
29
|
+
# "sender": "user1",
|
30
|
+
# "content": json.dumps({"instruction": "User message"}),
|
31
|
+
# },
|
32
|
+
# {
|
33
|
+
# "node_id": "3",
|
34
|
+
# "timestamp": "2021-01-01 00:02:00",
|
35
|
+
# "role": "assistant",
|
36
|
+
# "sender": "assistant",
|
37
|
+
# "content": json.dumps({"response": "Assistant response"}),
|
38
|
+
# },
|
39
|
+
# {
|
40
|
+
# "node_id": "4",
|
41
|
+
# "timestamp": "2021-01-01 00:03:00",
|
42
|
+
# "role": "assistant",
|
43
|
+
# "sender": "action_request",
|
44
|
+
# "content": json.dumps({"action_request": "Action request"}),
|
45
|
+
# },
|
46
|
+
# {
|
47
|
+
# "node_id": "5",
|
48
|
+
# "timestamp": "2021-01-01 00:04:00",
|
49
|
+
# "role": "assistant",
|
50
|
+
# "sender": "action_response",
|
51
|
+
# "content": json.dumps({"action_response": "Action response"}),
|
52
|
+
# },
|
53
|
+
# ]
|
54
|
+
# self.branch = Branch(
|
55
|
+
# branch_name="TestBranch", messages=pd.DataFrame(self.test_messages)
|
56
|
+
# )
|
57
|
+
|
58
|
+
# def sample_func(param1: int) -> bool:
|
59
|
+
# """Sample function.
|
60
|
+
|
61
|
+
# Args:
|
62
|
+
# param1 (int): Description of param1.
|
63
|
+
|
64
|
+
# Returns:
|
65
|
+
# bool: Description of return value.
|
66
|
+
# """
|
67
|
+
# return True
|
68
|
+
|
69
|
+
# self.tool = func_to_tool(sample_func)
|
70
|
+
|
71
|
+
# def test_initialization(self):
|
72
|
+
# """Test the initialization of the Branch class."""
|
73
|
+
# self.assertEqual(self.branch.branch_name, "TestBranch")
|
74
|
+
# self.assertIsInstance(self.branch.tool_manager, ToolManager)
|
75
|
+
# self.assertIsInstance(self.branch.datalogger, DataLogger)
|
76
|
+
# self.assertEqual(self.branch.sender, "system")
|
77
|
+
|
78
|
+
# def test_has_tools_property(self):
|
79
|
+
# """Test the has_tools property."""
|
80
|
+
# # Initially, no tools are registered
|
81
|
+
# self.assertFalse(self.branch.has_tools)
|
82
|
+
|
83
|
+
# # Mock tool registration
|
84
|
+
# self.branch.register_tools(self.tool)
|
85
|
+
# self.assertTrue(self.branch.has_tools)
|
86
|
+
|
87
|
+
# # @patch("lionagi.core.branch.BaseBranch._from_csv")
|
88
|
+
# # def test_from_csv(self, mock_from_csv):
|
89
|
+
# # """Test creating a Branch instance from a CSV file."""
|
90
|
+
# # filepath = "path/to/your/csvfile.csv"
|
91
|
+
# # Branch.from_csv(filepath=filepath, branch_name="TestBranchFromCSV")
|
92
|
+
# # mock_from_csv.assert_called_once_with(
|
93
|
+
# # filepath=filepath,
|
94
|
+
# # read_kwargs=None,
|
95
|
+
# # branch_name="TestBranchFromCSV",
|
96
|
+
# # service=None,
|
97
|
+
# # llmconfig=None,
|
98
|
+
# # tools=None,
|
99
|
+
# # datalogger=None,
|
100
|
+
# # persist_path=None,
|
101
|
+
# # tool_manager=None,
|
102
|
+
# # )
|
103
|
+
|
104
|
+
# # @patch("lionagi.core.branch.BaseBranch._from_json")
|
105
|
+
# # def test_from_json(self, mock_from_json):
|
106
|
+
# # """Test creating a Branch instance from a JSON file."""
|
107
|
+
# # filepath = "path/to/your/jsonfile.json"
|
108
|
+
# # Branch.from_json_string(filepath=filepath, branch_name="TestBranchFromJSON")
|
109
|
+
# # mock_from_json.assert_called_once_with(
|
110
|
+
# # filepath=filepath,
|
111
|
+
# # read_kwargs=None,
|
112
|
+
# # branch_name="TestBranchFromJSON",
|
113
|
+
# # service=None,
|
114
|
+
# # llmconfig=None,
|
115
|
+
# # tools=None,
|
116
|
+
# # datalogger=None,
|
117
|
+
# # persist_path=None,
|
118
|
+
# # tool_manager=None,
|
119
|
+
# # )
|
120
|
+
|
121
|
+
# def test_messages_describe(self):
|
122
|
+
# """Test the messages_describe method for accuracy."""
|
123
|
+
# # Assuming self.branch has been set up with some messages
|
124
|
+
# description = self.branch.messages_describe()
|
125
|
+
# self.assertIn("total_messages", description)
|
126
|
+
# self.assertIn("summary_by_role", description)
|
127
|
+
# self.assertIn("summary_by_sender", description)
|
128
|
+
# self.assertIn("registered_tools", description)
|
129
|
+
|
130
|
+
# def test_merge_branch(self):
|
131
|
+
# """Test merging another Branch instance into the current one."""
|
132
|
+
# mes = [
|
133
|
+
# {
|
134
|
+
# "node_id": "6",
|
135
|
+
# "timestamp": "2021-01-01 00:01:00",
|
136
|
+
# "role": "user",
|
137
|
+
# "sender": "user1",
|
138
|
+
# "content": json.dumps({"instruction": "User message"}),
|
139
|
+
# }
|
140
|
+
# ]
|
141
|
+
# other_branch = Branch(branch_name="OtherBranch", messages=pd.DataFrame(mes))
|
142
|
+
|
143
|
+
# original_message_count = len(self.branch.messages)
|
144
|
+
# self.branch.merge_branch(other_branch)
|
145
|
+
# merged_message_count = len(self.branch.messages)
|
146
|
+
# self.assertTrue(merged_message_count > original_message_count)
|
147
|
+
|
148
|
+
# def test_register_and_delete_tools(self):
|
149
|
+
# """Test tool registration and deletion."""
|
150
|
+
# self.branch.register_tools(self.tool)
|
151
|
+
# self.assertIn("sample_func", self.branch.tool_manager.registry)
|
152
|
+
# self.branch.delete_tools(self.tool, verbose=False)
|
153
|
+
# self.assertNotIn("sample_func", self.branch.tool_manager.registry)
|
154
|
+
|
155
|
+
# def test_send(self):
|
156
|
+
# """Test sending a mail package."""
|
157
|
+
# package = {"data": "example"}
|
158
|
+
# self.branch.send(recipient="BranchB", category="messages", package=package)
|
159
|
+
# self.assertEqual(len(self.branch.pending_outs), 1)
|
160
|
+
# mail = self.branch.pending_outs[0]
|
161
|
+
# self.assertEqual(mail.sender, "system")
|
162
|
+
# self.assertEqual(mail.recipient, "BranchB")
|
163
|
+
# self.assertEqual(mail.category, "messages")
|
164
|
+
# self.assertEqual(mail.package, package)
|
165
|
+
|
166
|
+
# # def test_is_invoked_true(self):
|
167
|
+
# # branch = Branch()
|
168
|
+
|
169
|
+
# # mock_messages = [
|
170
|
+
# # MessageUtil.to_json_content({"action_response": {"function": "func_name", "arguments": {}, "output": "result"}})
|
171
|
+
# # ]
|
172
|
+
# # branch.messages = pd.DataFrame(mock_messages, columns=['content'])
|
173
|
+
# # self.assertTrue(branch._is_invoked())
|
174
|
+
|
175
|
+
# def test_is_invoked_false(self):
|
176
|
+
# """Test that _is_invoked returns False when the last message is not a valid action response."""
|
177
|
+
# self.assertFalse(self.branch._is_invoked())
|
178
|
+
|
179
|
+
|
180
|
+
# class TestBranchReceive(unittest.TestCase):
|
181
|
+
# def setUp(self):
|
182
|
+
# self.branch = Branch(branch_name="TestBranch")
|
183
|
+
# # Set up a mock sender and initial pending_ins structure
|
184
|
+
# self.sender = "MockSender"
|
185
|
+
# self.branch.pending_ins[self.sender] = deque()
|
186
|
+
|
187
|
+
# # @patch("lionagi.core.mail.BaseMail")
|
188
|
+
# # @patch("lionagi.core.branch.util.MessageUtil.validate_messages")
|
189
|
+
# # def test_receive_messages(self, mock_validate_messages, mock_base_mail):
|
190
|
+
# # # Prepare a mock mail package with messages
|
191
|
+
# # messages_df = pd.DataFrame(
|
192
|
+
# # [
|
193
|
+
# # {
|
194
|
+
# # "node_id": "1",
|
195
|
+
# # "timestamp": "2021-01-01 00:00:00",
|
196
|
+
# # "role": "system",
|
197
|
+
# # "sender": "system",
|
198
|
+
# # "content": json.dumps({"system_info": "System message"}),
|
199
|
+
# # }
|
200
|
+
# # ]
|
201
|
+
# # )
|
202
|
+
# # mail_package_messages = MagicMock(category="messages", package=messages_df)
|
203
|
+
# # self.branch.pending_ins[self.sender].append(mail_package_messages)
|
204
|
+
|
205
|
+
# # # Test receiving messages
|
206
|
+
# # self.branch.receive(self.sender)
|
207
|
+
# # mock_validate_messages.assert_called_once_with(messages_df)
|
208
|
+
# # self.assertTrue(len(self.branch.messages) > 0)
|
209
|
+
# # self.assertEqual(self.branch.pending_ins, {})
|
210
|
+
|
211
|
+
# # def test_receive_tools(self):
|
212
|
+
# # def sample_func(param1: int) -> bool:
|
213
|
+
# # """Sample function.
|
214
|
+
|
215
|
+
# # Args:
|
216
|
+
# # param1 (int): Description of param1.
|
217
|
+
|
218
|
+
# # Returns:
|
219
|
+
# # bool: Description of return value.
|
220
|
+
# # """
|
221
|
+
# # return True
|
222
|
+
|
223
|
+
# # tool = func_to_tool(sample_func)
|
224
|
+
# # mail_package_tools = MagicMock(category="tools", package=tool)
|
225
|
+
# # self.branch.pending_ins[self.sender].append(mail_package_tools)
|
226
|
+
|
227
|
+
# # # Test receiving tools
|
228
|
+
# # self.branch.receive(self.sender)
|
229
|
+
# # self.assertIn(tool, self.branch.tool_manager.registry.values())
|
230
|
+
|
231
|
+
# def test_receive_service(self):
|
232
|
+
# # Prepare a mock mail package with a service
|
233
|
+
# from lionagi.libs.ln_api import BaseService
|
234
|
+
|
235
|
+
# service = BaseService()
|
236
|
+
# mail_package_service = MagicMock(category="provider", package=service)
|
237
|
+
# self.branch.pending_ins[self.sender].append(mail_package_service)
|
238
|
+
|
239
|
+
# # Test receiving service
|
240
|
+
# self.branch.receive(self.sender)
|
241
|
+
# self.assertEqual(self.branch.service, service)
|
242
|
+
|
243
|
+
# def test_receive_llmconfig(self):
|
244
|
+
# # Prepare a mock mail package with llmconfig
|
245
|
+
# llmconfig = self.branch.llmconfig.copy()
|
246
|
+
# mail_package_llmconfig = MagicMock(category="llmconfig", package=llmconfig)
|
247
|
+
# self.branch.pending_ins[self.sender].append(mail_package_llmconfig)
|
248
|
+
|
249
|
+
# # Test receiving llmconfig
|
250
|
+
# self.branch.receive(self.sender)
|
251
|
+
# self.assertEqual(llmconfig, self.branch.llmconfig)
|
252
|
+
|
253
|
+
# def test_invalid_format(self):
|
254
|
+
# # Test handling of invalid package format
|
255
|
+
# invalid_package = MagicMock(category="messages", package="Not a DataFrame")
|
256
|
+
# self.branch.pending_ins[self.sender].append(invalid_package)
|
257
|
+
|
258
|
+
# with self.assertRaises(ValueError) as context:
|
259
|
+
# self.branch.receive(self.sender)
|
260
|
+
# self.assertTrue("Invalid messages format" in str(context.exception))
|
261
|
+
|
262
|
+
# def test_receive_all(self):
|
263
|
+
# messages_df = pd.DataFrame(
|
264
|
+
# [
|
265
|
+
# {
|
266
|
+
# "node_id": "1",
|
267
|
+
# "timestamp": "2021-01-01 00:00:00",
|
268
|
+
# "role": "system",
|
269
|
+
# "sender": "system",
|
270
|
+
# "content": json.dumps({"system_info": "System message"}),
|
271
|
+
# }
|
272
|
+
# ]
|
273
|
+
# )
|
274
|
+
# mail_package_messages = MagicMock(category="messages", package=messages_df)
|
275
|
+
# self.branch.pending_ins[self.sender].append(mail_package_messages)
|
276
|
+
|
277
|
+
# llmconfig = self.branch.llmconfig.copy()
|
278
|
+
# mail_package_llmconfig = MagicMock(category="llmconfig", package=llmconfig)
|
279
|
+
# self.branch.pending_ins[self.sender].append(mail_package_llmconfig)
|
280
|
+
|
281
|
+
# self.branch.receive_all()
|
282
|
+
# self.assertTrue(
|
283
|
+
# not self.branch.pending_ins,
|
284
|
+
# "pending_ins should be empty or contain only skipped requests",
|
285
|
+
# )
|
286
|
+
# self.assertTrue(..., "Additional assertions based on your implementation")
|
287
|
+
|
288
|
+
|
289
|
+
# # Chatflow: call_chatcompletion, chat, ReAct, auto_followup
|
290
|
+
|
291
|
+
# if __name__ == "__main__":
|
292
|
+
# unittest.main()
|