lionagi 0.0.306__py3-none-any.whl → 0.0.308__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 (78) hide show
  1. lionagi/__init__.py +2 -5
  2. lionagi/core/__init__.py +7 -5
  3. lionagi/core/agent/__init__.py +3 -0
  4. lionagi/core/agent/base_agent.py +10 -12
  5. lionagi/core/branch/__init__.py +4 -0
  6. lionagi/core/branch/base_branch.py +81 -81
  7. lionagi/core/branch/branch.py +16 -28
  8. lionagi/core/branch/branch_flow_mixin.py +3 -7
  9. lionagi/core/branch/executable_branch.py +86 -56
  10. lionagi/core/branch/util.py +77 -162
  11. lionagi/core/{flow/direct → direct}/__init__.py +1 -1
  12. lionagi/core/{flow/direct/predict.py → direct/parallel_predict.py} +39 -17
  13. lionagi/core/direct/parallel_react.py +0 -0
  14. lionagi/core/direct/parallel_score.py +0 -0
  15. lionagi/core/direct/parallel_select.py +0 -0
  16. lionagi/core/direct/parallel_sentiment.py +0 -0
  17. lionagi/core/direct/predict.py +174 -0
  18. lionagi/core/{flow/direct → direct}/react.py +2 -2
  19. lionagi/core/{flow/direct → direct}/score.py +28 -23
  20. lionagi/core/{flow/direct → direct}/select.py +48 -45
  21. lionagi/core/direct/utils.py +83 -0
  22. lionagi/core/flow/monoflow/ReAct.py +6 -5
  23. lionagi/core/flow/monoflow/__init__.py +9 -0
  24. lionagi/core/flow/monoflow/chat.py +10 -10
  25. lionagi/core/flow/monoflow/chat_mixin.py +11 -10
  26. lionagi/core/flow/monoflow/followup.py +6 -5
  27. lionagi/core/flow/polyflow/__init__.py +1 -0
  28. lionagi/core/flow/polyflow/chat.py +15 -3
  29. lionagi/core/mail/mail_manager.py +18 -19
  30. lionagi/core/mail/schema.py +5 -4
  31. lionagi/core/messages/schema.py +18 -20
  32. lionagi/core/prompt/__init__.py +0 -0
  33. lionagi/core/prompt/prompt_template.py +0 -0
  34. lionagi/core/schema/__init__.py +2 -2
  35. lionagi/core/schema/action_node.py +11 -3
  36. lionagi/core/schema/base_mixin.py +56 -59
  37. lionagi/core/schema/base_node.py +34 -37
  38. lionagi/core/schema/condition.py +24 -0
  39. lionagi/core/schema/data_logger.py +96 -99
  40. lionagi/core/schema/data_node.py +19 -19
  41. lionagi/core/schema/prompt_template.py +0 -0
  42. lionagi/core/schema/structure.py +171 -169
  43. lionagi/core/session/__init__.py +1 -3
  44. lionagi/core/session/session.py +196 -214
  45. lionagi/core/tool/tool_manager.py +95 -103
  46. lionagi/integrations/__init__.py +1 -3
  47. lionagi/integrations/bridge/langchain_/documents.py +17 -18
  48. lionagi/integrations/bridge/langchain_/langchain_bridge.py +14 -14
  49. lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +22 -22
  50. lionagi/integrations/bridge/llamaindex_/node_parser.py +12 -12
  51. lionagi/integrations/bridge/llamaindex_/reader.py +11 -11
  52. lionagi/integrations/bridge/llamaindex_/textnode.py +7 -7
  53. lionagi/integrations/config/openrouter_configs.py +0 -1
  54. lionagi/integrations/provider/oai.py +26 -26
  55. lionagi/integrations/provider/services.py +38 -38
  56. lionagi/libs/__init__.py +34 -1
  57. lionagi/libs/ln_api.py +211 -221
  58. lionagi/libs/ln_async.py +53 -60
  59. lionagi/libs/ln_convert.py +118 -120
  60. lionagi/libs/ln_dataframe.py +32 -33
  61. lionagi/libs/ln_func_call.py +334 -342
  62. lionagi/libs/ln_nested.py +99 -107
  63. lionagi/libs/ln_parse.py +161 -165
  64. lionagi/libs/sys_util.py +52 -52
  65. lionagi/tests/test_core/test_session.py +254 -266
  66. lionagi/tests/test_core/test_session_base_util.py +299 -300
  67. lionagi/tests/test_core/test_tool_manager.py +70 -74
  68. lionagi/tests/test_libs/test_nested.py +2 -7
  69. lionagi/tests/test_libs/test_parse.py +2 -2
  70. lionagi/version.py +1 -1
  71. {lionagi-0.0.306.dist-info → lionagi-0.0.308.dist-info}/METADATA +4 -2
  72. lionagi-0.0.308.dist-info/RECORD +115 -0
  73. lionagi/core/flow/direct/utils.py +0 -43
  74. lionagi-0.0.306.dist-info/RECORD +0 -106
  75. /lionagi/core/{flow/direct → direct}/sentiment.py +0 -0
  76. {lionagi-0.0.306.dist-info → lionagi-0.0.308.dist-info}/LICENSE +0 -0
  77. {lionagi-0.0.306.dist-info → lionagi-0.0.308.dist-info}/WHEEL +0 -0
  78. {lionagi-0.0.306.dist-info → lionagi-0.0.308.dist-info}/top_level.txt +0 -0
@@ -10,17 +10,17 @@ def to_llama_index_node(lion_node, node_type: Any = None, **kwargs: Any) -> Any:
10
10
  the expected Llama Index node schema, and then creates a Llama Index node object of the specified type.
11
11
 
12
12
  Args:
13
- lion_node: The Lion node to convert. Must have a `to_dict` method.
14
- node_type (Any, optional): The type of Llama Index node to create. Can be a string name of a node class
15
- within the Llama Index schema or a class that inherits from `BaseNode`. Defaults to 'TextNode'.
16
- **kwargs: Additional keyword arguments to be included in the Llama Index node's initialization.
13
+ lion_node: The Lion node to convert. Must have a `to_dict` method.
14
+ node_type (Any, optional): The type of Llama Index node to create. Can be a string name of a node class
15
+ within the Llama Index schema or a class that inherits from `BaseNode`. Defaults to 'TextNode'.
16
+ **kwargs: Additional keyword arguments to be included in the Llama Index node's initialization.
17
17
 
18
18
  Returns:
19
- Any: A new instance of the specified Llama Index node type populated with data from the Lion node.
19
+ Any: A new instance of the specified Llama Index node type populated with data from the Lion node.
20
20
 
21
21
  Raises:
22
- TypeError: If `node_type` is neither a string nor a subclass of `BaseNode`.
23
- AttributeError: If an error occurs due to an invalid node type or during the creation of the node object.
22
+ TypeError: If `node_type` is neither a string nor a subclass of `BaseNode`.
23
+ AttributeError: If an error occurs due to an invalid node type or during the creation of the node object.
24
24
  """
25
25
 
26
26
  SysUtil.check_import("llama_index", pip_name="llama-index")
@@ -56,7 +56,6 @@ openrouter_finetune_schema = {
56
56
  "config": openrouter_finetune_llmconfig,
57
57
  }
58
58
 
59
-
60
59
  openrouter_schema = {
61
60
  "chat/completions": openrouter_chat_schema,
62
61
  "finetune": openrouter_finetune_schema,
@@ -8,19 +8,19 @@ class OpenAIService(BaseService):
8
8
  A service to interact with OpenAI's API endpoints.
9
9
 
10
10
  Attributes:
11
- base_url (str): The base URL for the OpenAI API.
12
- available_endpoints (list): A list of available API endpoints.
13
- schema (dict): The schema configuration for the API.
14
- key_scheme (str): The environment variable name for OpenAI API key.
15
- token_encoding_name (str): The default token encoding scheme.
11
+ base_url (str): The base URL for the OpenAI API.
12
+ available_endpoints (list): A list of available API endpoints.
13
+ schema (dict): The schema configuration for the API.
14
+ key_scheme (str): The environment variable name for OpenAI API key.
15
+ token_encoding_name (str): The default token encoding scheme.
16
16
 
17
17
  Examples:
18
- >>> service = OpenAIService(api_key="your_api_key")
19
- >>> asyncio.run(service.serve("Hello, world!","chat/completions"))
20
- (payload, completion)
18
+ >>> service = OpenAIService(api_key="your_api_key")
19
+ >>> asyncio.run(service.serve("Hello, world!","chat/completions"))
20
+ (payload, completion)
21
21
 
22
- >>> service = OpenAIService()
23
- >>> asyncio.run(service.serve("Convert this text to speech.","audio_speech"))
22
+ >>> service = OpenAIService()
23
+ >>> asyncio.run(service.serve("Convert this text to speech.","audio_speech"))
24
24
  """
25
25
 
26
26
  base_url = "https://api.openai.com/v1/"
@@ -57,25 +57,25 @@ class OpenAIService(BaseService):
57
57
  Serves the input using the specified endpoint and method.
58
58
 
59
59
  Args:
60
- input_: The input text to be processed.
61
- endpoint: The API endpoint to use for processing.
62
- method: The HTTP method to use for the request.
63
- **kwargs: Additional keyword arguments to pass to the payload creation.
60
+ input_: The input text to be processed.
61
+ endpoint: The API endpoint to use for processing.
62
+ method: The HTTP method to use for the request.
63
+ **kwargs: Additional keyword arguments to pass to the payload creation.
64
64
 
65
65
  Returns:
66
- A tuple containing the payload and the completion assistant_response from the API.
66
+ A tuple containing the payload and the completion assistant_response from the API.
67
67
 
68
68
  Raises:
69
- ValueError: If the specified endpoint is not supported.
69
+ ValueError: If the specified endpoint is not supported.
70
70
 
71
71
  Examples:
72
- >>> service = OpenAIService(api_key="your_api_key")
73
- >>> asyncio.run(service.serve("Hello, world!","chat/completions"))
74
- (payload, completion)
72
+ >>> service = OpenAIService(api_key="your_api_key")
73
+ >>> asyncio.run(service.serve("Hello, world!","chat/completions"))
74
+ (payload, completion)
75
75
 
76
- >>> service = OpenAIService()
77
- >>> asyncio.run(service.serve("Convert this text to speech.","audio_speech"))
78
- ValueError: 'audio_speech' is currently not supported
76
+ >>> service = OpenAIService()
77
+ >>> asyncio.run(service.serve("Convert this text to speech.","audio_speech"))
78
+ ValueError: 'audio_speech' is currently not supported
79
79
  """
80
80
  if endpoint not in self.active_endpoint:
81
81
  await self.init_endpoint(endpoint)
@@ -89,14 +89,14 @@ class OpenAIService(BaseService):
89
89
  Serves the chat completion request with the given messages.
90
90
 
91
91
  Args:
92
- messages: The messages to be included in the chat completion.
93
- **kwargs: Additional keyword arguments for payload creation.
92
+ messages: The messages to be included in the chat completion.
93
+ **kwargs: Additional keyword arguments for payload creation.
94
94
 
95
95
  Returns:
96
- A tuple containing the payload and the completion assistant_response from the API.
96
+ A tuple containing the payload and the completion assistant_response from the API.
97
97
 
98
98
  Raises:
99
- Exception: If the API call fails.
99
+ Exception: If the API call fails.
100
100
  """
101
101
  if "chat/completions" not in self.active_endpoint:
102
102
  await self.init_endpoint("chat/completions")
@@ -6,15 +6,15 @@ class Services:
6
6
  A provider to interact with OpenAI's API endpoints.
7
7
 
8
8
  Attributes:
9
- api_key (Optional[str]): The API key used for authentication.
10
- schema (Dict[str, Any]): The schema defining the provider's endpoints.
11
- status_tracker (StatusTracker): The object tracking the status of API calls.
12
- endpoints (Dict[str, EndPoint]): A dictionary of endpoint objects.
13
- base_url (str): The base URL for the OpenAI API.
14
- available_endpoints (list): A list of available API endpoints, including
15
- 'chat/completions'
16
- key_scheme (str): The environment variable name for API key.
17
- token_encoding_name (str): The default token encoding scheme.
9
+ api_key (Optional[str]): The API key used for authentication.
10
+ schema (Dict[str, Any]): The schema defining the provider's endpoints.
11
+ status_tracker (StatusTracker): The object tracking the status of API calls.
12
+ endpoints (Dict[str, EndPoint]): A dictionary of endpoint objects.
13
+ base_url (str): The base URL for the OpenAI API.
14
+ available_endpoints (list): A list of available API endpoints, including
15
+ 'chat/completions'
16
+ key_scheme (str): The environment variable name for API key.
17
+ token_encoding_name (str): The default token encoding scheme.
18
18
  """
19
19
 
20
20
  from lionagi.integrations.provider.oai import OpenAIService
@@ -27,15 +27,15 @@ class Services:
27
27
  A provider to interact with OpenRouter's API endpoints.
28
28
 
29
29
  Attributes:
30
- api_key (Optional[str]): The API key used for authentication.
31
- schema (Dict[str, Any]): The schema defining the provider's endpoints.
32
- status_tracker (StatusTracker): The object tracking the status of API calls.
33
- endpoints (Dict[str, EndPoint]): A dictionary of endpoint objects.
34
- base_url (str): The base URL for the OpenAI API.
35
- available_endpoints (list): A list of available API endpoints, including
36
- 'chat/completions'
37
- key_scheme (str): The environment variable name for API key.
38
- token_encoding_name (str): The default token encoding scheme.
30
+ api_key (Optional[str]): The API key used for authentication.
31
+ schema (Dict[str, Any]): The schema defining the provider's endpoints.
32
+ status_tracker (StatusTracker): The object tracking the status of API calls.
33
+ endpoints (Dict[str, EndPoint]): A dictionary of endpoint objects.
34
+ base_url (str): The base URL for the OpenAI API.
35
+ available_endpoints (list): A list of available API endpoints, including
36
+ 'chat/completions'
37
+ key_scheme (str): The environment variable name for API key.
38
+ token_encoding_name (str): The default token encoding scheme.
39
39
  """
40
40
 
41
41
  from lionagi.integrations.provider.openrouter import OpenRouterService
@@ -48,24 +48,24 @@ class Services:
48
48
  A provider to interact with Transformers' pipeline
49
49
 
50
50
  Attributes:
51
- task (str): The specific task to be performed by the transformer model.
52
- Currently, only 'conversational' tasks are supported.
53
- model (Union[str, Any]): Identifier for the transformer model to be used. This
54
- can be a model name or a path to a model.
55
- config (Union[str, Dict, Any]): Configuration for the transformer model. Can
56
- include tokenizer information among others.
57
- pipe (pipeline): The loaded transformer pipeline for the specified task, model,
58
- and configuration.
51
+ task (str): The specific task to be performed by the transformer model.
52
+ Currently, only 'conversational' tasks are supported.
53
+ model (Union[str, Any]): Identifier for the transformer model to be used. This
54
+ can be a model name or a path to a model.
55
+ config (Union[str, Dict, Any]): Configuration for the transformer model. Can
56
+ include tokenizer information among others.
57
+ pipe (pipeline): The loaded transformer pipeline for the specified task, model,
58
+ and configuration.
59
59
 
60
60
  Warnings:
61
- - Ensure the selected model is suitable for conversational tasks to avoid
62
- unexpected behavior.
63
- - As this provider heavily relies on external libraries (Hugging Face's
64
- Transformers), ensure they are installed and updated to compatible versions.
61
+ - Ensure the selected model is suitable for conversational tasks to avoid
62
+ unexpected behavior.
63
+ - As this provider heavily relies on external libraries (Hugging Face's
64
+ Transformers), ensure they are installed and updated to compatible versions.
65
65
 
66
66
  Dependencies:
67
- - Requires the `transformers` library by Hugging Face and `asyncio` for
68
- asynchronous operations.
67
+ - Requires the `transformers` library by Hugging Face and `asyncio` for
68
+ asynchronous operations.
69
69
  """
70
70
 
71
71
  from lionagi.integrations.provider.transformers import TransformersService
@@ -99,8 +99,8 @@ class Services:
99
99
  A provider to interact with Ollama
100
100
 
101
101
  Attributes:
102
- model (str): name of the model to use
103
- kwargs (Optional[Any]): additional kwargs for calling the model
102
+ model (str): name of the model to use
103
+ kwargs (Optional[Any]): additional kwargs for calling the model
104
104
  """
105
105
 
106
106
  from lionagi.integrations.provider.ollama import OllamaService
@@ -113,8 +113,8 @@ class Services:
113
113
  A provider to interact with Litellm
114
114
 
115
115
  Attributes:
116
- model (str): name of the model to use
117
- kwargs (Optional[Any]): additional kwargs for calling the model
116
+ model (str): name of the model to use
117
+ kwargs (Optional[Any]): additional kwargs for calling the model
118
118
  """
119
119
 
120
120
  from .litellm import LiteLLMService
@@ -127,8 +127,8 @@ class Services:
127
127
  A provider to interact with MlX
128
128
 
129
129
  Attributes:
130
- model (str): name of the model to use
131
- kwargs (Optional[Any]): additional kwargs for calling the model
130
+ model (str): name of the model to use
131
+ kwargs (Optional[Any]): additional kwargs for calling the model
132
132
  """
133
133
 
134
134
  from lionagi.integrations.provider.mlx_service import MlXService
lionagi/libs/__init__.py CHANGED
@@ -1 +1,34 @@
1
- from . import *
1
+ from lionagi.libs.sys_util import SysUtil
2
+ from lionagi.libs.ln_async import AsyncUtil
3
+
4
+ import lionagi.libs.ln_convert as convert
5
+ import lionagi.libs.ln_dataframe as dataframe
6
+ import lionagi.libs.ln_func_call as func_call
7
+ from lionagi.libs.ln_func_call import CallDecorator
8
+ import lionagi.libs.ln_nested as nested
9
+ from lionagi.libs.ln_parse import ParseUtil, StringMatch
10
+
11
+ from lionagi.libs.ln_api import (
12
+ APIUtil,
13
+ SimpleRateLimiter,
14
+ StatusTracker,
15
+ BaseService,
16
+ PayloadPackage,
17
+ )
18
+
19
+ __all__ = [
20
+ "SysUtil",
21
+ "convert",
22
+ "func_call",
23
+ "dataframe",
24
+ "nested",
25
+ "AsyncUtil",
26
+ "ParseUtil",
27
+ "StringMatch",
28
+ "APIUtil",
29
+ "BaseService",
30
+ "PayloadPackage",
31
+ "StatusTracker",
32
+ "SimpleRateLimiter",
33
+ "CallDecorator",
34
+ ]