lionagi 0.0.313__tar.gz → 0.0.315__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. {lionagi-0.0.313/lionagi.egg-info → lionagi-0.0.315}/PKG-INFO +15 -19
  2. {lionagi-0.0.313 → lionagi-0.0.315}/README.md +14 -18
  3. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/__init__.py +3 -0
  4. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/direct/__init__.py +2 -1
  5. lionagi-0.0.315/lionagi/core/direct/cot.py +1 -0
  6. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/direct/predict.py +3 -2
  7. lionagi-0.0.315/lionagi/core/direct/react.py +167 -0
  8. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/direct/score.py +2 -1
  9. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/direct/select.py +2 -1
  10. lionagi-0.0.315/lionagi/core/direct/sentiment.py +1 -0
  11. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/messages/schema.py +1 -1
  12. lionagi-0.0.315/lionagi/core/prompt/action_template.py +26 -0
  13. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/prompt/field_validator.py +40 -1
  14. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/prompt/prompt_template.py +36 -40
  15. lionagi-0.0.315/lionagi/core/prompt/scored_template.py +13 -0
  16. lionagi-0.0.315/lionagi/core/tool/manual.py +1 -0
  17. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/tool/tool_manager.py +3 -1
  18. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/bridge/llamaindex_/node_parser.py +6 -9
  19. lionagi-0.0.315/lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +1 -0
  20. lionagi-0.0.315/lionagi/integrations/chunker/chunk.py +175 -0
  21. lionagi-0.0.315/lionagi/integrations/loader/load.py +152 -0
  22. lionagi-0.0.315/lionagi/integrations/loader/load_util.py +266 -0
  23. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/provider/ollama.py +1 -1
  24. lionagi-0.0.315/lionagi/tests/test_libs/test_async.py +0 -0
  25. lionagi-0.0.315/lionagi/version.py +1 -0
  26. {lionagi-0.0.313 → lionagi-0.0.315/lionagi.egg-info}/PKG-INFO +15 -19
  27. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi.egg-info/SOURCES.txt +11 -1
  28. lionagi-0.0.313/lionagi/integrations/bridge/pydantic_/base_model.py +0 -7
  29. lionagi-0.0.313/lionagi/version.py +0 -1
  30. {lionagi-0.0.313 → lionagi-0.0.315}/LICENSE +0 -0
  31. {lionagi-0.0.313 → lionagi-0.0.315}/README.rst +0 -0
  32. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/__init__.py +0 -0
  33. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/agent/__init__.py +0 -0
  34. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/agent/base_agent.py +0 -0
  35. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/branch/__init__.py +0 -0
  36. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/branch/base/__init__.py +0 -0
  37. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/branch/base_branch.py +0 -0
  38. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/branch/branch.py +0 -0
  39. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/branch/branch_flow_mixin.py +0 -0
  40. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/branch/executable_branch.py +0 -0
  41. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/branch/util.py +0 -0
  42. /lionagi-0.0.313/lionagi/core/flow/__init__.py → /lionagi-0.0.315/lionagi/core/direct/plan.py +0 -0
  43. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/direct/utils.py +0 -0
  44. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/direct/vote.py +0 -0
  45. {lionagi-0.0.313/lionagi/core/flow/base → lionagi-0.0.315/lionagi/core/flow}/__init__.py +0 -0
  46. {lionagi-0.0.313/lionagi/core/prompt → lionagi-0.0.315/lionagi/core/flow/base}/__init__.py +0 -0
  47. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/flow/base/baseflow.py +0 -0
  48. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/flow/monoflow/ReAct.py +0 -0
  49. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/flow/monoflow/__init__.py +0 -0
  50. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/flow/monoflow/chat.py +0 -0
  51. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/flow/monoflow/chat_mixin.py +0 -0
  52. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/flow/monoflow/followup.py +0 -0
  53. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/flow/polyflow/__init__.py +0 -0
  54. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/flow/polyflow/chat.py +0 -0
  55. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/mail/__init__.py +0 -0
  56. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/mail/mail_manager.py +0 -0
  57. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/mail/schema.py +0 -0
  58. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/messages/__init__.py +0 -0
  59. {lionagi-0.0.313/lionagi/integrations/bridge/langchain_ → lionagi-0.0.315/lionagi/core/prompt}/__init__.py +0 -0
  60. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/schema/__init__.py +0 -0
  61. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/schema/action_node.py +0 -0
  62. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/schema/base_mixin.py +0 -0
  63. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/schema/base_node.py +0 -0
  64. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/schema/condition.py +0 -0
  65. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/schema/data_logger.py +0 -0
  66. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/schema/data_node.py +0 -0
  67. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/schema/prompt_template.py +0 -0
  68. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/schema/structure.py +0 -0
  69. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/session/__init__.py +0 -0
  70. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/session/session.py +0 -0
  71. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/core/tool/__init__.py +0 -0
  72. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/__init__.py +0 -0
  73. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/bridge/__init__.py +0 -0
  74. {lionagi-0.0.313/lionagi/integrations/bridge/llamaindex_ → lionagi-0.0.315/lionagi/integrations/bridge/langchain_}/__init__.py +0 -0
  75. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/bridge/langchain_/documents.py +0 -0
  76. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/bridge/langchain_/langchain_bridge.py +0 -0
  77. {lionagi-0.0.313/lionagi/integrations/bridge/pydantic_ → lionagi-0.0.315/lionagi/integrations/bridge/llamaindex_}/__init__.py +0 -0
  78. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/bridge/llamaindex_/index.py +0 -0
  79. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +0 -0
  80. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/bridge/llamaindex_/reader.py +0 -0
  81. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/bridge/llamaindex_/textnode.py +0 -0
  82. {lionagi-0.0.313/lionagi/tests → lionagi-0.0.315/lionagi/integrations/bridge/pydantic_}/__init__.py +0 -0
  83. {lionagi-0.0.313/lionagi/tests/test_core → lionagi-0.0.315/lionagi/integrations/chunker}/__init__.py +0 -0
  84. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/config/__init__.py +0 -0
  85. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/config/mlx_configs.py +0 -0
  86. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/config/oai_configs.py +0 -0
  87. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/config/ollama_configs.py +0 -0
  88. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/config/openrouter_configs.py +0 -0
  89. {lionagi-0.0.313/lionagi/tests/test_integrations → lionagi-0.0.315/lionagi/integrations/loader}/__init__.py +0 -0
  90. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/provider/__init__.py +0 -0
  91. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/provider/litellm.py +0 -0
  92. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/provider/mistralai.py +0 -0
  93. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/provider/mlx_service.py +0 -0
  94. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/provider/oai.py +0 -0
  95. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/provider/openrouter.py +0 -0
  96. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/provider/services.py +0 -0
  97. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/integrations/provider/transformers.py +0 -0
  98. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/libs/__init__.py +0 -0
  99. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/libs/ln_api.py +0 -0
  100. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/libs/ln_async.py +0 -0
  101. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/libs/ln_convert.py +0 -0
  102. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/libs/ln_dataframe.py +0 -0
  103. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/libs/ln_func_call.py +0 -0
  104. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/libs/ln_nested.py +0 -0
  105. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/libs/ln_parse.py +0 -0
  106. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/libs/sys_util.py +0 -0
  107. {lionagi-0.0.313/lionagi/tests/test_libs → lionagi-0.0.315/lionagi/tests}/__init__.py +0 -0
  108. /lionagi-0.0.313/lionagi/core/tool/manual.py → /lionagi-0.0.315/lionagi/tests/test_core/__init__.py +0 -0
  109. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_core/test_base_branch.py +0 -0
  110. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_core/test_branch.py +0 -0
  111. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_core/test_chat_flow.py +0 -0
  112. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_core/test_mail_manager.py +0 -0
  113. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_core/test_prompts.py +0 -0
  114. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_core/test_session.py +0 -0
  115. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_core/test_session_base_util.py +0 -0
  116. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_core/test_tool_manager.py +0 -0
  117. /lionagi-0.0.313/lionagi/integrations/bridge/pydantic_/pydantic_bridge.py → /lionagi-0.0.315/lionagi/tests/test_integrations/__init__.py +0 -0
  118. /lionagi-0.0.313/lionagi/tests/test_libs/test_async.py → /lionagi-0.0.315/lionagi/tests/test_libs/__init__.py +0 -0
  119. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_libs/test_api.py +0 -0
  120. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_libs/test_convert.py +0 -0
  121. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_libs/test_func_call.py +0 -0
  122. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_libs/test_nested.py +0 -0
  123. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_libs/test_parse.py +0 -0
  124. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi/tests/test_libs/test_sys_util.py +0 -0
  125. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi.egg-info/dependency_links.txt +0 -0
  126. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi.egg-info/requires.txt +0 -0
  127. {lionagi-0.0.313 → lionagi-0.0.315}/lionagi.egg-info/top_level.txt +0 -0
  128. {lionagi-0.0.313 → lionagi-0.0.315}/pyproject.toml +0 -0
  129. {lionagi-0.0.313 → lionagi-0.0.315}/setup.cfg +0 -0
  130. {lionagi-0.0.313 → lionagi-0.0.315}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lionagi
3
- Version: 0.0.313
3
+ Version: 0.0.315
4
4
  Summary: Towards automated general intelligence.
5
5
  Author: HaiyangLi
6
6
  Author-email: Haiyang Li <ocean@lionagi.ai>
@@ -43,39 +43,35 @@ To contribute, you need to make a fork first, and then make pull request from yo
43
43
 
44
44
  # LionAGI
45
45
 
46
-
47
- **LionAGI is undergoing major transformation.**
46
+ **Powerful Intelligent Workflow Automation**
48
47
 
49
48
  It is an intelligent agentic workflow automation framework. It introduces advanced ML models into any existing workflows and data infrastructure.
50
49
 
51
- #### Currently, it can
52
50
 
53
- - generate inferences from almost all models including local
54
- - run most model inferencing in parallel
55
- - produce structured pydantic outputs with flexible usage
51
+ ### Currently, it can
52
+
53
+ - interact with almost any models including local*
54
+ - run interactions in parallel for most models (OpenRouter, OpenAI, Ollama, litellm...)
55
+ - produce structured pydantic outputs with flexible usage\*\*
56
56
  - automate workflow via graph based agents
57
57
  - use advanced prompting techniques, i.e. ReAct (reason-action)
58
58
  - …
59
-
60
- #### It aims to:
61
59
 
62
- - provide a centralized agent-managed framework for ML-powered tools coordination.
60
+ ### It aims to:
61
+
62
+ - provide a centralized agent-managed framework for, "ML-powered tools coordination".
63
+ - The ways of coordination and possible path can occur among nodes is what we also refers to as `workflow` (the concept of workflow is still in design).
63
64
  - such that, people can utilize intelligence to solve their problems in real life.
64
65
  - achieve the goal by dramatically lowering the barrier of entries for creating use-case/domain specific tools.
65
66
 
66
- #### Why?
67
67
 
68
- - To better the human experience for more.
69
-
70
- ---
71
-
72
-
73
- **Powerful Intelligent Workflow Automation**
68
+ All notebooks should run, as of 0.0.313,
74
69
 
75
- LionAGI is an **intelligent agent framework**. Tailored for **big data analysis** in conjunction with advanced **machine learning** tools, designed for data-centric, production-level projects. Lionagi provides a set of robust tools, enabling flexible and rapid design of agentic workflow, for your own data.
70
+ \* if there are models on providers that have not been configured, you can do so by configuring your own AI providers, and endpoints.
76
71
 
72
+ \*\* Structured Input/Output, Graph based agent system, as well as more advanced prompting techniques are undergoing fast interations...
77
73
 
78
- ## Why Automating Workflows?
74
+ ### Why Automating Workflows?
79
75
 
80
76
  Intelligent AI models such as [Large Language Model (LLM)](https://en.wikipedia.org/wiki/Large_language_model), introduced new possibilities of human-computer interaction. LLMs is drawing a lot of attention worldwide due to its “one model fits all”, and incredible performance. One way of using LLM is to use as search engine, however, this usage is complicated by the fact that LLMs [hallucinate](https://arxiv.org/abs/2311.05232).
81
77
 
@@ -12,39 +12,35 @@ To contribute, you need to make a fork first, and then make pull request from yo
12
12
 
13
13
  # LionAGI
14
14
 
15
-
16
- **LionAGI is undergoing major transformation.**
15
+ **Powerful Intelligent Workflow Automation**
17
16
 
18
17
  It is an intelligent agentic workflow automation framework. It introduces advanced ML models into any existing workflows and data infrastructure.
19
18
 
20
- #### Currently, it can
21
19
 
22
- - generate inferences from almost all models including local
23
- - run most model inferencing in parallel
24
- - produce structured pydantic outputs with flexible usage
20
+ ### Currently, it can
21
+
22
+ - interact with almost any models including local*
23
+ - run interactions in parallel for most models (OpenRouter, OpenAI, Ollama, litellm...)
24
+ - produce structured pydantic outputs with flexible usage\*\*
25
25
  - automate workflow via graph based agents
26
26
  - use advanced prompting techniques, i.e. ReAct (reason-action)
27
27
  - …
28
-
29
- #### It aims to:
30
28
 
31
- - provide a centralized agent-managed framework for ML-powered tools coordination.
29
+ ### It aims to:
30
+
31
+ - provide a centralized agent-managed framework for, "ML-powered tools coordination".
32
+ - The ways of coordination and possible path can occur among nodes is what we also refers to as `workflow` (the concept of workflow is still in design).
32
33
  - such that, people can utilize intelligence to solve their problems in real life.
33
34
  - achieve the goal by dramatically lowering the barrier of entries for creating use-case/domain specific tools.
34
35
 
35
- #### Why?
36
36
 
37
- - To better the human experience for more.
38
-
39
- ---
40
-
41
-
42
- **Powerful Intelligent Workflow Automation**
37
+ All notebooks should run, as of 0.0.313,
43
38
 
44
- LionAGI is an **intelligent agent framework**. Tailored for **big data analysis** in conjunction with advanced **machine learning** tools, designed for data-centric, production-level projects. Lionagi provides a set of robust tools, enabling flexible and rapid design of agentic workflow, for your own data.
39
+ \* if there are models on providers that have not been configured, you can do so by configuring your own AI providers, and endpoints.
45
40
 
41
+ \*\* Structured Input/Output, Graph based agent system, as well as more advanced prompting techniques are undergoing fast interations...
46
42
 
47
- ## Why Automating Workflows?
43
+ ### Why Automating Workflows?
48
44
 
49
45
  Intelligent AI models such as [Large Language Model (LLM)](https://en.wikipedia.org/wiki/Large_language_model), introduced new possibilities of human-computer interaction. LLMs is drawing a lot of attention worldwide due to its “one model fits all”, and incredible performance. One way of using LLM is to use as search engine, however, this usage is complicated by the fact that LLMs [hallucinate](https://arxiv.org/abs/2311.05232).
50
46
 
@@ -8,6 +8,9 @@ from dotenv import load_dotenv
8
8
 
9
9
  from .core import direct, Branch, Session, func_to_tool
10
10
  from .integrations.provider.services import Services
11
+ from .integrations.chunker.chunk import chunk
12
+ from .integrations.loader.load import load
13
+
11
14
 
12
15
  logger = logging.getLogger(__name__)
13
16
  logger.setLevel(logging.INFO)
@@ -1,6 +1,7 @@
1
1
  from .predict import predict
2
2
  from .select import select
3
3
  from .score import score
4
+ from .react import react
4
5
  from .vote import vote
5
6
 
6
- __all__ = ["predict", "select", "score", "vote"]
7
+ __all__ = ["predict", "select", "score", "vote", "react"]
@@ -0,0 +1 @@
1
+ # TODO: chain of thoughts
@@ -6,9 +6,10 @@ using a language model. It includes fields for the input sentence, number of sen
6
6
  confidence score, and reason for the prediction.
7
7
  """
8
8
 
9
- from pydantic import Field
10
9
  from lionagi.libs import func_call
11
- from ..prompt.prompt_template import ScoredTemplate
10
+ from lionagi.integrations.bridge.pydantic_.pydantic_bridge import Field
11
+
12
+ from ..prompt.scored_template import ScoredTemplate
12
13
  from ..branch import Branch
13
14
 
14
15
 
@@ -0,0 +1,167 @@
1
+ from lionagi.libs import func_call, convert, AsyncUtil
2
+
3
+ from lionagi.integrations.bridge.pydantic_.pydantic_bridge import Field
4
+ from ..prompt.action_template import ActionedTemplate
5
+ from ..branch import Branch
6
+
7
+
8
+ class ReactTemplate(ActionedTemplate):
9
+ template_name: str = "default_react"
10
+ sentence: str | list | dict = Field(
11
+ default_factory=str,
12
+ description="the given sentence(s) to reason and take actions on",
13
+ )
14
+
15
+ def __init__(
16
+ self,
17
+ sentence=None,
18
+ instruction=None,
19
+ confidence_score=False,
20
+ **kwargs,
21
+ ):
22
+ super().__init__(**kwargs)
23
+
24
+ self.sentence = sentence
25
+ self.task = f"Think step by step. Perform reasoning and prepare actions with given tools only.Instruction: {instruction}. Absolutely DO NOT MAKE UP FUNCTIONS !!!"
26
+
27
+ if confidence_score:
28
+ self.output_fields.append("confidence_score")
29
+
30
+
31
+ async def _react(
32
+ sentence,
33
+ *,
34
+ instruction=None,
35
+ branch=None,
36
+ confidence_score=False,
37
+ retries=2,
38
+ delay=0.5,
39
+ backoff_factor=2,
40
+ default_value=None,
41
+ timeout=None,
42
+ branch_name=None,
43
+ system=None,
44
+ messages=None,
45
+ service=None,
46
+ sender=None,
47
+ llmconfig=None,
48
+ tools=None,
49
+ datalogger=None,
50
+ persist_path=None,
51
+ tool_manager=None,
52
+ return_branch=False,
53
+ **kwargs,
54
+ ):
55
+
56
+ if "temperature" not in kwargs:
57
+ kwargs["temperature"] = 0.1
58
+
59
+ instruction = instruction or ""
60
+
61
+ branch = branch or Branch(
62
+ name=branch_name,
63
+ system=system,
64
+ messages=messages,
65
+ service=service,
66
+ sender=sender,
67
+ llmconfig=llmconfig,
68
+ tools=tools,
69
+ datalogger=datalogger,
70
+ persist_path=persist_path,
71
+ tool_manager=tool_manager,
72
+ )
73
+
74
+ _template = ReactTemplate(
75
+ sentence=sentence,
76
+ instruction=instruction,
77
+ confidence_score=confidence_score,
78
+ )
79
+
80
+ await func_call.rcall(
81
+ branch.chat,
82
+ prompt_template=_template,
83
+ retries=retries,
84
+ delay=delay,
85
+ backoff_factor=backoff_factor,
86
+ default=default_value,
87
+ timeout=timeout,
88
+ **kwargs,
89
+ )
90
+
91
+ if _template.action_needed:
92
+ actions = _template.actions
93
+ tasks = [branch.tool_manager.invoke(i.values()) for i in actions]
94
+ results = await AsyncUtil.execute_tasks(*tasks)
95
+
96
+ a = []
97
+ for idx, item in enumerate(actions):
98
+ res = {
99
+ "function": item["function"],
100
+ "arguments": item["arguments"],
101
+ "output": results[idx],
102
+ }
103
+ branch.add_message(response=res)
104
+ a.append(res)
105
+
106
+ _template.__setattr__("action_response", a)
107
+
108
+ return (_template, branch) if return_branch else _template
109
+
110
+
111
+ async def react(
112
+ sentence,
113
+ *,
114
+ instruction=None,
115
+ num_instances=1,
116
+ branch=None,
117
+ confidence_score=False,
118
+ retries=2,
119
+ delay=0.5,
120
+ backoff_factor=2,
121
+ default_value=None,
122
+ timeout=None,
123
+ branch_name=None,
124
+ system=None,
125
+ messages=None,
126
+ service=None,
127
+ sender=None,
128
+ llmconfig=None,
129
+ tools=None,
130
+ datalogger=None,
131
+ persist_path=None,
132
+ tool_manager=None,
133
+ return_branch=False,
134
+ **kwargs,
135
+ ):
136
+
137
+ async def _inner(i=0):
138
+ return await _react(
139
+ sentence=sentence,
140
+ instruction=instruction,
141
+ num_instances=num_instances,
142
+ branch=branch,
143
+ confidence_score=confidence_score,
144
+ retries=retries,
145
+ delay=delay,
146
+ backoff_factor=backoff_factor,
147
+ default_value=default_value,
148
+ timeout=timeout,
149
+ branch_name=branch_name,
150
+ system=system,
151
+ messages=messages,
152
+ service=service,
153
+ sender=sender,
154
+ llmconfig=llmconfig,
155
+ tools=tools,
156
+ datalogger=datalogger,
157
+ persist_path=persist_path,
158
+ tool_manager=tool_manager,
159
+ return_branch=return_branch,
160
+ **kwargs,
161
+ )
162
+
163
+ if num_instances == 1:
164
+ return await _inner()
165
+
166
+ elif num_instances > 1:
167
+ return await func_call.alcall(range(num_instances), _inner)
@@ -12,7 +12,7 @@ ScoreTemplate class and a language model.
12
12
  from pydantic import Field
13
13
  import numpy as np
14
14
  from lionagi.libs import func_call, convert
15
- from ..prompt.prompt_template import ScoredTemplate
15
+ from ..prompt.scored_template import ScoredTemplate
16
16
  from ..branch import Branch
17
17
 
18
18
 
@@ -183,6 +183,7 @@ async def _score(
183
183
 
184
184
  async def score(
185
185
  sentence,
186
+ *,
186
187
  num_instances=1,
187
188
  instruction=None,
188
189
  score_range=(1, 10),
@@ -13,7 +13,7 @@ from enum import Enum
13
13
  from pydantic import Field
14
14
 
15
15
  from lionagi.libs import func_call, StringMatch
16
- from ..prompt.prompt_template import ScoredTemplate
16
+ from ..prompt.scored_template import ScoredTemplate
17
17
  from ..branch import Branch
18
18
 
19
19
 
@@ -39,6 +39,7 @@ class SelectTemplate(ScoredTemplate):
39
39
  answer: Enum | str = Field(
40
40
  default_factory=str, description="selection from given choices"
41
41
  )
42
+ choices: list = Field(default_factory=list, description="the given choices")
42
43
 
43
44
  signature: str = "sentence -> answer"
44
45
 
@@ -0,0 +1 @@
1
+ # TODO: sentiment analysis
@@ -173,7 +173,7 @@ class Instruction(BaseMessage):
173
173
 
174
174
  if output_fields:
175
175
  format_ = f"""
176
- Follow the following response format.
176
+ MUST EXACTLY Follow the following response format. NO ADDITIONAL COMMENTS ALLOWED!
177
177
  ```json
178
178
  {output_fields}
179
179
  ```
@@ -0,0 +1,26 @@
1
+ from typing import Any
2
+ from lionagi.integrations.bridge.pydantic_.pydantic_bridge import Field
3
+
4
+ from .scored_template import ScoredTemplate
5
+
6
+
7
+ class ActionRequest: ...
8
+
9
+
10
+ class ActionedTemplate(ScoredTemplate):
11
+
12
+ action_needed: bool | None = Field(
13
+ False, description="true if actions are needed else false"
14
+ )
15
+
16
+ actions: list[dict | ActionRequest | Any] | None = Field(
17
+ default_factory=list,
18
+ description="""provide The list of action(s) to take, each action in {"function": function_name, "arguments": {param1:..., param2:..., ...}}. Leave blank if no further actions are needed, you must use provided parameters for each action, DO NOT MAKE UP KWARG NAME!!!""",
19
+ )
20
+
21
+ answer: str | dict | Any | None = Field(
22
+ default_factory=str,
23
+ description="output answer to the questions asked if further actions are not needed, leave blank if an accurate answer cannot be provided from context during this step",
24
+ )
25
+
26
+ signature: str = "sentence -> reason, action_needed, actions, answer"
@@ -6,7 +6,45 @@ including numeric, boolean, string, and enum. It also provides a dictionary `val
6
6
  maps data types to their corresponding validation functions.
7
7
  """
8
8
 
9
- from lionagi.libs import convert, StringMatch
9
+ from lionagi.libs import convert, StringMatch, ParseUtil
10
+
11
+
12
+ def _has_action_keys(dict_):
13
+ return list(dict_.keys()) >= ["function", "arguments"]
14
+
15
+
16
+ def check_action_field(x, fix_=True, **kwargs):
17
+ if (
18
+ isinstance(x, list)
19
+ and convert.is_same_dtype(x, dict)
20
+ and all(_has_action_keys(y) for y in x)
21
+ ):
22
+ return x
23
+ try:
24
+ x = _fix_action_field(x, fix_)
25
+ return x
26
+ except Exception as e:
27
+ raise ValueError("Invalid action field type.") from e
28
+
29
+
30
+ def _fix_action_field(x, discard_=True):
31
+ corrected = []
32
+ if isinstance(x, str):
33
+ x = ParseUtil.fuzzy_parse_json(x)
34
+
35
+ try:
36
+ x = convert.to_list(x)
37
+
38
+ for i in x:
39
+ i = convert.to_dict(i)
40
+ if _has_action_keys(i):
41
+ corrected.append(i)
42
+ elif not discard_:
43
+ raise ValueError(f"Invalid action field: {i}")
44
+ except Exception as e:
45
+ raise ValueError(f"Invalid action field: {e}") from e
46
+
47
+ return corrected
10
48
 
11
49
 
12
50
  def check_number_field(x, fix_=True, **kwargs):
@@ -236,4 +274,5 @@ validation_funcs = {
236
274
  "bool": check_bool_field,
237
275
  "str": check_str_field,
238
276
  "enum": check_enum_field,
277
+ "action": check_action_field,
239
278
  }
@@ -207,6 +207,10 @@ class PromptTemplate(BaseComponent):
207
207
  setattr(self, k, v_)
208
208
  return True
209
209
 
210
+ if "lionagi.core.prompt.action_template.actionrequest" in str_:
211
+ self.__setattr__(k, validation_funcs["action"](v))
212
+ return True
213
+
210
214
  elif "bool" in str_:
211
215
  self.__setattr__(k, validation_funcs["bool"](v, fix_=fix_, **kwargs))
212
216
  return True
@@ -227,48 +231,50 @@ class PromptTemplate(BaseComponent):
227
231
  if k not in kwargs:
228
232
  kwargs = {k: {}}
229
233
 
230
- try:
231
- if (
232
- self.model_fields[k].json_schema_extra["choices"] is not None
233
- and "choices" in self.model_fields[k].json_schema_extra
234
+ if self._field_has_choices(k):
235
+ self.choices[k] = self.model_fields[k].json_schema_extra["choices"]
236
+ if self._validate_field(
237
+ k, v, choices=self.choices[k], fix_=fix_, **kwargs[k]
234
238
  ):
235
- self.choices[k] = self.model_fields[k].json_schema_extra["choices"]
236
- if self._validate_field(
237
- k, v, choices=self.choices[k], fix_=fix_, **kwargs[k]
238
- ):
239
- continue
240
- else:
241
- raise ValueError(f"{k} has no choices")
242
-
243
- except Exception as e:
244
- if self._validate_field(k, v, fix_=fix_, **kwargs[k]):
245
239
  continue
246
240
  else:
247
- raise ValueError(f"failed to validate field {k}") from e
241
+ raise ValueError(f"{k} has no choices")
242
+
243
+ elif self._validate_field(k, v, fix_=fix_, **kwargs[k]):
244
+ continue
245
+ else:
246
+ raise ValueError(f"failed to validate field {k}")
247
+
248
+ def _field_has_choices(self, k):
249
+ try:
250
+ a = (
251
+ self.model_fields[k].json_schema_extra["choices"] is not None
252
+ and "choices" in self.model_fields[k].json_schema_extra
253
+ )
254
+ return a if isinstance(a, bool) else False
255
+ except Exception:
256
+ return False
248
257
 
249
258
  def _process_response(self, out_, fix_=True):
250
259
  kwargs = self.out_validation_kwargs.copy()
251
260
  for k, v in out_.items():
252
261
  if k not in kwargs:
253
262
  kwargs = {k: {}}
254
- try:
255
- if (
256
- self.model_fields[k].json_schema_extra["choices"] is not None
257
- and "choices" in self.model_fields[k].json_schema_extra
263
+
264
+ if self._field_has_choices(k):
265
+ self.choices[k] = self.model_fields[k].json_schema_extra["choices"]
266
+ if self._validate_field(
267
+ k, v, choices=self.choices[k], fix_=fix_, **kwargs[k]
258
268
  ):
259
- self.choices[k] = self.model_fields[k].json_schema_extra["choices"]
260
- if self._validate_field(
261
- k, v, choices=self.choices[k], fix_=fix_, **kwargs[k]
262
- ):
263
- continue
264
- else:
265
- raise ValueError(f"{k} has no choices")
266
-
267
- except Exception as e:
268
- if self._validate_field(k, v, fix_=fix_, **kwargs[k]):
269
269
  continue
270
270
  else:
271
- raise ValueError(f"failed to validate field {k}") from e
271
+ raise ValueError(f"{k} has no choices")
272
+
273
+ elif self._validate_field(k, v, fix_=fix_, **kwargs[k]):
274
+ continue
275
+
276
+ else:
277
+ raise ValueError(f"failed to validate field {k} with value {v}")
272
278
 
273
279
  @property
274
280
  def in_(self):
@@ -288,16 +294,6 @@ class PromptTemplate(BaseComponent):
288
294
  return self
289
295
 
290
296
 
291
- class ScoredTemplate(PromptTemplate):
292
- confidence_score: float | None = Field(
293
- -1,
294
- description="a numeric score between 0 to 1 formatted in num:0.2f",
295
- )
296
- reason: str | None = Field(
297
- default_factory=str, description="brief reason for the given output"
298
- )
299
-
300
-
301
297
  # class Weather(PromptTemplate):
302
298
  # sunny: bool = Field(True, description="true if the weather is sunny outside else false")
303
299
  # rainy: bool = Field(False, description="true if it is raining outside else false")
@@ -0,0 +1,13 @@
1
+ from lionagi.integrations.bridge.pydantic_.pydantic_bridge import Field
2
+
3
+ from .prompt_template import PromptTemplate
4
+
5
+
6
+ class ScoredTemplate(PromptTemplate):
7
+ confidence_score: float | None = Field(
8
+ -1,
9
+ description="a numeric score between 0 to 1 formatted in num:0.2f",
10
+ )
11
+ reason: str | None = Field(
12
+ default_factory=str, description="brief reason for the given output"
13
+ )
@@ -0,0 +1 @@
1
+ # TODO: tool manual, instruction on how to use the tool for LLM
@@ -38,7 +38,7 @@ class ToolManager:
38
38
  def has_tools(self):
39
39
  return self.registry != {}
40
40
 
41
- def _register_tool(self, tool: Tool) -> None:
41
+ def _register_tool(self, tool: Tool | Callable) -> None:
42
42
  """
43
43
  Registers a tool in the registry. Raises a TypeError if the object is not an instance of Tool.
44
44
 
@@ -48,6 +48,8 @@ class ToolManager:
48
48
  Raises:
49
49
  TypeError: If the provided object is not an instance of Tool.
50
50
  """
51
+ if isinstance(tool, Callable):
52
+ tool = func_to_tool(tool)[0]
51
53
  if not isinstance(tool, Tool):
52
54
  raise TypeError("Please register a Tool object.")
53
55
  name = tool.schema_["function"]["name"]
@@ -29,19 +29,18 @@ def get_llama_index_node_parser(node_parser: Any):
29
29
  import llama_index.core.node_parser
30
30
 
31
31
  if not isinstance(node_parser, str) and not issubclass(node_parser, NodeParser):
32
- raise TypeError(f"node_parser must be a string or NodeParser.")
32
+ raise TypeError("node_parser must be a string or NodeParser.")
33
33
 
34
34
  if isinstance(node_parser, str):
35
35
  if node_parser == "CodeSplitter":
36
36
  SysUtil.check_import("tree_sitter_languages")
37
37
 
38
38
  try:
39
- parser = getattr(llama_index.core.node_parser, node_parser)
40
- return parser
39
+ return getattr(llama_index.core.node_parser, node_parser)
41
40
  except Exception as e:
42
41
  raise AttributeError(
43
42
  f"llama_index_core has no such attribute:" f" {node_parser}, Error: {e}"
44
- )
43
+ ) from e
45
44
 
46
45
  elif isinstance(node_parser, NodeParser):
47
46
  return node_parser
@@ -75,10 +74,8 @@ def llama_index_parse_node(
75
74
  parser = get_llama_index_node_parser(node_parser)
76
75
  try:
77
76
  parser = parser(*parser_args, **parser_kwargs)
78
- except:
77
+ except Exception:
79
78
  parser = parser.from_defaults(*parser_args, **parser_kwargs)
80
- nodes = parser.get_nodes_from_documents(documents)
81
- return nodes
82
-
79
+ return parser.get_nodes_from_documents(documents)
83
80
  except Exception as e:
84
- raise ValueError(f"Failed to parse. Error: {e}")
81
+ raise ValueError(f"Failed to parse. Error: {e}") from e
@@ -0,0 +1 @@
1
+ from pydantic import BaseModel, Field, ValidationError, AliasChoices, field_serializer