gllm-core-binary 0.3.23b3__py3-none-any.whl → 0.4.2b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. gllm_core/adapters/__init__.py +5 -0
  2. gllm_core/adapters/__init__.pyi +3 -0
  3. gllm_core/adapters/tool/__init__.py +6 -0
  4. gllm_core/adapters/tool/__init__.pyi +4 -0
  5. gllm_core/adapters/tool/google_adk.py +91 -0
  6. gllm_core/adapters/tool/google_adk.pyi +23 -0
  7. gllm_core/adapters/tool/langchain.py +130 -0
  8. gllm_core/adapters/tool/langchain.pyi +31 -0
  9. gllm_core/constants.py +0 -1
  10. gllm_core/constants.pyi +0 -1
  11. gllm_core/event/event_emitter.py +8 -44
  12. gllm_core/event/event_emitter.pyi +9 -21
  13. gllm_core/event/handler/console_event_handler.py +1 -12
  14. gllm_core/event/handler/console_event_handler.pyi +0 -1
  15. gllm_core/event/handler/print_event_handler.py +15 -59
  16. gllm_core/event/handler/print_event_handler.pyi +1 -2
  17. gllm_core/schema/__init__.py +2 -2
  18. gllm_core/schema/__init__.pyi +2 -2
  19. gllm_core/schema/component.py +236 -27
  20. gllm_core/schema/component.pyi +164 -17
  21. gllm_core/schema/schema_generator.py +150 -0
  22. gllm_core/schema/schema_generator.pyi +35 -0
  23. gllm_core/schema/tool.py +31 -1
  24. gllm_core/schema/tool.pyi +21 -0
  25. gllm_core/utils/__init__.py +2 -0
  26. gllm_core/utils/__init__.pyi +2 -1
  27. gllm_core/utils/analyzer.py +24 -1
  28. gllm_core/utils/analyzer.pyi +15 -1
  29. gllm_core/utils/concurrency.py +2 -2
  30. gllm_core/utils/logger_manager.py +17 -7
  31. gllm_core/utils/logger_manager.pyi +3 -0
  32. gllm_core/utils/main_method_resolver.py +185 -0
  33. gllm_core/utils/main_method_resolver.pyi +54 -0
  34. gllm_core/utils/retry.py +130 -21
  35. gllm_core/utils/retry.pyi +6 -29
  36. {gllm_core_binary-0.3.23b3.dist-info → gllm_core_binary-0.4.2b1.dist-info}/METADATA +6 -1
  37. {gllm_core_binary-0.3.23b3.dist-info → gllm_core_binary-0.4.2b1.dist-info}/RECORD +39 -27
  38. {gllm_core_binary-0.3.23b3.dist-info → gllm_core_binary-0.4.2b1.dist-info}/WHEEL +0 -0
  39. {gllm_core_binary-0.3.23b3.dist-info → gllm_core_binary-0.4.2b1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,5 @@
1
+ """Adapters for external formats."""
2
+
3
+ from gllm_core.adapters.tool import from_google_function, from_langchain_tool
4
+
5
+ __all__ = ["from_google_function", "from_langchain_tool"]
@@ -0,0 +1,3 @@
1
+ from gllm_core.adapters.tool import from_google_function as from_google_function, from_langchain_tool as from_langchain_tool
2
+
3
+ __all__ = ['from_google_function', 'from_langchain_tool']
@@ -0,0 +1,6 @@
1
+ """Tool adapters for external formats."""
2
+
3
+ from gllm_core.adapters.tool.google_adk import from_google_function
4
+ from gllm_core.adapters.tool.langchain import from_langchain_tool
5
+
6
+ __all__ = ["from_langchain_tool", "from_google_function"]
@@ -0,0 +1,4 @@
1
+ from gllm_core.adapters.tool.google_adk import from_google_function as from_google_function
2
+ from gllm_core.adapters.tool.langchain import from_langchain_tool as from_langchain_tool
3
+
4
+ __all__ = ['from_langchain_tool', 'from_google_function']
@@ -0,0 +1,91 @@
1
+ """Google ADK tool adapter conversions.
2
+
3
+ Authors:
4
+ Dimitrij Ray (dimitrij.ray@gdplabs.id)
5
+
6
+ References:
7
+ NONE
8
+ """
9
+
10
+ import asyncio
11
+ from typing import Any, Callable
12
+
13
+ from gllm_core.schema.tool import Tool
14
+
15
+ _DEFAULT_SCHEMA: dict[str, Any] = {"type": "object", "properties": {}}
16
+
17
+
18
+ def _validate_and_extract_schema(parameters: Any) -> dict[str, Any]:
19
+ """Validate and extract the input schema from Google ADK parameters.
20
+
21
+ Args:
22
+ parameters (Any): The parameters from the Google ADK function declaration.
23
+
24
+ Returns:
25
+ dict[str, Any]: The validated input schema.
26
+
27
+ Raises:
28
+ TypeError: If the schema has invalid structure.
29
+ """
30
+ if parameters is None:
31
+ return _DEFAULT_SCHEMA.copy()
32
+
33
+ if isinstance(parameters, dict):
34
+ if "properties" in parameters and not isinstance(parameters.get("properties"), dict):
35
+ raise TypeError("Google ADK function schema 'properties' must be a dictionary.")
36
+ return parameters
37
+
38
+ return dict(parameters) if hasattr(parameters, "__iter__") else _DEFAULT_SCHEMA.copy()
39
+
40
+
41
+ def from_google_function(function_declaration: Any, func: Callable | None = None) -> Tool:
42
+ """Convert a Google ADK function declaration into the SDK Tool representation.
43
+
44
+ The Google ADK `FunctionDeclaration` provides access to:
45
+ 1. `name`: The function name
46
+ 2. `description`: The function description
47
+ 3. `parameters`: A dict in JSON Schema format (OpenAPI 3.0 compatible)
48
+
49
+ Args:
50
+ function_declaration (Any): The Google ADK function declaration to convert.
51
+ func (Callable | None, optional): The implementation function for the tool. Defaults to None.
52
+
53
+ Returns:
54
+ Tool: The converted SDK tool.
55
+
56
+ Raises:
57
+ ValueError: If the function declaration is None or has invalid fields.
58
+ AttributeError: If required attributes are missing.
59
+ TypeError: If field types are incorrect.
60
+ """
61
+ if function_declaration is None:
62
+ raise ValueError("Google ADK function declaration cannot be None.")
63
+
64
+ for attr in ("name", "description"):
65
+ if not hasattr(function_declaration, attr):
66
+ raise AttributeError(f"Google ADK function declaration must have a {attr!r} attribute.")
67
+
68
+ name = function_declaration.name
69
+ description = function_declaration.description
70
+
71
+ if not isinstance(name, str) or not name:
72
+ raise ValueError("Google ADK function 'name' must be a non-empty string.")
73
+
74
+ if description is not None and not isinstance(description, str):
75
+ raise TypeError("Google ADK function 'description' must be a string when provided.")
76
+
77
+ if func is not None and not callable(func):
78
+ raise TypeError("Google ADK tool implementation must be callable when provided.")
79
+
80
+ parameters = getattr(function_declaration, "parameters", None)
81
+ input_schema = _validate_and_extract_schema(parameters)
82
+
83
+ is_async = asyncio.iscoroutinefunction(func) if func else False
84
+
85
+ return Tool(
86
+ name=name,
87
+ description=description,
88
+ input_schema=input_schema,
89
+ func=func,
90
+ is_async=is_async,
91
+ )
@@ -0,0 +1,23 @@
1
+ from gllm_core.schema.tool import Tool as Tool
2
+ from typing import Any, Callable
3
+
4
+ def from_google_function(function_declaration: Any, func: Callable | None = None) -> Tool:
5
+ """Convert a Google ADK function declaration into the SDK Tool representation.
6
+
7
+ The Google ADK `FunctionDeclaration` provides access to:
8
+ 1. `name`: The function name
9
+ 2. `description`: The function description
10
+ 3. `parameters`: A dict in JSON Schema format (OpenAPI 3.0 compatible)
11
+
12
+ Args:
13
+ function_declaration (Any): The Google ADK function declaration to convert.
14
+ func (Callable | None, optional): The implementation function for the tool. Defaults to None.
15
+
16
+ Returns:
17
+ Tool: The converted SDK tool.
18
+
19
+ Raises:
20
+ ValueError: If the function declaration is None or has invalid fields.
21
+ AttributeError: If required attributes are missing.
22
+ TypeError: If field types are incorrect.
23
+ """
@@ -0,0 +1,130 @@
1
+ """LangChain tool adapter conversions.
2
+
3
+ Authors:
4
+ Dimitrij Ray (dimitrij.ray@gdplabs.id)
5
+
6
+ References:
7
+ NONE
8
+ """
9
+
10
+ import asyncio
11
+ from typing import Any, Callable
12
+
13
+ from gllm_core.schema.tool import Tool
14
+
15
+
16
+ class LangChainToolKeys:
17
+ """Constants for LangChain tool attribute keys."""
18
+
19
+ FUNC = "func"
20
+ COROUTINE = "coroutine"
21
+ RUN = "_run"
22
+ ARUN = "_arun"
23
+ NAME = "name"
24
+ DESCRIPTION = "description"
25
+ ARGS_SCHEMA = "args_schema"
26
+
27
+
28
+ LANGCHAIN_FUNCTION_ATTRS = (
29
+ LangChainToolKeys.FUNC,
30
+ LangChainToolKeys.COROUTINE,
31
+ LangChainToolKeys.RUN,
32
+ LangChainToolKeys.ARUN,
33
+ )
34
+
35
+
36
+ def _extract_attribute(tool: Any, attr_name: str) -> Any:
37
+ """Extract an attribute from a LangChain tool.
38
+
39
+ A LangChain tool can be either a dictionary-like object or an object with attributes.
40
+ This function handles both cases:
41
+ 1. If the tool has the attribute as an attribute, it returns the attribute value.
42
+ 2. If the tool has the attribute as a key (is a dictionary-like object), it returns the key value.
43
+ 3. Otherwise, it returns None.
44
+
45
+ Args:
46
+ tool (Any): The LangChain tool to extract the attribute from.
47
+ attr_name (str): The attribute name to extract.
48
+
49
+ Returns:
50
+ Any: The attribute value, or None if not found.
51
+ """
52
+ if hasattr(tool, attr_name):
53
+ return getattr(tool, attr_name)
54
+
55
+ if hasattr(tool, "get"):
56
+ return tool.get(attr_name)
57
+
58
+ return None
59
+
60
+
61
+ def _get_langchain_tool_func(tool: Any) -> Callable | None:
62
+ """Gets the function from a LangChain tool.
63
+
64
+ This function extracts the appropriate callable from a LangChain tool, with the following priority:
65
+ 1. func
66
+ 2. coroutine
67
+ 3. _run
68
+ 4. _arun
69
+
70
+ Args:
71
+ tool (Any): The LangChain tool to extract the function from.
72
+
73
+ Returns:
74
+ Callable | None: The extracted function, or None if no function is found.
75
+ """
76
+ for func_key in LANGCHAIN_FUNCTION_ATTRS:
77
+ func = _extract_attribute(tool, func_key)
78
+ if callable(func):
79
+ return func
80
+
81
+ return None
82
+
83
+
84
+ def _get_input_schema(tool: Any) -> dict[str, Any]:
85
+ """Get input schema from a LangChain tool.
86
+
87
+ Args:
88
+ tool (Any): The LangChain tool to get schema from.
89
+
90
+ Returns:
91
+ dict[str, Any]: The input schema, or default empty schema if none found.
92
+ """
93
+ input_schema = _extract_attribute(tool, LangChainToolKeys.ARGS_SCHEMA)
94
+
95
+ return input_schema if input_schema is not None else {"type": "object", "properties": {}}
96
+
97
+
98
+ def from_langchain_tool(langchain_tool: Any) -> Tool:
99
+ """Convert a LangChain tool into the SDK Tool representation.
100
+
101
+ This function handles both traditional LangChain tools created with the @tool decorator
102
+ and tools created by subclassing the LangChain Tool class.
103
+
104
+ Args:
105
+ langchain_tool (Any): The LangChain tool to convert.
106
+
107
+ Returns:
108
+ Tool: The converted SDK tool.
109
+
110
+ Raises:
111
+ ValueError: If the input is not a valid LangChain tool.
112
+ """
113
+ name = _extract_attribute(langchain_tool, LangChainToolKeys.NAME)
114
+ if not name:
115
+ raise ValueError("LangChain tool must have a 'name' attribute or key.")
116
+
117
+ description = _extract_attribute(langchain_tool, LangChainToolKeys.DESCRIPTION)
118
+ if not description:
119
+ raise ValueError("LangChain tool must have a 'description' attribute or key.")
120
+
121
+ func = _get_langchain_tool_func(langchain_tool)
122
+ input_schema = _get_input_schema(langchain_tool)
123
+
124
+ return Tool(
125
+ name=name,
126
+ description=description,
127
+ input_schema=input_schema,
128
+ func=func,
129
+ is_async=asyncio.iscoroutinefunction(func) if func is not None else False,
130
+ )
@@ -0,0 +1,31 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_core.schema.tool import Tool as Tool
3
+ from typing import Any
4
+
5
+ class LangChainToolKeys:
6
+ """Constants for LangChain tool attribute keys."""
7
+ FUNC: str
8
+ COROUTINE: str
9
+ RUN: str
10
+ ARUN: str
11
+ NAME: str
12
+ DESCRIPTION: str
13
+ ARGS_SCHEMA: str
14
+
15
+ LANGCHAIN_FUNCTION_ATTRS: Incomplete
16
+
17
+ def from_langchain_tool(langchain_tool: Any) -> Tool:
18
+ """Convert a LangChain tool into the SDK Tool representation.
19
+
20
+ This function handles both traditional LangChain tools created with the @tool decorator
21
+ and tools created by subclassing the LangChain Tool class.
22
+
23
+ Args:
24
+ langchain_tool (Any): The LangChain tool to convert.
25
+
26
+ Returns:
27
+ Tool: The converted SDK tool.
28
+
29
+ Raises:
30
+ ValueError: If the input is not a valid LangChain tool.
31
+ """
gllm_core/constants.py CHANGED
@@ -26,7 +26,6 @@ class EventType(StrEnum):
26
26
 
27
27
  ACTIVITY = "activity"
28
28
  CODE = "code"
29
- DATA = "data" # TODO: Remove in v0.4
30
29
  REFERENCE = "reference"
31
30
  RESPONSE = "response"
32
31
  STATUS = "status"
gllm_core/constants.pyi CHANGED
@@ -13,7 +13,6 @@ class EventType(StrEnum):
13
13
  """Defines event types for the event emitter module."""
14
14
  ACTIVITY = 'activity'
15
15
  CODE = 'code'
16
- DATA = 'data'
17
16
  REFERENCE = 'reference'
18
17
  RESPONSE = 'response'
19
18
  STATUS = 'status'
@@ -7,10 +7,9 @@ References:
7
7
  NONE
8
8
  """
9
9
 
10
- from datetime import datetime
11
- from typing import Any, AsyncGenerator
10
+ from typing import AsyncGenerator
12
11
 
13
- from gllm_core.constants import EventLevel, EventType
12
+ from gllm_core.constants import EventLevel
14
13
  from gllm_core.event.handler import ConsoleEventHandler, PrintEventHandler, StreamEventHandler
15
14
  from gllm_core.event.handler.event_handler import BaseEventHandler
16
15
  from gllm_core.event.hook.event_hook import BaseEventHook
@@ -158,55 +157,20 @@ class EventEmitter:
158
157
  """
159
158
  return cls(handlers=[StreamEventHandler()], event_level=event_level, hooks=hooks)
160
159
 
161
- # TODO: Reorder parameters in v0.4, some can even be made keyword-only
162
- async def emit( # noqa: PLR0913
163
- self,
164
- value: str | dict[str, Any] | Event,
165
- event_level: EventLevel = EventLevel.DEBUG, # TODO: Change default to EventLevel.INFO in v0.4
166
- event_type: str = EventType.STATUS.value, # TODO: Change default to EventType.RESPONSE.value in v0.4
167
- metadata: dict[str, Any] | None = None,
168
- event_id: str | None = None,
169
- disabled_handlers: list[str] | None = None,
170
- ) -> None:
160
+ async def emit(self, event: Event, disabled_handlers: list[str] | None = None) -> None:
171
161
  """Emits an event using the configured event handlers.
172
162
 
173
- If the value is an Event object, it is used directly and other parameters are ignored.
174
- Otherwise, a new Event object is created with the provided parameters. The event is
175
- then passed to all handlers except those listed in disabled_handlers. Events are only
176
- processed if their severity level meets or exceeds the EventEmitter's configured level.
163
+ Events are emitted by passing them to all handlers except those listed in disabled_handlers.
164
+ Events are only processed if their severity level meets or exceeds the EventEmitter's configured level.
177
165
 
178
166
  Args:
179
- value (str | dict[str, Any] | Event): The event value or Event object to emit. If an Event object
180
- is provided, other parameters are ignored and the Event is used as-is.
181
- event_level (EventLevel, optional): The severity level of the event.
182
- Defaults to EventLevel.DEBUG.
183
- event_type (str, optional): The type of event (e.g., "status", "response").
184
- Defaults to EventType.STATUS.value.
185
- metadata (dict[str, Any] | None, optional): Additional metadata for the event.
186
- Defaults to None, which creates an empty dictionary.
187
- event_id (str | None, optional): Unique identifier for the event.
188
- Defaults to None, which creates an empty string.
189
- disabled_handlers (list[str] | None, optional): Names of handlers to skip for
190
- this event. Defaults to None.
167
+ event (Event): The event to emit.
168
+ disabled_handlers (list[str] | None, optional): Names of handlers to skip for this event. Defaults to None.
191
169
 
192
170
  Raises:
193
171
  ValueError: If the provided event_level is not a valid EventLevel.
194
172
  """
195
- if isinstance(value, Event):
196
- event = value
197
- event_level = value.level
198
- else:
199
- validate_string_enum(EventLevel, event_level)
200
- event = Event(
201
- id=event_id,
202
- value=value,
203
- level=event_level,
204
- type=event_type,
205
- metadata=metadata or {},
206
- timestamp=datetime.now(),
207
- )
208
-
209
- if event_level < self.severity:
173
+ if event.level < self.severity:
210
174
  return
211
175
 
212
176
  for hook in self.hooks:
@@ -1,11 +1,11 @@
1
1
  from _typeshed import Incomplete
2
- from gllm_core.constants import EventLevel as EventLevel, EventType as EventType
2
+ from gllm_core.constants import EventLevel as EventLevel
3
3
  from gllm_core.event.handler import ConsoleEventHandler as ConsoleEventHandler, PrintEventHandler as PrintEventHandler, StreamEventHandler as StreamEventHandler
4
4
  from gllm_core.event.handler.event_handler import BaseEventHandler as BaseEventHandler
5
5
  from gllm_core.event.hook.event_hook import BaseEventHook as BaseEventHook
6
6
  from gllm_core.schema import Event as Event
7
7
  from gllm_core.utils import validate_string_enum as validate_string_enum
8
- from typing import Any, AsyncGenerator
8
+ from typing import AsyncGenerator
9
9
 
10
10
  class EventEmitter:
11
11
  '''Handles events emitting using event handlers with various levels and types.
@@ -123,31 +123,19 @@ class EventEmitter:
123
123
  Returns:
124
124
  EventEmitter: A new instance of the EventEmitter class with a single StreamEventHandler.
125
125
  """
126
- async def emit(self, value: str | dict[str, Any] | Event, event_level: EventLevel = ..., event_type: str = ..., metadata: dict[str, Any] | None = None, event_id: str | None = None, disabled_handlers: list[str] | None = None) -> None:
127
- '''Emits an event using the configured event handlers.
126
+ async def emit(self, event: Event, disabled_handlers: list[str] | None = None) -> None:
127
+ """Emits an event using the configured event handlers.
128
128
 
129
- If the value is an Event object, it is used directly and other parameters are ignored.
130
- Otherwise, a new Event object is created with the provided parameters. The event is
131
- then passed to all handlers except those listed in disabled_handlers. Events are only
132
- processed if their severity level meets or exceeds the EventEmitter\'s configured level.
129
+ Events are emitted by passing them to all handlers except those listed in disabled_handlers.
130
+ Events are only processed if their severity level meets or exceeds the EventEmitter's configured level.
133
131
 
134
132
  Args:
135
- value (str | dict[str, Any] | Event): The event value or Event object to emit. If an Event object
136
- is provided, other parameters are ignored and the Event is used as-is.
137
- event_level (EventLevel, optional): The severity level of the event.
138
- Defaults to EventLevel.DEBUG.
139
- event_type (str, optional): The type of event (e.g., "status", "response").
140
- Defaults to EventType.STATUS.value.
141
- metadata (dict[str, Any] | None, optional): Additional metadata for the event.
142
- Defaults to None, which creates an empty dictionary.
143
- event_id (str | None, optional): Unique identifier for the event.
144
- Defaults to None, which creates an empty string.
145
- disabled_handlers (list[str] | None, optional): Names of handlers to skip for
146
- this event. Defaults to None.
133
+ event (Event): The event to emit.
134
+ disabled_handlers (list[str] | None, optional): Names of handlers to skip for this event. Defaults to None.
147
135
 
148
136
  Raises:
149
137
  ValueError: If the provided event_level is not a valid EventLevel.
150
- '''
138
+ """
151
139
  async def close(self) -> None:
152
140
  """Closes all handlers in the handler list.
153
141
 
@@ -7,11 +7,8 @@ References:
7
7
  NONE
8
8
  """
9
9
 
10
- import json
11
-
12
10
  from rich.console import Console
13
11
 
14
- from gllm_core.constants import EventType
15
12
  from gllm_core.event.handler.event_handler import BaseEventHandler
16
13
  from gllm_core.schema import Event
17
14
 
@@ -47,13 +44,5 @@ class ConsoleEventHandler(BaseEventHandler):
47
44
  Raises:
48
45
  ValueError: If the event type is invalid.
49
46
  """
50
- # TODO: Refactor in v0.4
51
- if event.type == EventType.DATA:
52
- try:
53
- color = self._get_rich_color(json.loads(event.value)["data_type"])
54
- except (KeyError, json.JSONDecodeError):
55
- color = self._get_rich_color(event.type)
56
- else:
57
- color = self._get_rich_color(event.type)
58
-
47
+ color = self._get_rich_color(event.type)
59
48
  self.console.print(f"[{color}]{event.model_dump_json()}[/]")
@@ -1,5 +1,4 @@
1
1
  from _typeshed import Incomplete
2
- from gllm_core.constants import EventType as EventType
3
2
  from gllm_core.event.handler.event_handler import BaseEventHandler as BaseEventHandler
4
3
  from gllm_core.schema import Event as Event
5
4
 
@@ -7,7 +7,7 @@ References:
7
7
  NONE
8
8
  """
9
9
 
10
- import json
10
+ from typing import Any
11
11
 
12
12
  from rich.console import Console
13
13
  from rich.panel import Panel
@@ -34,7 +34,6 @@ class PrintEventHandler(BaseEventHandler):
34
34
  name: str | None = None,
35
35
  color_map: dict[str, str] | None = None,
36
36
  padding_char: str = "=",
37
- separator_length: int | None = None, # TODO: Remove in v0.4
38
37
  ):
39
38
  """Initializes a new instance of the PrintEventHandler class.
40
39
 
@@ -44,15 +43,11 @@ class PrintEventHandler(BaseEventHandler):
44
43
  color_map (dict[str, str], optional): The dictionary that maps certain event types to their corresponding
45
44
  colors in Rich format. Defaults to None, in which case the default color map will be used.
46
45
  padding_char (str, optional): The character to use for padding. Defaults to "=".
47
- separator_length (int | None, optional): Deprecated parameter. Defaults to None.
48
46
  """
49
47
  super().__init__(name, color_map)
50
48
  self.padding_char = padding_char
51
49
  self.console = Console(highlight=False)
52
50
 
53
- if separator_length is not None:
54
- self._logger.warning("The 'separator_length' parameter is deprecated and will be removed in v0.4.")
55
-
56
51
  async def emit(self, event: Event) -> None:
57
52
  """Emits the given event.
58
53
 
@@ -63,47 +58,15 @@ class PrintEventHandler(BaseEventHandler):
63
58
  self.console.print(f"[{event.level.name}][{event.timestamp}] {event.value}")
64
59
  return
65
60
 
66
- token_type, token_value = self._extract_token_data(event) # TODO: Remove in v0.4
67
-
68
- if token_type == EventType.ACTIVITY:
69
- self._print_activity(token_type, token_value)
70
- elif token_type.endswith(EventTypeSuffix.START) or token_type.endswith(EventTypeSuffix.END):
71
- self._print_start_end(token_type)
61
+ if event.type == EventType.ACTIVITY:
62
+ self._print_activity(event.value)
63
+ elif event.type.endswith(EventTypeSuffix.START) or event.type.endswith(EventTypeSuffix.END):
64
+ self._print_start_end(event.type)
72
65
  else:
73
- style = Style(color=self._get_rich_color(token_type))
74
- self.console.print(token_value, end="", style=style)
75
-
76
- # TODO: Remove in v0.4
77
- def _extract_token_data(self, event: Event) -> tuple[str, str]:
78
- """Extracts the token data from the event.
79
-
80
- This method extracts the token data from the event. If the event type is `EventType.DATA`, the token data
81
- are extracted further from the event value.
82
-
83
- Example:
84
- If the event value is `{"data_type": "data", "data_value": "test"}`:
85
- 1. The token type will be "data".
86
- 2. The token value will be "test".
87
-
88
- Args:
89
- event (Event): The event to be extracted.
90
-
91
- Returns:
92
- tuple[str, str]: The token type and value.
93
- """
94
- token_type, token_value = event.type, event.value
95
-
96
- if token_type == EventType.DATA:
97
- try:
98
- parsed_value = json.loads(token_value)
99
- token_type = parsed_value["data_type"]
100
- token_value = parsed_value["data_value"]
101
- except (json.JSONDecodeError, KeyError):
102
- token_type, token_value = event.type, event.value
103
-
104
- return token_type, token_value
66
+ style = Style(color=self._get_rich_color(event.type))
67
+ self.console.print(event.value, end="", style=style)
105
68
 
106
- def _print_activity(self, token_type: str, token_value: str) -> None:
69
+ def _print_activity(self, activity: dict[str, Any]) -> None:
107
70
  """Prints the activity.
108
71
 
109
72
  This method prints the activity with the following format:
@@ -115,24 +78,17 @@ class PrintEventHandler(BaseEventHandler):
115
78
  >>> key2: value2
116
79
 
117
80
  Args:
118
- token_type (str): The type of the token.
119
- token_value (str): The value of the token.
81
+ activity (dict[str, Any]): The activity to print.
120
82
  """
121
- # TODO: Refactor in v0.4
122
- try:
123
- activity = json.loads(token_value)
124
- except (TypeError, json.JSONDecodeError):
125
- activity = token_value
126
-
127
- color = self._get_rich_color(token_type)
128
- panel = self._create_separator_panel(token_type, color)
83
+ color = self._get_rich_color(EventType.ACTIVITY)
84
+ panel = self._create_separator_panel(EventType.ACTIVITY, color)
129
85
  self.console.print()
130
86
  self.console.print(panel)
131
87
 
132
88
  for key, value in activity.items():
133
89
  self.console.print(f">>> {key}: {value}", style=Style(color=color))
134
90
 
135
- def _print_start_end(self, token_type: str) -> None:
91
+ def _print_start_end(self, event_type: str) -> None:
136
92
  """Prints the start or end of block based events.
137
93
 
138
94
  This method prints the start or end of block based events with the following format:
@@ -146,10 +102,10 @@ class PrintEventHandler(BaseEventHandler):
146
102
  ╰───────────────────╯
147
103
 
148
104
  Args:
149
- token_type (str): The type of the token.
105
+ event_type (str): The type of the event.
150
106
  """
151
- color = self._get_rich_color(token_type)
152
- panel = self._create_separator_panel(token_type, color)
107
+ color = self._get_rich_color(event_type)
108
+ panel = self._create_separator_panel(event_type, color)
153
109
  self.console.print()
154
110
  self.console.print(panel)
155
111
 
@@ -15,7 +15,7 @@ class PrintEventHandler(BaseEventHandler):
15
15
  """
16
16
  padding_char: Incomplete
17
17
  console: Incomplete
18
- def __init__(self, name: str | None = None, color_map: dict[str, str] | None = None, padding_char: str = '=', separator_length: int | None = None) -> None:
18
+ def __init__(self, name: str | None = None, color_map: dict[str, str] | None = None, padding_char: str = '=') -> None:
19
19
  '''Initializes a new instance of the PrintEventHandler class.
20
20
 
21
21
  Args:
@@ -24,7 +24,6 @@ class PrintEventHandler(BaseEventHandler):
24
24
  color_map (dict[str, str], optional): The dictionary that maps certain event types to their corresponding
25
25
  colors in Rich format. Defaults to None, in which case the default color map will be used.
26
26
  padding_char (str, optional): The character to use for padding. Defaults to "=".
27
- separator_length (int | None, optional): Deprecated parameter. Defaults to None.
28
27
  '''
29
28
  async def emit(self, event: Event) -> None:
30
29
  """Emits the given event.
@@ -1,8 +1,8 @@
1
1
  """Modules concerning the schemas used throughout the Gen AI applications."""
2
2
 
3
3
  from gllm_core.schema.chunk import Chunk
4
- from gllm_core.schema.component import Component
4
+ from gllm_core.schema.component import Component, main
5
5
  from gllm_core.schema.event import Event
6
6
  from gllm_core.schema.tool import Tool, tool
7
7
 
8
- __all__ = ["Chunk", "Component", "Event", "Tool", "tool"]
8
+ __all__ = ["Chunk", "Component", "Event", "Tool", "main", "tool"]
@@ -1,6 +1,6 @@
1
1
  from gllm_core.schema.chunk import Chunk as Chunk
2
- from gllm_core.schema.component import Component as Component
2
+ from gllm_core.schema.component import Component as Component, main as main
3
3
  from gllm_core.schema.event import Event as Event
4
4
  from gllm_core.schema.tool import Tool as Tool, tool as tool
5
5
 
6
- __all__ = ['Chunk', 'Component', 'Event', 'Tool', 'tool']
6
+ __all__ = ['Chunk', 'Component', 'Event', 'Tool', 'main', 'tool']