lionagi 0.0.306__py3-none-any.whl → 0.0.308__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -4,7 +4,6 @@ import pandas as pd
4
4
 
5
5
  from lionagi.libs import ln_convert as convert
6
6
 
7
-
8
7
  ln_DataFrame = pd.DataFrame
9
8
  ln_Series = pd.Series
10
9
 
@@ -21,13 +20,13 @@ def extend_dataframe(
21
20
  Merges two DataFrames while ensuring no duplicate entries based on a specified unique column.
22
21
 
23
22
  Args:
24
- df1: The primary DataFrame.
25
- df2: The DataFrame to merge with the primary DataFrame.
26
- unique_col: The column name to check for duplicate entries. Defaults to 'node_id'.
27
- **kwargs: Additional keyword arguments for `drop_duplicates`.
23
+ df1: The primary DataFrame.
24
+ df2: The DataFrame to merge with the primary DataFrame.
25
+ unique_col: The column name to check for duplicate entries. Defaults to 'node_id'.
26
+ **kwargs: Additional keyword arguments for `drop_duplicates`.
28
27
 
29
28
  Returns:
30
- A DataFrame combined from df1 and df2 with duplicates removed based on the unique column.
29
+ A DataFrame combined from df1 and df2 with duplicates removed based on the unique column.
31
30
  """
32
31
  try:
33
32
  if len(df2.dropna(how="all")) > 0 and len(df1.dropna(how="all")) > 0:
@@ -40,7 +39,7 @@ def extend_dataframe(
40
39
  raise ValueError("No data to extend")
41
40
 
42
41
  except Exception as e:
43
- raise ValueError(f"Error in extending messages: {e}")
42
+ raise ValueError(f"Error in extending messages: {e}") from e
44
43
 
45
44
 
46
45
  def search_keywords(
@@ -57,16 +56,16 @@ def search_keywords(
57
56
  Filters a DataFrame for rows where a specified column contains given keywords.
58
57
 
59
58
  Args:
60
- df: The DataFrame to search through.
61
- keywords: A keyword or list of keywords to search for.
62
- col: The column to perform the search in. Defaults to "content".
63
- case_sensitive: Whether the search should be case-sensitive. Defaults to False.
64
- reset_index: Whether to reset the DataFrame's index after filtering. Defaults to False.
65
- dropna: Whether to drop rows with NA values before searching. Defaults to False.
59
+ df: The DataFrame to search through.
60
+ keywords: A keyword or list of keywords to search for.
61
+ col: The column to perform the search in. Defaults to "content".
62
+ case_sensitive: Whether the search should be case-sensitive. Defaults to False.
63
+ reset_index: Whether to reset the DataFrame's index after filtering. Defaults to False.
64
+ dropna: Whether to drop rows with NA values before searching. Defaults to False.
66
65
 
67
66
  Returns:
68
- A filtered DataFrame containing only rows where the specified column contains
69
- any of the provided keywords.
67
+ A filtered DataFrame containing only rows where the specified column contains
68
+ any of the provided keywords.
70
69
  """
71
70
 
72
71
  if isinstance(keywords, list):
@@ -99,11 +98,11 @@ def replace_keyword(
99
98
  Replaces occurrences of a specified keyword with a replacement string in a DataFrame column.
100
99
 
101
100
  Args:
102
- df: The DataFrame to modify.
103
- keyword: The keyword to be replaced.
104
- replacement: The string to replace the keyword with.
105
- col: The column in which to perform the replacement.
106
- case_sensitive: If True, performs a case-sensitive replacement. Defaults to False.
101
+ df: The DataFrame to modify.
102
+ keyword: The keyword to be replaced.
103
+ replacement: The string to replace the keyword with.
104
+ col: The column in which to perform the replacement.
105
+ case_sensitive: If True, performs a case-sensitive replacement. Defaults to False.
107
106
  """
108
107
 
109
108
  df_ = df.copy(deep=False) if inplace else df.copy()
@@ -123,11 +122,11 @@ def read_csv(filepath: str, **kwargs) -> pd.DataFrame:
123
122
  Reads a CSV file into a DataFrame with optional additional pandas read_csv parameters.
124
123
 
125
124
  Args:
126
- filepath: The path to the CSV file to read.
127
- **kwargs: Additional keyword arguments to pass to pandas.read_csv function.
125
+ filepath: The path to the CSV file to read.
126
+ **kwargs: Additional keyword arguments to pass to pandas.read_csv function.
128
127
 
129
128
  Returns:
130
- A DataFrame containing the data read from the CSV file.
129
+ A DataFrame containing the data read from the CSV file.
131
130
  """
132
131
  df = pd.read_csv(filepath, **kwargs)
133
132
  return convert.to_df(df)
@@ -143,14 +142,14 @@ def remove_last_n_rows(df: pd.DataFrame, steps: int) -> pd.DataFrame:
143
142
  Removes the last 'n' rows from a DataFrame.
144
143
 
145
144
  Args:
146
- df: The DataFrame from which to remove rows.
147
- steps: The number of rows to remove from the end of the DataFrame.
145
+ df: The DataFrame from which to remove rows.
146
+ steps: The number of rows to remove from the end of the DataFrame.
148
147
 
149
148
  Returns:
150
- A DataFrame with the last 'n' rows removed.
149
+ A DataFrame with the last 'n' rows removed.
151
150
 
152
151
  Raises:
153
- ValueError: If 'steps' is negative or greater than the number of rows in the DataFrame.
152
+ ValueError: If 'steps' is negative or greater than the number of rows in the DataFrame.
154
153
  """
155
154
 
156
155
  if steps < 0 or steps > len(df):
@@ -166,17 +165,17 @@ def update_row(df: pd.DataFrame, row: str | int, column: str | int, value: Any)
166
165
  Updates a row's value for a specified column in a DataFrame.
167
166
 
168
167
  Args:
169
- df: The DataFrame to update.
170
- col: The column whose value is to be updated.
171
- old_value: The current value to search for in the specified column.
172
- new_value: The new value to replace the old value with.
168
+ df: The DataFrame to update.
169
+ col: The column whose value is to be updated.
170
+ old_value: The current value to search for in the specified column.
171
+ new_value: The new value to replace the old value with.
173
172
 
174
173
  Returns:
175
- True if the update was successful, False otherwise.
174
+ True if the update was successful, False otherwise.
176
175
  """
177
176
 
178
177
  try:
179
178
  df.loc[row, column] = value
180
179
  return True
181
- except:
180
+ except Exception:
182
181
  return False