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
lionagi/core/typing/id.py DELETED
@@ -1,221 +0,0 @@
1
- # Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- from lionagi.libs.utils import insert_random_hyphens, unique_hash
6
- from lionagi.settings import LionIDConfig, Settings
7
-
8
- from .concepts import Container, Generic, ItemError, Observable, Ordering, T
9
- from .pydantic_ import Field
10
- from .typing_ import Annotated, Container, Mapping, Sequence, TypeAlias
11
-
12
- LnID: TypeAlias = Annotated[str, Field(description="A unique identifier.")]
13
-
14
-
15
- class IDError(ItemError):
16
- """Exception raised when an item does not have a Lion ID."""
17
-
18
- def __init__(
19
- self,
20
- message: str = "Item must contain a Lion ID.",
21
- item_id: str | None = None,
22
- ):
23
- super().__init__(message, item_id)
24
-
25
-
26
- class ID(Generic[T]):
27
- """
28
- A generic class that provides ID-related functionality for Observable objects.
29
-
30
- This class handles the generation, validation, and management of unique identifiers
31
- within the Lion system. It provides type aliases for various ID-related operations
32
- and methods for working with IDs.
33
- """
34
-
35
- # For functions that accept either ID or item
36
- Ref: TypeAlias = LnID | T # type: ignore
37
-
38
- # For functions requiring just the ID
39
- ID: TypeAlias = LnID
40
-
41
- # For functions requiring Observable object
42
- Item = T # type: ignore
43
-
44
- # For collections
45
- IDSeq: TypeAlias = Sequence[LnID] | Ordering[LnID]
46
- ItemSeq: TypeAlias = ( # type: ignore
47
- Sequence[T] | Mapping[LnID, T] | Container[LnID | T]
48
- )
49
- RefSeq: TypeAlias = IDSeq | ItemSeq
50
-
51
- # For system-level interactions
52
- SenderRecipient: TypeAlias = LnID | T # type: ignore
53
-
54
- @staticmethod
55
- def id(
56
- config: LionIDConfig = Settings.Config.ID,
57
- n: int = None,
58
- prefix: str = None,
59
- postfix: str = None,
60
- random_hyphen: bool = None,
61
- num_hyphens: int = None,
62
- hyphen_start_index: int = None,
63
- hyphen_end_index: int = None,
64
- ) -> LnID:
65
- """
66
- Generate a unique identifier.
67
-
68
- Args:
69
- n: Length of the ID (excluding prefix and postfix).
70
- prefix: String to prepend to the ID.
71
- postfix: String to append to the ID.
72
- random_hyphen: If True, insert random hyphens into the ID.
73
- num_hyphens: Number of hyphens to insert if random_hyphen is True.
74
- hyphen_start_index: Start index for hyphen insertion.
75
- hyphen_end_index: End index for hyphen insertion.
76
-
77
- Returns:
78
- A unique identifier string.
79
- """
80
- _dict = {
81
- "n": n,
82
- "prefix": prefix,
83
- "postfix": postfix,
84
- "random_hyphen": random_hyphen,
85
- "num_hyphens": num_hyphens,
86
- "hyphen_start_index": hyphen_start_index,
87
- "hyphen_end_index": hyphen_end_index,
88
- }
89
- _dict = {k: v for k, v in _dict.items() if v is not None}
90
- config = {**config.to_dict(), **_dict}
91
- return ID._id(**config)
92
-
93
- @staticmethod
94
- def _id(
95
- *,
96
- n: int,
97
- prefix: str = "",
98
- postfix: str = "",
99
- random_hyphen: bool = False,
100
- num_hyphens: int = 0,
101
- hyphen_start_index: int = 6,
102
- hyphen_end_index: int = -6,
103
- ):
104
- _id = unique_hash(n)
105
- if random_hyphen:
106
- _id = insert_random_hyphens(
107
- s=_id,
108
- num_hyphens=num_hyphens,
109
- start_index=hyphen_start_index,
110
- end_index=hyphen_end_index,
111
- )
112
- if prefix:
113
- _id = f"{prefix}{_id}"
114
- if postfix:
115
- _id = f"{_id}{postfix}"
116
-
117
- return _id
118
-
119
- @staticmethod
120
- def get_id(
121
- item,
122
- config: LionIDConfig = Settings.Config.ID,
123
- /,
124
- ) -> str:
125
- """
126
- Get the Lion ID of an item.
127
-
128
- Args:
129
- item: The item to get the ID from.
130
- config: Configuration dictionary for ID validation.
131
-
132
- Returns:
133
- The Lion ID of the item.
134
-
135
- Raises:
136
- LionIDError: If the item does not contain a valid Lion ID.
137
- """
138
-
139
- item_id = None
140
- if isinstance(item, Sequence) and len(item) == 1:
141
- item = item[0]
142
-
143
- if isinstance(item, Observable):
144
- item_id: str = item.ln_id
145
- else:
146
- item_id = item
147
-
148
- check = isinstance(item_id, str)
149
- if check:
150
- id_len = (
151
- (len(config.prefix) if config.prefix else 0)
152
- + config.n
153
- + config.num_hyphens
154
- + (len(config.postfix) if config.postfix else 0)
155
- )
156
- if len(item_id) != id_len:
157
- check = False
158
- if check and config.prefix:
159
- if item_id.startswith(config.prefix):
160
- item_id = item_id[len(config.prefix) :] # noqa
161
- else:
162
- check = False
163
- if check and config.postfix:
164
- if item_id.endswith(config.postfix):
165
- item_id = item_id[: -len(config.postfix)]
166
- else:
167
- check = False
168
- if check and config.num_hyphens:
169
- if config.num_hyphens != item_id.count("-"):
170
- check = False
171
- if check and config.hyphen_start_index:
172
- idx = config.hyphen_start_index - len(config.prefix)
173
- if idx > 0 and "-" in item_id[:idx]:
174
- check = False
175
- if check and config.hyphen_end_index:
176
- if config.hyphen_end_index < 0:
177
- idx = config.hyphen_end_index + id_len
178
- idx -= len(config.prefix + config.postfix)
179
- if idx < 0 and "-" in item_id[idx:]:
180
- check = False
181
-
182
- if check:
183
- return config.prefix + item_id + config.postfix
184
- if (
185
- isinstance(item_id, str) and len(item_id) == 32
186
- ): # for backward compatibility
187
- return item_id
188
- raise IDError(
189
- f"The input object of type <{type(item).__name__}> does "
190
- "not contain or is not a valid Lion ID. Item must be an instance"
191
- " of `Observable` or a valid `ln_id`."
192
- )
193
-
194
- @staticmethod
195
- def is_id(
196
- item,
197
- config: LionIDConfig = Settings.Config.ID,
198
- /,
199
- ) -> bool:
200
- """
201
- Check if an item is a valid Lion ID.
202
-
203
- Args:
204
- item: The item to check.
205
- config: Configuration dictionary for ID validation.
206
-
207
- Returns:
208
- True if the item is a valid Lion ID, False otherwise.
209
- """
210
- try:
211
- ID.get_id(item, config)
212
- return True
213
- except IDError:
214
- return False
215
-
216
-
217
- __all__ = [
218
- "LnID",
219
- "ID",
220
- "IDError",
221
- ]
File without changes
File without changes
File without changes