lionagi 0.16.2__py3-none-any.whl → 0.17.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lionagi/adapters/_utils.py +10 -23
- lionagi/adapters/async_postgres_adapter.py +83 -79
- lionagi/ln/__init__.py +4 -4
- lionagi/ln/_json_dump.py +0 -6
- lionagi/ln/fuzzy/__init__.py +4 -1
- lionagi/ln/fuzzy/_fuzzy_validate.py +109 -0
- lionagi/ln/fuzzy/_to_dict.py +388 -0
- lionagi/models/__init__.py +0 -2
- lionagi/operations/__init__.py +0 -6
- lionagi/operations/_visualize_graph.py +285 -0
- lionagi/operations/brainstorm/brainstorm.py +14 -12
- lionagi/operations/builder.py +23 -302
- lionagi/operations/communicate/communicate.py +1 -1
- lionagi/operations/flow.py +14 -11
- lionagi/operations/node.py +14 -3
- lionagi/operations/operate/operate.py +5 -11
- lionagi/operations/parse/parse.py +2 -3
- lionagi/operations/types.py +0 -2
- lionagi/operations/utils.py +11 -5
- lionagi/protocols/generic/pile.py +3 -7
- lionagi/protocols/graph/graph.py +23 -6
- lionagi/protocols/graph/node.py +0 -2
- lionagi/protocols/messages/message.py +0 -1
- lionagi/protocols/operatives/operative.py +2 -2
- lionagi/protocols/types.py +0 -15
- lionagi/service/connections/endpoint.py +11 -5
- lionagi/service/connections/match_endpoint.py +2 -10
- lionagi/service/connections/providers/types.py +1 -3
- lionagi/service/hooks/hook_event.py +1 -1
- lionagi/service/hooks/hook_registry.py +1 -1
- lionagi/service/rate_limited_processor.py +1 -1
- lionagi/session/branch.py +24 -18
- lionagi/session/session.py +2 -18
- lionagi/utils.py +3 -335
- lionagi/version.py +1 -1
- {lionagi-0.16.2.dist-info → lionagi-0.17.0.dist-info}/METADATA +4 -13
- {lionagi-0.16.2.dist-info → lionagi-0.17.0.dist-info}/RECORD +39 -61
- lionagi/adapters/postgres_model_adapter.py +0 -131
- lionagi/libs/concurrency.py +0 -1
- lionagi/libs/nested/__init__.py +0 -3
- lionagi/libs/nested/flatten.py +0 -172
- lionagi/libs/nested/nfilter.py +0 -59
- lionagi/libs/nested/nget.py +0 -45
- lionagi/libs/nested/ninsert.py +0 -104
- lionagi/libs/nested/nmerge.py +0 -158
- lionagi/libs/nested/npop.py +0 -69
- lionagi/libs/nested/nset.py +0 -94
- lionagi/libs/nested/unflatten.py +0 -83
- lionagi/libs/nested/utils.py +0 -189
- lionagi/libs/parse.py +0 -31
- lionagi/libs/schema/json_schema.py +0 -231
- lionagi/libs/unstructured/__init__.py +0 -0
- lionagi/libs/unstructured/pdf_to_image.py +0 -45
- lionagi/libs/unstructured/read_image_to_base64.py +0 -33
- lionagi/libs/validate/fuzzy_match_keys.py +0 -7
- lionagi/libs/validate/fuzzy_validate_mapping.py +0 -144
- lionagi/libs/validate/string_similarity.py +0 -7
- lionagi/libs/validate/xml_parser.py +0 -203
- lionagi/models/note.py +0 -387
- lionagi/protocols/graph/_utils.py +0 -22
- lionagi/service/connections/providers/claude_code_.py +0 -299
- {lionagi-0.16.2.dist-info → lionagi-0.17.0.dist-info}/WHEEL +0 -0
- {lionagi-0.16.2.dist-info → lionagi-0.17.0.dist-info}/licenses/LICENSE +0 -0
@@ -5,12 +5,11 @@ lionagi/_types.py,sha256=j8XwSGeGrYwfmSJ8o-80bsfoalLWJgQH41ZkVevc4wk,75
|
|
5
5
|
lionagi/config.py,sha256=D13nnjpgJKz_LlQrzaKKVefm4hqesz_dP9ROjWmGuLE,3811
|
6
6
|
lionagi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
lionagi/settings.py,sha256=HDuKCEJCpc4HudKodBnhoQUGuTGhRHdlIFhbtf3VBtY,1633
|
8
|
-
lionagi/utils.py,sha256=
|
9
|
-
lionagi/version.py,sha256=
|
8
|
+
lionagi/utils.py,sha256=pfAibR84sx-aPxGNPrdlHqUAf2OXoCBGRCMseMrzhi4,18046
|
9
|
+
lionagi/version.py,sha256=XpM3lncCzPBIwMSvDN7i10pke_c6KdJtVLZYbCiaTRw,23
|
10
10
|
lionagi/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
lionagi/adapters/_utils.py,sha256=
|
12
|
-
lionagi/adapters/async_postgres_adapter.py,sha256=
|
13
|
-
lionagi/adapters/postgres_model_adapter.py,sha256=uwWrbnihtYsCIttHExmtAIZwyohFtKoxnHU1N1M2NvQ,4519
|
11
|
+
lionagi/adapters/_utils.py,sha256=sniMG1LDDkwJNzUF2K32jv7rA6Y1QcohgyNclYsptzI,453
|
12
|
+
lionagi/adapters/async_postgres_adapter.py,sha256=2XlxYNPow78dFHIQs8W1oJ2zkVD5Udn3aynMBF9Nf3k,3498
|
14
13
|
lionagi/fields/__init__.py,sha256=yrn9NDAM6_v73kK7aJeb-Pvqigeu8WASaV-My-6CDsc,939
|
15
14
|
lionagi/fields/action.py,sha256=OziEpbaUeEVo34KdtbzDxXJBgkf3QLxlcKIQAfHe4O0,5791
|
16
15
|
lionagi/fields/base.py,sha256=mvgqxLonCROszMjnG8QWt00l-MvIr_mnGvCtaH-SQ_k,3814
|
@@ -20,8 +19,6 @@ lionagi/fields/instruct.py,sha256=2koYdY7XyJh5lrd7tD_BA9bqCbmpsdTDaASEv_dX4i8,43
|
|
20
19
|
lionagi/fields/reason.py,sha256=6IjgJWv-dhsGmg5O1sq2J5syBibYfRBy3--7q7_ZpMY,1452
|
21
20
|
lionagi/fields/research.py,sha256=eEPKocx8eQy2E9FExRWVIo6MK_xvmwBAoRZciBY3RG0,1421
|
22
21
|
lionagi/libs/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
23
|
-
lionagi/libs/concurrency.py,sha256=45iic6IdetVFMXFhUWTGfj3g8A0dd2eaVvCSiK-cIWc,57
|
24
|
-
lionagi/libs/parse.py,sha256=6tDijmB7yzHLHbLtDnc8Bsn7NgIDWta4JKjdwodTF9E,1051
|
25
22
|
lionagi/libs/file/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
26
23
|
lionagi/libs/file/_utils.py,sha256=lCNCD-WNUq9f8ZlNecGESIz0GncWkJei8xYtvyY8qd4,334
|
27
24
|
lionagi/libs/file/chunk.py,sha256=XeVMwM33JF0X1W6udz_nhlb3DCevA_EK6A50Hn_e5SY,9300
|
@@ -30,38 +27,20 @@ lionagi/libs/file/concat_files.py,sha256=FoI983oWFzp9VfFDP7kmbRb3t1CPe5F5LCtsux0
|
|
30
27
|
lionagi/libs/file/file_ops.py,sha256=HBiIh1EljIJ5VTIXuyvJM0ppSs0YYOPUWmgDMJT634U,3430
|
31
28
|
lionagi/libs/file/process.py,sha256=XTfh1JDPancjFU0qr4-ONB2OXfKKkhQxL49sChYLl-0,8672
|
32
29
|
lionagi/libs/file/save.py,sha256=jTiJMTOK3IiuCz1XbYZlzFmsqiy2q_Xz6subc4ZTJps,3063
|
33
|
-
lionagi/libs/nested/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
34
|
-
lionagi/libs/nested/flatten.py,sha256=sB4jxZRoaUbjak9RbIWVWNKz2hzkhQJPFffV_Ws1GA0,5479
|
35
|
-
lionagi/libs/nested/nfilter.py,sha256=kF7AWjLFHr22SOjRBSTx-7iRPaR7gs0FY5Y4XF2sWJ8,1768
|
36
|
-
lionagi/libs/nested/nget.py,sha256=sQRz3OKx3bYlgoyLSHOXlHzd3ob-f_jmsMfTCNZkJfo,1284
|
37
|
-
lionagi/libs/nested/ninsert.py,sha256=NiQk4Ne5YKGGW4qiKXDkOkNvrIOeNQsM0lPVCQZ-KMg,3822
|
38
|
-
lionagi/libs/nested/nmerge.py,sha256=Jve5-BC4XXGVPbYNewrOOb57WOSV50CKMLbwqI0qwgs,5289
|
39
|
-
lionagi/libs/nested/npop.py,sha256=jxzjDPF-3gGPjrs_jWaG-g1u-kSa74jOI3EotOS4s8I,2173
|
40
|
-
lionagi/libs/nested/nset.py,sha256=vkLR970hSzj8xCk-Z3RNQMJL2x0uMHmx1pw0VZQx2T0,3393
|
41
|
-
lionagi/libs/nested/unflatten.py,sha256=lTON1LfCyhZ3xeTEdBiIONcHLQouPcBNARTbXzHZ03U,2618
|
42
|
-
lionagi/libs/nested/utils.py,sha256=r8xuBpH0qQaHMnCqXPF6unIKzw-TqwVbq-ARooWRERo,6090
|
43
30
|
lionagi/libs/schema/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
44
31
|
lionagi/libs/schema/as_readable.py,sha256=p8ke8ZxLwLQxmsJWD_N7Q_AYDYK60nuHztUREbTa5sk,12027
|
45
32
|
lionagi/libs/schema/extract_code_block.py,sha256=PuJbJj1JnqR5fSZudowPcVPpEoKISLr0MjTOOVXSzwY,2394
|
46
33
|
lionagi/libs/schema/extract_docstring.py,sha256=uWyUevXS4JSN60tfouoBBAyE4_jyE-fz45CiS-fvKeI,5714
|
47
34
|
lionagi/libs/schema/function_to_schema.py,sha256=XAB031WbYu3a7eFJyYjXVMAjmtWYSYr5kC_DYgjiuyM,5604
|
48
|
-
lionagi/libs/schema/json_schema.py,sha256=cuHcaMr748O9g6suNGmRx4tRXcidd5-c7AMGjTIZyHM,7670
|
49
35
|
lionagi/libs/schema/load_pydantic_model_from_schema.py,sha256=WIgJPmOu558az35CfOHvwyyTYQ5OBlk0hchvaEOADjQ,10109
|
50
|
-
lionagi/libs/unstructured/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
51
|
-
lionagi/libs/unstructured/pdf_to_image.py,sha256=lJ2CVxOYh61-3-55nusHXMOGqtEyLXsXmDjZ9yjkM48,1394
|
52
|
-
lionagi/libs/unstructured/read_image_to_base64.py,sha256=EJXWBJxCTa9vHBIFPRqQj0jeFXyDv1cs2oPBrWt-waQ,897
|
53
36
|
lionagi/libs/validate/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
54
37
|
lionagi/libs/validate/common_field_validators.py,sha256=1BHznXnJYcLQrHqvHKUnP6aqCptuQ0qN7KJRCExcJBU,4778
|
55
|
-
lionagi/libs/validate/fuzzy_match_keys.py,sha256=Nec5W1CVdmUgzcyDHcHiaELY6tFsicjbVsMI5dsIilk,190
|
56
|
-
lionagi/libs/validate/fuzzy_validate_mapping.py,sha256=MZpRop3whCQQtgYwJgg66nbN0KxNuKXqulaAgA0Y1_g,4935
|
57
|
-
lionagi/libs/validate/string_similarity.py,sha256=kuOQFNnI773bV8KKj_PUYxx8vLRdWay8PhuvkOWsU9E,186
|
58
38
|
lionagi/libs/validate/to_num.py,sha256=ZRHDjpTCykPfDIZZa4rZKNaR_8ZHbPDFlw9rc02DrII,11610
|
59
39
|
lionagi/libs/validate/validate_boolean.py,sha256=bjiX_WZ3Bg8XcqoWLzE1G9BpO0AisrlZUxrpye_mlGk,3614
|
60
|
-
lionagi/
|
61
|
-
lionagi/ln/__init__.py,sha256=1D21gwXiZ8rLr9dP7y85MupXkBULRKMO22e5x-iTKN4,1603
|
40
|
+
lionagi/ln/__init__.py,sha256=dQvfTU1MHUrG4C4KoqEs7Xg801seML-GNjihbdUtp3E,1575
|
62
41
|
lionagi/ln/_async_call.py,sha256=mnqq5l-hNIBWrWh7X7CtmwPafg1kT-lnWWm3nJnbPoI,9384
|
63
42
|
lionagi/ln/_hash.py,sha256=WLwKsbJISE7KtOrpiE30AFtfwyOCSBjb1GslBlvj5ac,4529
|
64
|
-
lionagi/ln/_json_dump.py,sha256=
|
43
|
+
lionagi/ln/_json_dump.py,sha256=zOeoOE3JbaGAzL-lfAdMqdgaXWYXFliqcgXsZ_pxonI,10347
|
65
44
|
lionagi/ln/_list_call.py,sha256=zvISmCeNAH7yjBcusQI1s17n556tILgePhRMdAM2plA,2831
|
66
45
|
lionagi/ln/_to_list.py,sha256=YOlrMplSpQhXDSTK4fkMF7Mhuw1wS0jGip5mS88Otro,6610
|
67
46
|
lionagi/ln/_utils.py,sha256=5Z_AsDxdtH5wNB-P4IiihhH0dYUcZMT-hTxFQBQPwL0,4303
|
@@ -76,46 +55,47 @@ lionagi/ln/concurrency/resource_tracker.py,sha256=ffLr0FkHyaHsUa4UDyWwse-8wGLaLM
|
|
76
55
|
lionagi/ln/concurrency/task.py,sha256=VS5keFI3Ct0fqCKbFl4kEWT5I2CgjIYizPU-S2YjGKo,2675
|
77
56
|
lionagi/ln/concurrency/throttle.py,sha256=yUAM4hnone6VzlFEos0fWERkZU9YC4J6TncZL-MqkG4,2319
|
78
57
|
lionagi/ln/concurrency/utils.py,sha256=MUWupnFtWxR15hWnligLZrS4Z1SAQ7j3cuCG08cK3GQ,431
|
79
|
-
lionagi/ln/fuzzy/__init__.py,sha256=
|
58
|
+
lionagi/ln/fuzzy/__init__.py,sha256=Py7hPV7uk5rPRGvQ4yPjMzXS32aQ7QVkO-mX69FfsMM,544
|
80
59
|
lionagi/ln/fuzzy/_extract_json.py,sha256=rYHaK36yzRpie8qO-T7mZKOue2yqCLx3ixiuKhsaKvg,2224
|
81
60
|
lionagi/ln/fuzzy/_fuzzy_json.py,sha256=S0lCkNvprn7XZHoYdRfzXueexSbjxTeLPkpyJ9IAO3A,3860
|
82
61
|
lionagi/ln/fuzzy/_fuzzy_match.py,sha256=MBL2qB180MsGkIvhiHQpVObfikBFjcLcFWG9T6vLZQ0,5915
|
83
|
-
lionagi/ln/fuzzy/_fuzzy_validate.py,sha256=
|
62
|
+
lionagi/ln/fuzzy/_fuzzy_validate.py,sha256=kl-IUGA6O8rY2eKXSwMMTRX6YIV4986r9zd0djidr-o,5212
|
84
63
|
lionagi/ln/fuzzy/_string_similarity.py,sha256=axgLjDgDfBT-soxZFU2iH2bZYmGePSzc9Mxl3WlOxAA,8718
|
85
|
-
lionagi/
|
64
|
+
lionagi/ln/fuzzy/_to_dict.py,sha256=H9W6f5-QWR0_40kzKLf5_CMF4iUd1IRqBDwPmthsX5c,11844
|
65
|
+
lionagi/models/__init__.py,sha256=b7A4AaVGq4pZvYyTG8N_yvtRzwWJ8MxE9Y6mDZb8U0k,422
|
86
66
|
lionagi/models/field_model.py,sha256=JdmCp2pmwoy5HuduF21ivqyvMaJ04CTXu6Un-AeSwLU,23652
|
87
67
|
lionagi/models/hashable_model.py,sha256=oOqR3OJCU9cJfWHiG0WaEw0GMqfE2WTt4cy7WsAsiRg,829
|
88
68
|
lionagi/models/model_params.py,sha256=zVU-PHp3skjK5ZVjpsPs1k_VJiS8X0hgct0xs6Z6W_Y,10955
|
89
|
-
lionagi/models/note.py,sha256=OsTxh5D931Pcd0uiIk4BadX45iBEW0Id0K8wM8QjXB8,12242
|
90
69
|
lionagi/models/operable_model.py,sha256=Zm_Hxdauqyh0za3_TJLCZ3g6nR4F45Rrnc0ZM3d54Gs,20111
|
91
70
|
lionagi/models/schema_model.py,sha256=ghRIM8aBNaToAknwNlhQKpuKXcwzyCw5pDE31bVKxs0,667
|
92
|
-
lionagi/operations/__init__.py,sha256=
|
93
|
-
lionagi/operations/
|
94
|
-
lionagi/operations/
|
71
|
+
lionagi/operations/__init__.py,sha256=DU9sIhtw1vPBVllZ1Fbum8GE3qC9yfyQtt6_8vyv_cA,444
|
72
|
+
lionagi/operations/_visualize_graph.py,sha256=F0KadgRthP-6-R-FPgvlwiiaiWH3ueO-rjSd1bzRUbE,8594
|
73
|
+
lionagi/operations/builder.py,sha256=c6OIBwIX2-V4oH7wRBQf4SEs38L9lHdSX1ODb7ETLuI,14722
|
74
|
+
lionagi/operations/flow.py,sha256=StGPmpPLe_ZFVwWmc9RiUpH7i1gkhN4q7A94ax0_b1E,22298
|
95
75
|
lionagi/operations/manager.py,sha256=YZr3VjPAZVVFd_bIjF1aoQqzzKZHNA1kcqefNi5QFFM,683
|
96
|
-
lionagi/operations/node.py,sha256=
|
97
|
-
lionagi/operations/types.py,sha256=
|
98
|
-
lionagi/operations/utils.py,sha256=
|
76
|
+
lionagi/operations/node.py,sha256=zntelS3kO6q4H6vpS2lpw3iNUTLR3a6I3dp07fdSGJs,3465
|
77
|
+
lionagi/operations/types.py,sha256=zBhTQ4od4yXo84_Osbed7Zqhnp-PA90mrjGsQSSCuzw,644
|
78
|
+
lionagi/operations/utils.py,sha256=xSRJkPyorhUHkibtW45ICGkGwrg7IkIALXIYBtvj6cc,1373
|
99
79
|
lionagi/operations/ReAct/ReAct.py,sha256=UzW3MClv9_w1AqrZIuATOZ9ASTb8HPD0Rlotlp0mYOg,13388
|
100
80
|
lionagi/operations/ReAct/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
101
81
|
lionagi/operations/ReAct/utils.py,sha256=qYh-zTRCHXyuNpSgBmooTG0TVp9Pdht0tONPwdv8BT4,4102
|
102
82
|
lionagi/operations/_act/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
103
83
|
lionagi/operations/_act/act.py,sha256=LfN4UqTTHVvO1h9tqmDhVfVafVUOry4YGEivIZbmLqc,2810
|
104
84
|
lionagi/operations/brainstorm/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
105
|
-
lionagi/operations/brainstorm/brainstorm.py,sha256=
|
85
|
+
lionagi/operations/brainstorm/brainstorm.py,sha256=o7szKzx9axhBB656p3wDnFM_syXKFhIHt25CJ28XiGI,18797
|
106
86
|
lionagi/operations/brainstorm/prompt.py,sha256=Dqi4NNeztdI4iutggRqjnOrG4a4E2JtwIAtRnjZ_ghQ,610
|
107
87
|
lionagi/operations/chat/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
108
88
|
lionagi/operations/chat/chat.py,sha256=F5ugFtMm4OdNCQhaKN-0ezIcfInR_za5I7WbBC9qfzQ,5493
|
109
89
|
lionagi/operations/communicate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
110
|
-
lionagi/operations/communicate/communicate.py,sha256=
|
90
|
+
lionagi/operations/communicate/communicate.py,sha256=AKMcLle8roqB9Yn280VnaG0Qcd6Js9L3ccAIRy1Go3Y,3658
|
111
91
|
lionagi/operations/instruct/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
112
92
|
lionagi/operations/instruct/instruct.py,sha256=7pxhyP5jxwpgqjmQNb1rnGF4QAVlbMENpsyl22mbKRM,794
|
113
93
|
lionagi/operations/interpret/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
114
94
|
lionagi/operations/interpret/interpret.py,sha256=yl1NSp2iOm3dbycVLEcnV3absnqKoubfH15v6lQgySU,1500
|
115
95
|
lionagi/operations/operate/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
116
|
-
lionagi/operations/operate/operate.py,sha256=
|
96
|
+
lionagi/operations/operate/operate.py,sha256=I20CwJGx-hxlZ3kmd0-Hh6kWbqCCA3-aJMR8hHHpzd4,7532
|
117
97
|
lionagi/operations/parse/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
118
|
-
lionagi/operations/parse/parse.py,sha256=
|
98
|
+
lionagi/operations/parse/parse.py,sha256=gI6xbMdc7XDHYyfJRMlH4YBorxMmKhGSQZ2oHlrmULs,6590
|
119
99
|
lionagi/operations/plan/__init__.py,sha256=yGBPll6lOqVjadbTvDLGrTlMx3FfBW-e00z7AMvg7Uo,156
|
120
100
|
lionagi/operations/plan/plan.py,sha256=qonV5kJjJCBAWfsvH7gqUj5Gyo-N-Nh_2dr-OZcDQ1Q,15315
|
121
101
|
lionagi/operations/plan/prompt.py,sha256=GUNZ8RpHIa89D-_y7GK--Spg0JADI3K13sjf_w3a2mI,993
|
@@ -126,7 +106,7 @@ lionagi/protocols/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM
|
|
126
106
|
lionagi/protocols/_concepts.py,sha256=ZBN5OYpLMWLrl9uZqSg9GD4uwf60V4VHcxRnBTRWIRc,1555
|
127
107
|
lionagi/protocols/contracts.py,sha256=ii7luaPJsEKOb3J-rcaNysPDGU3nEzpgy_8g1z5_CCA,1398
|
128
108
|
lionagi/protocols/ids.py,sha256=RM40pP_4waMJcfCGmEK_PfS8-k_DuDbC1fG-2Peuf6s,2472
|
129
|
-
lionagi/protocols/types.py,sha256=
|
109
|
+
lionagi/protocols/types.py,sha256=6GJ5ZgDyWl8tckNLXB0z8jbtkordWpgm5r4ht31KVRc,2431
|
130
110
|
lionagi/protocols/action/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
131
111
|
lionagi/protocols/action/function_calling.py,sha256=jFy6Ruh3QWkERtBHXqPWVwrOH5aDitEo8oJHZgW5xnI,5066
|
132
112
|
lionagi/protocols/action/manager.py,sha256=XmdQIaVgSpmFBFW9kbW_rdwdQmlBteP4VRanxh_f918,8549
|
@@ -140,14 +120,13 @@ lionagi/protocols/generic/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGv
|
|
140
120
|
lionagi/protocols/generic/element.py,sha256=yD4SWNOGZsLTgxtz6TKtJfqkUvDmUH9wIH3Liw6QmmA,15839
|
141
121
|
lionagi/protocols/generic/event.py,sha256=n5EraAJ5bPiwegTdkxsILs7-vFJwmnXhB2om4xMQnK0,6529
|
142
122
|
lionagi/protocols/generic/log.py,sha256=AnPr2RweSZcJdxOK0KGb1eyvAPZmME3hEm9HraUoftQ,8212
|
143
|
-
lionagi/protocols/generic/pile.py,sha256=
|
123
|
+
lionagi/protocols/generic/pile.py,sha256=AHxj1q5apabATmdgGXlAhkcqIug9r_75wmufdq9XLt4,36894
|
144
124
|
lionagi/protocols/generic/processor.py,sha256=uiNIldAYPEujuboLFyrIJADMlhRghy3H86hYintj5D4,11705
|
145
125
|
lionagi/protocols/generic/progression.py,sha256=HCV_EnQCFvjg6D7eF4ygGrZNQPEOtu75zvW1sJbAVrM,15190
|
146
126
|
lionagi/protocols/graph/__init__.py,sha256=UPu3OmUpjSgX2aBuBJUdG2fppGlfqAH96hU0qIMBMp0,253
|
147
|
-
lionagi/protocols/graph/_utils.py,sha256=mts4M2wcGKdY9hC-1917lxIJT5oycW9VnRgfRx8ydbI,605
|
148
127
|
lionagi/protocols/graph/edge.py,sha256=YxSGj4w_fG7khm-zpKduuK5fJzhJDx23JhU1dZp29d8,5241
|
149
|
-
lionagi/protocols/graph/graph.py,sha256=
|
150
|
-
lionagi/protocols/graph/node.py,sha256=
|
128
|
+
lionagi/protocols/graph/graph.py,sha256=l-12vTRblpWS_M4Ae-NTZThdeioaQvmhCS83mjB2fe8,11159
|
129
|
+
lionagi/protocols/graph/node.py,sha256=TuPNHSlkSpqp7nxUV2gj-SkCZVkY4ZocnB79ONlkY6o,4467
|
151
130
|
lionagi/protocols/mail/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
152
131
|
lionagi/protocols/mail/exchange.py,sha256=P1PcrFylIBeiQa8kox9H1qyJ4kjhUlbLiTUT8rs1OXg,7041
|
153
132
|
lionagi/protocols/mail/mail.py,sha256=RB5CUft_4J85H9nM9g6aRXomTaqKwF5xVjJacPAhoa8,1356
|
@@ -161,7 +140,7 @@ lionagi/protocols/messages/assistant_response.py,sha256=jrzRPVHHDnPw86Xp0IHnPy0t
|
|
161
140
|
lionagi/protocols/messages/base.py,sha256=Ng1Q8yIIIFauUv53LnwDeyOrM-cSCfsHM1GwkxChf2o,2317
|
162
141
|
lionagi/protocols/messages/instruction.py,sha256=Qpme1oSc406V3-F2iOyqC8TVT2GWVduZaoDfdGdBnDI,21127
|
163
142
|
lionagi/protocols/messages/manager.py,sha256=ABDiN-QULbfbSrHVlPe3kqBxr7e7sYoT49wHQMLiT6c,16897
|
164
|
-
lionagi/protocols/messages/message.py,sha256=
|
143
|
+
lionagi/protocols/messages/message.py,sha256=invP8Lu7bep_y5ve97LD9engQCHmhg7BhV5H3B0umvc,7941
|
165
144
|
lionagi/protocols/messages/system.py,sha256=x0F1C57SFHaO2-Z9cy1QshYlxv8wjl7VppooaGKbMIg,4658
|
166
145
|
lionagi/protocols/messages/templates/README.md,sha256=Ch4JrKSjd85fLitAYO1OhZjNOGKHoEwaKQlcV16jiUI,1286
|
167
146
|
lionagi/protocols/messages/templates/action_request.jinja2,sha256=d6OmxHKyvvNDSK4bnBM3TGSUk_HeE_Q2EtLAQ0ZBEJg,120
|
@@ -171,36 +150,35 @@ lionagi/protocols/messages/templates/instruction_message.jinja2,sha256=L-ptw5OHx
|
|
171
150
|
lionagi/protocols/messages/templates/system_message.jinja2,sha256=JRKJ0aFpYfaXSFouKc_N4unZ35C3yZTOWhIrIdCB5qk,215
|
172
151
|
lionagi/protocols/messages/templates/tool_schemas.jinja2,sha256=ozIaSDCRjIAhLyA8VM6S-YqS0w2NcctALSwx4LjDwII,126
|
173
152
|
lionagi/protocols/operatives/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
174
|
-
lionagi/protocols/operatives/operative.py,sha256=
|
153
|
+
lionagi/protocols/operatives/operative.py,sha256=Y_prGR7aPQtO3ws91W_KkjJTVnb5lYkfwMKaEIN2FVU,13331
|
175
154
|
lionagi/protocols/operatives/step.py,sha256=uF92QO2KZiY3YR1cxhrbD844VFidOKfmeQn2Fv637iY,9280
|
176
155
|
lionagi/service/__init__.py,sha256=C_TPk1roVYz6uVLK1JVxrK3tPtYqN6W0D7FzI-s6CWY,556
|
177
156
|
lionagi/service/imodel.py,sha256=ya406sf42-KRrKN4TJJLtI6wsKeM5hAhWr7Hubg7W0E,16371
|
178
157
|
lionagi/service/manager.py,sha256=tN3p0kM7pg_CEs6wXK62_B_h49Q3nrU-9qniFhw2ABE,1164
|
179
|
-
lionagi/service/rate_limited_processor.py,sha256=
|
158
|
+
lionagi/service/rate_limited_processor.py,sha256=h2_F71aVeBrgZ0a7ARS8-8NDaAHvfWrLykI5QcNuYbk,6099
|
180
159
|
lionagi/service/resilience.py,sha256=91RPFtQY4QyNga_nuSNLsbzNE26pXJMTAfLaQqVdvmg,18714
|
181
160
|
lionagi/service/token_calculator.py,sha256=piTidArzUkIMCtOLC_HBLoZNYZcENQywgeKM31bxezM,6457
|
182
161
|
lionagi/service/types.py,sha256=9zX08BhdmPE9FE1YTyvsy14hdDGRYzyyVBmoBURzQvI,1096
|
183
162
|
lionagi/service/connections/__init__.py,sha256=yHQZ7OJpCftd6CStYR8inbxjJydYdmv9kCvbUBhJ2zU,362
|
184
163
|
lionagi/service/connections/api_calling.py,sha256=fY-fzwSJvQKpUT27TF0MTfE5TxroYKkL4SHWYrmYznI,9958
|
185
|
-
lionagi/service/connections/endpoint.py,sha256=
|
164
|
+
lionagi/service/connections/endpoint.py,sha256=0r4-8NPyAvLNey09BBsUr5KGJCXchBmVZm2pCe3Nbq4,15165
|
186
165
|
lionagi/service/connections/endpoint_config.py,sha256=6sA06uCzriT6p0kFxhDCFH8N6V6MVp8ytlOw5ctBhDI,5169
|
187
166
|
lionagi/service/connections/header_factory.py,sha256=IYeTQQk7r8FXcdhmW7orCxHjNO-Nb1EOXhgNK7CAp-I,1821
|
188
|
-
lionagi/service/connections/match_endpoint.py,sha256=
|
167
|
+
lionagi/service/connections/match_endpoint.py,sha256=QlOw9CbR1peExP-b-XlkRpqqGIksfNefI2EZCw9P7_E,2575
|
189
168
|
lionagi/service/connections/providers/__init__.py,sha256=3lzOakDoBWmMaNnT2g-YwktPKa_Wme4lnPRSmOQfayY,105
|
190
169
|
lionagi/service/connections/providers/anthropic_.py,sha256=vok8mIyFiuV3K83tOjdYfruA6cv1h_57ML6RtpuW-bU,3157
|
191
|
-
lionagi/service/connections/providers/claude_code_.py,sha256=ltk41ZdMCf-QSxqUhbb_Un9VC7J0Ek6n20LFJDeoSyY,10589
|
192
170
|
lionagi/service/connections/providers/claude_code_cli.py,sha256=kqEOnCUOOh2O_3NGi6W7r-gdLsbW-Jcp11tm30VEv4Q,4455
|
193
171
|
lionagi/service/connections/providers/exa_.py,sha256=kuWD7yyYRqIa4ChSn0TsxFA5V5LwvFUD-w8TZ6mx4rk,1048
|
194
172
|
lionagi/service/connections/providers/nvidia_nim_.py,sha256=95vmo0DSONYBVHkR9SGJ5BiHNKFZNZBrjw4_7ShOXQA,3154
|
195
173
|
lionagi/service/connections/providers/oai_.py,sha256=3x5d6Ei1hKu8Mix0N2V2K21O9dd-2jtAELHhHXj5iHk,6071
|
196
174
|
lionagi/service/connections/providers/ollama_.py,sha256=oqYLWn81KrWoQgId4e4GD_bgrDjQLPOmhqlc5uBuFGk,4569
|
197
175
|
lionagi/service/connections/providers/perplexity_.py,sha256=1GMmxAXsKGsB-xlqxO6hW-QdqoqkU2705NLyejetFSw,1646
|
198
|
-
lionagi/service/connections/providers/types.py,sha256=
|
176
|
+
lionagi/service/connections/providers/types.py,sha256=omKWbmJYu_ozK_qJLcxQezVcauXTqhp4ClOWAyENEFU,807
|
199
177
|
lionagi/service/hooks/__init__.py,sha256=Ayllxjd1fR_6NByZlE2zslQ7I0Od-s6-OVe0mzZIeu4,569
|
200
178
|
lionagi/service/hooks/_types.py,sha256=AJKODnj0bWmXZrcMgIdZpJNTgaSCzouCheiQXPpxetg,1169
|
201
179
|
lionagi/service/hooks/_utils.py,sha256=51dqdRrln2aJCkCz8g4L6Ik_v9atdFHPzjm9ASu6OvA,2560
|
202
|
-
lionagi/service/hooks/hook_event.py,sha256=
|
203
|
-
lionagi/service/hooks/hook_registry.py,sha256=
|
180
|
+
lionagi/service/hooks/hook_event.py,sha256=NH3PdoWwAt96GQQi99TjqAu-zU-zTgWz6pDdIaKureE,2418
|
181
|
+
lionagi/service/hooks/hook_registry.py,sha256=IEJF3UpLCmTXkd-7daFIo_p0CVTuAoA6Z8gzXkMIGsg,7870
|
204
182
|
lionagi/service/third_party/README.md,sha256=qFjWnI8rmLivIyr6Tc-hRZh-rQwntROp76af4MBNJJc,2214
|
205
183
|
lionagi/service/third_party/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
206
184
|
lionagi/service/third_party/anthropic_models.py,sha256=oqSPSlcayYG-fS5BLiLeTtkrpaxgkPhEK_YgneumrOo,4004
|
@@ -209,15 +187,15 @@ lionagi/service/third_party/exa_models.py,sha256=G_hnekcy-DillPLzMoDQ8ZisVAL8Mp7
|
|
209
187
|
lionagi/service/third_party/openai_model_names.py,sha256=C44tnqexgc4ZU2-3I_sn5d688hf3WWx-25xBd50bvas,5121
|
210
188
|
lionagi/service/third_party/pplx_models.py,sha256=-EhyJgOWR6rzSv3zczUtk80X6c19p18Dg9KC6l8BFRQ,6473
|
211
189
|
lionagi/session/__init__.py,sha256=kDypY6L3kGPnatAw7YNQAykgg-9MlIBnlhHExaXvt-c,202
|
212
|
-
lionagi/session/branch.py,sha256=
|
190
|
+
lionagi/session/branch.py,sha256=Gz9QOhZ2e6UJtTTkqY4P1Oa0UnjXHwIJTP7YCpcbA9o,65064
|
213
191
|
lionagi/session/prompts.py,sha256=GPr0jibyAAqS3awDzGC8SoCL6aWJLLCCbXY0JUuxOC0,3170
|
214
|
-
lionagi/session/session.py,sha256=
|
192
|
+
lionagi/session/session.py,sha256=BVouy9xiqVfD6AucTVs80vSvs7nIKsgGjgvIFgMsO0Q,12970
|
215
193
|
lionagi/tools/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
216
194
|
lionagi/tools/base.py,sha256=hEGnE4MD0CM4UqnF0xsDRKB0aM-pyrTFHl8utHhyJLU,1897
|
217
195
|
lionagi/tools/types.py,sha256=XtJLY0m-Yi_ZLWhm0KycayvqMCZd--HxfQ0x9vFUYDE,230
|
218
196
|
lionagi/tools/file/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
219
197
|
lionagi/tools/file/reader.py,sha256=2YKgU3VKo76zfL_buDAUQJoPLC56f6WJ4_mdJjlMDIM,9509
|
220
|
-
lionagi-0.
|
221
|
-
lionagi-0.
|
222
|
-
lionagi-0.
|
223
|
-
lionagi-0.
|
198
|
+
lionagi-0.17.0.dist-info/METADATA,sha256=x9SSUvfLlKC40Tta8exQJnp7T5ajT9dX-FjFCW3iBvc,22674
|
199
|
+
lionagi-0.17.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
200
|
+
lionagi-0.17.0.dist-info/licenses/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
|
201
|
+
lionagi-0.17.0.dist-info/RECORD,,
|
@@ -1,131 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Clean LionAGI PostgreSQL adapter for integration into lionagi core.
|
3
|
-
|
4
|
-
This adapter handles the metadata field conflict and provides seamless
|
5
|
-
PostgreSQL persistence for lionagi Nodes.
|
6
|
-
"""
|
7
|
-
|
8
|
-
from __future__ import annotations
|
9
|
-
|
10
|
-
from typing import Union, get_args, get_origin
|
11
|
-
|
12
|
-
from pydantic import BaseModel
|
13
|
-
|
14
|
-
from ._utils import check_postgres_available
|
15
|
-
|
16
|
-
_POSTGRES_AVAILABLE = check_postgres_available()
|
17
|
-
if isinstance(_POSTGRES_AVAILABLE, ImportError):
|
18
|
-
raise _POSTGRES_AVAILABLE
|
19
|
-
|
20
|
-
from pydapter.model_adapters.postgres_model import PostgresModelAdapter
|
21
|
-
from sqlalchemy import String
|
22
|
-
from sqlalchemy.orm import DeclarativeBase
|
23
|
-
|
24
|
-
|
25
|
-
class LionAGIPostgresAdapter(PostgresModelAdapter):
|
26
|
-
"""
|
27
|
-
PostgreSQL adapter for lionagi Nodes with automatic metadata field mapping.
|
28
|
-
|
29
|
-
Solves the core issue where lionagi's 'metadata' field conflicts with
|
30
|
-
SQLAlchemy's reserved 'metadata' attribute by automatically mapping it
|
31
|
-
to 'node_metadata' in the database schema.
|
32
|
-
|
33
|
-
Features:
|
34
|
-
- Automatic metadata field mapping (metadata → node_metadata)
|
35
|
-
- Handles Union types like list[float] | None for embedding fields
|
36
|
-
- Preserves all PostgreSQL-specific type support from parent
|
37
|
-
- Transparent to lionagi users - Elements work seamlessly
|
38
|
-
"""
|
39
|
-
|
40
|
-
# Core field mapping to resolve SQLAlchemy conflicts
|
41
|
-
FIELD_MAPPINGS = {"metadata": "node_metadata"}
|
42
|
-
|
43
|
-
def __init__(self):
|
44
|
-
super().__init__()
|
45
|
-
self._register_lionagi_types()
|
46
|
-
|
47
|
-
def _register_lionagi_types(self):
|
48
|
-
"""Register lionagi-specific type mappings."""
|
49
|
-
try:
|
50
|
-
# Handle lionagi IDType as String (UUID)
|
51
|
-
from lionagi.protocols.generic.element import IDType
|
52
|
-
|
53
|
-
self.register_type_mapping(
|
54
|
-
python_type=IDType,
|
55
|
-
sql_type_factory=lambda: String(36), # UUID string length
|
56
|
-
python_to_sql=lambda x: str(x),
|
57
|
-
sql_to_python=lambda x: IDType.validate(x) if x else None,
|
58
|
-
)
|
59
|
-
except ImportError:
|
60
|
-
pass # lionagi not available
|
61
|
-
|
62
|
-
@classmethod
|
63
|
-
def pydantic_model_to_sql(
|
64
|
-
cls,
|
65
|
-
model: type[BaseModel],
|
66
|
-
*,
|
67
|
-
table_name: str | None = None,
|
68
|
-
pk_field: str = "id",
|
69
|
-
schema: str | None = None,
|
70
|
-
) -> type[DeclarativeBase]:
|
71
|
-
"""
|
72
|
-
Generate SQLAlchemy model with lionagi field mapping.
|
73
|
-
|
74
|
-
Automatically handles:
|
75
|
-
- metadata → node_metadata mapping
|
76
|
-
- Union type resolution (e.g., list[float] | None → list[float])
|
77
|
-
- Standard lionagi Node field structure
|
78
|
-
"""
|
79
|
-
|
80
|
-
# Create modified field mapping for lionagi compatibility
|
81
|
-
modified_fields = {}
|
82
|
-
|
83
|
-
for name, info in model.model_fields.items():
|
84
|
-
# Apply field name mapping
|
85
|
-
field_name = cls.FIELD_MAPPINGS.get(name, name)
|
86
|
-
|
87
|
-
# Resolve Union types by extracting non-None type
|
88
|
-
annotation = info.annotation
|
89
|
-
origin = get_origin(annotation)
|
90
|
-
|
91
|
-
if origin is Union or (
|
92
|
-
hasattr(annotation, "__class__")
|
93
|
-
and annotation.__class__.__name__ == "UnionType"
|
94
|
-
):
|
95
|
-
args = get_args(annotation)
|
96
|
-
non_none_args = [arg for arg in args if arg is not type(None)]
|
97
|
-
if len(non_none_args) == 1:
|
98
|
-
annotation = non_none_args[0]
|
99
|
-
|
100
|
-
# Create field info with resolved annotation
|
101
|
-
from pydantic.fields import FieldInfo
|
102
|
-
|
103
|
-
modified_fields[field_name] = FieldInfo(
|
104
|
-
annotation=annotation,
|
105
|
-
default=info.default,
|
106
|
-
default_factory=info.default_factory,
|
107
|
-
alias=info.alias,
|
108
|
-
title=info.title,
|
109
|
-
description=info.description,
|
110
|
-
json_schema_extra=info.json_schema_extra,
|
111
|
-
frozen=info.frozen,
|
112
|
-
validate_default=info.validate_default,
|
113
|
-
repr=info.repr,
|
114
|
-
init_var=info.init_var,
|
115
|
-
kw_only=info.kw_only,
|
116
|
-
)
|
117
|
-
|
118
|
-
# Create temporary model with mapped fields
|
119
|
-
class ModifiedModel(BaseModel):
|
120
|
-
model_config = getattr(model, "model_config", {})
|
121
|
-
|
122
|
-
ModifiedModel.model_fields = modified_fields
|
123
|
-
ModifiedModel.__name__ = model.__name__
|
124
|
-
|
125
|
-
# Generate SQLAlchemy model with parent's logic
|
126
|
-
return super().pydantic_model_to_sql(
|
127
|
-
ModifiedModel,
|
128
|
-
table_name=table_name,
|
129
|
-
pk_field=pk_field,
|
130
|
-
schema=schema,
|
131
|
-
)
|
lionagi/libs/concurrency.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
from ..ln.concurrency import * # backward compatibility
|
lionagi/libs/nested/__init__.py
DELETED
lionagi/libs/nested/flatten.py
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from collections import deque
|
6
|
-
from collections.abc import Mapping, Sequence
|
7
|
-
from typing import Any, Literal, TypeVar, overload
|
8
|
-
|
9
|
-
T = TypeVar("T")
|
10
|
-
|
11
|
-
|
12
|
-
@overload
|
13
|
-
def flatten(
|
14
|
-
nested_structure: T,
|
15
|
-
/,
|
16
|
-
*,
|
17
|
-
parent_key: tuple = (),
|
18
|
-
sep: str = "|",
|
19
|
-
coerce_keys: Literal[True] = True,
|
20
|
-
dynamic: bool = True,
|
21
|
-
coerce_sequence: Literal["dict", None] = None,
|
22
|
-
max_depth: int | None = None,
|
23
|
-
) -> dict[str, Any] | None: ...
|
24
|
-
|
25
|
-
|
26
|
-
@overload
|
27
|
-
def flatten(
|
28
|
-
nested_structure: T,
|
29
|
-
/,
|
30
|
-
*,
|
31
|
-
parent_key: tuple = (),
|
32
|
-
sep: str = "|",
|
33
|
-
coerce_keys: Literal[False],
|
34
|
-
dynamic: bool = True,
|
35
|
-
coerce_sequence: Literal["dict", "list", None] = None,
|
36
|
-
max_depth: int | None = None,
|
37
|
-
) -> dict[tuple, Any] | None: ...
|
38
|
-
|
39
|
-
|
40
|
-
def flatten(
|
41
|
-
nested_structure: Any,
|
42
|
-
/,
|
43
|
-
*,
|
44
|
-
parent_key: tuple = (),
|
45
|
-
sep: str = "|",
|
46
|
-
coerce_keys: bool = True,
|
47
|
-
dynamic: bool = True,
|
48
|
-
coerce_sequence: Literal["dict", "list"] | None = None,
|
49
|
-
max_depth: int | None = None,
|
50
|
-
) -> dict[tuple | str, Any] | None:
|
51
|
-
"""Flatten a nested structure into a single-level dictionary.
|
52
|
-
|
53
|
-
Recursively traverses the input, creating keys that represent the path
|
54
|
-
to each value in the flattened result.
|
55
|
-
|
56
|
-
Args:
|
57
|
-
nested_structure: The nested structure to flatten.
|
58
|
-
parent_key: Base key for the current recursion level. Default: ().
|
59
|
-
sep: Separator for joining keys. Default: "|".
|
60
|
-
coerce_keys: Join keys into strings if True, keep as tuples if False.
|
61
|
-
Default: True.
|
62
|
-
dynamic: Handle sequences (except strings) dynamically if True.
|
63
|
-
Default: True.
|
64
|
-
coerce_sequence: Force sequences to be treated as dicts or lists.
|
65
|
-
Options: "dict", "list", or None. Default: None.
|
66
|
-
max_depth: Maximum depth to flatten. None for complete flattening.
|
67
|
-
Default: None.
|
68
|
-
|
69
|
-
Returns:
|
70
|
-
A flattened dictionary with keys as tuples or strings (based on
|
71
|
-
coerce_keys) representing the path to each value.
|
72
|
-
|
73
|
-
Raises:
|
74
|
-
ValueError: If coerce_sequence is "list" and coerce_keys is True.
|
75
|
-
|
76
|
-
Example:
|
77
|
-
>>> nested = {"a": 1, "b": {"c": 2, "d": [3, 4]}}
|
78
|
-
>>> flatten(nested)
|
79
|
-
{'a': 1, 'b|c': 2, 'b|d|0': 3, 'b|d|1': 4}
|
80
|
-
|
81
|
-
Note:
|
82
|
-
- Preserves order of keys in dicts and indices in sequences.
|
83
|
-
- With dynamic=True, treats sequences (except strings) as nestable.
|
84
|
-
- coerce_sequence allows forcing sequence handling for homogeneity.
|
85
|
-
"""
|
86
|
-
|
87
|
-
if coerce_keys and coerce_sequence == "list":
|
88
|
-
raise ValueError(
|
89
|
-
"coerce_sequence cannot be 'list' when coerce_keys is True"
|
90
|
-
)
|
91
|
-
|
92
|
-
coerce_sequence_to_list = None
|
93
|
-
coerce_sequence_to_dict = None
|
94
|
-
|
95
|
-
if dynamic and coerce_sequence:
|
96
|
-
if coerce_sequence == "dict":
|
97
|
-
coerce_sequence_to_dict = True
|
98
|
-
elif coerce_sequence == "list":
|
99
|
-
coerce_sequence_to_list = True
|
100
|
-
|
101
|
-
return _flatten_iterative(
|
102
|
-
obj=nested_structure,
|
103
|
-
parent_key=parent_key,
|
104
|
-
sep=sep,
|
105
|
-
coerce_keys=coerce_keys,
|
106
|
-
dynamic=dynamic,
|
107
|
-
coerce_sequence_to_list=coerce_sequence_to_list,
|
108
|
-
coerce_sequence_to_dict=coerce_sequence_to_dict,
|
109
|
-
max_depth=max_depth,
|
110
|
-
)
|
111
|
-
|
112
|
-
|
113
|
-
def _flatten_iterative(
|
114
|
-
obj: Any,
|
115
|
-
parent_key: tuple,
|
116
|
-
sep: str,
|
117
|
-
coerce_keys: bool,
|
118
|
-
dynamic: bool,
|
119
|
-
coerce_sequence_to_list: bool = False,
|
120
|
-
coerce_sequence_to_dict: bool = False,
|
121
|
-
max_depth: int | None = None,
|
122
|
-
) -> dict[tuple | str, Any]:
|
123
|
-
stack = deque([(obj, parent_key, 0)])
|
124
|
-
result = {}
|
125
|
-
|
126
|
-
while stack:
|
127
|
-
current_obj, current_key, depth = stack.pop()
|
128
|
-
|
129
|
-
if max_depth is not None and depth >= max_depth:
|
130
|
-
result[_format_key(current_key, sep, coerce_keys)] = current_obj
|
131
|
-
continue
|
132
|
-
|
133
|
-
if isinstance(current_obj, Mapping):
|
134
|
-
for k, v in current_obj.items():
|
135
|
-
new_key = current_key + (k,)
|
136
|
-
if (
|
137
|
-
v
|
138
|
-
and isinstance(v, (Mapping, Sequence))
|
139
|
-
and not isinstance(v, (str, bytes, bytearray))
|
140
|
-
):
|
141
|
-
stack.appendleft((v, new_key, depth + 1))
|
142
|
-
else:
|
143
|
-
result[_format_key(new_key, sep, coerce_keys)] = v
|
144
|
-
|
145
|
-
elif (
|
146
|
-
dynamic
|
147
|
-
and isinstance(current_obj, Sequence)
|
148
|
-
and not isinstance(current_obj, (str, bytes, bytearray))
|
149
|
-
):
|
150
|
-
if coerce_sequence_to_dict:
|
151
|
-
dict_obj = {str(i): v for i, v in enumerate(current_obj)}
|
152
|
-
for k, v in dict_obj.items():
|
153
|
-
new_key = current_key + (k,)
|
154
|
-
stack.appendleft((v, new_key, depth + 1))
|
155
|
-
elif coerce_sequence_to_list:
|
156
|
-
for i, v in enumerate(current_obj):
|
157
|
-
new_key = current_key + (i,)
|
158
|
-
stack.appendleft((v, new_key, depth + 1))
|
159
|
-
else:
|
160
|
-
for i, v in enumerate(current_obj):
|
161
|
-
new_key = current_key + (str(i),)
|
162
|
-
stack.appendleft((v, new_key, depth + 1))
|
163
|
-
else:
|
164
|
-
result[_format_key(current_key, sep, coerce_keys)] = current_obj
|
165
|
-
|
166
|
-
return result
|
167
|
-
|
168
|
-
|
169
|
-
def _format_key(key: tuple, sep: str, coerce_keys: bool, /) -> tuple | str:
|
170
|
-
if not key:
|
171
|
-
return key
|
172
|
-
return sep.join(map(str, key)) if coerce_keys else key
|
lionagi/libs/nested/nfilter.py
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from collections.abc import Callable
|
6
|
-
from typing import Any
|
7
|
-
|
8
|
-
|
9
|
-
def nfilter(
|
10
|
-
nested_structure: dict[Any, Any] | list[Any],
|
11
|
-
/,
|
12
|
-
condition: Callable[[Any], bool],
|
13
|
-
) -> dict[Any, Any] | list[Any]:
|
14
|
-
"""Filter elements in a nested structure based on a condition.
|
15
|
-
|
16
|
-
Args:
|
17
|
-
nested_structure: The nested structure (dict or list) to filter.
|
18
|
-
condition: Function returning True for elements to keep, False to
|
19
|
-
discard.
|
20
|
-
|
21
|
-
Returns:
|
22
|
-
The filtered nested structure.
|
23
|
-
|
24
|
-
Raises:
|
25
|
-
TypeError: If nested_structure is not a dict or list.
|
26
|
-
|
27
|
-
Example:
|
28
|
-
>>> data = {"a": 1, "b": {"c": 2, "d": 3}, "e": [4, 5, 6]}
|
29
|
-
>>> nfilter(data, lambda x: isinstance(x, int) and x > 2)
|
30
|
-
{'b': {'d': 3}, 'e': [4, 5, 6]}
|
31
|
-
"""
|
32
|
-
if isinstance(nested_structure, dict):
|
33
|
-
return _filter_dict(nested_structure, condition)
|
34
|
-
elif isinstance(nested_structure, list):
|
35
|
-
return _filter_list(nested_structure, condition)
|
36
|
-
else:
|
37
|
-
raise TypeError(
|
38
|
-
"The nested_structure must be either a dict or a list."
|
39
|
-
)
|
40
|
-
|
41
|
-
|
42
|
-
def _filter_dict(
|
43
|
-
dictionary: dict[Any, Any], condition: Callable[[tuple[Any, Any]], bool]
|
44
|
-
) -> dict[Any, Any]:
|
45
|
-
return {
|
46
|
-
k: nfilter(v, condition) if isinstance(v, dict | list) else v
|
47
|
-
for k, v in dictionary.items()
|
48
|
-
if condition(v) or isinstance(v, dict | list)
|
49
|
-
}
|
50
|
-
|
51
|
-
|
52
|
-
def _filter_list(
|
53
|
-
lst: list[Any], condition: Callable[[Any], bool]
|
54
|
-
) -> list[Any]:
|
55
|
-
return [
|
56
|
-
nfilter(item, condition) if isinstance(item, dict | list) else item
|
57
|
-
for item in lst
|
58
|
-
if condition(item) or isinstance(item, dict | list)
|
59
|
-
]
|
lionagi/libs/nested/nget.py
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from typing import Any
|
6
|
-
|
7
|
-
from lionagi.utils import UNDEFINED
|
8
|
-
|
9
|
-
from .utils import get_target_container
|
10
|
-
|
11
|
-
|
12
|
-
def nget(
|
13
|
-
nested_structure: dict[Any, Any] | list[Any],
|
14
|
-
/,
|
15
|
-
indices: list[int | str],
|
16
|
-
default: Any = UNDEFINED,
|
17
|
-
) -> Any:
|
18
|
-
try:
|
19
|
-
target_container = get_target_container(nested_structure, indices[:-1])
|
20
|
-
last_index = indices[-1]
|
21
|
-
|
22
|
-
if (
|
23
|
-
isinstance(target_container, list)
|
24
|
-
and isinstance(last_index, int)
|
25
|
-
and last_index < len(target_container)
|
26
|
-
):
|
27
|
-
return target_container[last_index]
|
28
|
-
elif (
|
29
|
-
isinstance(target_container, dict)
|
30
|
-
and last_index in target_container
|
31
|
-
):
|
32
|
-
return target_container[last_index]
|
33
|
-
elif default is not UNDEFINED:
|
34
|
-
return default
|
35
|
-
else:
|
36
|
-
raise LookupError(
|
37
|
-
"Target not found and no default value provided."
|
38
|
-
)
|
39
|
-
except (IndexError, KeyError, TypeError):
|
40
|
-
if default is not UNDEFINED:
|
41
|
-
return default
|
42
|
-
else:
|
43
|
-
raise LookupError(
|
44
|
-
"Target not found and no default value provided."
|
45
|
-
)
|