glchat-plugin 0.4.3__py3-none-any.whl → 0.4.4__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.
- glchat_plugin/pipeline/pipeline_handler.py +76 -5
- glchat_plugin/pipeline/pipeline_plugin.py +16 -0
- glchat_plugin/pipeline/tool_processor.py +105 -0
- {glchat_plugin-0.4.3.dist-info → glchat_plugin-0.4.4.dist-info}/METADATA +1 -1
- {glchat_plugin-0.4.3.dist-info → glchat_plugin-0.4.4.dist-info}/RECORD +7 -6
- {glchat_plugin-0.4.3.dist-info → glchat_plugin-0.4.4.dist-info}/WHEEL +0 -0
- {glchat_plugin-0.4.3.dist-info → glchat_plugin-0.4.4.dist-info}/top_level.txt +0 -0
|
@@ -12,6 +12,7 @@ from typing import Any, Type
|
|
|
12
12
|
|
|
13
13
|
from bosa_core import Plugin
|
|
14
14
|
from bosa_core.plugin.handler import PluginHandler
|
|
15
|
+
from gllm_core.schema import Tool
|
|
15
16
|
from gllm_core.utils import LoggerManager
|
|
16
17
|
from gllm_inference.catalog import LMRequestProcessorCatalog, PromptBuilderCatalog
|
|
17
18
|
from gllm_pipeline.pipeline.pipeline import Pipeline
|
|
@@ -19,6 +20,7 @@ from pydantic import BaseModel, ConfigDict
|
|
|
19
20
|
|
|
20
21
|
from glchat_plugin.config.app_config import AppConfig
|
|
21
22
|
from glchat_plugin.config.constant import DEFAULT_ORGANIZATION_ID
|
|
23
|
+
from glchat_plugin.pipeline.tool_processor import ToolProcessor
|
|
22
24
|
from glchat_plugin.storage.base_chat_history_storage import BaseChatHistoryStorage
|
|
23
25
|
|
|
24
26
|
|
|
@@ -64,6 +66,73 @@ class ChatbotPresetMapping(BaseModel):
|
|
|
64
66
|
chatbot_preset_map: dict[str, PipelinePresetConfig]
|
|
65
67
|
|
|
66
68
|
|
|
69
|
+
class PipelineBundle:
|
|
70
|
+
"""Pipeline bundle.
|
|
71
|
+
|
|
72
|
+
Attributes:
|
|
73
|
+
pipeline (Pipeline): The pipeline.
|
|
74
|
+
tools (list[ToolProcessor]): The tools.
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
pipeline: Pipeline
|
|
78
|
+
tools: dict[str, ToolProcessor]
|
|
79
|
+
|
|
80
|
+
def __init__(self, pipeline: Pipeline, tools: list[ToolProcessor]):
|
|
81
|
+
"""Initialize the pipeline bundle.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
pipeline (Pipeline): The pipeline.
|
|
85
|
+
tools (list[ToolProcessor]): The tools.
|
|
86
|
+
"""
|
|
87
|
+
self.pipeline = pipeline
|
|
88
|
+
self.tools = {tool.name: tool for tool in tools}
|
|
89
|
+
|
|
90
|
+
async def invoke(self, **kwargs: Any) -> dict[str, Any]:
|
|
91
|
+
"""Invoke the pipeline bundle.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
kwargs (Any): The keyword arguments to pass to the pipeline.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
dict[str, Any]: The result of the pipeline invocation.
|
|
98
|
+
"""
|
|
99
|
+
return await self.pipeline.invoke(**kwargs)
|
|
100
|
+
|
|
101
|
+
async def invoke_as_tool(
|
|
102
|
+
self,
|
|
103
|
+
tool_name: str,
|
|
104
|
+
pipeline_config: dict[str, Any],
|
|
105
|
+
inputs: dict[str, Any],
|
|
106
|
+
config: dict[str, Any],
|
|
107
|
+
**kwargs: Any,
|
|
108
|
+
) -> Any:
|
|
109
|
+
"""Invoke the pipeline bundle as a tool.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
tool_name (str): The name of the tool.
|
|
113
|
+
pipeline_config (dict[str, Any]): The pipeline configuration.
|
|
114
|
+
inputs (dict[str, Any]): The inputs to the tool.
|
|
115
|
+
config (dict[str, Any]): The configuration of the tool.
|
|
116
|
+
kwargs (Any): The keyword arguments to pass to the tool.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
Any: The result of the tool invocation.
|
|
120
|
+
|
|
121
|
+
Raises:
|
|
122
|
+
ValueError: If the tool is not found in the pipeline bundle.
|
|
123
|
+
"""
|
|
124
|
+
tool = self.tools.get(tool_name)
|
|
125
|
+
if not tool:
|
|
126
|
+
raise ValueError(f"Tool `{tool_name}` not found in pipeline bundle")
|
|
127
|
+
|
|
128
|
+
return await tool.process(
|
|
129
|
+
pipeline_config=pipeline_config,
|
|
130
|
+
inputs=inputs,
|
|
131
|
+
config=config,
|
|
132
|
+
**kwargs,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
67
136
|
logger = LoggerManager().get_logger(__name__)
|
|
68
137
|
|
|
69
138
|
|
|
@@ -98,7 +167,7 @@ class PipelineHandler(PluginHandler):
|
|
|
98
167
|
_chatbot_configs: dict[tuple[str, str], ChatbotConfig] = {}
|
|
99
168
|
_builders: dict[tuple[str, str], Plugin] = {}
|
|
100
169
|
_plugins: dict[tuple[str, str], Plugin] = {}
|
|
101
|
-
_pipeline_cache: dict[tuple[str, str, str],
|
|
170
|
+
_pipeline_cache: dict[tuple[str, str, str], PipelineBundle] = {}
|
|
102
171
|
_chatbot_pipeline_keys: dict[tuple[str, str], set[tuple[str, str, str]]] = {}
|
|
103
172
|
_pipeline_build_errors: dict[tuple[str, str, str], str] = {}
|
|
104
173
|
|
|
@@ -218,9 +287,10 @@ class PipelineHandler(PluginHandler):
|
|
|
218
287
|
internal_plugin.lmrp_catalogs = instance._chatbot_configs[chatbot_organization_id].lmrp_catalogs
|
|
219
288
|
pipeline_config = instance._chatbot_configs[chatbot_organization_id].pipeline_config.copy()
|
|
220
289
|
pipeline = await internal_plugin.build(pipeline_config)
|
|
290
|
+
pipeline_tools = await internal_plugin.build_tools(pipeline_config)
|
|
221
291
|
pipeline_key = (chatbot_id, f"__{pipeline_type}__", organization_id)
|
|
222
292
|
instance._chatbot_pipeline_keys.setdefault(chatbot_organization_id, set()).add(pipeline_key)
|
|
223
|
-
instance._pipeline_cache[pipeline_key] = pipeline
|
|
293
|
+
instance._pipeline_cache[pipeline_key] = PipelineBundle(pipeline, pipeline_tools)
|
|
224
294
|
|
|
225
295
|
# Clear any previous error for this internal pipeline if build succeeded
|
|
226
296
|
instance._pipeline_build_errors.pop(pipeline_key, None)
|
|
@@ -252,9 +322,10 @@ class PipelineHandler(PluginHandler):
|
|
|
252
322
|
pipeline_config["api_key"] = credentials
|
|
253
323
|
|
|
254
324
|
pipeline = await plugin.build(pipeline_config)
|
|
325
|
+
pipeline_tools = await plugin.build_tools(pipeline_config)
|
|
255
326
|
pipeline_key = (chatbot_id, str(model_id), organization_id)
|
|
256
327
|
instance._chatbot_pipeline_keys.setdefault(chatbot_organization_id, set()).add(pipeline_key)
|
|
257
|
-
instance._pipeline_cache[pipeline_key] = pipeline
|
|
328
|
+
instance._pipeline_cache[pipeline_key] = PipelineBundle(pipeline, pipeline_tools)
|
|
258
329
|
|
|
259
330
|
# Clear any previous error for this pipeline if build succeeded
|
|
260
331
|
instance._pipeline_build_errors.pop(pipeline_key, None)
|
|
@@ -394,7 +465,7 @@ class PipelineHandler(PluginHandler):
|
|
|
394
465
|
|
|
395
466
|
async def aget_pipeline(
|
|
396
467
|
self, chatbot_id: str, model_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID
|
|
397
|
-
) ->
|
|
468
|
+
) -> PipelineBundle:
|
|
398
469
|
"""Get a pipeline instance for the given chatbot and model ID (async version).
|
|
399
470
|
|
|
400
471
|
Args:
|
|
@@ -403,7 +474,7 @@ class PipelineHandler(PluginHandler):
|
|
|
403
474
|
organization_id (str): The organization ID.
|
|
404
475
|
|
|
405
476
|
Returns:
|
|
406
|
-
|
|
477
|
+
PipelineBundle: The pipeline bundle instance.
|
|
407
478
|
|
|
408
479
|
Raises:
|
|
409
480
|
ValueError: If the chatbot ID is invalid.
|
|
@@ -11,11 +11,13 @@ from abc import ABC, abstractmethod
|
|
|
11
11
|
from typing import Any, Generic, Type, TypeVar
|
|
12
12
|
|
|
13
13
|
from bosa_core.plugin.plugin import Plugin
|
|
14
|
+
from gllm_core.schema import Tool
|
|
14
15
|
from gllm_inference.catalog.catalog import BaseCatalog
|
|
15
16
|
from gllm_pipeline.pipeline.pipeline import Pipeline
|
|
16
17
|
|
|
17
18
|
from glchat_plugin.config.constant import DEFAULT_ORGANIZATION_ID
|
|
18
19
|
from glchat_plugin.pipeline.pipeline_handler import PipelineHandler
|
|
20
|
+
from glchat_plugin.pipeline.tool_processor import ToolProcessor
|
|
19
21
|
|
|
20
22
|
PipelineState = TypeVar("PipelineState")
|
|
21
23
|
PipelinePresetConfig = TypeVar("PipelinePresetConfig", bound="BasePipelinePresetConfig")
|
|
@@ -131,3 +133,17 @@ class PipelineBuilderPlugin(Plugin, Generic[PipelineState, PipelinePresetConfig]
|
|
|
131
133
|
if self.preset_config_class:
|
|
132
134
|
return self.preset_config_class().model_dump()
|
|
133
135
|
return {}
|
|
136
|
+
|
|
137
|
+
async def build_tools(
|
|
138
|
+
self,
|
|
139
|
+
pipeline_config: dict[str, Any],
|
|
140
|
+
) -> list[ToolProcessor]:
|
|
141
|
+
"""Build a pipeline instance.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
pipeline_config (dict[str, Any]): Pipeline configuration including model name and other settings.
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
list[ToolProcessor]: Built tool processors.
|
|
148
|
+
"""
|
|
149
|
+
return []
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Tool processor.
|
|
2
|
+
|
|
3
|
+
This module provides a base class for tool processors.
|
|
4
|
+
|
|
5
|
+
Authors:
|
|
6
|
+
Surya Mahadi (surya.mahadi@gdplabs.id)
|
|
7
|
+
|
|
8
|
+
References:
|
|
9
|
+
None
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from abc import ABC, abstractmethod
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from gllm_core.schema import Tool
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ToolProcessor(ABC):
|
|
19
|
+
"""Tool processor.
|
|
20
|
+
|
|
21
|
+
This class is responsible for processing tools.
|
|
22
|
+
|
|
23
|
+
Attributes:
|
|
24
|
+
tool (Tool): The tool.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, tool: Tool):
|
|
28
|
+
"""Initialize the tool processor.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
tool (Tool): The tool.
|
|
32
|
+
"""
|
|
33
|
+
self.tool = tool
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def name(self) -> str:
|
|
37
|
+
"""Get the name of the tool.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
str: The name of the tool.
|
|
41
|
+
"""
|
|
42
|
+
return self.tool.name
|
|
43
|
+
|
|
44
|
+
@abstractmethod
|
|
45
|
+
async def preprocess(
|
|
46
|
+
self,
|
|
47
|
+
pipeline_config: dict[str, Any],
|
|
48
|
+
inputs: dict[str, Any],
|
|
49
|
+
config: dict[str, Any],
|
|
50
|
+
**kwargs: Any,
|
|
51
|
+
) -> tuple[dict[str, Any], dict[str, Any]]:
|
|
52
|
+
"""Process a tool.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
pipeline_config (dict[str, Any]): The pipeline configuration.
|
|
56
|
+
inputs (dict[str, Any]): The inputs to the tool.
|
|
57
|
+
config (dict[str, Any]): The configuration of the tool.
|
|
58
|
+
kwargs (Any): The keyword arguments to pass to the tool.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
tuple[dict[str, Any], dict[str, Any]]: The inputs and configuration for the tool invocation.
|
|
62
|
+
"""
|
|
63
|
+
raise NotImplementedError
|
|
64
|
+
|
|
65
|
+
@abstractmethod
|
|
66
|
+
async def postprocess(self, result: Any) -> dict[str, Any]:
|
|
67
|
+
"""Postprocess a tool for json friendly output.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
result (Any): The result of the tool invocation.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
dict[str, Any]: The result of the tool invocation.
|
|
74
|
+
"""
|
|
75
|
+
raise NotImplementedError
|
|
76
|
+
|
|
77
|
+
async def process(
|
|
78
|
+
self,
|
|
79
|
+
pipeline_config: dict[str, Any],
|
|
80
|
+
inputs: dict[str, Any],
|
|
81
|
+
config: dict[str, Any],
|
|
82
|
+
**kwargs: Any,
|
|
83
|
+
) -> Any:
|
|
84
|
+
"""Process a tool.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
pipeline_config (dict[str, Any]): The pipeline configuration.
|
|
88
|
+
inputs (dict[str, Any]): The inputs to the tool.
|
|
89
|
+
config (dict[str, Any]): The configuration of the tool.
|
|
90
|
+
kwargs (Any): The keyword arguments to pass to the tool.
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
Any: The result of the tool invocation.
|
|
94
|
+
"""
|
|
95
|
+
tool_input, config = await self.preprocess(
|
|
96
|
+
pipeline_config=pipeline_config,
|
|
97
|
+
inputs=inputs,
|
|
98
|
+
config=config,
|
|
99
|
+
**kwargs,
|
|
100
|
+
)
|
|
101
|
+
result = await self.tool.invoke(
|
|
102
|
+
input=tool_input,
|
|
103
|
+
context=config,
|
|
104
|
+
)
|
|
105
|
+
return await self.postprocess(result)
|
|
@@ -8,8 +8,9 @@ glchat_plugin/handler/__init__.py,sha256=H5DJaAfwwtRsvMcOaEzHfGMQk25H7la0E7uPfks
|
|
|
8
8
|
glchat_plugin/handler/base_post_login_handler.py,sha256=48xSbe_LwTCjRY-lCuzWXqbnEr1ql8bAhQih1Xeh8f8,2835
|
|
9
9
|
glchat_plugin/pipeline/__init__.py,sha256=Sk-NfIGyA9VKIg0Bt5OHatNUYyWVPh9i5xhE5DFAfbo,41
|
|
10
10
|
glchat_plugin/pipeline/base_pipeline_preset_config.py,sha256=lbMH8y_HU3LrqtMYXLzQ2906ZkMXARKY5vBuIGvRVdA,2969
|
|
11
|
-
glchat_plugin/pipeline/pipeline_handler.py,sha256=
|
|
12
|
-
glchat_plugin/pipeline/pipeline_plugin.py,sha256=
|
|
11
|
+
glchat_plugin/pipeline/pipeline_handler.py,sha256=BaGnbH4sy0DXyoZpeAlp6gWmqJMZlg7W9KpxCSMu-u8,36527
|
|
12
|
+
glchat_plugin/pipeline/pipeline_plugin.py,sha256=fDQWJkEMgbbY6bK81gHjzp3fLZZN0a0Pv6_DS4wSKL0,5040
|
|
13
|
+
glchat_plugin/pipeline/tool_processor.py,sha256=pc-uHoBqOSXjLM8R_Wgws_z5ehPtaSeb9Bhk9aeLDus,2731
|
|
13
14
|
glchat_plugin/service/__init__.py,sha256=9T4qzyYL052qLqva5el1F575OTRNaaf9tb9UvW-leTc,47
|
|
14
15
|
glchat_plugin/service/base_rate_limiter_service.py,sha256=tgKwdr4EqnGo5iDRVJPnlg8W9q0hiUzfeewAtdW4IjU,1232
|
|
15
16
|
glchat_plugin/service/base_tenant_service.py,sha256=CB-jJWXi87nTcjO1XhPoSgNMf2YA_LfXoHr30ye0VtI,734
|
|
@@ -19,7 +20,7 @@ glchat_plugin/storage/base_anonymizer_storage.py,sha256=oFwovWrsjM7v1YjeN-4p-M3O
|
|
|
19
20
|
glchat_plugin/storage/base_chat_history_storage.py,sha256=YIGM8zv7s5BQ8O7W1LfaLyQW4SF9Bt3aolowsoDaQw8,11257
|
|
20
21
|
glchat_plugin/tools/__init__.py,sha256=OFotHbgQ8mZEbdlvlv5aVMdxfubPvkVWAcTwhIPdIqQ,542
|
|
21
22
|
glchat_plugin/tools/decorators.py,sha256=AvQBV18wzXWdC483RSSmpfh92zsqTyp8SzDLIkreIGU,3925
|
|
22
|
-
glchat_plugin-0.4.
|
|
23
|
-
glchat_plugin-0.4.
|
|
24
|
-
glchat_plugin-0.4.
|
|
25
|
-
glchat_plugin-0.4.
|
|
23
|
+
glchat_plugin-0.4.4.dist-info/METADATA,sha256=bQlhz2exJI-pcGGfjYFNpbdV5kMSePxbdCYhO6cvxZo,2063
|
|
24
|
+
glchat_plugin-0.4.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
25
|
+
glchat_plugin-0.4.4.dist-info/top_level.txt,sha256=fzKSXmct5dY4CAKku4-mkdHX-QPAyQVvo8vpQj8qizY,14
|
|
26
|
+
glchat_plugin-0.4.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|