lionagi 0.0.115__py3-none-any.whl → 0.0.204__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. lionagi/__init__.py +1 -2
  2. lionagi/_services/__init__.py +5 -0
  3. lionagi/_services/anthropic.py +79 -0
  4. lionagi/_services/base_service.py +414 -0
  5. lionagi/_services/oai.py +98 -0
  6. lionagi/_services/openrouter.py +44 -0
  7. lionagi/_services/services.py +91 -0
  8. lionagi/_services/transformers.py +46 -0
  9. lionagi/bridge/langchain.py +26 -16
  10. lionagi/bridge/llama_index.py +50 -20
  11. lionagi/configs/oai_configs.py +2 -14
  12. lionagi/configs/openrouter_configs.py +2 -2
  13. lionagi/core/__init__.py +7 -8
  14. lionagi/core/branch/branch.py +589 -0
  15. lionagi/core/branch/branch_manager.py +139 -0
  16. lionagi/core/branch/conversation.py +484 -0
  17. lionagi/core/core_util.py +59 -0
  18. lionagi/core/flow/flow.py +19 -0
  19. lionagi/core/flow/flow_util.py +62 -0
  20. lionagi/core/instruction_set/__init__.py +0 -5
  21. lionagi/core/instruction_set/instruction_set.py +343 -0
  22. lionagi/core/messages/messages.py +176 -0
  23. lionagi/core/sessions/__init__.py +0 -5
  24. lionagi/core/sessions/session.py +428 -0
  25. lionagi/loaders/chunker.py +51 -47
  26. lionagi/loaders/load_util.py +2 -2
  27. lionagi/loaders/reader.py +45 -39
  28. lionagi/models/imodel.py +53 -0
  29. lionagi/schema/async_queue.py +158 -0
  30. lionagi/schema/base_node.py +318 -147
  31. lionagi/schema/base_tool.py +31 -1
  32. lionagi/schema/data_logger.py +74 -38
  33. lionagi/schema/data_node.py +57 -6
  34. lionagi/structures/graph.py +132 -10
  35. lionagi/structures/relationship.py +58 -20
  36. lionagi/structures/structure.py +36 -25
  37. lionagi/tests/test_utils/test_api_util.py +219 -0
  38. lionagi/tests/test_utils/test_call_util.py +785 -0
  39. lionagi/tests/test_utils/test_encrypt_util.py +323 -0
  40. lionagi/tests/test_utils/test_io_util.py +238 -0
  41. lionagi/tests/test_utils/test_nested_util.py +338 -0
  42. lionagi/tests/test_utils/test_sys_util.py +358 -0
  43. lionagi/tools/tool_manager.py +186 -0
  44. lionagi/tools/tool_util.py +266 -3
  45. lionagi/utils/__init__.py +21 -61
  46. lionagi/utils/api_util.py +359 -71
  47. lionagi/utils/call_util.py +839 -264
  48. lionagi/utils/encrypt_util.py +283 -16
  49. lionagi/utils/io_util.py +178 -93
  50. lionagi/utils/nested_util.py +672 -0
  51. lionagi/utils/pd_util.py +57 -0
  52. lionagi/utils/sys_util.py +284 -156
  53. lionagi/utils/url_util.py +55 -0
  54. lionagi/version.py +1 -1
  55. {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/METADATA +21 -17
  56. lionagi-0.0.204.dist-info/RECORD +106 -0
  57. lionagi/core/conversations/__init__.py +0 -5
  58. lionagi/core/conversations/conversation.py +0 -107
  59. lionagi/core/flows/__init__.py +0 -8
  60. lionagi/core/flows/flow.py +0 -8
  61. lionagi/core/flows/flow_util.py +0 -62
  62. lionagi/core/instruction_set/instruction_sets.py +0 -7
  63. lionagi/core/sessions/sessions.py +0 -185
  64. lionagi/endpoints/__init__.py +0 -5
  65. lionagi/endpoints/audio.py +0 -17
  66. lionagi/endpoints/chatcompletion.py +0 -54
  67. lionagi/messages/__init__.py +0 -11
  68. lionagi/messages/instruction.py +0 -15
  69. lionagi/messages/message.py +0 -110
  70. lionagi/messages/response.py +0 -33
  71. lionagi/messages/system.py +0 -12
  72. lionagi/objs/__init__.py +0 -11
  73. lionagi/objs/abc_objs.py +0 -39
  74. lionagi/objs/async_queue.py +0 -135
  75. lionagi/objs/messenger.py +0 -85
  76. lionagi/objs/tool_manager.py +0 -253
  77. lionagi/services/__init__.py +0 -11
  78. lionagi/services/base_api_service.py +0 -230
  79. lionagi/services/oai.py +0 -34
  80. lionagi/services/openrouter.py +0 -31
  81. lionagi/tests/test_api_util.py +0 -46
  82. lionagi/tests/test_call_util.py +0 -115
  83. lionagi/tests/test_convert_util.py +0 -202
  84. lionagi/tests/test_encrypt_util.py +0 -33
  85. lionagi/tests/test_flat_util.py +0 -426
  86. lionagi/tests/test_sys_util.py +0 -0
  87. lionagi/utils/convert_util.py +0 -229
  88. lionagi/utils/flat_util.py +0 -599
  89. lionagi-0.0.115.dist-info/RECORD +0 -110
  90. /lionagi/{services → _services}/anyscale.py +0 -0
  91. /lionagi/{services → _services}/azure.py +0 -0
  92. /lionagi/{services → _services}/bedrock.py +0 -0
  93. /lionagi/{services → _services}/everlyai.py +0 -0
  94. /lionagi/{services → _services}/gemini.py +0 -0
  95. /lionagi/{services → _services}/gpt4all.py +0 -0
  96. /lionagi/{services → _services}/huggingface.py +0 -0
  97. /lionagi/{services → _services}/litellm.py +0 -0
  98. /lionagi/{services → _services}/localai.py +0 -0
  99. /lionagi/{services → _services}/mistralai.py +0 -0
  100. /lionagi/{services → _services}/ollama.py +0 -0
  101. /lionagi/{services → _services}/openllm.py +0 -0
  102. /lionagi/{services → _services}/perplexity.py +0 -0
  103. /lionagi/{services → _services}/predibase.py +0 -0
  104. /lionagi/{services → _services}/rungpt.py +0 -0
  105. /lionagi/{services → _services}/vllm.py +0 -0
  106. /lionagi/{services → _services}/xinference.py +0 -0
  107. /lionagi/{endpoints/assistants.py → agents/__init__.py} +0 -0
  108. /lionagi/{tools → agents}/planner.py +0 -0
  109. /lionagi/{tools → agents}/prompter.py +0 -0
  110. /lionagi/{tools → agents}/scorer.py +0 -0
  111. /lionagi/{tools → agents}/summarizer.py +0 -0
  112. /lionagi/{tools → agents}/validator.py +0 -0
  113. /lionagi/{endpoints/embeddings.py → core/branch/__init__.py} +0 -0
  114. /lionagi/{services/anthropic.py → core/branch/cluster.py} +0 -0
  115. /lionagi/{endpoints/finetune.py → core/flow/__init__.py} +0 -0
  116. /lionagi/{endpoints/image.py → core/messages/__init__.py} +0 -0
  117. /lionagi/{endpoints/moderation.py → models/__init__.py} +0 -0
  118. /lionagi/{endpoints/vision.py → models/base_model.py} +0 -0
  119. /lionagi/{objs → schema}/status_tracker.py +0 -0
  120. /lionagi/tests/{test_io_util.py → test_utils/__init__.py} +0 -0
  121. {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/LICENSE +0 -0
  122. {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/WHEEL +0 -0
  123. {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/top_level.txt +0 -0
@@ -1,115 +0,0 @@
1
- # import asyncio
2
- # import unittest
3
- # from unittest.mock import patch, MagicMock
4
- # from lionagi.utils.sys_util import create_copy
5
- # from lionagi.utils.flat_util import to_list
6
- # from typing import Callable
7
-
8
- # # Assuming the Python module with the above functions is named 'call_utils'
9
- # from lionagi.utils.call_util import *
10
-
11
- # class TestCallUtils(unittest.TestCase):
12
-
13
- # def setUp(self):
14
- # self.sample_input = [1, 2, 3]
15
- # self.sample_func = MagicMock(return_value=42)
16
-
17
- # def test_hcall(self):
18
- # with patch('time.sleep', return_value=None):
19
- # result = hcall(self.sample_input, self.sample_func)
20
- # self.sample_func.assert_called_once_with(self.sample_input)
21
- # self.assertEqual(result, 42)
22
-
23
- # def test_ahcall(self):
24
- # async def async_test():
25
- # self.sample_func.reset_mock()
26
- # with patch('asyncio.sleep', return_value=None):
27
- # result = await ahcall(self.sample_input, self.sample_func)
28
- # self.sample_func.assert_called_once_with(self.sample_input)
29
- # self.assertEqual(result, 42)
30
-
31
- # asyncio.run(async_test())
32
-
33
- # def test_lcall(self):
34
- # expected_result = [42, 42, 42]
35
- # result = lcall(self.sample_input, self.sample_func)
36
- # self.assertEqual(result, expected_result)
37
- # calls = [unittest.mock.call(item) for item in self.sample_input]
38
- # self.sample_func.assert_has_calls(calls, any_order=True)
39
-
40
- # def test_alcall(self):
41
- # async def async_test():
42
- # expected_result = [42, 42, 42]
43
- # self.sample_func.reset_mock()
44
- # result = await alcall(self.sample_input, self.sample_func)
45
- # self.assertEqual(result, expected_result)
46
- # calls = [unittest.mock.call(item) for item in self.sample_input]
47
- # self.sample_func.assert_has_calls(calls, any_order=True)
48
-
49
- # asyncio.run(async_test())
50
-
51
-
52
- # class TestCallUtils2(unittest.TestCase):
53
-
54
- # def setUp(self):
55
- # self.sample_input = [1, 2, 3]
56
- # self.sample_func = MagicMock(side_effect=lambda x: x + 1)
57
- # self.sample_async_func = MagicMock(side_effect=lambda x: x + 1)
58
-
59
- # def test_mcall_single_function(self):
60
- # result = mcall(self.sample_input, self.sample_func)
61
- # self.sample_func.assert_has_calls([unittest.mock.call(i) for i in self.sample_input], any_order=True)
62
- # self.assertEqual(result, [2, 3, 4])
63
-
64
- # def test_mcall_multiple_functions(self):
65
- # # Define multiple functions
66
- # funcs = [
67
- # MagicMock(side_effect=lambda x: x + 1),
68
- # MagicMock(side_effect=lambda x: x * 2),
69
- # MagicMock(side_effect=lambda x: x - 1)
70
- # ]
71
- # result = mcall(self.sample_input, funcs)
72
- # for i, func in enumerate(funcs):
73
- # func.assert_called_once_with(self.sample_input[i])
74
- # self.assertEqual(result, [2, 4, 2])
75
-
76
- # def test_amcall_single_function(self):
77
- # async def async_test():
78
- # result = await amcall(self.sample_input, self.sample_async_func)
79
- # self.sample_async_func.assert_has_calls([unittest.mock.call(i) for i in self.sample_input], any_order=True)
80
- # self.assertEqual(result, [2, 3, 4])
81
-
82
- # asyncio.run(async_test())
83
-
84
- # def test_amcall_multiple_functions(self):
85
- # # Define multiple asynchronous functions
86
- # async_funcs = [
87
- # MagicMock(side_effect=lambda x: x + 1),
88
- # MagicMock(side_effect=lambda x: x * 2),
89
- # MagicMock(side_effect=lambda x: x - 1)
90
- # ]
91
-
92
- # async def async_test():
93
- # result = await amcall(self.sample_input, async_funcs)
94
- # for i, func in enumerate(async_funcs):
95
- # func.assert_called_once_with(self.sample_input[i])
96
- # self.assertEqual(result, [2, 4, 2])
97
-
98
- # asyncio.run(async_test())
99
-
100
- # def test_ecall(self):
101
- # funcs = [MagicMock(side_effect=lambda x: x * x)]
102
- # result = ecall(self.sample_input, funcs)
103
- # self.assertEqual(result, [[1, 4, 9]])
104
-
105
- # def test_aecall(self):
106
- # async_funcs = [MagicMock(side_effect=lambda x: x * x)]
107
-
108
- # async def async_test():
109
- # result = await aecall(self.sample_input, async_funcs)
110
- # self.assertEqual(result, [[1, 4, 9]])
111
-
112
- # asyncio.run(async_test())
113
-
114
- # if __name__ == '__main__':
115
- # unittest.main()
@@ -1,202 +0,0 @@
1
- import unittest
2
- from lionagi.utils.convert_util import *
3
-
4
- # Test cases for the function
5
- class TestStrToNum(unittest.TestCase):
6
- def test_valid_int(self):
7
- self.assertEqual(str_to_num("123"), 123)
8
- self.assertEqual(str_to_num("-123"), -123)
9
-
10
- def test_valid_float(self):
11
- self.assertEqual(str_to_num("123.45", num_type=float), 123.45)
12
- self.assertEqual(str_to_num("-123.45", num_type=float), -123.45)
13
-
14
- def test_precision(self):
15
- self.assertEqual(str_to_num("123.456", num_type=float, precision=1), 123.5)
16
- self.assertEqual(str_to_num("123.444", num_type=float, precision=2), 123.44)
17
-
18
- def test_bounds(self):
19
- self.assertEqual(str_to_num("10", lower_bound=5, upper_bound=15), 10)
20
- with self.assertRaises(ValueError):
21
- str_to_num("20", upper_bound=15)
22
- with self.assertRaises(ValueError):
23
- str_to_num("2", lower_bound=5)
24
-
25
- def test_invalid_input(self):
26
- with self.assertRaises(ValueError):
27
- str_to_num("abc")
28
- with self.assertRaises(ValueError):
29
- str_to_num("123abc", num_type=str)
30
-
31
- def test_no_numeric_value(self):
32
- with self.assertRaises(ValueError):
33
- str_to_num("No numbers here")
34
-
35
-
36
-
37
- # Functions to be tested
38
- def dict_to_xml(data: Dict[str, Any], root_tag: str = 'node') -> str:
39
- root = ET.Element(root_tag)
40
- _build_xml(root, data)
41
- return ET.tostring(root, encoding='unicode')
42
-
43
- def _build_xml(element: ET.Element, data: Any):
44
- if isinstance(data, dict):
45
- for key, value in data.items():
46
- sub_element = ET.SubElement(element, key)
47
- _build_xml(sub_element, value)
48
- elif isinstance(data, list):
49
- for item in data:
50
- item_element = ET.SubElement(element, 'item')
51
- _build_xml(item_element, item)
52
- else:
53
- element.text = str(data)
54
-
55
- def xml_to_dict(element: ET.Element) -> Dict[str, Any]:
56
- dict_data = {}
57
- for child in element:
58
- if list(child):
59
- dict_data[child.tag] = xml_to_dict(child)
60
- else:
61
- dict_data[child.tag] = child.text
62
- return dict_data
63
-
64
- # Test cases for the functions
65
- class TestDictXMLConversion(unittest.TestCase):
66
- def setUp(self):
67
- self.data = {
68
- 'name': 'John',
69
- 'age': 30,
70
- 'children': [
71
- {'name': 'Alice', 'age': 5},
72
- {'name': 'Bob', 'age': 7}
73
- ]
74
- }
75
- self.root_tag = 'person'
76
- self.xml = dict_to_xml(self.data, self.root_tag)
77
- self.xml_element = ET.fromstring(self.xml)
78
-
79
- def test_dict_to_xml(self):
80
- self.assertIn('<name>John</name>', self.xml)
81
- self.assertIn('<age>30</age>', self.xml)
82
- self.assertIn('<children>', self.xml)
83
- self.assertIn('<item>', self.xml)
84
-
85
- # def test_xml_to_dict(self):
86
- # data_from_xml = xml_to_dict(self.xml_element)
87
- # self.assertEqual(data_from_xml, self.data)
88
-
89
- # def test_xml_to_dict_to_xml(self):
90
- # data_from_xml = xml_to_dict(self.xml_element)
91
- # xml_from_dict = dict_to_xml(data_from_xml, self.root_tag)
92
- # self.assertEqual(xml_from_dict, self.xml)
93
-
94
- # def test_invalid_input(self):
95
- # with self.assertRaises(TypeError):
96
- # dict_to_xml("not a dict", self.root_tag)
97
-
98
-
99
-
100
- class TestDocstringExtraction(unittest.TestCase):
101
- def test_google_style_extraction(self):
102
- def sample_func(arg1, arg2):
103
- """
104
- This is a sample function.
105
-
106
- Args:
107
- arg1 (int): The first argument.
108
- arg2 (str): The second argument.
109
-
110
- Returns:
111
- bool: The truth value.
112
- """
113
- return True
114
-
115
- description, params = extract_docstring_details_google(sample_func)
116
- self.assertEqual(description, "This is a sample function.")
117
- self.assertEqual(params, {
118
- 'arg1': 'The first argument.',
119
- 'arg2': 'The second argument.'
120
- })
121
-
122
- def test_rest_style_extraction(self):
123
- def sample_func(arg1, arg2):
124
- """
125
- This is a sample function.
126
-
127
- :param int arg1: The first argument.
128
- :param str arg2: The second argument.
129
- :return: The truth value.
130
- :rtype: bool
131
- """
132
- return True
133
-
134
- description, params = extract_docstring_details_rest(sample_func)
135
- self.assertEqual(description, "This is a sample function.")
136
- self.assertEqual(params, {
137
- 'arg1': 'The first argument.',
138
- 'arg2': 'The second argument.'
139
- })
140
-
141
- def test_extract_docstring_details_with_invalid_style(self):
142
- def sample_func(arg1, arg2):
143
- return True
144
-
145
- with self.assertRaises(ValueError):
146
- extract_docstring_details(sample_func, style='unsupported')
147
-
148
- class TestPythonToJsonTypeConversion(unittest.TestCase):
149
- def test_python_to_json_type_conversion(self):
150
- self.assertEqual(python_to_json_type('str'), 'string')
151
- self.assertEqual(python_to_json_type('int'), 'number')
152
- self.assertEqual(python_to_json_type('float'), 'number')
153
- self.assertEqual(python_to_json_type('list'), 'array')
154
- self.assertEqual(python_to_json_type('tuple'), 'array')
155
- self.assertEqual(python_to_json_type('bool'), 'boolean')
156
- self.assertEqual(python_to_json_type('dict'), 'object')
157
- self.assertEqual(python_to_json_type('nonexistent'), 'object')
158
-
159
- class TestFunctionToSchema(unittest.TestCase):
160
- def test_func_to_schema(self):
161
- def sample_func(arg1: int, arg2: str) -> bool:
162
- """
163
- This is a sample function.
164
-
165
- Args:
166
- arg1 (int): The first argument.
167
- arg2 (str): The second argument.
168
-
169
- Returns:
170
- bool: The truth value.
171
- """
172
- return True
173
-
174
- schema = func_to_schema(sample_func, style='google')
175
- expected_schema = {
176
- "type": "function",
177
- "function": {
178
- "name": "sample_func",
179
- "description": "This is a sample function.",
180
- "parameters": {
181
- "type": "object",
182
- "properties": {
183
- "arg1": {
184
- "type": "number",
185
- "description": "The first argument."
186
- },
187
- "arg2": {
188
- "type": "string",
189
- "description": "The second argument."
190
- }
191
- },
192
- "required": ["arg1", "arg2"]
193
- }
194
- }
195
- }
196
- self.assertEqual(schema, expected_schema)
197
-
198
- if __name__ == '__main__':
199
- unittest.main()
200
-
201
-
202
- # --------------------------------------------------
@@ -1,33 +0,0 @@
1
- import unittest
2
- from cryptography.fernet import Fernet
3
-
4
- # Assuming the Python module with the above functions is named 'encryption_utils'
5
- from lionagi.utils.encrypt_util import generate_encryption_key, encrypt, decrypt
6
-
7
- class TestEncryptionUtils(unittest.TestCase):
8
-
9
- def test_generate_encryption_key(self):
10
- key = generate_encryption_key()
11
- self.assertIsInstance(key, str)
12
- self.assertEqual(len(key), 44) # Fernet keys are 44 bytes long in URL-safe base64 encoding
13
-
14
- def test_encrypt_decrypt(self):
15
- key = generate_encryption_key()
16
- original_data = "Test data for encryption"
17
- encrypted_data = encrypt(original_data, key)
18
- decrypted_data = decrypt(encrypted_data, key)
19
-
20
- self.assertNotEqual(encrypted_data, original_data)
21
- self.assertEqual(decrypted_data, original_data)
22
-
23
- def test_invalid_key(self):
24
- key = generate_encryption_key()
25
- wrong_key = Fernet.generate_key().decode()
26
- original_data = "Test data for encryption"
27
- encrypted_data = encrypt(original_data, key)
28
-
29
- with self.assertRaises(Exception):
30
- decrypt(encrypted_data, wrong_key)
31
-
32
- if __name__ == '__main__':
33
- unittest.main()