lionagi 0.5.0__py3-none-any.whl → 0.5.2__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.
Files changed (79) hide show
  1. lionagi/__init__.py +0 -1
  2. lionagi/core/action/tool.py +3 -5
  3. lionagi/core/communication/action_request.py +3 -3
  4. lionagi/core/communication/message.py +3 -3
  5. lionagi/core/communication/utils.py +3 -3
  6. lionagi/core/generic/component.py +4 -4
  7. lionagi/core/generic/element.py +51 -47
  8. lionagi/core/generic/graph.py +1 -1
  9. lionagi/core/generic/log.py +2 -2
  10. lionagi/core/generic/pile.py +10 -11
  11. lionagi/core/generic/progression.py +19 -12
  12. lionagi/core/generic/utils.py +6 -3
  13. lionagi/core/models/base.py +11 -68
  14. lionagi/core/models/field_model.py +42 -19
  15. lionagi/core/models/{new_model_params.py → model_params.py} +5 -6
  16. lionagi/core/models/note.py +2 -2
  17. lionagi/core/models/operable_model.py +8 -4
  18. lionagi/core/models/schema_model.py +9 -31
  19. lionagi/core/models/types.py +15 -6
  20. lionagi/core/session/branch.py +10 -7
  21. lionagi/core/session/branch_mixins.py +52 -15
  22. lionagi/core/session/session.py +1 -2
  23. lionagi/core/typing/__init__.py +4 -4
  24. lionagi/core/typing/{concepts.py → _concepts.py} +43 -2
  25. lionagi/core/typing/_id.py +104 -0
  26. lionagi/integrations/anthropic_/AnthropicModel.py +8 -3
  27. lionagi/integrations/anthropic_/AnthropicService.py +4 -0
  28. lionagi/integrations/groq_/GroqModel.py +11 -4
  29. lionagi/integrations/groq_/GroqService.py +4 -0
  30. lionagi/integrations/litellm_/imodel.py +10 -8
  31. lionagi/integrations/ollama_/OllamaService.py +4 -0
  32. lionagi/integrations/openai_/OpenAIModel.py +12 -3
  33. lionagi/integrations/openai_/image_token_calculator/image_token_calculator.py +14 -8
  34. lionagi/integrations/perplexity_/PerplexityModel.py +8 -3
  35. lionagi/integrations/perplexity_/PerplexityService.py +4 -0
  36. lionagi/libs/func/async_calls/__init__.py +6 -3
  37. lionagi/libs/func/async_calls/alcall.py +46 -0
  38. lionagi/libs/func/async_calls/bcall.py +49 -1
  39. lionagi/libs/func/async_calls/rcall.py +32 -0
  40. lionagi/libs/utils.py +12 -1
  41. lionagi/operations/brainstorm/brainstorm.py +3 -3
  42. lionagi/operations/plan/plan.py +3 -3
  43. lionagi/protocols/__init__.py +3 -0
  44. lionagi/protocols/configs/__init__.py +0 -15
  45. lionagi/protocols/configs/branch_config.py +1 -1
  46. lionagi/protocols/configs/imodel_config.py +2 -2
  47. lionagi/protocols/configs/log_config.py +1 -1
  48. lionagi/protocols/configs/types.py +15 -0
  49. lionagi/protocols/operatives/__init__.py +3 -15
  50. lionagi/protocols/operatives/action.py +4 -0
  51. lionagi/protocols/operatives/instruct.py +6 -2
  52. lionagi/protocols/operatives/operative.py +9 -21
  53. lionagi/protocols/operatives/prompts.py +4 -0
  54. lionagi/protocols/operatives/reason.py +4 -0
  55. lionagi/protocols/operatives/step.py +11 -23
  56. lionagi/protocols/operatives/types.py +19 -0
  57. lionagi/protocols/registries/__init__.py +3 -0
  58. lionagi/protocols/registries/_component_registry.py +4 -0
  59. lionagi/protocols/registries/_pile_registry.py +4 -0
  60. lionagi/service/__init__.py +3 -0
  61. lionagi/service/imodel.py +22 -7
  62. lionagi/service/service.py +4 -0
  63. lionagi/service/service_match_util.py +4 -4
  64. lionagi/settings.py +10 -18
  65. lionagi/strategies/base.py +4 -5
  66. lionagi/strategies/concurrent.py +4 -3
  67. lionagi/strategies/concurrent_chunk.py +3 -3
  68. lionagi/strategies/concurrent_sequential_chunk.py +3 -3
  69. lionagi/strategies/params.py +7 -4
  70. lionagi/version.py +1 -1
  71. {lionagi-0.5.0.dist-info → lionagi-0.5.2.dist-info}/METADATA +214 -15
  72. {lionagi-0.5.0.dist-info → lionagi-0.5.2.dist-info}/RECORD +77 -76
  73. lionagi/core/typing/config.py +0 -15
  74. lionagi/core/typing/id.py +0 -221
  75. /lionagi/core/typing/{pydantic_.py → _pydantic.py} +0 -0
  76. /lionagi/core/typing/{typing_.py → _typing.py} +0 -0
  77. /lionagi/integrations/{services.py → _services.py} +0 -0
  78. {lionagi-0.5.0.dist-info → lionagi-0.5.2.dist-info}/WHEEL +0 -0
  79. {lionagi-0.5.0.dist-info → lionagi-0.5.2.dist-info}/licenses/LICENSE +0 -0
@@ -4,7 +4,6 @@
4
4
 
5
5
  from pathlib import Path
6
6
 
7
- import yaml
8
7
  from dotenv import load_dotenv
9
8
  from pydantic import (
10
9
  BaseModel,
@@ -34,6 +33,12 @@ price_config_file_name = path / "anthropic_price_data.yaml"
34
33
  max_output_token_file_name = path / "anthropic_max_output_token_data.yaml"
35
34
 
36
35
 
36
+ class _ModuleImportClass:
37
+ from lionagi.libs.package.imports import check_import
38
+
39
+ yaml = check_import("yaml", pip_name="pyyaml")
40
+
41
+
37
42
  class AnthropicModel(BaseModel):
38
43
  model: str = Field(description="ID of the model to use.")
39
44
 
@@ -234,7 +239,7 @@ class AnthropicModel(BaseModel):
234
239
  )
235
240
  if estimated_output_len == 0:
236
241
  with open(max_output_token_file_name) as file:
237
- output_token_config = yaml.safe_load(file)
242
+ output_token_config = _ModuleImportClass.yaml.safe_load(file)
238
243
  estimated_output_len = output_token_config.get(self.model, 0)
239
244
  self.estimated_output_len = estimated_output_len
240
245
 
@@ -256,7 +261,7 @@ class AnthropicModel(BaseModel):
256
261
  num_of_input_tokens = self.text_token_calculator.calculate(input_text)
257
262
 
258
263
  with open(price_config_file_name) as file:
259
- price_config = yaml.safe_load(file)
264
+ price_config = _ModuleImportClass.yaml.safe_load(file)
260
265
 
261
266
  model_price_info_dict = price_config["model"][self.model]
262
267
  estimated_price = (
@@ -111,3 +111,7 @@ class AnthropicService(Service):
111
111
  return self.check_rate_limiter(
112
112
  model_obj, limit_requests=limit_requests, limit_tokens=limit_tokens
113
113
  )
114
+
115
+ @property
116
+ def allowed_roles(self):
117
+ return ["user", "assistant"]
@@ -5,7 +5,6 @@
5
5
  import warnings
6
6
  from pathlib import Path
7
7
 
8
- import yaml
9
8
  from dotenv import load_dotenv
10
9
  from pydantic import (
11
10
  BaseModel,
@@ -34,6 +33,12 @@ max_output_token_file_name = path / "groq_max_output_token_data.yaml"
34
33
  rate_limits_file_name = path / "groq_rate_limits.yaml"
35
34
 
36
35
 
36
+ class _ModuleImportClass:
37
+ from lionagi.libs.package.imports import check_import
38
+
39
+ yaml = check_import("yaml", pip_name="pyyaml")
40
+
41
+
37
42
  class GroqModel(BaseModel):
38
43
  model: str = Field(description="ID of the model to use.")
39
44
  request_model: GroqRequest = Field(description="Making requests")
@@ -67,7 +72,7 @@ class GroqModel(BaseModel):
67
72
  # Load rate limits from YAML
68
73
  try:
69
74
  with open(rate_limits_file_name) as file:
70
- rate_limits = yaml.safe_load(file)
75
+ rate_limits = _ModuleImportClass.yaml.safe_load(file)
71
76
  model_name = data.get("model")
72
77
  model_limits = None
73
78
 
@@ -261,7 +266,9 @@ class GroqModel(BaseModel):
261
266
  if estimated_output_len == 0:
262
267
  try:
263
268
  with open(max_output_token_file_name) as file:
264
- output_token_config = yaml.safe_load(file)
269
+ output_token_config = _ModuleImportClass.yaml.safe_load(
270
+ file
271
+ )
265
272
  estimated_output_len = output_token_config.get(
266
273
  self.model, 2048
267
274
  ) # Default to 2048
@@ -297,7 +304,7 @@ class GroqModel(BaseModel):
297
304
 
298
305
  try:
299
306
  with open(price_config_file_name) as file:
300
- price_config = yaml.safe_load(file)
307
+ price_config = _ModuleImportClass.yaml.safe_load(file)
301
308
  except FileNotFoundError:
302
309
  raise ValueError(
303
310
  f"Price config file not found: {price_config_file_name}"
@@ -145,3 +145,7 @@ class GroqService(Service):
145
145
  model_obj,
146
146
  limit_requests=limit_requests,
147
147
  )
148
+
149
+ @property
150
+ def allowed_roles(self):
151
+ return ["user", "assistant", "system"]
@@ -5,13 +5,6 @@
5
5
  import json
6
6
  import os
7
7
 
8
- import litellm
9
- from dotenv import load_dotenv
10
-
11
- litellm.drop_params = True
12
- load_dotenv()
13
-
14
-
15
8
  RESERVED_PARAMS = [
16
9
  "invoke_action",
17
10
  "instruction",
@@ -21,6 +14,11 @@ RESERVED_PARAMS = [
21
14
 
22
15
  class LiteiModel:
23
16
 
17
+ from lionagi.libs.package.imports import check_import
18
+
19
+ litellm = check_import("litellm")
20
+ litellm.drop_params = True
21
+
24
22
  def __init__(self, **kwargs):
25
23
  if "api_key" in kwargs:
26
24
  try:
@@ -33,7 +31,7 @@ class LiteiModel:
33
31
  except Exception:
34
32
  pass
35
33
  self.kwargs = kwargs
36
- self.acompletion = litellm.acompletion
34
+ self.acompletion = self.litellm.acompletion
37
35
 
38
36
  def to_dict(self) -> dict:
39
37
  dict_ = {
@@ -67,3 +65,7 @@ class LiteiModel:
67
65
  v = str(v)
68
66
  hashable_items.append((k, v))
69
67
  return hash(frozenset(hashable_items))
68
+
69
+ @property
70
+ def allowed_roles(self):
71
+ return ["user", "assistant", "system"]
@@ -136,3 +136,7 @@ class OllamaService(Service):
136
136
  # List Running Models
137
137
  def list_running_models(self):
138
138
  return OllamaRequest(endpoint="ps", method="GET")
139
+
140
+ @property
141
+ def allowed_roles(self):
142
+ return ["user", "assistant", "system"]
@@ -1,7 +1,6 @@
1
1
  import warnings
2
2
  from pathlib import Path
3
3
 
4
- import yaml
5
4
  from dotenv import load_dotenv
6
5
  from pydantic import (
7
6
  BaseModel,
@@ -35,6 +34,12 @@ price_config_file_name = path / "openai_max_output_token_data.yaml"
35
34
  max_output_token_file_name = path / "openai_price_data.yaml"
36
35
 
37
36
 
37
+ class _ModuleImportClass:
38
+ from lionagi.libs.package.imports import check_import
39
+
40
+ yaml = check_import("yaml", pip_name="pyyaml")
41
+
42
+
38
43
  class OpenAIModel(BaseModel):
39
44
  model: str = Field(description="ID of the model to use.")
40
45
 
@@ -303,7 +308,7 @@ class OpenAIModel(BaseModel):
303
308
  )
304
309
  if estimated_output_len == 0:
305
310
  with open(max_output_token_file_name) as file:
306
- output_token_config = yaml.safe_load(file)
311
+ output_token_config = _ModuleImportClass.yaml.safe_load(file)
307
312
  estimated_output_len = output_token_config.get(self.model, 0)
308
313
  self.estimated_output_len = (
309
314
  estimated_output_len # update to default max output len
@@ -388,7 +393,7 @@ class OpenAIModel(BaseModel):
388
393
 
389
394
  # read openai price info from config file
390
395
  with open(price_config_file_name) as file:
391
- price_config = yaml.safe_load(file)
396
+ price_config = _ModuleImportClass.yaml.safe_load(file)
392
397
 
393
398
  if self.request_model.endpoint == "chat/completions":
394
399
  model_price_info_dict = price_config["model"][self.model]
@@ -412,3 +417,7 @@ class OpenAIModel(BaseModel):
412
417
  "Estimating price currently only supports chat/completions endpoint"
413
418
  )
414
419
  return estimated_price
420
+
421
+ @property
422
+ def allowed_roles(self):
423
+ return ["user", "assistant", "system"]
@@ -4,9 +4,6 @@ import os
4
4
  from io import BytesIO
5
5
  from typing import Literal
6
6
 
7
- import aiohttp
8
- import yaml
9
- from PIL import Image
10
7
  from pydantic import BaseModel, Field, field_validator
11
8
 
12
9
  image_token_config_file_name = os.path.join(
@@ -14,6 +11,15 @@ image_token_config_file_name = os.path.join(
14
11
  )
15
12
 
16
13
 
14
+ class _ModuelImportClass:
15
+
16
+ from lionagi.libs.package.imports import check_import
17
+
18
+ yaml = check_import("yaml", pip_name="pyyaml")
19
+ Image = check_import("PIL.Image", pip_name="Pillow")
20
+ aiohttp = check_import("aiohttp")
21
+
22
+
17
23
  class OpenAIImageTokenCalculator(BaseModel):
18
24
  model: str = Field(description="ID of the model to use.")
19
25
 
@@ -21,7 +27,7 @@ class OpenAIImageTokenCalculator(BaseModel):
21
27
  @classmethod
22
28
  def validate_model_image_function(cls, value: str):
23
29
  with open(image_token_config_file_name) as file:
24
- token_config = yaml.safe_load(file)
30
+ token_config = _ModuelImportClass.yaml.safe_load(file)
25
31
 
26
32
  token_config = token_config.get(value, None)
27
33
 
@@ -36,16 +42,16 @@ class OpenAIImageTokenCalculator(BaseModel):
36
42
  image_base64 = url.split("data:image/jpeg;base64,")[1]
37
43
  image_base64.strip("{}")
38
44
  image_data = base64.b64decode(image_base64)
39
- image = Image.open(BytesIO(image_data))
45
+ image = _ModuelImportClass.Image.open(BytesIO(image_data))
40
46
  else:
41
47
  # image url
42
- async with aiohttp.ClientSession() as client:
48
+ async with _ModuelImportClass.aiohttp.ClientSession() as client:
43
49
  async with client.get(url=url) as response:
44
50
  response.raise_for_status()
45
51
 
46
52
  content = await response.read()
47
53
 
48
- image = Image.open(BytesIO(content))
54
+ image = _ModuelImportClass.Image.open(BytesIO(content))
49
55
 
50
56
  return image.size
51
57
 
@@ -58,7 +64,7 @@ class OpenAIImageTokenCalculator(BaseModel):
58
64
  )
59
65
 
60
66
  with open(image_token_config_file_name) as file:
61
- token_config = yaml.safe_load(file)
67
+ token_config = _ModuelImportClass.yaml.safe_load(file)
62
68
 
63
69
  token_config = token_config.get(self.model, None)
64
70
 
@@ -5,7 +5,6 @@
5
5
  import os
6
6
  from pathlib import Path
7
7
 
8
- import yaml
9
8
  from dotenv import load_dotenv
10
9
  from pydantic import (
11
10
  BaseModel,
@@ -35,6 +34,12 @@ price_config_file_name = path / "perplexity_price_data.yaml"
35
34
  max_output_token_file_name = path / "perplexity_max_output_token_data.yaml"
36
35
 
37
36
 
37
+ class _ModuleImportClass:
38
+ from lionagi.libs.package.imports import check_import
39
+
40
+ yaml = check_import("yaml", pip_name="pyyaml")
41
+
42
+
38
43
  class PerplexityModel(BaseModel):
39
44
  model: str = Field(description="ID of the model to use.")
40
45
 
@@ -235,7 +240,7 @@ class PerplexityModel(BaseModel):
235
240
  )
236
241
  if estimated_output_len == 0:
237
242
  with open(max_output_token_file_name) as file:
238
- output_token_config = yaml.safe_load(file)
243
+ output_token_config = _ModuleImportClass.yaml.safe_load(file)
239
244
  estimated_output_len = output_token_config.get(self.model, 0)
240
245
  self.estimated_output_len = estimated_output_len
241
246
 
@@ -257,7 +262,7 @@ class PerplexityModel(BaseModel):
257
262
  num_of_input_tokens = self.text_token_calculator.calculate(input_text)
258
263
 
259
264
  with open(price_config_file_name) as file:
260
- price_config = yaml.safe_load(file)
265
+ price_config = _ModuleImportClass.yaml.safe_load(file)
261
266
 
262
267
  model_price_info_dict = price_config["model"][self.model]
263
268
  estimated_price = (
@@ -107,3 +107,7 @@ class PerplexityService(Service):
107
107
  return self.check_rate_limiter(
108
108
  model_obj, limit_requests=limit_requests, limit_tokens=limit_tokens
109
109
  )
110
+
111
+ @property
112
+ def allowed_roles(self):
113
+ return ["user", "assistant", "system"]
@@ -2,11 +2,11 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
- from .alcall import alcall
6
- from .bcall import bcall
5
+ from .alcall import ALCallParams, alcall
6
+ from .bcall import BCallParams, bcall
7
7
  from .mcall import mcall
8
8
  from .pcall import pcall
9
- from .rcall import rcall
9
+ from .rcall import RCallParams, rcall
10
10
  from .tcall import tcall
11
11
  from .ucall import ucall
12
12
 
@@ -18,4 +18,7 @@ __all__ = [
18
18
  "rcall",
19
19
  "tcall",
20
20
  "ucall",
21
+ "ALCallParams",
22
+ "BCallParams",
23
+ "RCallParams",
21
24
  ]
@@ -1,7 +1,10 @@
1
1
  import asyncio
2
2
  from collections.abc import Callable
3
+ from dataclasses import dataclass
3
4
  from typing import Any, TypeVar
4
5
 
6
+ from lionagi.libs.utils import DataClass
7
+
5
8
  from ...constants import UNDEFINED
6
9
  from ...parse import to_list
7
10
  from .ucall import ucall
@@ -9,6 +12,49 @@ from .ucall import ucall
9
12
  T = TypeVar("T")
10
13
 
11
14
 
15
+ @dataclass
16
+ class ALCallParams(DataClass):
17
+ function: Callable[..., T]
18
+ num_retries: int = 0
19
+ initial_delay: float = 0
20
+ retry_delay: float = 0
21
+ backoff_factor: float = 1
22
+ retry_default: Any = UNDEFINED
23
+ retry_timeout: float | None = None
24
+ retry_timing: bool = False
25
+ verbose: bool = True
26
+ error_msg: str | None = None
27
+ error_map: dict[type, Callable[[Exception], None]] | None = None
28
+ max_concurrent: int | None = None
29
+ throttle_period: float | None = None
30
+ flatten: bool = False
31
+ dropna: bool = False
32
+ unique: bool = False
33
+
34
+ async def __call__(self, input_, *args, **kwargs):
35
+ return await alcall(
36
+ input_,
37
+ self.function,
38
+ *args,
39
+ num_retries=self.num_retries,
40
+ initial_delay=self.initial_delay,
41
+ retry_delay=self.retry_delay,
42
+ backoff_factor=self.backoff_factor,
43
+ retry_default=self.retry_default,
44
+ retry_timeout=self.retry_timeout,
45
+ retry_timing=self.retry_timing,
46
+ verbose_retry=self.verbose,
47
+ error_msg=self.error_msg,
48
+ error_map=self.error_map,
49
+ max_concurrent=self.max_concurrent,
50
+ throttle_period=self.throttle_period,
51
+ flatten=self.flatten,
52
+ dropna=self.dropna,
53
+ unique=self.unique,
54
+ **kwargs,
55
+ )
56
+
57
+
12
58
  async def alcall(
13
59
  input_: list[Any],
14
60
  func: Callable[..., T],
@@ -1,13 +1,61 @@
1
- import asyncio
2
1
  from collections.abc import AsyncGenerator, Callable
2
+ from dataclasses import dataclass
3
3
  from typing import Any, TypeVar
4
4
 
5
+ from lionagi.libs.constants import UNDEFINED
6
+ from lionagi.libs.utils import DataClass
7
+
5
8
  from ...parse import to_list
6
9
  from .alcall import alcall
7
10
 
8
11
  T = TypeVar("T")
9
12
 
10
13
 
14
+ @dataclass
15
+ class BCallParams(DataClass):
16
+ function: Callable[..., T]
17
+ batch_size: int
18
+ num_retries: int = 0
19
+ initial_delay: float = 0
20
+ retry_delay: float = 0
21
+ backoff_factor: float = 1
22
+ retry_default: Any = UNDEFINED
23
+ retry_timeout: float | None = None
24
+ retry_timing: bool = False
25
+ verbose_retry: bool = True
26
+ error_msg: str | None = None
27
+ error_map: dict[type, Callable[[Exception], None]] | None = None
28
+ max_concurrent: int | None = None
29
+ throttle_period: float | None = None
30
+ flatten: bool = False
31
+ dropna: bool = False
32
+ unique: bool = False
33
+
34
+ async def __call__(self, input_, *args, **kwargs):
35
+ return await bcall(
36
+ input_,
37
+ self.function,
38
+ *args,
39
+ batch_size=self.batch_size,
40
+ num_retries=self.num_retries,
41
+ initial_delay=self.initial_delay,
42
+ retry_delay=self.retry_delay,
43
+ backoff_factor=self.backoff_factor,
44
+ default=self.retry_default,
45
+ timeout=self.retry_timeout,
46
+ timing=self.retry_timing,
47
+ verbose=self.verbose_retry,
48
+ error_msg=self.error_msg,
49
+ error_map=self.error_map,
50
+ max_concurrent=self.max_concurrent,
51
+ throttle_period=self.throttle_period,
52
+ flatten=self.flatten,
53
+ dropna=self.dropna,
54
+ unique=self.unique,
55
+ **kwargs,
56
+ )
57
+
58
+
11
59
  async def bcall(
12
60
  input_: Any,
13
61
  func: Callable[..., T],
@@ -1,7 +1,10 @@
1
1
  import asyncio
2
2
  from collections.abc import Callable
3
+ from dataclasses import dataclass
3
4
  from typing import Any, TypeVar
4
5
 
6
+ from lionagi.libs.utils import DataClass
7
+
5
8
  from ...constants import UNDEFINED
6
9
  from ...utils import time as _t
7
10
  from .ucall import ucall
@@ -9,6 +12,35 @@ from .ucall import ucall
9
12
  T = TypeVar("T")
10
13
 
11
14
 
15
+ @dataclass
16
+ class RCallParams(DataClass):
17
+ function: Callable[..., T]
18
+ num_retries: int = 0
19
+ initial_delay: float = 0
20
+ retry_delay: float = 0
21
+ backoff_factor: float = 1
22
+ retry_default: Any = UNDEFINED
23
+ retry_timeout: float | None = None
24
+ retry_timing: bool = False
25
+ verbose_retry: bool = True
26
+
27
+ async def __call__(self, input_, *args, **kwargs):
28
+ return await rcall(
29
+ input_,
30
+ self.function,
31
+ *args,
32
+ num_retries=self.num_retries,
33
+ initial_delay=self.initial_delay,
34
+ retry_delay=self.retry_delay,
35
+ backoff_factor=self.backoff_factor,
36
+ retry_default=self.retry_default,
37
+ retry_timeout=self.retry_timeout,
38
+ retry_timing=self.retry_timing,
39
+ verbose_retry=self.verbose_retry,
40
+ **kwargs,
41
+ )
42
+
43
+
12
44
  async def rcall(
13
45
  func: Callable[..., T],
14
46
  /,
lionagi/libs/utils.py CHANGED
@@ -8,13 +8,24 @@ import random
8
8
  import subprocess
9
9
  import sys
10
10
  from collections.abc import Mapping, Sequence
11
+ from dataclasses import asdict
11
12
  from datetime import datetime, timezone
12
13
  from hashlib import sha256
13
- from typing import Literal, TypeVar
14
+ from typing import Literal, Self, TypeVar
14
15
 
15
16
  T = TypeVar("T")
16
17
 
17
18
 
19
+ class DataClass:
20
+
21
+ def to_dict(self) -> dict:
22
+ return asdict(self)
23
+
24
+ @classmethod
25
+ def from_dict(cls, data: dict) -> Self:
26
+ return cls(**data)
27
+
28
+
18
29
  def unique_hash(n: int = 32) -> str:
19
30
  """unique random hash"""
20
31
  current_time = datetime.now().isoformat().encode("utf-8")
@@ -9,7 +9,7 @@ from lionagi.core.typing import ID, Any, BaseModel
9
9
  from lionagi.libs.func import alcall
10
10
  from lionagi.libs.parse import to_flat_list
11
11
  from lionagi.protocols.operatives.instruct import (
12
- INSTRUCT_MODEL_FIELD,
12
+ INSTRUCT_FIELD_MODEL,
13
13
  Instruct,
14
14
  InstructResponse,
15
15
  )
@@ -118,8 +118,8 @@ async def brainstorm(
118
118
  print(f"Starting brainstorming...")
119
119
 
120
120
  field_models: list = kwargs.get("field_models", [])
121
- if INSTRUCT_MODEL_FIELD not in field_models:
122
- field_models.append(INSTRUCT_MODEL_FIELD)
121
+ if INSTRUCT_FIELD_MODEL not in field_models:
122
+ field_models.append(INSTRUCT_FIELD_MODEL)
123
123
 
124
124
  kwargs["field_models"] = field_models
125
125
  session, branch = prepare_session(session, branch, branch_kwargs)
@@ -7,7 +7,7 @@ from lionagi.core.session.branch import Branch
7
7
  from lionagi.core.session.session import Session
8
8
  from lionagi.core.typing import ID, Any, BaseModel, Literal
9
9
  from lionagi.protocols.operatives.instruct import (
10
- INSTRUCT_MODEL_FIELD,
10
+ INSTRUCT_FIELD_MODEL,
11
11
  Instruct,
12
12
  InstructResponse,
13
13
  )
@@ -95,8 +95,8 @@ async def plan(
95
95
  print(f"Planning execution with {num_steps} steps...")
96
96
 
97
97
  field_models: list = kwargs.get("field_models", [])
98
- if INSTRUCT_MODEL_FIELD not in field_models:
99
- field_models.append(INSTRUCT_MODEL_FIELD)
98
+ if INSTRUCT_FIELD_MODEL not in field_models:
99
+ field_models.append(INSTRUCT_FIELD_MODEL)
100
100
  kwargs["field_models"] = field_models
101
101
  session, branch = prepare_session(session, branch, branch_kwargs)
102
102
  execute_branch: Branch = session.split(branch)
@@ -0,0 +1,3 @@
1
+ # Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
@@ -1,15 +0,0 @@
1
- from .branch_config import BranchConfig, MessageConfig
2
- from .id_config import LionIDConfig
3
- from .imodel_config import iModelConfig
4
- from .log_config import LogConfig
5
- from .retry_config import RetryConfig, TimedFuncCallConfig
6
-
7
- __all__ = [
8
- "LogConfig",
9
- "LionIDConfig",
10
- "RetryConfig",
11
- "TimedFuncCallConfig",
12
- "iModelConfig",
13
- "BranchConfig",
14
- "MessageConfig",
15
- ]
@@ -5,7 +5,7 @@
5
5
  from typing import Any, Literal
6
6
 
7
7
  from lionagi.core.models.schema_model import SchemaModel
8
- from lionagi.core.typing.pydantic_ import Field
8
+ from lionagi.core.typing._pydantic import Field
9
9
 
10
10
  from .imodel_config import iModelConfig
11
11
  from .log_config import LogConfig
@@ -6,8 +6,8 @@ import json
6
6
  import os
7
7
 
8
8
  from lionagi.core.models.schema_model import SchemaModel
9
- from lionagi.core.typing.pydantic_ import Field
10
- from lionagi.core.typing.typing_ import Any
9
+ from lionagi.core.typing._pydantic import Field
10
+ from lionagi.core.typing._typing import Any
11
11
 
12
12
 
13
13
  class iModelConfig(SchemaModel):
@@ -8,7 +8,7 @@ from typing import Any
8
8
  from pydantic import field_validator
9
9
 
10
10
  from lionagi.core.models.schema_model import SchemaModel
11
- from lionagi.core.typing.pydantic_ import Field
11
+ from lionagi.core.typing._pydantic import Field
12
12
 
13
13
 
14
14
  class LogConfig(SchemaModel):
@@ -0,0 +1,15 @@
1
+ from .branch_config import BranchConfig, MessageConfig
2
+ from .id_config import LionIDConfig
3
+ from .imodel_config import iModelConfig
4
+ from .log_config import LogConfig
5
+ from .retry_config import RetryConfig, TimedFuncCallConfig
6
+
7
+ __all__ = [
8
+ "LogConfig",
9
+ "LionIDConfig",
10
+ "RetryConfig",
11
+ "TimedFuncCallConfig",
12
+ "iModelConfig",
13
+ "BranchConfig",
14
+ "MessageConfig",
15
+ ]
@@ -1,15 +1,3 @@
1
- from .action import ActionRequestModel, ActionResponseModel
2
- from .instruct import Instruct
3
- from .operative import Operative
4
- from .reason import ReasonModel
5
- from .step import Step, StepModel
6
-
7
- __all__: list[str] = [
8
- "Operative",
9
- "Step",
10
- "ActionRequestModel",
11
- "ActionResponseModel",
12
- "StepModel",
13
- "Instruct",
14
- "ReasonModel",
15
- ]
1
+ # Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
@@ -1,3 +1,7 @@
1
+ # Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
1
5
  import re
2
6
 
3
7
  from lionagi.core.typing import (