lionagi 0.0.208__py3-none-any.whl → 0.0.210__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. lionagi/__init__.py +4 -6
  2. lionagi/api_service/base_endpoint.py +65 -0
  3. lionagi/api_service/base_rate_limiter.py +121 -0
  4. lionagi/api_service/base_service.py +146 -0
  5. lionagi/api_service/chat_completion.py +6 -0
  6. lionagi/api_service/embeddings.py +6 -0
  7. lionagi/api_service/payload_package.py +47 -0
  8. lionagi/api_service/status_tracker.py +29 -0
  9. lionagi/core/__init__.py +5 -9
  10. lionagi/core/branch.py +1191 -0
  11. lionagi/core/flow.py +423 -0
  12. lionagi/core/{instruction_set/instruction_set.py → instruction_set.py} +3 -3
  13. lionagi/core/session.py +872 -0
  14. lionagi/schema/__init__.py +5 -8
  15. lionagi/schema/base_schema.py +821 -0
  16. lionagi/{_services → services}/base_service.py +4 -4
  17. lionagi/{_services → services}/oai.py +4 -4
  18. lionagi/structures/graph.py +1 -1
  19. lionagi/structures/relationship.py +1 -1
  20. lionagi/structures/structure.py +1 -1
  21. lionagi/tools/tool_manager.py +0 -163
  22. lionagi/tools/tool_util.py +2 -1
  23. lionagi/utils/__init__.py +7 -14
  24. lionagi/utils/api_util.py +63 -2
  25. lionagi/utils/core_utils.py +338 -0
  26. lionagi/utils/sys_util.py +3 -3
  27. lionagi/version.py +1 -1
  28. {lionagi-0.0.208.dist-info → lionagi-0.0.210.dist-info}/METADATA +28 -29
  29. lionagi-0.0.210.dist-info/RECORD +56 -0
  30. lionagi/_services/anthropic.py +0 -79
  31. lionagi/_services/anyscale.py +0 -0
  32. lionagi/_services/azure.py +0 -1
  33. lionagi/_services/bedrock.py +0 -0
  34. lionagi/_services/everlyai.py +0 -0
  35. lionagi/_services/gemini.py +0 -0
  36. lionagi/_services/gpt4all.py +0 -0
  37. lionagi/_services/huggingface.py +0 -0
  38. lionagi/_services/litellm.py +0 -33
  39. lionagi/_services/localai.py +0 -0
  40. lionagi/_services/openllm.py +0 -0
  41. lionagi/_services/openrouter.py +0 -44
  42. lionagi/_services/perplexity.py +0 -0
  43. lionagi/_services/predibase.py +0 -0
  44. lionagi/_services/rungpt.py +0 -0
  45. lionagi/_services/vllm.py +0 -0
  46. lionagi/_services/xinference.py +0 -0
  47. lionagi/agents/planner.py +0 -1
  48. lionagi/agents/prompter.py +0 -1
  49. lionagi/agents/scorer.py +0 -1
  50. lionagi/agents/summarizer.py +0 -1
  51. lionagi/agents/validator.py +0 -1
  52. lionagi/bridge/__init__.py +0 -22
  53. lionagi/bridge/langchain.py +0 -195
  54. lionagi/bridge/llama_index.py +0 -266
  55. lionagi/core/branch/__init__.py +0 -0
  56. lionagi/core/branch/branch.py +0 -841
  57. lionagi/core/branch/cluster.py +0 -1
  58. lionagi/core/branch/conversation.py +0 -787
  59. lionagi/core/core_util.py +0 -0
  60. lionagi/core/flow/__init__.py +0 -0
  61. lionagi/core/flow/flow.py +0 -19
  62. lionagi/core/flow/flow_util.py +0 -62
  63. lionagi/core/instruction_set/__init__.py +0 -0
  64. lionagi/core/messages/__init__.py +0 -0
  65. lionagi/core/sessions/__init__.py +0 -0
  66. lionagi/core/sessions/session.py +0 -504
  67. lionagi/datastores/__init__.py +0 -1
  68. lionagi/datastores/chroma.py +0 -1
  69. lionagi/datastores/deeplake.py +0 -1
  70. lionagi/datastores/elasticsearch.py +0 -1
  71. lionagi/datastores/lantern.py +0 -1
  72. lionagi/datastores/pinecone.py +0 -1
  73. lionagi/datastores/postgres.py +0 -1
  74. lionagi/datastores/qdrant.py +0 -1
  75. lionagi/loaders/__init__.py +0 -18
  76. lionagi/loaders/chunker.py +0 -166
  77. lionagi/loaders/load_util.py +0 -240
  78. lionagi/loaders/reader.py +0 -122
  79. lionagi/models/__init__.py +0 -0
  80. lionagi/models/base_model.py +0 -0
  81. lionagi/models/imodel.py +0 -53
  82. lionagi/schema/async_queue.py +0 -158
  83. lionagi/schema/base_condition.py +0 -1
  84. lionagi/schema/base_node.py +0 -422
  85. lionagi/schema/base_tool.py +0 -44
  86. lionagi/schema/data_logger.py +0 -126
  87. lionagi/schema/data_node.py +0 -88
  88. lionagi/schema/status_tracker.py +0 -37
  89. lionagi/tests/test_utils/test_encrypt_util.py +0 -323
  90. lionagi/utils/encrypt_util.py +0 -283
  91. lionagi/utils/url_util.py +0 -55
  92. lionagi-0.0.208.dist-info/RECORD +0 -106
  93. lionagi/{agents → api_service}/__init__.py +0 -0
  94. lionagi/core/{branch/branch_manager.py → branch_manager.py} +0 -0
  95. lionagi/core/{messages/messages.py → messages.py} +3 -3
  96. /lionagi/{_services → services}/__init__.py +0 -0
  97. /lionagi/{_services → services}/mistralai.py +0 -0
  98. /lionagi/{_services → services}/mlx_service.py +0 -0
  99. /lionagi/{_services → services}/ollama.py +0 -0
  100. /lionagi/{_services → services}/services.py +0 -0
  101. /lionagi/{_services → services}/transformers.py +0 -0
  102. {lionagi-0.0.208.dist-info → lionagi-0.0.210.dist-info}/LICENSE +0 -0
  103. {lionagi-0.0.208.dist-info → lionagi-0.0.210.dist-info}/WHEEL +0 -0
  104. {lionagi-0.0.208.dist-info → lionagi-0.0.210.dist-info}/top_level.txt +0 -0
lionagi/core/core_util.py DELETED
File without changes
File without changes
lionagi/core/flow/flow.py DELETED
@@ -1,19 +0,0 @@
1
- """async def critic_workflow():
2
-
3
- @ cd.max_concurrency(limit=3)
4
- async def run_critic_stage(critic_idx=None, step_num=None, outs=None, max_num_tool_uses=5):
5
-
6
- async def inner_func_():
7
- critic_ = f"critic{critic_idx}"
8
- name_ = li.nget(critics, [critic_, "name"])
9
- tool = li.nget(critics, [critic_, "tool"])
10
- instruction_ = li.nget(critics, [critic_, f"step{step_num}"])
11
-
12
-
13
-
14
- out = await researcher.auto_followup(branch=name_, instruction=instruction_, tools=tool, num=max_num_tool_uses)
15
- add_name_to_messages(name_)
16
- last_response = last_response_row(df=researcher.branches[name_].messages, name_=name_)
17
- outs.append(last_response)
18
-
19
- return out"""
@@ -1,62 +0,0 @@
1
- # from .sessions import Session
2
-
3
- # def get_config(temperature, max_tokens, key_scheme, n):
4
- # f = lambda i:{
5
- # "temperature": temperature[i],
6
- # "max_tokens": max_tokens[i],
7
- # }
8
- # return {
9
- # "key": f"{key_scheme}{n+1}",
10
- # "config": f(n)
11
- # }
12
-
13
- # async def run_workflow(
14
- # session, prompts, temperature, max_tokens,
15
- # key_scheme, num_prompts, context
16
- # ):
17
- # for i in range(num_prompts):
18
- # key_, config_ = get_config(temperature, max_tokens, key_scheme, i)
19
- # if i == 0:
20
- # await session.initiate(instruction=prompts[key_], context=context, **config_)
21
- # else:
22
- # await session.followup(instruction=prompts[key_], **config_)
23
-
24
- # return session
25
-
26
- # async def run_auto_workflow(
27
- # session, prompts, temperature, max_tokens,
28
- # key_scheme, num_prompts, context
29
- # ):
30
- # for i in range(num_prompts):
31
- # key_, config_ = get_config(temperature, max_tokens, key_scheme, i)
32
- # if i == 0:
33
- # await session.initiate(instruction=prompts[key_], context=context, **config_)
34
- # else:
35
- # await session.auto_followup(instruction=prompts[key_], **config_)
36
-
37
- # return session
38
-
39
- # async def run_session(
40
- # prompts, dir, llmconfig, key_scheme, num_prompts,
41
- # temperature, max_tokens, type_=None, tools=None
42
- # ):
43
- # prompts_ = prompts.copy()
44
- # session = Session(
45
- # system=prompts_.pop('system', 'You are a helpful assistant'),
46
- # dir = dir,
47
- # llmconfig = llmconfig
48
- # )
49
- # if tools:
50
- # session.register_tools(tools)
51
- # if type_ is None:
52
- # session = await run_workflow(
53
- # session, prompts_, temperature, max_tokens,
54
- # key_scheme=key_scheme, num_prompts=num_prompts
55
- # )
56
- # elif type_ == 'auto':
57
- # session = await run_auto_workflow(
58
- # session, prompts_, temperature, max_tokens,
59
- # key_scheme=key_scheme, num_prompts=num_prompts
60
- # )
61
-
62
- # return session
File without changes
File without changes
File without changes
@@ -1,504 +0,0 @@
1
- import pandas as pd
2
-
3
- from typing import Any, List, Union, Dict, Optional, Callable, Tuple
4
- from dotenv import load_dotenv
5
-
6
- from lionagi.schema import Tool
7
- from lionagi._services.oai import OpenAIService
8
- from ..messages.messages import System, Instruction
9
- from ..branch.branch import Branch
10
- from ..branch.branch_manager import BranchManager
11
-
12
- load_dotenv()
13
-
14
-
15
- class Session:
16
- """
17
- Manages sessions with conversation branches, tool management, and interaction logging.
18
-
19
- This class orchestrates the handling of different conversation branches, enabling distinct conversational contexts to coexist within a single session. It facilitates the integration with external services for processing chat completions, tool management, and the logging of session activities.
20
-
21
- Attributes:
22
- branches (Dict[str, Branch]): Maps branch names to Branch instances.
23
- default_branch (Branch): The primary branch for the session.
24
- default_branch_name (str): Identifier for the default branch.
25
- llmconfig (Dict[str, Any]): Configurations for language model interactions.
26
- service (OpenAIService): Interface for external service interactions.
27
- """
28
- def __init__(
29
- self,
30
- system: Optional[Union[str, System]] = None,
31
- sender: Optional[str] = None,
32
- llmconfig: Optional[Dict[str, Any]] = None,
33
- service: OpenAIService = None,
34
- branches: Optional[Dict[str, Branch]] = None,
35
- default_branch: Optional[Branch] = None,
36
- default_branch_name: str = 'main',
37
- ):
38
- """
39
- Initializes a session with optional settings for branches, service, and language model configurations.
40
-
41
- Args:
42
- system (Optional[Union[str, System]]): Initial system message or configuration.
43
- sender (Optional[str]): Identifier for the sender of the system message.
44
- llmconfig (Optional[Dict[str, Any]]): Language model configuration settings.
45
- service (OpenAIService): External service for chat completions and other operations.
46
- branches (Optional[Dict[str, Branch]]): Predefined conversation branches.
47
- default_branch (Optional[Branch]): Preselected default branch for the session.
48
- default_branch_name (str): Name for the default branch, defaults to 'main'.
49
- """
50
-
51
- self.branches = branches if isinstance(branches, dict) else {}
52
- if service is None:
53
- service = OpenAIService()
54
-
55
- self._setup_default_branch(
56
- default_branch, default_branch_name, service, llmconfig, system, sender)
57
-
58
- self._verify_default_branch()
59
- self.branch_manager = BranchManager(self.branches)
60
-
61
- def new_branch(
62
- self,
63
- branch_name: str,
64
- dir: Optional[str] = None,
65
- messages: Optional[pd.DataFrame] = None,
66
- tools: Optional[Union[Tool, List[Tool]]] = None,
67
- system: Optional[Union[str, System]] = None,
68
- sender: Optional[str] = None,
69
- service: Optional[OpenAIService] = None,
70
- llmconfig: Optional[Dict] = None,
71
- ) -> None:
72
- """
73
- Creates a new branch within the session.
74
-
75
- Args:
76
- branch_name (str): Name for the new branch.
77
- dir (Optional[str]): Path for storing branch-related logs.
78
- messages (Optional[pd.DataFrame]): Initial set of messages for the branch.
79
- tools (Optional[Union[Tool, List[Tool]]]): Tools to register in the new branch.
80
- system (Optional[Union[str, System]]): System message or configuration for the branch.
81
- sender (Optional[str]): Identifier for the sender of the initial message.
82
- service (Optional[OpenAIService]): Service interface specific to the branch.
83
- llmconfig (Optional[Dict[str, Any]]): Language model configurations for the branch.
84
-
85
- Raises:
86
- ValueError: If the branch name already exists within the session.
87
- """
88
- if branch_name in self.branches.keys():
89
- raise ValueError(f'Invalid new branch name {branch_name}. Already existed.')
90
- new_ = Branch(name=branch_name, dir=dir, messages=messages, service=service, llmconfig=llmconfig)
91
- if system:
92
- new_.add_message(system=system, sender=sender)
93
- if tools:
94
- new_.register_tools(tools=tools)
95
- self.branches[branch_name] = new_
96
-
97
- self.branch_manager.sources[branch_name] = new_
98
- self.branch_manager.requests[branch_name] = {}
99
-
100
- def get_branch(
101
- self,
102
- branch: Optional[Union[Branch, str]] = None,
103
- get_name: bool = False
104
- ) -> Union[Branch, Tuple[Branch, str]]:
105
- """
106
- Retrieves a branch from the session by name or as a Branch object.
107
-
108
- If no branch is specified, returns the default branch. Optionally, can also return the branch's name.
109
-
110
- Args:
111
- branch (Optional[Union[Branch, str]]): The branch name or Branch object to retrieve. Defaults to None, which refers to the default branch.
112
- get_name (bool): If True, also returns the name of the branch alongside the Branch object.
113
-
114
- Returns:
115
- Union[Branch, Tuple[Branch, str]]: The requested Branch object, or a tuple of the Branch object and its name if `get_name` is True.
116
-
117
- Raises:
118
- ValueError: If the specified branch does not exist within the session.
119
- """
120
- if isinstance(branch, str):
121
- if branch not in self.branches.keys():
122
- raise ValueError(f'Invalid branch name {branch}. Not exist.')
123
- else:
124
- if get_name:
125
- return self.branches[branch], branch
126
- return self.branches[branch]
127
-
128
- elif isinstance(branch, Branch) and branch in self.branches.values():
129
- if get_name:
130
- return branch, [key for key, value in self.branches.items() if value == branch][0]
131
- return branch
132
-
133
- elif branch is None:
134
- if get_name:
135
- return self.default_branch, self.default_branch_name
136
- return self.default_branch
137
-
138
- else:
139
- raise ValueError(f'Invalid branch input {branch}.')
140
-
141
- def change_default(self, branch: Union[str, Branch]) -> None:
142
- """
143
- Changes the default branch of the session.
144
-
145
- Args:
146
- branch (Union[str, Branch]): The branch name or Branch object to set as the new default branch.
147
- """
148
- branch_, name_ = self.get_branch(branch, get_name=True)
149
- self.default_branch = branch_
150
- self.default_branch_name = name_
151
-
152
- def delete_branch(self, branch: Union[Branch, str], verbose: bool = True) -> bool:
153
- """
154
- Delete a branch from the session.
155
-
156
- Args:
157
- branch (Union[Branch, str]): The branch object or its name to be deleted.
158
- verbose (bool, optional): If True, prints a confirmation message.
159
-
160
- Returns:
161
- bool: True if the branch is successfully deleted, False otherwise.
162
-
163
- Raises:
164
- ValueError: If trying to delete the current default branch.
165
- """
166
- _, branch_name = self.get_branch(branch, get_name=True)
167
-
168
- if branch_name == self.default_branch_name:
169
- raise ValueError(
170
- f'{branch_name} is the current default branch, please switch to another branch before delete it.'
171
- )
172
- else:
173
- self.branches.pop(branch_name)
174
- # self.branch_manager.sources.pop(branch_name)
175
- self.branch_manager.requests.pop(branch_name)
176
- if verbose:
177
- print(f'Branch {branch_name} is deleted.')
178
- return True
179
-
180
- def merge_branch(
181
- self,
182
- from_: Union[str, Branch],
183
- to_: Union[str, Branch],
184
- update: bool = True,
185
- del_: bool = False
186
- ) -> None:
187
- """
188
- Merge one branch into another within the session.
189
-
190
- Args:
191
- from_ (Union[str, Branch]): The branch or its name to merge from.
192
- to_ (Union[str, Branch]): The branch or its name to merge into.
193
- update (bool, optional): If True, updates the target branch's system message to be same as `from_`.
194
- del_ (bool, optional): If True, deletes the 'from' branch after merging.
195
-
196
- Raises:
197
- ValueError: If the branch does not exist in the session.
198
- """
199
- from_ = self.get_branch(branch=from_)
200
- to_, to_name = self.get_branch(branch=to_, get_name=True)
201
- to_.merge_branch(from_, update=update)
202
-
203
- if del_:
204
- if from_ == self.default_branch:
205
- self.default_branch_name = to_name
206
- self.default_branch = to_
207
- self.delete_branch(from_, verbose=False)
208
-
209
- async def chat(
210
- self,
211
- instruction: Union[Instruction, str],
212
- to_: Optional[Union[Branch, str]] = None,
213
- system: Optional[Union[System, str, Dict]] = None,
214
- context: Optional[Any] = None,
215
- out: bool = True,
216
- sender: Optional[str] = None,
217
- invoke: bool = True,
218
- tools: Union[bool, Tool, List[Tool], str, List[str]] = False,
219
- fallback: Optional[Callable] = None,
220
- fallback_kwargs: Dict = {},
221
- **kwargs
222
- ) -> None:
223
- """
224
- Initiate a chat with the specified branch using an instruction.
225
-
226
- Args:
227
- instruction (Union[Instruction, str]): The instruction or message to send.
228
- to_ (Optional[Union[Branch, str]], optional): The target branch or its name. Default is the main branch.
229
- system (Optional[Union[System, str, Dict]], optional): System message or data to use.
230
- context (Optional[Any], optional): Additional context for the chat.
231
- out (bool, optional): If True, sends the output message.
232
- sender (Optional[str], optional): The sender's name.
233
- invoke (bool, optional): If True, invokes tool processing.
234
- tools (Union[bool, Tool, List[Tool], str, List[str]], optional): Tools to be used or not used.
235
- fallback (Optional[Callable], optional): Fallback function to call in case of an exception.
236
- fallback_kwargs (Dict, optional): Keyword arguments for the fallback function.
237
- **kwargs: Additional keyword arguments.
238
-
239
- Raises:
240
- Exception: If an exception occurs in the chat process and no fallback is provided.
241
- """
242
- branch_ = self.get_branch(to_)
243
- if fallback:
244
- try:
245
- return await branch_.chat(
246
- instruction=instruction, system=system, context=context,
247
- out=out, sender=sender, invoke=invoke, tools=tools, **kwargs
248
- )
249
- except:
250
- return fallback(**fallback_kwargs)
251
-
252
- return await branch_.chat(
253
- instruction=instruction, system=system, context=context,
254
- out=out, sender=sender, invoke=invoke, tools=tools, **kwargs)
255
-
256
- async def ReAct(
257
- self,
258
- instruction: Union[Instruction, str],
259
- context = None,
260
- sender = None,
261
- to_ = None,
262
- system = None,
263
- tools = None,
264
- num_rounds: int = 1,
265
- fallback: Optional[Callable] = None,
266
- fallback_kwargs: Optional[Dict] = None,
267
- out=True,
268
- **kwargs
269
- ):
270
- """
271
- Performs a sequence of reasoning and action steps in a specified or default branch.
272
-
273
- Args:
274
- instruction (Union[Instruction, str]): Instruction to initiate the ReAct process.
275
- context: Additional context for reasoning and action. Defaults to None.
276
- sender: Identifier for the sender. Defaults to None.
277
- to_: Target branch name or object for ReAct. Defaults to the default branch.
278
- system: System message or configuration. Defaults to None.
279
- tools: Tools to be used for actions. Defaults to None.
280
- num_rounds (int): Number of reasoning-action cycles. Defaults to 1.
281
- fallback (Optional[Callable]): Fallback function in case of an error. Defaults to None.
282
- fallback_kwargs (Optional[Dict]): Arguments for the fallback function. Defaults to None.
283
- out (bool): If True, outputs the result of the ReAct process. Defaults to True.
284
- **kwargs: Arbitrary keyword arguments for additional customization.
285
-
286
- Returns:
287
- The outcome of the ReAct process, depending on the specified branch and instructions.
288
- """
289
- branch = self.get_branch(to_)
290
- return await branch.ReAct(
291
- instruction=instruction, context=context, sender=sender, system=system, tools=tools,
292
- num_rounds=num_rounds, fallback=fallback, fallback_kwargs=fallback_kwargs,
293
- out=out, **kwargs
294
- )
295
-
296
- async def auto_followup(
297
- self,
298
- instruction: Union[Instruction, str],
299
- to_: Optional[Union[Branch, str]] = None,
300
- num: int = 3,
301
- tools: Union[bool, Tool, List[Tool], str, List[str], List[Dict]] = False,
302
- fallback: Optional[Callable] = None,
303
- fallback_kwargs: Dict = {},
304
- **kwargs
305
- ) -> None:
306
- """
307
- Automatically follow up on a chat conversation within a branch with multiple messages.
308
-
309
- Args:
310
- instruction (Union[Instruction, str]): The initial instruction or message to send.
311
- to_ (Optional[Union[Branch, str]], optional): The target branch or its name. Default is the main branch.
312
- num (int, optional): The number of follow-up messages to send.
313
- tools (Union[bool, Tool, List[Tool], str, List[str], List[Dict]], optional): Tools to be used or not used.
314
- fallback (Optional[Callable], optional): Fallback function to call in case of an exception.
315
- fallback_kwargs (Dict, optional): Keyword arguments for the fallback function.
316
- **kwargs: Additional keyword arguments.
317
-
318
- Raises:
319
- Exception: If an exception occurs in the auto-followup process and no fallback is provided.
320
- """
321
-
322
- branch_ = self.get_branch(to_)
323
- return await branch_.auto_followup(
324
- instruction=instruction, num=num, tools=tools, fallback=fallback, fallback_kwargs=fallback_kwargs, **kwargs
325
- )
326
-
327
- def change_first_system_message(self, system: Union[System, str]) -> None:
328
- """
329
- Change the system message of the current default branch.
330
-
331
- Args:
332
- system (Union[System, str]): The new system message or a System object.
333
- """
334
- self.default_branch.change_first_system_message(system)
335
-
336
- def collect(self, from_: Union[str, Branch, List[str], List[Branch]] = None):
337
- """
338
- Collect requests from specified branches or all branches if none specified.
339
-
340
- Args:
341
- from_ (Union[str, Branch, List[str], List[Branch]], optional): The source branch(es) from which to collect requests.
342
- If None, data is collected from all branches. Can be a single branch or a list of branches.
343
- """
344
- if from_ is None:
345
- for branch in self.branches.keys():
346
- self.branch_manager.collect(branch)
347
- else:
348
- if not isinstance(from_, list):
349
- from_ = [from_]
350
- for branch in from_:
351
- if isinstance(branch, Branch):
352
- branch = branch.name
353
- if isinstance(branch, str):
354
- self.branch_manager.collect(branch)
355
-
356
- def send(self, to_: Union[str, Branch, List[str], List[Branch]] = None):
357
- """
358
- Collect requests from specified branches or all branches if none specified.
359
-
360
- Args:
361
- to_ (Union[str, Branch, List[str], List[Branch]], optional): The target branch(es) to which to send requests.
362
- If None, requests are sent to all branches. Can be a single branch or a list of branches.
363
- """
364
- if to_ is None:
365
- for branch in self.branches.keys():
366
- self.branch_manager.send(branch)
367
- else:
368
- if not isinstance(to_, list):
369
- to_ = [to_]
370
- for branch in to_:
371
- if isinstance(branch, Branch):
372
- branch = branch.name
373
- if isinstance(branch, str):
374
- self.branch_manager.send(branch)
375
-
376
- def collect_send_all(self, receive_all=False):
377
- """
378
- Collect and send requests across all branches, with an option to invoke receive_all on each branch.
379
-
380
- Args:
381
- receive_all (bool, optional): If True, triggers the receive_all method on each branch after sending requests.
382
- """
383
- self.collect()
384
- self.send()
385
- if receive_all:
386
- for branch in self.branches.values():
387
- branch.receive_all()
388
-
389
- def register_tools(self, tools: Union[Tool, List[Tool]]) -> None:
390
- """
391
- Registers one or more tools to the current default branch.
392
-
393
- Args:
394
- tools (Union[Tool, List[Tool]]): The tool or list of tools to register.
395
- """
396
- self.default_branch.register_tools(tools)
397
-
398
- def delete_tool(self, name: str) -> bool:
399
- """
400
- Deletes a tool from the current default branch.
401
-
402
- Args:
403
- name (str): The name of the tool to delete.
404
-
405
- Returns:
406
- bool: True if the tool is deleted, False otherwise.
407
- """
408
- return self.default_branch.delete_tool(name)
409
-
410
- @property
411
- def describe(self) -> Dict[str, Any]:
412
- """
413
- Generates a report of the current default branch.
414
-
415
- Returns:
416
- Dict[str, Any]: The report of the current default branch.
417
- """
418
- return self.default_branch.describe
419
-
420
- @property
421
- def messages(self) -> pd.DataFrame:
422
- """
423
- Get the DataFrame containing conversation messages.
424
-
425
- Returns:
426
- pd.DataFrame: A DataFrame containing conversation messages.
427
- """
428
- return self.default_branch.messages
429
-
430
-
431
- @property
432
- def first_system(self) -> pd.Series:
433
- """
434
- Get the first system message of the current default branch.
435
-
436
- Returns:
437
- System: The first system message of the current default branch.
438
- """
439
- return self.default_branch.first_system
440
-
441
- @property
442
- def last_response(self) -> pd.Series:
443
- """
444
- Get the last response message of the current default branch.
445
-
446
- Returns:
447
- str: The last response message of the current default branch.
448
- """
449
- return self.default_branch.last_response
450
-
451
-
452
- @property
453
- def last_response_content(self) -> Dict:
454
- """
455
- Get the last response content of the current default branch.
456
-
457
- Returns:
458
- Dict: The last response content of the current default branch.
459
- """
460
- return self.default_branch.last_response_content
461
-
462
-
463
- def _verify_default_branch(self):
464
- if self.branches:
465
- if self.default_branch_name not in self.branches.keys():
466
- raise ValueError('default branch name is not in imported branches')
467
- if self.default_branch is not self.branches[self.default_branch_name]:
468
- raise ValueError(f'default branch does not match Branch object under {self.default_branch_name}')
469
-
470
- if not self.branches:
471
- self.branches[self.default_branch_name] = self.default_branch
472
-
473
- def _setup_default_branch(
474
- self, default_branch, default_branch_name, service, llmconfig, system, sender
475
- ):
476
- self.default_branch = default_branch if default_branch else Branch(
477
- name=default_branch_name, service=service, llmconfig=llmconfig
478
- )
479
- self.default_branch_name = default_branch_name
480
- if system:
481
- self.default_branch.add_message(system=system, sender=sender)
482
-
483
- self.llmconfig = self.default_branch.llmconfig
484
- # def add_instruction_set(self, name: str, instruction_set: InstructionSet) -> None:
485
- # """
486
- # Adds an instruction set to the current active branch.
487
- #
488
- # Args:
489
- # name (str): The name of the instruction set.
490
- # instruction_set (InstructionSet): The instruction set to add.
491
- # """
492
- # self.default_branch.add_instruction_set(name, instruction_set)
493
- #
494
- # def remove_instruction_set(self, name: str) -> bool:
495
- # """
496
- # Removes an instruction set from the current active branch.
497
- #
498
- # Args:
499
- # name (str): The name of the instruction set to remove.
500
- #
501
- # Returns:
502
- # bool: True if the instruction set is removed, False otherwise.
503
- # """
504
- # return self.default_branch.remove_instruction_set(name)
@@ -1 +0,0 @@
1
- # TODO
@@ -1 +0,0 @@
1
- # TODO
@@ -1 +0,0 @@
1
- # TODO
@@ -1 +0,0 @@
1
- # TODO
@@ -1 +0,0 @@
1
- # TODO
@@ -1 +0,0 @@
1
- # TODO
@@ -1 +0,0 @@
1
- # TODO
@@ -1 +0,0 @@
1
- # TODO
@@ -1,18 +0,0 @@
1
- from .load_util import dir_to_path, dir_to_nodes, chunk_text, read_text, file_to_chunks
2
- from .reader import load, ReaderType, text_reader
3
- from .chunker import chunk, datanodes_convert, ChunkerType, text_chunker
4
-
5
- __all__ = [
6
- 'load',
7
- 'chunk',
8
- 'datanodes_convert',
9
- 'text_reader',
10
- 'text_chunker',
11
- 'ReaderType',
12
- 'ChunkerType',
13
- 'dir_to_path',
14
- 'dir_to_nodes',
15
- 'chunk_text',
16
- 'read_text',
17
- 'file_to_chunks'
18
- ]