lionagi 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lionagi/core/session/directive_mixin.py +14 -3
- lionagi/core/unit/unit.py +34 -2
- lionagi/version.py +1 -1
- {lionagi-0.3.0.dist-info → lionagi-0.3.2.dist-info}/METADATA +2 -2
- {lionagi-0.3.0.dist-info → lionagi-0.3.2.dist-info}/RECORD +7 -7
- {lionagi-0.3.0.dist-info → lionagi-0.3.2.dist-info}/LICENSE +0 -0
- {lionagi-0.3.0.dist-info → lionagi-0.3.2.dist-info}/WHEEL +0 -0
@@ -1,4 +1,5 @@
|
|
1
1
|
# lionagi/core/session/directive_mixin.py
|
2
|
+
from pydantic import BaseModel
|
2
3
|
|
3
4
|
from lionagi.core.unit import Unit
|
4
5
|
|
@@ -33,13 +34,14 @@ class DirectiveMixin:
|
|
33
34
|
default=None,
|
34
35
|
timeout: float = None,
|
35
36
|
timing: bool = False,
|
36
|
-
return_branch=False,
|
37
37
|
images=None,
|
38
38
|
image_path=None,
|
39
39
|
template=None,
|
40
40
|
verbose=True,
|
41
41
|
formatter=None,
|
42
42
|
format_kwargs=None,
|
43
|
+
pydantic_model: type[BaseModel] = None,
|
44
|
+
return_pydantic_model: bool = False,
|
43
45
|
**kwargs,
|
44
46
|
):
|
45
47
|
"""
|
@@ -120,7 +122,7 @@ class DirectiveMixin:
|
|
120
122
|
|
121
123
|
images = ImageUtil.read_image_to_base64(image_path)
|
122
124
|
|
123
|
-
|
125
|
+
output = await directive.chat(
|
124
126
|
instruction=instruction,
|
125
127
|
context=context,
|
126
128
|
sender=sender,
|
@@ -139,10 +141,19 @@ class DirectiveMixin:
|
|
139
141
|
timeout=timeout,
|
140
142
|
timing=timing,
|
141
143
|
clear_messages=clear_messages,
|
142
|
-
return_branch=return_branch,
|
143
144
|
images=images,
|
145
|
+
return_pydantic_model=return_pydantic_model,
|
146
|
+
pydantic_model=pydantic_model,
|
147
|
+
return_branch=False,
|
144
148
|
**kwargs,
|
145
149
|
)
|
150
|
+
if (
|
151
|
+
isinstance(output, tuple | list)
|
152
|
+
and len(output) == 2
|
153
|
+
and output[0] == output[1]
|
154
|
+
):
|
155
|
+
output = output[0]
|
156
|
+
return output
|
146
157
|
|
147
158
|
async def direct(
|
148
159
|
self,
|
lionagi/core/unit/unit.py
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
import logging
|
1
2
|
from collections.abc import Callable
|
2
3
|
|
4
|
+
from lionfuncs import to_dict
|
5
|
+
from pydantic import BaseModel
|
6
|
+
|
3
7
|
from lionagi.core.collections import iModel
|
4
8
|
from lionagi.core.collections.abc import Directive
|
5
9
|
from lionagi.core.report.form import Form
|
@@ -71,6 +75,8 @@ class Unit(Directive, DirectiveMixin):
|
|
71
75
|
return_branch=False,
|
72
76
|
formatter=None,
|
73
77
|
format_kwargs={},
|
78
|
+
pydantic_model: type[BaseModel] = None,
|
79
|
+
return_pydantic_model: bool = False,
|
74
80
|
**kwargs,
|
75
81
|
):
|
76
82
|
"""
|
@@ -100,7 +106,17 @@ class Unit(Directive, DirectiveMixin):
|
|
100
106
|
Any: The processed response.
|
101
107
|
"""
|
102
108
|
kwargs = {**retry_kwargs, **kwargs}
|
103
|
-
|
109
|
+
|
110
|
+
if pydantic_model:
|
111
|
+
if form:
|
112
|
+
raise ValueError("Cannot use both form and pydantic_model.")
|
113
|
+
if requested_fields:
|
114
|
+
raise ValueError(
|
115
|
+
"Cannot use both requested_fields and pydantic_model."
|
116
|
+
)
|
117
|
+
requested_fields = pydantic_model.model_json_schema()["properties"]
|
118
|
+
|
119
|
+
output, branch = await rcall(
|
104
120
|
self._chat,
|
105
121
|
instruction=instruction,
|
106
122
|
context=context,
|
@@ -118,11 +134,27 @@ class Unit(Directive, DirectiveMixin):
|
|
118
134
|
imodel=imodel,
|
119
135
|
clear_messages=clear_messages,
|
120
136
|
use_annotation=use_annotation,
|
121
|
-
return_branch=
|
137
|
+
return_branch=True,
|
122
138
|
formatter=formatter,
|
123
139
|
format_kwargs=format_kwargs,
|
124
140
|
**kwargs,
|
125
141
|
)
|
142
|
+
if isinstance(output, tuple | list) and len(output) == 1:
|
143
|
+
output = output[0]
|
144
|
+
|
145
|
+
if isinstance(output, tuple | list) and len(output) == 2:
|
146
|
+
if output[0] == output[1]:
|
147
|
+
output = output[0]
|
148
|
+
|
149
|
+
if return_pydantic_model:
|
150
|
+
try:
|
151
|
+
a_ = to_dict(output, recursive=True, max_recursive_depth=3)
|
152
|
+
output = pydantic_model(**a_)
|
153
|
+
return output, branch if return_branch else output
|
154
|
+
except Exception as e:
|
155
|
+
logging.error(f"Error converting to pydantic model: {e}")
|
156
|
+
|
157
|
+
return output, branch if return_branch else output
|
126
158
|
|
127
159
|
async def direct(
|
128
160
|
self,
|
lionagi/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.3.
|
1
|
+
__version__ = "0.3.2"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: lionagi
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.2
|
4
4
|
Summary: Towards automated general intelligence.
|
5
5
|
Author: HaiyangLi
|
6
6
|
Author-email: quantocean.li@gmail.com
|
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.12
|
12
12
|
Requires-Dist: aiocache (>=0.12.0,<0.13.0)
|
13
13
|
Requires-Dist: ipython (>=8.0.0,<9.0.0)
|
14
|
-
Requires-Dist: lion-core (>=0.3.
|
14
|
+
Requires-Dist: lion-core (>=0.3.17,<0.4.0)
|
15
15
|
Requires-Dist: lion-openai (>=0.1.5,<0.2.0)
|
16
16
|
Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
|
17
17
|
Description-Content-Type: text/markdown
|
@@ -89,7 +89,7 @@ lionagi/core/rule/string.py,sha256=ZoTuqidyR_vS0BNKEZEj_Oc5Ie8hhy2qaBFGX5J4CrU,1
|
|
89
89
|
lionagi/core/rule/util.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
90
90
|
lionagi/core/session/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
91
91
|
lionagi/core/session/branch.py,sha256=cs51rCG4OSPENVrniOlvKAKBXlcyLbzP032HuiCaIX8,14381
|
92
|
-
lionagi/core/session/directive_mixin.py,sha256=
|
92
|
+
lionagi/core/session/directive_mixin.py,sha256=bUHuCDH70BZiPKutRXHXgb5vKSJPL9abQLaIkYnC0Kk,12100
|
93
93
|
lionagi/core/session/session.py,sha256=cLieD42-g8s2ticNY2YyzAAwjwxkyk5q7M5dVlHlMBQ,10479
|
94
94
|
lionagi/core/structure/__init__.py,sha256=DkeLUlrb7rGx3nZ04aADU9HXXu5mZTf_DBwT0xhzIv4,7
|
95
95
|
lionagi/core/structure/chain.py,sha256=DkeLUlrb7rGx3nZ04aADU9HXXu5mZTf_DBwT0xhzIv4,7
|
@@ -105,7 +105,7 @@ lionagi/core/unit/template/plan.py,sha256=i4FmKEB8eRsRCsTanvfoX-2RZ8SaM1qvLBluuY
|
|
105
105
|
lionagi/core/unit/template/predict.py,sha256=-EIZQo0ZjGKy3MiM0AtqmbnJpbXcrwtSCON5n3jcyVo,3160
|
106
106
|
lionagi/core/unit/template/score.py,sha256=ReUaIIr-NLjunSy4NNXQpIsH28NNceGBAUuPCRptzMc,3809
|
107
107
|
lionagi/core/unit/template/select.py,sha256=VSpkphJl9bHSE8i0X6MMJD8LB5QwOj1UORHm8VDIRKE,3047
|
108
|
-
lionagi/core/unit/unit.py,sha256=
|
108
|
+
lionagi/core/unit/unit.py,sha256=1kFz_rLM1f8OKn4pbwL2WiVyqTzyEPOmHL9OdIiwzHI,15252
|
109
109
|
lionagi/core/unit/unit_form.py,sha256=zK_ij3Tod5FwMVdIIhdVoEFvD3br-YM9RPe7WsOIW2s,10980
|
110
110
|
lionagi/core/unit/unit_mixin.py,sha256=c8GvHzgc65iJKQBKv71ET3afLPsIz5-Ce-4Eo6_bZiw,38823
|
111
111
|
lionagi/core/unit/util.py,sha256=yEIf4ksWLB4X0IZNmwvIphvXiRbtWtGqbWCPnIt1u-s,2048
|
@@ -219,8 +219,8 @@ lionagi/lions/researcher/data_source/finhub_.py,sha256=W63daXgIwHJQ6TDMR2ALQIDk1
|
|
219
219
|
lionagi/lions/researcher/data_source/google_.py,sha256=401SKHQaSpxiOUoXl7stadl4qeF7SIX72lUNK7bKesg,6797
|
220
220
|
lionagi/lions/researcher/data_source/wiki_.py,sha256=UPoa2dk_y5sELu7_rkdme2auDpUmc_Dn0Avgjwr2X2g,3145
|
221
221
|
lionagi/lions/researcher/data_source/yfinance_.py,sha256=snAf897J69MyAc6fcFjF0irrMjbAh81EZ3RvaFT3hxE,977
|
222
|
-
lionagi/version.py,sha256=
|
223
|
-
lionagi-0.3.
|
224
|
-
lionagi-0.3.
|
225
|
-
lionagi-0.3.
|
226
|
-
lionagi-0.3.
|
222
|
+
lionagi/version.py,sha256=vNiWJ14r_cw5t_7UDqDQIVZvladKFGyHH2avsLpN7Vg,22
|
223
|
+
lionagi-0.3.2.dist-info/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
|
224
|
+
lionagi-0.3.2.dist-info/METADATA,sha256=7DrVUgP-AuWQaUBz_bfuAEvjRRRPw-yAmeX7349rf40,3149
|
225
|
+
lionagi-0.3.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
226
|
+
lionagi-0.3.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|