lionagi 0.0.315__py3-none-any.whl → 0.1.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. lionagi/core/__init__.py +19 -8
  2. lionagi/core/agent/__init__.py +0 -3
  3. lionagi/core/agent/base_agent.py +26 -30
  4. lionagi/core/branch/__init__.py +0 -4
  5. lionagi/core/branch/{base_branch.py → base.py} +13 -14
  6. lionagi/core/branch/branch.py +22 -20
  7. lionagi/core/branch/executable_branch.py +0 -347
  8. lionagi/core/branch/{branch_flow_mixin.py → flow_mixin.py} +6 -6
  9. lionagi/core/branch/util.py +1 -1
  10. lionagi/core/direct/__init__.py +13 -1
  11. lionagi/core/direct/cot.py +123 -1
  12. lionagi/core/direct/plan.py +164 -0
  13. lionagi/core/direct/predict.py +13 -9
  14. lionagi/core/direct/react.py +12 -8
  15. lionagi/core/direct/score.py +4 -4
  16. lionagi/core/direct/select.py +4 -4
  17. lionagi/core/direct/utils.py +23 -0
  18. lionagi/core/direct/vote.py +2 -2
  19. lionagi/core/execute/base_executor.py +50 -0
  20. lionagi/core/execute/branch_executor.py +233 -0
  21. lionagi/core/execute/instruction_map_executor.py +131 -0
  22. lionagi/core/execute/structure_executor.py +218 -0
  23. lionagi/core/flow/monoflow/ReAct.py +4 -4
  24. lionagi/core/flow/monoflow/chat.py +6 -6
  25. lionagi/core/flow/monoflow/chat_mixin.py +24 -34
  26. lionagi/core/flow/monoflow/followup.py +4 -4
  27. lionagi/core/flow/polyflow/__init__.py +1 -1
  28. lionagi/core/flow/polyflow/chat.py +15 -12
  29. lionagi/core/{prompt/action_template.py → form/action_form.py} +2 -2
  30. lionagi/core/{prompt → form}/field_validator.py +40 -31
  31. lionagi/core/form/form.py +302 -0
  32. lionagi/core/form/mixin.py +214 -0
  33. lionagi/core/{prompt/scored_template.py → form/scored_form.py} +2 -2
  34. lionagi/core/generic/__init__.py +37 -0
  35. lionagi/core/generic/action.py +26 -0
  36. lionagi/core/generic/component.py +457 -0
  37. lionagi/core/generic/condition.py +44 -0
  38. lionagi/core/generic/data_logger.py +305 -0
  39. lionagi/core/generic/edge.py +110 -0
  40. lionagi/core/generic/mail.py +90 -0
  41. lionagi/core/generic/mailbox.py +36 -0
  42. lionagi/core/generic/node.py +285 -0
  43. lionagi/core/generic/relation.py +70 -0
  44. lionagi/core/generic/signal.py +22 -0
  45. lionagi/core/generic/structure.py +362 -0
  46. lionagi/core/generic/transfer.py +20 -0
  47. lionagi/core/generic/work.py +40 -0
  48. lionagi/core/graph/graph.py +126 -0
  49. lionagi/core/graph/tree.py +190 -0
  50. lionagi/core/mail/__init__.py +0 -8
  51. lionagi/core/mail/mail_manager.py +12 -10
  52. lionagi/core/mail/schema.py +9 -2
  53. lionagi/core/messages/__init__.py +0 -3
  54. lionagi/core/messages/schema.py +17 -225
  55. lionagi/core/session/__init__.py +0 -3
  56. lionagi/core/session/session.py +25 -23
  57. lionagi/core/tool/__init__.py +3 -1
  58. lionagi/core/tool/tool.py +28 -0
  59. lionagi/core/tool/tool_manager.py +75 -75
  60. lionagi/integrations/chunker/chunk.py +7 -7
  61. lionagi/integrations/config/oai_configs.py +4 -4
  62. lionagi/integrations/loader/load.py +6 -6
  63. lionagi/integrations/loader/load_util.py +8 -8
  64. lionagi/libs/ln_api.py +3 -3
  65. lionagi/libs/ln_parse.py +43 -6
  66. lionagi/libs/ln_validate.py +288 -0
  67. lionagi/libs/sys_util.py +28 -6
  68. lionagi/tests/libs/test_async.py +0 -0
  69. lionagi/tests/libs/test_field_validators.py +353 -0
  70. lionagi/tests/test_core/test_base_branch.py +0 -1
  71. lionagi/tests/test_core/test_branch.py +3 -0
  72. lionagi/tests/test_core/test_session_base_util.py +1 -0
  73. lionagi/version.py +1 -1
  74. {lionagi-0.0.315.dist-info → lionagi-0.1.0.dist-info}/METADATA +1 -1
  75. lionagi-0.1.0.dist-info/RECORD +136 -0
  76. lionagi/core/prompt/prompt_template.py +0 -312
  77. lionagi/core/schema/__init__.py +0 -22
  78. lionagi/core/schema/action_node.py +0 -29
  79. lionagi/core/schema/base_mixin.py +0 -296
  80. lionagi/core/schema/base_node.py +0 -199
  81. lionagi/core/schema/condition.py +0 -24
  82. lionagi/core/schema/data_logger.py +0 -354
  83. lionagi/core/schema/data_node.py +0 -93
  84. lionagi/core/schema/prompt_template.py +0 -67
  85. lionagi/core/schema/structure.py +0 -912
  86. lionagi/core/tool/manual.py +0 -1
  87. lionagi-0.0.315.dist-info/RECORD +0 -121
  88. /lionagi/core/{branch/base → execute}/__init__.py +0 -0
  89. /lionagi/core/flow/{base/baseflow.py → baseflow.py} +0 -0
  90. /lionagi/core/flow/{base/__init__.py → mono_chat_mixin.py} +0 -0
  91. /lionagi/core/{prompt → form}/__init__.py +0 -0
  92. /lionagi/{tests/test_integrations → core/graph}/__init__.py +0 -0
  93. /lionagi/tests/{test_libs → integrations}/__init__.py +0 -0
  94. /lionagi/tests/{test_libs/test_async.py → libs/__init__.py} +0 -0
  95. /lionagi/tests/{test_libs → libs}/test_api.py +0 -0
  96. /lionagi/tests/{test_libs → libs}/test_convert.py +0 -0
  97. /lionagi/tests/{test_libs → libs}/test_func_call.py +0 -0
  98. /lionagi/tests/{test_libs → libs}/test_nested.py +0 -0
  99. /lionagi/tests/{test_libs → libs}/test_parse.py +0 -0
  100. /lionagi/tests/{test_libs → libs}/test_sys_util.py +0 -0
  101. {lionagi-0.0.315.dist-info → lionagi-0.1.0.dist-info}/LICENSE +0 -0
  102. {lionagi-0.0.315.dist-info → lionagi-0.1.0.dist-info}/WHEEL +0 -0
  103. {lionagi-0.0.315.dist-info → lionagi-0.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,190 @@
1
+ """
2
+ This module provides classes for representing and working with tree structures.
3
+
4
+ The module includes the following classes:
5
+ - TreeLabel: An enumeration representing tree relationships (parent and child).
6
+ - TreeNode: A specialized node representing a node within a tree structure,
7
+ extending the basic node functionality with parent-child relationships.
8
+ - Tree: Represents a tree structure, extending the graph with tree-specific
9
+ functionalities like managing parent-child relationships.
10
+ """
11
+
12
+ from enum import Enum
13
+ from pydantic import Field
14
+
15
+ from lionagi.core.generic import Node, Condition
16
+ from lionagi.core.graph.graph import Graph
17
+
18
+
19
+ class TreeLabel(str, Enum):
20
+ """
21
+ Enumeration representing tree relationships.
22
+
23
+ Attributes:
24
+ PARENT (str): Represents the parent edge.
25
+ CHILD (str): Represents the child edge.
26
+ """
27
+
28
+ PARENT = "parent"
29
+ CHILD = "child"
30
+
31
+
32
+ class TreeNode(Node):
33
+ """
34
+ A specialized node representing a node within a tree structure.
35
+
36
+ Extends the basic node functionality with parent-child relationships.
37
+
38
+ Attributes:
39
+ parent (Node | None): The parent node. Defaults to None if the node has
40
+ no parent.
41
+ """
42
+
43
+ parent: Node | None = Field(
44
+ default=None,
45
+ description="The parent node, as an instance of Node.",
46
+ )
47
+
48
+ @property
49
+ def children(self) -> list[str]:
50
+ """
51
+ Retrieves the IDs of all child nodes.
52
+
53
+ Returns:
54
+ list[str]: A list containing the IDs of the child nodes.
55
+ """
56
+ if not self.parent:
57
+ return list(self.related_nodes)
58
+ else:
59
+ return [
60
+ node_id for node_id in self.related_nodes if node_id != self.parent.id_
61
+ ]
62
+
63
+ def relate_child(
64
+ self,
65
+ child: Node | list[Node],
66
+ condition: Condition | None = None,
67
+ bundle: bool = False,
68
+ ) -> None:
69
+ """
70
+ Establishes a parent-child relationship between this node and the given
71
+ child node(s).
72
+
73
+ Args:
74
+ child (Node | list[Node]): The child node or list of child nodes to
75
+ be related.
76
+ condition (Condition | None): The condition associated with the
77
+ relationship, if any.
78
+ bundle (bool): Indicates whether to bundle the relation into a
79
+ single transaction. Defaults to False.
80
+ """
81
+ children = [child] if isinstance(child, Node) else child
82
+ for _child in children:
83
+ self.relate(
84
+ _child,
85
+ node_as="head",
86
+ label=TreeLabel.PARENT,
87
+ condition=condition,
88
+ bundle=bundle,
89
+ )
90
+ if isinstance(_child, TreeNode):
91
+ _child.parent = self
92
+
93
+ def relate_parent(
94
+ self,
95
+ parent: Node,
96
+ condition: Condition | None = None,
97
+ bundle: bool = False,
98
+ ) -> None:
99
+ """
100
+ Establishes a parent-child relationship between the given parent node
101
+ and this node.
102
+
103
+ Args:
104
+ parent (Node): The parent node to be related.
105
+ condition (Condition | None): The condition associated with the
106
+ relationship, if any.
107
+ bundle (bool): Indicates whether to bundle the relation into a
108
+ single transaction. Defaults to False.
109
+ """
110
+ if self.parent:
111
+ self.unrelate(self.parent)
112
+ self.relate(
113
+ parent,
114
+ node_as="tail",
115
+ label=TreeLabel.PARENT,
116
+ condition=condition,
117
+ bundle=bundle,
118
+ )
119
+ self.parent = parent
120
+
121
+ def unrelate_parent(self):
122
+ """
123
+ Removes the parent relationship of this node.
124
+ """
125
+ self.unrelate(self.parent)
126
+ self.parent = None
127
+
128
+ def unrelate_child(self, child: Node | list[Node]):
129
+ """
130
+ Removes the child relationship between this node and the given child
131
+ node(s).
132
+
133
+ Args:
134
+ child (Node | list[Node]): The child node or list of child nodes to
135
+ be unrelated.
136
+ """
137
+ children: list[Node] = [child] if isinstance(child, Node) else child
138
+ for _child in children:
139
+ self.unrelate(_child)
140
+ if isinstance(_child, TreeNode):
141
+ _child.parent = None
142
+
143
+
144
+ class Tree(Graph):
145
+ """
146
+ Represents a tree structure, extending the graph with tree-specific
147
+ functionalities.
148
+
149
+ Manages parent-child relationships within the tree.
150
+
151
+ Attributes:
152
+ root (TreeNode | None): The root node of the tree. Defaults to None.
153
+ """
154
+
155
+ root: TreeNode | None = Field(
156
+ default=None, description="The root node of the tree graph."
157
+ )
158
+
159
+ def relate_parent_child(
160
+ self,
161
+ parent: TreeNode,
162
+ children: list[TreeNode],
163
+ condition: Condition | None = None,
164
+ bundle: bool = False,
165
+ ) -> None:
166
+ """
167
+ Establishes parent-child relationships between the given parent node and
168
+ child node(s).
169
+
170
+ Args:
171
+ parent (TreeNode): The parent node.
172
+ children (list[TreeNode]): A list of child nodes.
173
+ condition (Condition | None): The condition associated with the
174
+ relationships, if any.
175
+ bundle (bool): Indicates whether to bundle the relations into a
176
+ single transaction. Defaults to False.
177
+ """
178
+ children = [children] if isinstance(children, TreeNode) else children
179
+ for child in children:
180
+ if child.id_ not in self.internal_nodes:
181
+ self.add_node(child)
182
+
183
+ for child in children:
184
+ parent.relate_child(child, condition=condition, bundle=bundle)
185
+
186
+ if parent.id_ not in self.internal_nodes:
187
+ self.add_node(parent)
188
+
189
+ if self.root is None:
190
+ self.root = parent
@@ -1,8 +0,0 @@
1
- from .schema import BaseMail, StartMail
2
- from .mail_manager import MailManager
3
-
4
- __all__ = [
5
- "BaseMail",
6
- "StartMail",
7
- "MailManager",
8
- ]
@@ -1,7 +1,7 @@
1
1
  from collections import deque
2
2
  from lionagi.libs import AsyncUtil
3
- from ..schema import BaseNode
4
- from .schema import BaseMail
3
+ from lionagi.core.generic import Node
4
+ from lionagi.core.mail.schema import BaseMail, MailCategory
5
5
 
6
6
 
7
7
  class MailManager:
@@ -34,18 +34,20 @@ class MailManager:
34
34
  if v.id_ not in self.sources:
35
35
  self.sources[v.id_] = v
36
36
  self.mails[v.id_] = {}
37
+ else:
38
+ raise ValueError("Failed to add source, please input list or dict.")
37
39
 
38
40
  @staticmethod
39
41
  def create_mail(sender_id, recipient_id, category, package):
40
42
  return BaseMail(sender_id, recipient_id, category, package)
41
43
 
42
- def add_source(self, sources: list[BaseNode]):
43
- for source in sources:
44
- if source.id_ in self.sources:
45
- # raise ValueError(f"Source {source.id_} exists, please input a different name.")
46
- continue
47
- self.sources[source.id_] = source
48
- self.mails[source.id_] = {}
44
+ # def add_source(self, sources: list[Node]):
45
+ # for source in sources:
46
+ # if source.id_ in self.sources:
47
+ # # raise ValueError(f"Source {source.id_} exists, please input a different name.")
48
+ # continue
49
+ # self.sources[source.id_] = source
50
+ # self.mails[source.id_] = {}
49
51
 
50
52
  def delete_source(self, source_id):
51
53
  if source_id not in self.sources:
@@ -65,7 +67,7 @@ class MailManager:
65
67
  f"Recipient source {mail_.recipient_id} does not exist"
66
68
  )
67
69
  if mail_.sender_id not in self.mails[mail_.recipient_id]:
68
- self.mails[mail_.recipient_id] = {mail_.sender_id: deque()}
70
+ self.mails[mail_.recipient_id].update({mail_.sender_id: deque()})
69
71
  self.mails[mail_.recipient_id][mail_.sender_id].append(mail_)
70
72
 
71
73
  def send(self, recipient_id):
@@ -1,7 +1,7 @@
1
1
  from collections import deque
2
2
  from enum import Enum
3
3
 
4
- from lionagi.core.schema.base_node import BaseRelatableNode
4
+ from lionagi.core.generic import Node
5
5
 
6
6
 
7
7
  class MailCategory(str, Enum):
@@ -39,7 +39,7 @@ class BaseMail:
39
39
  self.package = package
40
40
 
41
41
 
42
- class StartMail(BaseRelatableNode):
42
+ class StartMail(Node):
43
43
 
44
44
  def __init__(self, **kwargs):
45
45
  super().__init__(**kwargs)
@@ -54,3 +54,10 @@ class StartMail(BaseRelatableNode):
54
54
  package=start_mail_content,
55
55
  )
56
56
  self.pending_outs.append(start_mail)
57
+
58
+
59
+ class MailTransfer(Node):
60
+ def __init__(self):
61
+ super().__init__()
62
+ self.pending_ins = {}
63
+ self.pending_outs = deque()
@@ -1,3 +0,0 @@
1
- from .schema import System, Instruction, Response
2
-
3
- __all__ = ["System", "Instruction", "Response"]
@@ -1,15 +1,12 @@
1
1
  from enum import Enum
2
2
 
3
3
  from lionagi.libs import nested, convert
4
- from ..schema import DataNode
5
- from ..prompt.prompt_template import PromptTemplate
4
+ from lionagi.core.generic import Node
5
+ from lionagi.core.form.form import Form
6
6
 
7
7
  _message_fields = ["node_id", "timestamp", "role", "sender", "recipient", "content"]
8
8
 
9
9
 
10
- # ToDo: actually implement the new message classes
11
-
12
-
13
10
  class BranchColumns(list[str], Enum):
14
11
  COLUMNS = _message_fields
15
12
 
@@ -94,14 +91,14 @@ class MessageType(dict, Enum):
94
91
  }
95
92
 
96
93
 
97
- class BaseMessage(DataNode):
94
+ class BaseMessage(Node):
98
95
  """
99
96
  Represents a message in a chatbot-like system, inheriting from BaseNode.
100
97
 
101
98
  Attributes:
102
- role (str | None): The role of the entity sending the message, e.g., 'user', 'system'.
103
- sender (str | None): The identifier of the sender of the message.
104
- content (Any): The actual content of the message.
99
+ role (str | None): The role of the entity sending the message, e.g., 'user', 'system'.
100
+ sender (str | None): The identifier of the sender of the message.
101
+ content (Any): The actual content of the message.
105
102
  """
106
103
 
107
104
  role: str | None = None
@@ -114,7 +111,7 @@ class BaseMessage(DataNode):
114
111
  Constructs and returns a dictionary representation of the message.
115
112
 
116
113
  Returns:
117
- A dictionary representation of the message with 'role' and 'content' keys.
114
+ A dictionary representation of the message with 'role' and 'content' keys.
118
115
  """
119
116
  return self._to_message()
120
117
 
@@ -124,7 +121,7 @@ class BaseMessage(DataNode):
124
121
  Gets the 'content' field of the message.
125
122
 
126
123
  Returns:
127
- The 'content' part of the message.
124
+ The 'content' part of the message.
128
125
  """
129
126
  return self.msg["content"]
130
127
 
@@ -133,7 +130,7 @@ class BaseMessage(DataNode):
133
130
  Constructs and returns a dictionary representation of the message.
134
131
 
135
132
  Returns:
136
- dict: A dictionary representation of the message with 'role' and 'content' keys.
133
+ dict: A dictionary representation of the message with 'role' and 'content' keys.
137
134
  """
138
135
  return {"role": self.role, "content": convert.to_str(self.content)}
139
136
 
@@ -187,16 +184,16 @@ class Instruction(BaseMessage):
187
184
  return self.content["instruction"]
188
185
 
189
186
  @classmethod
190
- def from_prompt_template(
187
+ def from_form(
191
188
  cls,
192
- prompt_template: PromptTemplate,
189
+ form: Form,
193
190
  sender: str | None = None,
194
191
  recipient=None,
195
192
  ):
196
193
  return cls(
197
- instruction=prompt_template.instruction,
198
- context=prompt_template.instruction_context,
199
- output_fields=prompt_template.instruction_output_fields,
194
+ instruction=form.instruction,
195
+ context=form.instruction_context,
196
+ output_fields=form.instruction_output_fields,
200
197
  sender=sender,
201
198
  recipient=recipient,
202
199
  )
@@ -297,13 +294,13 @@ class Response(BaseMessage):
297
294
  Processes an action request response and extracts relevant information.
298
295
 
299
296
  Args:
300
- response (dict): The response dictionary containing tool calls and other information.
297
+ response (dict): The response dictionary containing tool calls and other information.
301
298
 
302
299
  Returns:
303
- list: A list of dictionaries, each representing a function call with action and arguments.
300
+ list: A list of dictionaries, each representing a function call with action and arguments.
304
301
 
305
302
  Raises:
306
- ValueError: If the response does not conform to the expected format for action requests.
303
+ ValueError: If the response does not conform to the expected format for action requests.
307
304
  """
308
305
  try:
309
306
  tool_count = 0
@@ -326,208 +323,3 @@ class Response(BaseMessage):
326
323
  raise ValueError(
327
324
  "Response message must be one of regular response or function calling"
328
325
  )
329
-
330
-
331
- # class BaseMessage(DataNode):
332
-
333
-
334
- # def __init__():
335
- # ...
336
-
337
- # role: MessageRoleType = Field(..., alias=MessageField.ROLE.value)
338
- # sender: str = Field(..., alias=MessageField.SENDER.value) # Customizable sender
339
- # recipient: str | None = Field(None,
340
- # alias=MessageField.RECIPIENT.value) # Optional recipient
341
-
342
- # class Config:
343
- # extra = 'allow'
344
- # use_enum_values = True
345
- # populate_by_name = True
346
-
347
- # @model_validator(mode='before')
348
- # def handle_extra_fields(cls, values):
349
- # """Move undefined fields to metadata."""
350
- # fields = set(values.keys())
351
- # defined_fields = set(cls.model_fields.keys())
352
- # extra_fields = fields - defined_fields
353
-
354
- # if extra_fields:
355
- # metadata = values.get('metadata', {})
356
- # for field in extra_fields:
357
- # if field in metadata:
358
- # metadata[f"{field}_1"] = values.pop(field)
359
- # else:
360
- # metadata[field] = values.pop(field)
361
- # values['metadata'] = metadata
362
- # return values
363
-
364
- # def _to_roled_message(self):
365
- # return {
366
- # MessageField.ROLE.value: self.role.value,
367
- # MessageField.CONTENT.value: (
368
- # json.dumps(self.content) if isinstance(self.content, dict)
369
- # else self.content
370
- # )
371
- # }
372
-
373
- # def to_pd_series(self, *args, **kwargs):
374
- # msg_dict = self.to_dict(*args, **kwargs)
375
- # if isinstance(to_dict(msg_dict['content']), dict):
376
- # msg_dict['content'] = json.dumps(msg_dict['content'])
377
- # return pd.Series(msg_dict)
378
-
379
- # @classmethod
380
- # def from_pd_series(cls, series: pd.Series, **kwargs):
381
- # self = cls.from_dict(series.to_dict(**kwargs))
382
- # if isinstance(self.content, str):
383
- # try:
384
- # self.content = to_dict(self.content)
385
- # except:
386
- # pass
387
- # return self
388
-
389
-
390
- # def __str__(self):
391
- # content_preview = self.content[:50] + "..." if len(
392
- # self.content) > 50 else self.content
393
- # meta_preview = str(self.metadata)[:50] + "..." if len(
394
- # str(self.metadata)) > 50 else str(self.metadata)
395
-
396
- # return (
397
- # f"Message({self.role.value or 'none'}, {self._sender or 'none'}, "
398
- # f"{content_preview or 'none'}, {self.recipient or 'none'},"
399
- # f"{self.timestamp or 'none'}, {meta_preview or 'none'}"
400
- # )
401
-
402
- # class Instruction(BaseMessage):
403
-
404
- # def __init__(self, instruction: Any, context: Any = None,
405
- # sender: str | None = None, recipient: str | None | Any = None,
406
- # metadata: dict | None = None, relation: list | None | Any = None,
407
- # **kwargs):
408
- # super().__init__(
409
- # role=MessageType.INSTRUCTION.value[MessageField.ROLE.value],
410
- # sender=sender or MessageType.INSTRUCTION.value[MessageField.SENDER.value],
411
- # content={MessageType.INSTRUCTION.value["content_key"]: instruction},
412
- # recipient=recipient or MessageType.SYSTEM.value[MessageField.RECIPIENT.value],
413
- # metadata=metadata or {}, relation=relation or [], **kwargs
414
- # )
415
- # if context:
416
- # self.content.update({MessageType.CONTEXT.value["content_key"]: context})
417
-
418
-
419
- # class System(BaseMessage):
420
-
421
- # def __init__(self, system: Any, sender: str | None = None, recipient: Optional[
422
- # str] = None, metadata: Optional[dict] = None, relation: Optional[list] = None,
423
- # **kwargs):
424
- # super().__init__(
425
- # role=MessageType.SYSTEM.value[MessageField.ROLE.value],
426
- # sender=sender or MessageType.SYSTEM.value[MessageField.SENDER.value],
427
- # content={MessageType.SYSTEM.value["content_key"]: system},
428
- # recipient=recipient or MessageType.SYSTEM.value[MessageField.RECIPIENT.value],
429
- # metadata=metadata or {}, relation=relation or [], **kwargs
430
- # )
431
-
432
-
433
- # class ActionRequest(BaseMessage):
434
-
435
- # def __init__(self, action_request: Any, sender: str | None = None,
436
- # recipient: Optional[
437
- # str] = None, metadata: Optional[dict] = None,
438
- # relation: Optional[list] = None,
439
- # **kwargs
440
- # ):
441
-
442
- # super().__init__(
443
- # role=MessageType.ACTION_REQUEST.value[MessageField.ROLE.value],
444
- # sender=sender or MessageType.ACTION_REQUEST.value[MessageField.SENDER.value],
445
- # content={MessageType.ACTION_REQUEST.value["content_key"]: action_request},
446
- # recipient=recipient or MessageType.ACTION_REQUEST.value[
447
- # MessageField.RECIPIENT.value],
448
- # metadata=metadata or {}, relation=relation or [], **kwargs
449
- # )
450
-
451
- # @classmethod
452
- # def from_response(cls, response, sender=None, recipient=None, metadata=None,
453
- # relation=None,
454
- # **kwargs):
455
- # return cls(action_request=response, sender=sender, recipient=recipient,
456
- # metadata=metadata,
457
- # relation=relation, **kwargs)
458
-
459
- # @staticmethod
460
- # def _handle_action_request(response):
461
- # try:
462
- # tool_count = 0
463
- # func_list = []
464
- # while tool_count < len(response['tool_calls']):
465
- # _path = ['tool_calls', tool_count, 'type']
466
-
467
- # if nget(response, _path) == 'function':
468
- # _path1 = ['tool_calls', tool_count, 'function', 'name']
469
- # _path2 = ['tool_calls', tool_count, 'function', 'arguments']
470
-
471
- # func_content = {
472
- # "action": ("action_" + nget(response, _path1)),
473
- # "arguments": nget(response, _path2)
474
- # }
475
- # func_list.append(func_content)
476
- # tool_count += 1
477
- # return func_list
478
- # except:
479
- # raise ValueError(
480
- # "Response message must be one of regular response or function calling"
481
- # )
482
-
483
-
484
- # class ActionResponse(BaseMessage):
485
-
486
- # def __init__(self, action_response: Any, sender: str | None = None,
487
- # recipient: Optional[
488
- # str] = None, metadata: Optional[dict] = None,
489
- # relation: Optional[list] = None,
490
- # **kwargs
491
- # ):
492
- # super().__init__(
493
- # role=MessageType.ACTION_RESPONSE.value[MessageField.ROLE.value],
494
- # sender=sender or MessageType.ACTION_RESPONSE.value[MessageField.SENDER.value],
495
- # content={MessageType.ACTION_RESPONSE.value["content_key"]: action_response},
496
- # recipient=recipient or MessageType.ACTION_RESPONSE.value[
497
- # MessageField.RECIPIENT.value],
498
- # metadata=metadata or {}, relation=relation or [], **kwargs
499
- # )
500
-
501
- # @classmethod
502
- # def from_response(cls, response, sender=None, recipient=None, metadata=None,
503
- # relation=None,
504
- # **kwargs):
505
- # return cls(action_response=response, sender=sender, recipient=recipient,
506
- # metadata=metadata,
507
- # relation=relation, **kwargs)
508
-
509
-
510
- # class AssistantResponse(BaseMessage):
511
-
512
- # def __init__(self, response: Any, sender: str | None = None,
513
- # recipient: Optional[
514
- # str] = None, metadata: Optional[dict] = None,
515
- # relation: Optional[list] = None,
516
- # **kwargs
517
- # ):
518
- # super().__init__(
519
- # role='assistant',
520
- # sender=sender or MessageType.RESPONSE.value[MessageField.SENDER.value],
521
- # content={MessageType.RESPONSE.value["content_key"]: response},
522
- # recipient=recipient or MessageType.RESPONSE.value[
523
- # MessageField.RECIPIENT.value],
524
- # metadata=metadata or {}, relation=relation or [], **kwargs
525
- # )
526
-
527
- # @classmethod
528
- # def from_response(cls, response, sender=None, recipient=None, metadata=None,
529
- # relation=None,
530
- # **kwargs):
531
- # return cls(response=response, sender=sender, recipient=recipient,
532
- # metadata=metadata,
533
- # relation=relation, **kwargs)
@@ -1,3 +0,0 @@
1
- from .session import Session
2
-
3
- __all__ = ["Session"]