lionagi 0.3.3__py3-none-any.whl → 0.3.5__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/core/unit/unit.py CHANGED
@@ -12,7 +12,7 @@ from lionagi.libs.ln_func_call import rcall
12
12
 
13
13
  from .unit_form import UnitForm
14
14
  from .unit_mixin import DirectiveMixin
15
- from .util import retry_kwargs
15
+ from .util import break_down_annotation, retry_kwargs
16
16
 
17
17
 
18
18
  class Unit(Directive, DirectiveMixin):
@@ -75,7 +75,7 @@ class Unit(Directive, DirectiveMixin):
75
75
  return_branch=False,
76
76
  formatter=None,
77
77
  format_kwargs={},
78
- pydantic_model: type[BaseModel] = None,
78
+ pydantic_model: type[BaseModel] | BaseModel = None,
79
79
  return_pydantic_model: bool = False,
80
80
  **kwargs,
81
81
  ):
@@ -114,7 +114,11 @@ class Unit(Directive, DirectiveMixin):
114
114
  raise ValueError(
115
115
  "Cannot use both requested_fields and pydantic_model."
116
116
  )
117
- requested_fields = pydantic_model.model_json_schema()["properties"]
117
+ requested_fields = break_down_annotation(pydantic_model)
118
+ context = {
119
+ "info": context,
120
+ "return_guidance": pydantic_model.model_json_schema(),
121
+ }
118
122
 
119
123
  output, branch = await rcall(
120
124
  self._chat,
@@ -148,8 +152,13 @@ class Unit(Directive, DirectiveMixin):
148
152
 
149
153
  if return_pydantic_model:
150
154
  try:
151
- a_ = to_dict(output, recursive=True, max_recursive_depth=3)
152
- output = pydantic_model(**a_)
155
+ a_ = to_dict(
156
+ output,
157
+ recursive=True,
158
+ max_recursive_depth=5,
159
+ fuzzy_parse=True,
160
+ )
161
+ output = pydantic_model.model_validate(a_)
153
162
  return output, branch if return_branch else output
154
163
  except Exception as e:
155
164
  logging.error(f"Error converting to pydantic model: {e}")
lionagi/core/unit/util.py CHANGED
@@ -1,3 +1,8 @@
1
+ import inspect
2
+ from typing import get_args
3
+
4
+ from pydantic import BaseModel
5
+
1
6
  retry_kwargs = {
2
7
  "retries": 0, # kwargs for rcall, number of retries if failed
3
8
  "delay": 0, # number of seconds to delay before retrying
@@ -74,3 +79,25 @@ async def _direct(
74
79
  )
75
80
 
76
81
  return await directive.direct(form=form, return_form=True, **kwargs)
82
+
83
+
84
+ def break_down_annotation(model: type[BaseModel]):
85
+
86
+ def _ispydantic_model(x):
87
+ return inspect.isclass(x) and issubclass(x, BaseModel)
88
+
89
+ if not _ispydantic_model(model):
90
+ return model
91
+
92
+ out = {}
93
+ for k, v in model.__annotations__.items():
94
+ if _ispydantic_model(v):
95
+ out[k] = break_down_annotation(v)
96
+ elif "list" in str(v) and get_args(v):
97
+ v = get_args(v)[0]
98
+ if _ispydantic_model(v):
99
+ v = break_down_annotation(v)
100
+ out[k] = [v]
101
+ else:
102
+ out[k] = v
103
+ return out
lionagi/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.3.3"
1
+ __version__ = "0.3.5"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lionagi
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: Towards automated general intelligence.
5
5
  Author: HaiyangLi
6
6
  Author-email: quantocean.li@gmail.com
@@ -105,10 +105,10 @@ 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=1kFz_rLM1f8OKn4pbwL2WiVyqTzyEPOmHL9OdIiwzHI,15252
108
+ lionagi/core/unit/unit.py,sha256=a3rauBXe50SBUgndv7Q9bqF4h7pJCYdsoTfPf1e8GCs,15548
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
- lionagi/core/unit/util.py,sha256=yEIf4ksWLB4X0IZNmwvIphvXiRbtWtGqbWCPnIt1u-s,2048
111
+ lionagi/core/unit/util.py,sha256=WN2Jop-LUwQNYJNubFPhOZrisQ6SQq-XMhD_KhzLkgE,2707
112
112
  lionagi/core/validator/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
113
113
  lionagi/core/validator/validator.py,sha256=901wwmqL92XNi25ajv57bNKIKZhmu-KprNLArMUiGqg,12255
114
114
  lionagi/core/work/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -229,8 +229,8 @@ lionagi/lions/researcher/data_source/finhub_.py,sha256=W63daXgIwHJQ6TDMR2ALQIDk1
229
229
  lionagi/lions/researcher/data_source/google_.py,sha256=401SKHQaSpxiOUoXl7stadl4qeF7SIX72lUNK7bKesg,6797
230
230
  lionagi/lions/researcher/data_source/wiki_.py,sha256=UPoa2dk_y5sELu7_rkdme2auDpUmc_Dn0Avgjwr2X2g,3145
231
231
  lionagi/lions/researcher/data_source/yfinance_.py,sha256=snAf897J69MyAc6fcFjF0irrMjbAh81EZ3RvaFT3hxE,977
232
- lionagi/version.py,sha256=8KcCYTXH99C2-gCLuPILJvtT9YftRWJsartIx6TQ2ZY,22
233
- lionagi-0.3.3.dist-info/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
234
- lionagi-0.3.3.dist-info/METADATA,sha256=aPmmyz7FbSYaeDChIRXx9r3C6-2ZVs-S8YzEZtnpyZg,3149
235
- lionagi-0.3.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
236
- lionagi-0.3.3.dist-info/RECORD,,
232
+ lionagi/version.py,sha256=ThnCuF3X7rsQSd5PAea_jfYA70ZmhLvkFcLBxBPwZnY,22
233
+ lionagi-0.3.5.dist-info/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
234
+ lionagi-0.3.5.dist-info/METADATA,sha256=preDwKyaqarnjXriVlSdy8ZzqVem9onrDw4BZVwyGpY,3149
235
+ lionagi-0.3.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
236
+ lionagi-0.3.5.dist-info/RECORD,,