glchat-plugin 0.3.10__py3-none-any.whl → 0.4.1__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/config/constant.py +2 -0
- glchat_plugin/context/context_manager.py +0 -48
- glchat_plugin/pipeline/pipeline_handler.py +208 -149
- glchat_plugin/pipeline/pipeline_plugin.py +3 -0
- glchat_plugin/service/base_user_service.py +0 -16
- {glchat_plugin-0.3.10.dist-info → glchat_plugin-0.4.1.dist-info}/METADATA +1 -1
- {glchat_plugin-0.3.10.dist-info → glchat_plugin-0.4.1.dist-info}/RECORD +9 -9
- {glchat_plugin-0.3.10.dist-info → glchat_plugin-0.4.1.dist-info}/WHEEL +0 -0
- {glchat_plugin-0.3.10.dist-info → glchat_plugin-0.4.1.dist-info}/top_level.txt +0 -0
glchat_plugin/config/constant.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""Provides a class for context manager.
|
|
2
2
|
|
|
3
3
|
Authors:
|
|
4
|
-
Ricky Setiawan (ricky.setiawan@gdplabs.id)
|
|
5
4
|
Ryan Ignatius Hadiwijaya (ryan.i.hadiwijaya@gdplabs.id)
|
|
6
5
|
|
|
7
6
|
References:
|
|
@@ -9,7 +8,6 @@ References:
|
|
|
9
8
|
"""
|
|
10
9
|
|
|
11
10
|
from contextvars import ContextVar
|
|
12
|
-
from typing import Any
|
|
13
11
|
|
|
14
12
|
|
|
15
13
|
class ContextManager:
|
|
@@ -20,8 +18,6 @@ class ContextManager:
|
|
|
20
18
|
|
|
21
19
|
_tenant: ContextVar[str | None] = ContextVar("tenant_id", default=None)
|
|
22
20
|
_user: ContextVar[str | None] = ContextVar("user_id", default=None)
|
|
23
|
-
_user_session: ContextVar[Any | None] = ContextVar("user_session", default=None)
|
|
24
|
-
_request_id: ContextVar[str | None] = ContextVar("request_id", default=None)
|
|
25
21
|
|
|
26
22
|
@classmethod
|
|
27
23
|
def set_tenant(cls, tenant_id: str | None) -> None:
|
|
@@ -59,47 +55,3 @@ class ContextManager:
|
|
|
59
55
|
str | None: The user id.
|
|
60
56
|
"""
|
|
61
57
|
return cls._user.get()
|
|
62
|
-
|
|
63
|
-
@classmethod
|
|
64
|
-
def set_user_session(cls, user_session: Any | None) -> None:
|
|
65
|
-
"""Set the user session in the context.
|
|
66
|
-
|
|
67
|
-
Args:
|
|
68
|
-
user_session (Any | None): The user session.
|
|
69
|
-
"""
|
|
70
|
-
cls._user_session.set(user_session)
|
|
71
|
-
|
|
72
|
-
@classmethod
|
|
73
|
-
def get_user_session(cls) -> Any | None:
|
|
74
|
-
"""Get the user session from the context.
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
Any | None: The user session.
|
|
78
|
-
"""
|
|
79
|
-
return cls._user_session.get()
|
|
80
|
-
|
|
81
|
-
@classmethod
|
|
82
|
-
def set_request_id(cls, request_id: str | None) -> None:
|
|
83
|
-
"""Set the request id in the context.
|
|
84
|
-
|
|
85
|
-
Args:
|
|
86
|
-
request_id (str | None): The request id.
|
|
87
|
-
"""
|
|
88
|
-
cls._request_id.set(request_id)
|
|
89
|
-
|
|
90
|
-
@classmethod
|
|
91
|
-
def get_request_id(cls) -> str | None:
|
|
92
|
-
"""Get the request id from the context.
|
|
93
|
-
|
|
94
|
-
Returns:
|
|
95
|
-
str | None: The request id.
|
|
96
|
-
"""
|
|
97
|
-
return cls._request_id.get()
|
|
98
|
-
|
|
99
|
-
@classmethod
|
|
100
|
-
def clear(cls) -> None:
|
|
101
|
-
"""Clear the context."""
|
|
102
|
-
cls._tenant.set(None)
|
|
103
|
-
cls._user.set(None)
|
|
104
|
-
cls._user_session.set(None)
|
|
105
|
-
cls._request_id.set(None)
|
|
@@ -18,6 +18,7 @@ from gllm_pipeline.pipeline.pipeline import Pipeline
|
|
|
18
18
|
from pydantic import BaseModel, ConfigDict
|
|
19
19
|
|
|
20
20
|
from glchat_plugin.config.app_config import AppConfig
|
|
21
|
+
from glchat_plugin.config.constant import DEFAULT_ORGANIZATION_ID
|
|
21
22
|
from glchat_plugin.storage.base_chat_history_storage import BaseChatHistoryStorage
|
|
22
23
|
|
|
23
24
|
|
|
@@ -75,32 +76,37 @@ class PipelineHandler(PluginHandler):
|
|
|
75
76
|
This handler manages pipeline builder plugins and provides caching for built pipelines.
|
|
76
77
|
|
|
77
78
|
Attributes:
|
|
78
|
-
app_config (AppConfig): Application configuration.
|
|
79
|
-
_activated_configs (dict[str, ChatbotPresetMapping]):
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
app_config (dict[str, AppConfig]): Application configuration.
|
|
80
|
+
_activated_configs (dict[tuple[str, str], ChatbotPresetMapping]):
|
|
81
|
+
Collection of chatbot preset mapping by pipeline types.
|
|
82
|
+
_chatbot_configs (dict[tuple[str, str], ChatbotConfig]):
|
|
83
|
+
Mapping of chatbot IDs to their configurations.
|
|
84
|
+
_builders (dict[tuple[str, str], Plugin]):
|
|
85
|
+
Mapping of chatbot IDs to their pipeline builder plugins.
|
|
86
|
+
_plugins (dict[tuple[str, str], Plugin]):
|
|
87
|
+
Mapping of pipeline types to their plugins.
|
|
88
|
+
_pipeline_cache (dict[tuple[str, str, str], Pipeline]):
|
|
89
|
+
Cache mapping (chatbot_id, model_id, organization_id) to Pipeline instances.
|
|
90
|
+
_chatbot_pipeline_keys (dict[tuple[str, str], set[tuple[str, str, str]]]):
|
|
91
|
+
Mapping of chatbot IDs to their pipeline keys.
|
|
92
|
+
_pipeline_build_errors (dict[tuple[str, str, str], str]):
|
|
93
|
+
Cache mapping (chatbot_id, model_id, organization_id) to error messages from failed pipeline builds.
|
|
88
94
|
"""
|
|
89
95
|
|
|
90
|
-
app_config: AppConfig
|
|
91
|
-
_activated_configs: dict[str, ChatbotPresetMapping] = {}
|
|
92
|
-
_chatbot_configs: dict[str, ChatbotConfig] = {}
|
|
93
|
-
_builders: dict[str, Plugin] = {}
|
|
94
|
-
_plugins: dict[str, Plugin] = {}
|
|
95
|
-
_pipeline_cache: dict[tuple[str, str], Pipeline] = {}
|
|
96
|
-
_chatbot_pipeline_keys: dict[str, set[tuple[str, str]]] = {}
|
|
97
|
-
_pipeline_build_errors: dict[tuple[str, str], str] = {}
|
|
96
|
+
app_config: dict[str, AppConfig] = {}
|
|
97
|
+
_activated_configs: dict[tuple[str, str], ChatbotPresetMapping] = {}
|
|
98
|
+
_chatbot_configs: dict[tuple[str, str], ChatbotConfig] = {}
|
|
99
|
+
_builders: dict[tuple[str, str], Plugin] = {}
|
|
100
|
+
_plugins: dict[tuple[str, str], Plugin] = {}
|
|
101
|
+
_pipeline_cache: dict[tuple[str, str, str], Pipeline] = {}
|
|
102
|
+
_chatbot_pipeline_keys: dict[tuple[str, str], set[tuple[str, str, str]]] = {}
|
|
103
|
+
_pipeline_build_errors: dict[tuple[str, str, str], str] = {}
|
|
98
104
|
|
|
99
|
-
def __init__(self, app_config: AppConfig, chat_history_storage: BaseChatHistoryStorage):
|
|
105
|
+
def __init__(self, app_config: dict[str, AppConfig], chat_history_storage: BaseChatHistoryStorage):
|
|
100
106
|
"""Initialize the pipeline handler.
|
|
101
107
|
|
|
102
108
|
Args:
|
|
103
|
-
app_config (AppConfig): Application configuration.
|
|
109
|
+
app_config (dict[str, AppConfig]): Application configuration.
|
|
104
110
|
chat_history_storage (BaseChatHistoryStorage): Chat history storage.
|
|
105
111
|
"""
|
|
106
112
|
self.app_config = app_config
|
|
@@ -118,7 +124,6 @@ class PipelineHandler(PluginHandler):
|
|
|
118
124
|
dict[Type[Any], Any]: Dictionary mapping service types to their instances.
|
|
119
125
|
"""
|
|
120
126
|
return {
|
|
121
|
-
AppConfig: instance.app_config,
|
|
122
127
|
BaseChatHistoryStorage: instance.chat_history_storage,
|
|
123
128
|
}
|
|
124
129
|
|
|
@@ -147,15 +152,18 @@ class PipelineHandler(PluginHandler):
|
|
|
147
152
|
plugin (Plugin): The pipeline builder plugin instance.
|
|
148
153
|
"""
|
|
149
154
|
pipeline_type = plugin.name
|
|
150
|
-
|
|
155
|
+
organization_id = plugin.organization_id
|
|
156
|
+
pipeline_type_organization_id = (pipeline_type, organization_id)
|
|
157
|
+
instance._plugins[pipeline_type_organization_id] = plugin
|
|
151
158
|
|
|
152
|
-
if
|
|
159
|
+
if pipeline_type_organization_id not in instance._activated_configs:
|
|
153
160
|
return
|
|
154
161
|
|
|
155
|
-
active_config = instance._activated_configs[
|
|
162
|
+
active_config = instance._activated_configs[pipeline_type_organization_id]
|
|
156
163
|
for chatbot_id, preset in active_config.chatbot_preset_map.items():
|
|
157
164
|
try:
|
|
158
|
-
|
|
165
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
166
|
+
if pipeline_type != instance._chatbot_configs[chatbot_organization_id].pipeline_type:
|
|
159
167
|
continue
|
|
160
168
|
|
|
161
169
|
await cls._build_plugin(instance, chatbot_id, preset.supported_models, plugin)
|
|
@@ -188,22 +196,25 @@ class PipelineHandler(PluginHandler):
|
|
|
188
196
|
supported_models (list[dict[str, Any]]): List of models (including config).
|
|
189
197
|
plugin (Plugin): The pipeline builder plugin instance.
|
|
190
198
|
"""
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
instance.
|
|
199
|
+
organization_id = plugin.organization_id
|
|
200
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
201
|
+
plugin.prompt_builder_catalogs = instance._chatbot_configs[chatbot_organization_id].prompt_builder_catalogs
|
|
202
|
+
plugin.lmrp_catalogs = instance._chatbot_configs[chatbot_organization_id].lmrp_catalogs
|
|
203
|
+
instance._builders[chatbot_organization_id] = plugin
|
|
194
204
|
|
|
195
205
|
for pipeline_type in INTERNAL_PIPELINES:
|
|
196
|
-
|
|
206
|
+
pipeline_type_organization_id = (pipeline_type, organization_id)
|
|
207
|
+
internal_plugin = instance._plugins.get(pipeline_type_organization_id)
|
|
197
208
|
if internal_plugin:
|
|
198
209
|
try:
|
|
199
210
|
internal_plugin.prompt_builder_catalogs = instance._chatbot_configs[
|
|
200
|
-
|
|
211
|
+
chatbot_organization_id
|
|
201
212
|
].prompt_builder_catalogs
|
|
202
|
-
internal_plugin.lmrp_catalogs = instance._chatbot_configs[
|
|
203
|
-
pipeline_config = instance._chatbot_configs[
|
|
213
|
+
internal_plugin.lmrp_catalogs = instance._chatbot_configs[chatbot_organization_id].lmrp_catalogs
|
|
214
|
+
pipeline_config = instance._chatbot_configs[chatbot_organization_id].pipeline_config.copy()
|
|
204
215
|
pipeline = await internal_plugin.build(pipeline_config)
|
|
205
|
-
pipeline_key = (chatbot_id, f"__{pipeline_type}__")
|
|
206
|
-
instance._chatbot_pipeline_keys.setdefault(
|
|
216
|
+
pipeline_key = (chatbot_id, f"__{pipeline_type}__", organization_id)
|
|
217
|
+
instance._chatbot_pipeline_keys.setdefault(chatbot_organization_id, set()).add(pipeline_key)
|
|
207
218
|
instance._pipeline_cache[pipeline_key] = pipeline
|
|
208
219
|
|
|
209
220
|
# Clear any previous error for this internal pipeline if build succeeded
|
|
@@ -216,7 +227,9 @@ class PipelineHandler(PluginHandler):
|
|
|
216
227
|
logger.warning(error_message)
|
|
217
228
|
|
|
218
229
|
# Store the error message for later retrieval
|
|
219
|
-
instance._store_pipeline_build_error(
|
|
230
|
+
instance._store_pipeline_build_error(
|
|
231
|
+
chatbot_id, f"__{pipeline_type}__", organization_id, error_message
|
|
232
|
+
)
|
|
220
233
|
|
|
221
234
|
for model in supported_models:
|
|
222
235
|
try:
|
|
@@ -224,7 +237,7 @@ class PipelineHandler(PluginHandler):
|
|
|
224
237
|
if not model_id:
|
|
225
238
|
continue
|
|
226
239
|
|
|
227
|
-
pipeline_config = instance._chatbot_configs[
|
|
240
|
+
pipeline_config = instance._chatbot_configs[chatbot_organization_id].pipeline_config.copy()
|
|
228
241
|
# use original model name
|
|
229
242
|
pipeline_config["model_name"] = model.get("name", model_id)
|
|
230
243
|
pipeline_config["model_kwargs"] = model.get("model_kwargs", {})
|
|
@@ -234,8 +247,8 @@ class PipelineHandler(PluginHandler):
|
|
|
234
247
|
pipeline_config["api_key"] = credentials
|
|
235
248
|
|
|
236
249
|
pipeline = await plugin.build(pipeline_config)
|
|
237
|
-
pipeline_key = (chatbot_id, str(model_id))
|
|
238
|
-
instance._chatbot_pipeline_keys.setdefault(
|
|
250
|
+
pipeline_key = (chatbot_id, str(model_id), organization_id)
|
|
251
|
+
instance._chatbot_pipeline_keys.setdefault(chatbot_organization_id, set()).add(pipeline_key)
|
|
239
252
|
instance._pipeline_cache[pipeline_key] = pipeline
|
|
240
253
|
|
|
241
254
|
# Clear any previous error for this pipeline if build succeeded
|
|
@@ -246,13 +259,14 @@ class PipelineHandler(PluginHandler):
|
|
|
246
259
|
logger.warning(error_message)
|
|
247
260
|
|
|
248
261
|
# Store the error message for later retrieval
|
|
249
|
-
instance._store_pipeline_build_error(chatbot_id, str(model_id), error_message)
|
|
262
|
+
instance._store_pipeline_build_error(chatbot_id, str(model_id), organization_id, error_message)
|
|
250
263
|
|
|
251
|
-
def get_pipeline_builder(self, chatbot_id: str) -> Plugin:
|
|
264
|
+
def get_pipeline_builder(self, chatbot_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID) -> Plugin:
|
|
252
265
|
"""Get a pipeline builder instance for the given chatbot.
|
|
253
266
|
|
|
254
267
|
Args:
|
|
255
268
|
chatbot_id (str): The chatbot ID.
|
|
269
|
+
organization_id (str): The organization ID.
|
|
256
270
|
|
|
257
271
|
Returns:
|
|
258
272
|
Plugin: The pipeline builder instance.
|
|
@@ -260,37 +274,45 @@ class PipelineHandler(PluginHandler):
|
|
|
260
274
|
Raises:
|
|
261
275
|
ValueError: If the chatbot ID is invalid or the model name is not supported.
|
|
262
276
|
"""
|
|
263
|
-
|
|
264
|
-
|
|
277
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
278
|
+
if chatbot_organization_id not in self._builders:
|
|
279
|
+
logger.warning(
|
|
280
|
+
f"Pipeline builder not found for chatbot `{chatbot_organization_id}`, attempting to rebuild..."
|
|
281
|
+
)
|
|
265
282
|
# Try to rebuild the plugin if it's not found
|
|
266
|
-
self._try_rebuild_plugin(chatbot_id)
|
|
283
|
+
self._try_rebuild_plugin(chatbot_id, organization_id)
|
|
267
284
|
|
|
268
|
-
if
|
|
269
|
-
raise ValueError(
|
|
285
|
+
if chatbot_organization_id not in self._builders:
|
|
286
|
+
raise ValueError(
|
|
287
|
+
f"Pipeline builder for chatbot `{chatbot_organization_id}` not found and could not be rebuilt"
|
|
288
|
+
)
|
|
270
289
|
|
|
271
|
-
return self._builders[
|
|
290
|
+
return self._builders[chatbot_organization_id]
|
|
272
291
|
|
|
273
|
-
def _try_rebuild_plugin(self, chatbot_id: str) -> None:
|
|
292
|
+
def _try_rebuild_plugin(self, chatbot_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID) -> None:
|
|
274
293
|
"""Try to rebuild a plugin for the given chatbot.
|
|
275
294
|
|
|
276
295
|
Args:
|
|
277
296
|
chatbot_id (str): The chatbot ID.
|
|
297
|
+
organization_id (str): The organization ID.
|
|
278
298
|
"""
|
|
299
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
279
300
|
try:
|
|
280
301
|
# Check if we have the chatbot configuration
|
|
281
|
-
if
|
|
282
|
-
logger.warning(f"Chatbot configuration not found for `{
|
|
302
|
+
if chatbot_organization_id not in self._chatbot_configs:
|
|
303
|
+
logger.warning(f"Chatbot configuration not found for `{chatbot_organization_id}`")
|
|
283
304
|
return
|
|
284
305
|
|
|
285
|
-
chatbot_config = self._chatbot_configs[
|
|
306
|
+
chatbot_config = self._chatbot_configs[chatbot_organization_id]
|
|
286
307
|
pipeline_type = chatbot_config.pipeline_type
|
|
308
|
+
pipeline_organization_id = (pipeline_type, organization_id)
|
|
287
309
|
|
|
288
310
|
# Check if we have the plugin for this pipeline type
|
|
289
|
-
if
|
|
290
|
-
logger.warning(f"Plugin not found for pipeline type `{
|
|
311
|
+
if pipeline_organization_id not in self._plugins:
|
|
312
|
+
logger.warning(f"Plugin not found for pipeline type `{pipeline_organization_id}`")
|
|
291
313
|
return
|
|
292
314
|
|
|
293
|
-
plugin = self._plugins[
|
|
315
|
+
plugin = self._plugins[pipeline_organization_id]
|
|
294
316
|
|
|
295
317
|
# Get supported models from the configuration
|
|
296
318
|
supported_models = list(chatbot_config.pipeline_config.get("supported_models", {}).values())
|
|
@@ -303,36 +325,40 @@ class PipelineHandler(PluginHandler):
|
|
|
303
325
|
# Set the catalogs
|
|
304
326
|
plugin.prompt_builder_catalogs = chatbot_config.prompt_builder_catalogs
|
|
305
327
|
plugin.lmrp_catalogs = chatbot_config.lmrp_catalogs
|
|
306
|
-
self._builders[
|
|
328
|
+
self._builders[chatbot_organization_id] = plugin
|
|
307
329
|
|
|
308
|
-
logger.info(f"Successfully rebuilt pipeline builder for chatbot `{
|
|
330
|
+
logger.info(f"Successfully rebuilt pipeline builder for chatbot `{chatbot_organization_id}`")
|
|
309
331
|
|
|
310
332
|
except Exception as e:
|
|
311
|
-
logger.warning(f"Error rebuilding plugin for chatbot `{
|
|
333
|
+
logger.warning(f"Error rebuilding plugin for chatbot `{chatbot_organization_id}`: {e}")
|
|
312
334
|
|
|
313
|
-
async def _async_rebuild_pipeline(
|
|
335
|
+
async def _async_rebuild_pipeline(
|
|
336
|
+
self, chatbot_id: str, model_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID
|
|
337
|
+
) -> None:
|
|
314
338
|
"""Asynchronously rebuild a pipeline for the given chatbot and model.
|
|
315
339
|
|
|
316
340
|
Args:
|
|
317
341
|
chatbot_id (str): The chatbot ID.
|
|
318
342
|
model_id (str): The model ID.
|
|
343
|
+
organization_id (str): The organization ID.
|
|
319
344
|
"""
|
|
345
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
320
346
|
try:
|
|
321
347
|
# First, ensure we have the pipeline builder
|
|
322
|
-
if
|
|
323
|
-
await self._async_rebuild_plugin(chatbot_id)
|
|
348
|
+
if chatbot_organization_id not in self._builders:
|
|
349
|
+
await self._async_rebuild_plugin(chatbot_id, organization_id)
|
|
324
350
|
|
|
325
|
-
if
|
|
326
|
-
logger.warning(f"Could not rebuild pipeline builder for chatbot `{
|
|
351
|
+
if chatbot_organization_id not in self._builders:
|
|
352
|
+
logger.warning(f"Could not rebuild pipeline builder for chatbot `{chatbot_organization_id}`")
|
|
327
353
|
return
|
|
328
354
|
|
|
329
355
|
# Check if we have the chatbot configuration
|
|
330
|
-
if
|
|
331
|
-
logger.warning(f"Chatbot configuration not found for `{
|
|
356
|
+
if chatbot_organization_id not in self._chatbot_configs:
|
|
357
|
+
logger.warning(f"Chatbot configuration not found for `{chatbot_organization_id}`")
|
|
332
358
|
return
|
|
333
359
|
|
|
334
|
-
chatbot_config = self._chatbot_configs[
|
|
335
|
-
plugin = self._builders[
|
|
360
|
+
chatbot_config = self._chatbot_configs[chatbot_organization_id]
|
|
361
|
+
plugin = self._builders[chatbot_organization_id]
|
|
336
362
|
|
|
337
363
|
# Find the model configuration
|
|
338
364
|
supported_models = list(chatbot_config.pipeline_config.get("supported_models", {}).values())
|
|
@@ -352,21 +378,24 @@ class PipelineHandler(PluginHandler):
|
|
|
352
378
|
# Use the existing _build_plugin method to rebuild the pipeline
|
|
353
379
|
await __class__._build_plugin(self, chatbot_id, [model_config], plugin)
|
|
354
380
|
|
|
355
|
-
logger.info(f"Successfully rebuilt pipeline for chatbot `{
|
|
381
|
+
logger.info(f"Successfully rebuilt pipeline for chatbot `{chatbot_organization_id}` model `{model_id}`")
|
|
356
382
|
|
|
357
383
|
except Exception as e:
|
|
358
|
-
error_message = f"Error rebuilding pipeline for chatbot `{
|
|
384
|
+
error_message = f"Error rebuilding pipeline for chatbot `{chatbot_organization_id}` model `{model_id}`: {e}"
|
|
359
385
|
logger.warning(error_message)
|
|
360
386
|
|
|
361
387
|
# Store the error message for later retrieval
|
|
362
|
-
self._store_pipeline_build_error(chatbot_id, model_id, error_message)
|
|
388
|
+
self._store_pipeline_build_error(chatbot_id, model_id, organization_id, error_message)
|
|
363
389
|
|
|
364
|
-
async def aget_pipeline(
|
|
390
|
+
async def aget_pipeline(
|
|
391
|
+
self, chatbot_id: str, model_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID
|
|
392
|
+
) -> Pipeline:
|
|
365
393
|
"""Get a pipeline instance for the given chatbot and model ID (async version).
|
|
366
394
|
|
|
367
395
|
Args:
|
|
368
396
|
chatbot_id (str): The chatbot ID.
|
|
369
397
|
model_id (str): The model ID to use for inference.
|
|
398
|
+
organization_id (str): The organization ID.
|
|
370
399
|
|
|
371
400
|
Returns:
|
|
372
401
|
Pipeline: The pipeline instance.
|
|
@@ -374,18 +403,18 @@ class PipelineHandler(PluginHandler):
|
|
|
374
403
|
Raises:
|
|
375
404
|
ValueError: If the chatbot ID is invalid.
|
|
376
405
|
"""
|
|
377
|
-
pipeline_key = (chatbot_id, str(model_id))
|
|
406
|
+
pipeline_key = (chatbot_id, str(model_id), organization_id)
|
|
378
407
|
|
|
379
408
|
if pipeline_key not in self._pipeline_cache:
|
|
380
409
|
logger.warning(
|
|
381
410
|
f"Pipeline not found for chatbot `{chatbot_id}` model `{model_id}`, attempting to rebuild..."
|
|
382
411
|
)
|
|
383
412
|
# Try to rebuild the pipeline if it's not found
|
|
384
|
-
await self._async_rebuild_pipeline(chatbot_id, str(model_id))
|
|
413
|
+
await self._async_rebuild_pipeline(chatbot_id, str(model_id), organization_id)
|
|
385
414
|
|
|
386
415
|
if pipeline_key not in self._pipeline_cache:
|
|
387
416
|
# Check if there's a stored error message for this pipeline
|
|
388
|
-
stored_error = self.get_pipeline_build_error(chatbot_id, str(model_id))
|
|
417
|
+
stored_error = self.get_pipeline_build_error(chatbot_id, str(model_id), organization_id)
|
|
389
418
|
if stored_error:
|
|
390
419
|
raise ValueError(
|
|
391
420
|
f"Pipeline for chatbot `{chatbot_id}` model `{model_id}` not found and could not be rebuilt. "
|
|
@@ -398,11 +427,12 @@ class PipelineHandler(PluginHandler):
|
|
|
398
427
|
|
|
399
428
|
return self._pipeline_cache[pipeline_key]
|
|
400
429
|
|
|
401
|
-
def get_pipeline_config(self, chatbot_id: str) -> dict[str, Any]:
|
|
430
|
+
def get_pipeline_config(self, chatbot_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID) -> dict[str, Any]:
|
|
402
431
|
"""Get the pipeline configuration by chatbot ID.
|
|
403
432
|
|
|
404
433
|
Args:
|
|
405
434
|
chatbot_id (str): The chatbot ID.
|
|
435
|
+
organization_id (str): The organization ID.
|
|
406
436
|
|
|
407
437
|
Returns:
|
|
408
438
|
dict[str, Any]: The pipeline configuration.
|
|
@@ -410,22 +440,24 @@ class PipelineHandler(PluginHandler):
|
|
|
410
440
|
Raises:
|
|
411
441
|
ValueError: If the chatbot or pipeline is not found.
|
|
412
442
|
"""
|
|
413
|
-
self._validate_pipeline(chatbot_id)
|
|
414
|
-
return self._chatbot_configs[chatbot_id].pipeline_config
|
|
443
|
+
self._validate_pipeline(chatbot_id, organization_id)
|
|
444
|
+
return self._chatbot_configs[(chatbot_id, organization_id)].pipeline_config
|
|
415
445
|
|
|
416
|
-
def get_pipeline_type(self, chatbot_id: str) -> str:
|
|
446
|
+
def get_pipeline_type(self, chatbot_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID) -> str:
|
|
417
447
|
"""Get the pipeline type for the given chatbot.
|
|
418
448
|
|
|
419
449
|
Args:
|
|
420
450
|
chatbot_id (str): The chatbot ID.
|
|
451
|
+
organization_id (str): The organization ID.
|
|
421
452
|
"""
|
|
422
|
-
return self._chatbot_configs[chatbot_id].pipeline_type
|
|
453
|
+
return self._chatbot_configs[(chatbot_id, organization_id)].pipeline_type
|
|
423
454
|
|
|
424
|
-
def get_use_docproc(self, chatbot_id: str) -> bool:
|
|
455
|
+
def get_use_docproc(self, chatbot_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID) -> bool:
|
|
425
456
|
"""Get whether DocProc should be used for this chatbot.
|
|
426
457
|
|
|
427
458
|
Args:
|
|
428
459
|
chatbot_id (str): The chatbot ID.
|
|
460
|
+
organization_id (str): The organization ID.
|
|
429
461
|
|
|
430
462
|
Returns:
|
|
431
463
|
bool: Whether DocProc should be used.
|
|
@@ -433,15 +465,16 @@ class PipelineHandler(PluginHandler):
|
|
|
433
465
|
Raises:
|
|
434
466
|
ValueError: If the chatbot or pipeline is not found.
|
|
435
467
|
"""
|
|
436
|
-
self._validate_pipeline(chatbot_id)
|
|
437
|
-
config = self._chatbot_configs[chatbot_id].pipeline_config
|
|
468
|
+
self._validate_pipeline(chatbot_id, organization_id)
|
|
469
|
+
config = self._chatbot_configs[(chatbot_id, organization_id)].pipeline_config
|
|
438
470
|
return config["use_docproc"]
|
|
439
471
|
|
|
440
|
-
def get_max_file_size(self, chatbot_id: str) -> int | None:
|
|
472
|
+
def get_max_file_size(self, chatbot_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID) -> int | None:
|
|
441
473
|
"""Get maximum file size for the given chatbot.
|
|
442
474
|
|
|
443
475
|
Args:
|
|
444
476
|
chatbot_id (str): The chatbot ID.
|
|
477
|
+
organization_id (str): The organization ID.
|
|
445
478
|
|
|
446
479
|
Returns:
|
|
447
480
|
int | None: The maximum file size if provided.
|
|
@@ -449,16 +482,19 @@ class PipelineHandler(PluginHandler):
|
|
|
449
482
|
Raises:
|
|
450
483
|
ValueError: If the chatbot or pipeline is not found.
|
|
451
484
|
"""
|
|
452
|
-
self._validate_pipeline(chatbot_id)
|
|
453
|
-
config = self._chatbot_configs[chatbot_id].pipeline_config
|
|
485
|
+
self._validate_pipeline(chatbot_id, organization_id)
|
|
486
|
+
config = self._chatbot_configs[(chatbot_id, organization_id)].pipeline_config
|
|
454
487
|
return config.get("max_file_size")
|
|
455
488
|
|
|
456
|
-
async def create_chatbot(
|
|
489
|
+
async def create_chatbot(
|
|
490
|
+
self, app_config: AppConfig, chatbot_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID
|
|
491
|
+
) -> None:
|
|
457
492
|
"""Create a new chatbot.
|
|
458
493
|
|
|
459
494
|
Args:
|
|
460
495
|
app_config (AppConfig): The application configuration.
|
|
461
496
|
chatbot_id (str): The ID of the chatbot.
|
|
497
|
+
organization_id (str): The organization ID.
|
|
462
498
|
"""
|
|
463
499
|
chatbot_info = app_config.chatbots.get(chatbot_id)
|
|
464
500
|
|
|
@@ -468,13 +504,14 @@ class PipelineHandler(PluginHandler):
|
|
|
468
504
|
|
|
469
505
|
pipeline_info = chatbot_info.pipeline
|
|
470
506
|
pipeline_type = pipeline_info["type"]
|
|
471
|
-
|
|
507
|
+
pipeline_organization_id = (pipeline_type, organization_id)
|
|
508
|
+
plugin = self._plugins.get(pipeline_organization_id)
|
|
472
509
|
if not plugin:
|
|
473
510
|
logger.warning(f"Pipeline plugin not found for chatbot `{chatbot_id}`")
|
|
474
511
|
return
|
|
475
512
|
|
|
476
513
|
logger.info(f"Storing pipeline config for chatbot `{chatbot_id}`")
|
|
477
|
-
self._chatbot_configs[chatbot_id] = ChatbotConfig(
|
|
514
|
+
self._chatbot_configs[(chatbot_id, organization_id)] = ChatbotConfig(
|
|
478
515
|
pipeline_type=pipeline_type,
|
|
479
516
|
pipeline_config=pipeline_info["config"],
|
|
480
517
|
prompt_builder_catalogs=pipeline_info["prompt_builder_catalogs"],
|
|
@@ -484,32 +521,38 @@ class PipelineHandler(PluginHandler):
|
|
|
484
521
|
supported_models = list(pipeline_info["config"].get("supported_models", {}).values())
|
|
485
522
|
await __class__._build_plugin(self, chatbot_id, supported_models, plugin)
|
|
486
523
|
|
|
487
|
-
async def delete_chatbot(self, chatbot_id: str) -> None:
|
|
524
|
+
async def delete_chatbot(self, chatbot_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID) -> None:
|
|
488
525
|
"""Delete a chatbot.
|
|
489
526
|
|
|
490
527
|
Args:
|
|
491
528
|
chatbot_id (str): The ID of the chatbot.
|
|
529
|
+
organization_id (str): The organization ID.
|
|
492
530
|
"""
|
|
493
|
-
|
|
531
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
532
|
+
for pipeline_key in self._chatbot_pipeline_keys.get(chatbot_organization_id, set()):
|
|
494
533
|
self._pipeline_cache.pop(pipeline_key, None)
|
|
495
534
|
|
|
496
535
|
# Clear stored error messages for this chatbot
|
|
497
|
-
error_keys_to_remove = [key for key in self._pipeline_build_errors.keys() if key[0] ==
|
|
536
|
+
error_keys_to_remove = [key for key in self._pipeline_build_errors.keys() if key[0] == chatbot_organization_id]
|
|
498
537
|
for key in error_keys_to_remove:
|
|
499
538
|
self._pipeline_build_errors.pop(key, None)
|
|
500
539
|
|
|
501
|
-
self._chatbot_pipeline_keys.pop(
|
|
502
|
-
self._chatbot_configs.pop(
|
|
503
|
-
self._builders.pop(
|
|
540
|
+
self._chatbot_pipeline_keys.pop(chatbot_organization_id, None)
|
|
541
|
+
self._chatbot_configs.pop(chatbot_organization_id, None)
|
|
542
|
+
self._builders.pop(chatbot_organization_id, None)
|
|
504
543
|
|
|
505
|
-
async def update_chatbots(
|
|
544
|
+
async def update_chatbots(
|
|
545
|
+
self, app_config: AppConfig, chatbot_ids: list[str], organization_id: str = DEFAULT_ORGANIZATION_ID
|
|
546
|
+
) -> None:
|
|
506
547
|
"""Update the chatbots.
|
|
507
548
|
|
|
508
549
|
Args:
|
|
509
550
|
app_config (AppConfig): The application configuration.
|
|
510
551
|
chatbot_ids (list[str]): The updated chatbot IDs.
|
|
552
|
+
organization_id (str): The organization ID.
|
|
511
553
|
"""
|
|
512
554
|
for chatbot_id in chatbot_ids:
|
|
555
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
513
556
|
try:
|
|
514
557
|
chatbot_info = app_config.chatbots.get(chatbot_id)
|
|
515
558
|
if not chatbot_info or not chatbot_info.pipeline:
|
|
@@ -522,8 +565,8 @@ class PipelineHandler(PluginHandler):
|
|
|
522
565
|
supported_models = list(pipeline_info["config"].get("supported_models", {}).values())
|
|
523
566
|
|
|
524
567
|
logger.info(f"Storing pipeline config for chatbot `{chatbot_id}`")
|
|
525
|
-
self._chatbot_configs.pop(
|
|
526
|
-
self._chatbot_configs[
|
|
568
|
+
self._chatbot_configs.pop(chatbot_organization_id, None)
|
|
569
|
+
self._chatbot_configs[chatbot_organization_id] = ChatbotConfig(
|
|
527
570
|
pipeline_type=pipeline_type,
|
|
528
571
|
pipeline_config=pipeline_info["config"],
|
|
529
572
|
prompt_builder_catalogs=pipeline_info["prompt_builder_catalogs"],
|
|
@@ -533,22 +576,23 @@ class PipelineHandler(PluginHandler):
|
|
|
533
576
|
new_pipeline_keys = set()
|
|
534
577
|
for model in supported_models:
|
|
535
578
|
model_id = model.get("model_id", model.get("name"))
|
|
536
|
-
new_pipeline_key = (chatbot_id, str(model_id))
|
|
579
|
+
new_pipeline_key = (chatbot_id, str(model_id), organization_id)
|
|
537
580
|
new_pipeline_keys.add(new_pipeline_key)
|
|
538
581
|
|
|
539
|
-
for pipeline_key in self._chatbot_pipeline_keys.get(
|
|
582
|
+
for pipeline_key in self._chatbot_pipeline_keys.get(chatbot_organization_id, set()):
|
|
540
583
|
if pipeline_key not in new_pipeline_keys:
|
|
541
584
|
self._pipeline_cache.pop(pipeline_key, None)
|
|
542
585
|
|
|
543
|
-
self._chatbot_pipeline_keys[
|
|
586
|
+
self._chatbot_pipeline_keys[chatbot_organization_id] = set()
|
|
544
587
|
|
|
545
|
-
|
|
588
|
+
pipeline_organization_id = (pipeline_type, organization_id)
|
|
589
|
+
plugin = self._plugins.get(pipeline_organization_id)
|
|
546
590
|
if not plugin:
|
|
547
591
|
logger.warning(f"Pipeline plugin not found for chatbot `{chatbot_id}`")
|
|
548
592
|
continue
|
|
549
593
|
|
|
550
|
-
self._builders.pop(
|
|
551
|
-
self._builders[
|
|
594
|
+
self._builders.pop(chatbot_organization_id, None)
|
|
595
|
+
self._builders[chatbot_organization_id] = plugin
|
|
552
596
|
|
|
553
597
|
await __class__._build_plugin(self, chatbot_id, supported_models, plugin)
|
|
554
598
|
except Exception as e:
|
|
@@ -556,77 +600,86 @@ class PipelineHandler(PluginHandler):
|
|
|
556
600
|
|
|
557
601
|
def _prepare_pipelines(self) -> None:
|
|
558
602
|
"""Build pipeline configurations from the chatbots configuration."""
|
|
559
|
-
pipeline_types: set[str] = set()
|
|
560
|
-
chatbot_preset_map: dict[str, PipelinePresetConfig] = {}
|
|
561
|
-
for
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
pipeline_type = pipeline_info["type"]
|
|
568
|
-
|
|
569
|
-
chatbot_preset_map[chatbot_id] = PipelinePresetConfig(
|
|
570
|
-
preset_id=pipeline_info["config"]["pipeline_preset_id"],
|
|
571
|
-
supported_models=list(pipeline_info["config"].get("supported_models", {}).values()),
|
|
572
|
-
)
|
|
603
|
+
pipeline_types: set[tuple[str, str]] = set()
|
|
604
|
+
chatbot_preset_map: dict[str, dict[str, PipelinePresetConfig]] = {}
|
|
605
|
+
for org_id, org_app_config in self.app_config.items():
|
|
606
|
+
chatbot_preset_map.setdefault(org_id, {})
|
|
607
|
+
for chatbot_id, chatbot_info in org_app_config.chatbots.items():
|
|
608
|
+
if not chatbot_info.pipeline:
|
|
609
|
+
logger.warning(f"Pipeline config not found for chatbot `{chatbot_id}`")
|
|
610
|
+
continue
|
|
573
611
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
pipeline_types.add(pipeline_type)
|
|
612
|
+
pipeline_info = chatbot_info.pipeline
|
|
613
|
+
pipeline_type = pipeline_info["type"]
|
|
614
|
+
|
|
615
|
+
chatbot_preset_map[org_id][chatbot_id] = PipelinePresetConfig(
|
|
616
|
+
preset_id=pipeline_info["config"]["pipeline_preset_id"],
|
|
617
|
+
supported_models=list(pipeline_info["config"].get("supported_models", {}).values()),
|
|
618
|
+
)
|
|
582
619
|
|
|
583
|
-
|
|
584
|
-
|
|
620
|
+
logger.info(f"Storing pipeline config for chatbot `{chatbot_id}`")
|
|
621
|
+
self._chatbot_configs[(chatbot_id, org_id)] = ChatbotConfig(
|
|
622
|
+
pipeline_type=pipeline_type,
|
|
623
|
+
pipeline_config=pipeline_info["config"],
|
|
624
|
+
prompt_builder_catalogs=pipeline_info["prompt_builder_catalogs"],
|
|
625
|
+
lmrp_catalogs=pipeline_info["lmrp_catalogs"],
|
|
626
|
+
)
|
|
627
|
+
pipeline_types.add((pipeline_type, org_id))
|
|
628
|
+
|
|
629
|
+
for pipeline_type, org_id in pipeline_types:
|
|
630
|
+
self._activated_configs[(pipeline_type, org_id)] = ChatbotPresetMapping(
|
|
585
631
|
pipeline_type=pipeline_type,
|
|
586
|
-
chatbot_preset_map=chatbot_preset_map,
|
|
632
|
+
chatbot_preset_map=chatbot_preset_map[org_id],
|
|
587
633
|
)
|
|
588
634
|
|
|
589
|
-
def _validate_pipeline(self, chatbot_id: str) -> None:
|
|
635
|
+
def _validate_pipeline(self, chatbot_id: str, organization_id: str) -> None:
|
|
590
636
|
"""Validate the pipeline configuration exists.
|
|
591
637
|
|
|
592
638
|
Args:
|
|
593
639
|
chatbot_id (str): The chatbot ID.
|
|
640
|
+
organization_id (str): The organization ID.
|
|
594
641
|
|
|
595
642
|
Raises:
|
|
596
643
|
ValueError: If the chatbot or pipeline configuration is not found.
|
|
597
644
|
"""
|
|
598
|
-
|
|
599
|
-
|
|
645
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
646
|
+
if chatbot_organization_id not in self._chatbot_configs:
|
|
647
|
+
raise ValueError(f"Pipeline configuration for chatbot `{chatbot_organization_id}` not found")
|
|
600
648
|
|
|
601
|
-
def _store_pipeline_build_error(
|
|
649
|
+
def _store_pipeline_build_error(
|
|
650
|
+
self, chatbot_id: str, model_id: str, organization_id: str, error_message: str
|
|
651
|
+
) -> None:
|
|
602
652
|
"""Store error message for failed pipeline build.
|
|
603
653
|
|
|
604
654
|
Args:
|
|
605
655
|
chatbot_id (str): The chatbot ID.
|
|
606
656
|
model_id (str): The model ID.
|
|
657
|
+
organization_id (str): The organization ID.
|
|
607
658
|
error_message (str): The error message to store.
|
|
608
659
|
"""
|
|
609
|
-
pipeline_key = (chatbot_id, str(model_id))
|
|
660
|
+
pipeline_key = (chatbot_id, str(model_id), organization_id)
|
|
610
661
|
self._pipeline_build_errors[pipeline_key] = error_message
|
|
611
662
|
|
|
612
|
-
def get_pipeline_build_error(self, chatbot_id: str, model_id: str) -> str | None:
|
|
663
|
+
def get_pipeline_build_error(self, chatbot_id: str, model_id: str, organization_id: str) -> str | None:
|
|
613
664
|
"""Get stored error message for failed pipeline build.
|
|
614
665
|
|
|
615
666
|
Args:
|
|
616
667
|
chatbot_id (str): The chatbot ID.
|
|
617
668
|
model_id (str): The model ID.
|
|
669
|
+
organization_id (str): The organization ID.
|
|
618
670
|
|
|
619
671
|
Returns:
|
|
620
672
|
str | None: The stored error message if available, None otherwise.
|
|
621
673
|
"""
|
|
622
|
-
pipeline_key = (chatbot_id, str(model_id))
|
|
674
|
+
pipeline_key = (chatbot_id, str(model_id), organization_id)
|
|
623
675
|
return self._pipeline_build_errors.get(pipeline_key)
|
|
624
676
|
|
|
625
|
-
async def aget_pipeline_builder(self, chatbot_id: str) -> Plugin:
|
|
677
|
+
async def aget_pipeline_builder(self, chatbot_id: str, organization_id: str) -> Plugin:
|
|
626
678
|
"""Get a pipeline builder instance for the given chatbot (async version).
|
|
627
679
|
|
|
628
680
|
Args:
|
|
629
681
|
chatbot_id (str): The chatbot ID.
|
|
682
|
+
organization_id (str): The organization ID.
|
|
630
683
|
|
|
631
684
|
Returns:
|
|
632
685
|
Plugin: The pipeline builder instance.
|
|
@@ -634,16 +687,19 @@ class PipelineHandler(PluginHandler):
|
|
|
634
687
|
Raises:
|
|
635
688
|
ValueError: If the chatbot ID is invalid or the model name is not supported.
|
|
636
689
|
"""
|
|
637
|
-
|
|
638
|
-
|
|
690
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
691
|
+
if chatbot_organization_id not in self._builders:
|
|
692
|
+
logger.warning(
|
|
693
|
+
f"Pipeline builder not found for chatbot `{chatbot_organization_id}`, attempting to rebuild..."
|
|
694
|
+
)
|
|
639
695
|
# Try to rebuild the plugin if it's not found
|
|
640
|
-
await self._async_rebuild_plugin(chatbot_id)
|
|
696
|
+
await self._async_rebuild_plugin(chatbot_id, organization_id)
|
|
641
697
|
|
|
642
|
-
if
|
|
698
|
+
if chatbot_organization_id not in self._builders:
|
|
643
699
|
# Check if there are any stored error messages for this chatbot
|
|
644
700
|
chatbot_errors = []
|
|
645
|
-
for (c_id, m_id), error_msg in self._pipeline_build_errors.items():
|
|
646
|
-
if c_id == chatbot_id:
|
|
701
|
+
for (c_id, m_id, o_id), error_msg in self._pipeline_build_errors.items():
|
|
702
|
+
if c_id == chatbot_id and o_id == organization_id:
|
|
647
703
|
chatbot_errors.append(f"Model `{m_id}`: {error_msg}")
|
|
648
704
|
|
|
649
705
|
if chatbot_errors:
|
|
@@ -655,29 +711,32 @@ class PipelineHandler(PluginHandler):
|
|
|
655
711
|
else:
|
|
656
712
|
raise ValueError(f"Pipeline builder for chatbot `{chatbot_id}` not found and could not be rebuilt")
|
|
657
713
|
|
|
658
|
-
return self._builders[
|
|
714
|
+
return self._builders[chatbot_organization_id]
|
|
659
715
|
|
|
660
|
-
async def _async_rebuild_plugin(self, chatbot_id: str) -> None:
|
|
716
|
+
async def _async_rebuild_plugin(self, chatbot_id: str, organization_id: str) -> None:
|
|
661
717
|
"""Asynchronously rebuild a plugin for the given chatbot.
|
|
662
718
|
|
|
663
719
|
Args:
|
|
664
720
|
chatbot_id (str): The chatbot ID.
|
|
721
|
+
organization_id (str): The organization ID.
|
|
665
722
|
"""
|
|
666
723
|
try:
|
|
667
724
|
# Check if we have the chatbot configuration
|
|
668
|
-
|
|
669
|
-
|
|
725
|
+
chatbot_organization_id = (chatbot_id, organization_id)
|
|
726
|
+
if chatbot_organization_id not in self._chatbot_configs:
|
|
727
|
+
logger.warning(f"Chatbot configuration not found for `{chatbot_organization_id}`")
|
|
670
728
|
return
|
|
671
729
|
|
|
672
|
-
chatbot_config = self._chatbot_configs[
|
|
730
|
+
chatbot_config = self._chatbot_configs[chatbot_organization_id]
|
|
673
731
|
pipeline_type = chatbot_config.pipeline_type
|
|
732
|
+
pipeline_organization_id = (pipeline_type, organization_id)
|
|
674
733
|
|
|
675
734
|
# Check if we have the plugin for this pipeline type
|
|
676
|
-
if
|
|
677
|
-
logger.warning(f"Plugin not found for pipeline type `{
|
|
735
|
+
if pipeline_organization_id not in self._plugins:
|
|
736
|
+
logger.warning(f"Plugin not found for pipeline type `{pipeline_organization_id}`")
|
|
678
737
|
return
|
|
679
738
|
|
|
680
|
-
plugin = self._plugins[
|
|
739
|
+
plugin = self._plugins[pipeline_organization_id]
|
|
681
740
|
|
|
682
741
|
# Get supported models from the configuration
|
|
683
742
|
supported_models = list(chatbot_config.pipeline_config.get("supported_models", {}).values())
|
|
@@ -696,4 +755,4 @@ class PipelineHandler(PluginHandler):
|
|
|
696
755
|
logger.warning(error_message)
|
|
697
756
|
|
|
698
757
|
# Store the error message for later retrieval (using a generic model_id for plugin-level errors)
|
|
699
|
-
self._store_pipeline_build_error(chatbot_id, "__plugin__", error_message)
|
|
758
|
+
self._store_pipeline_build_error(chatbot_id, "__plugin__", organization_id, error_message)
|
|
@@ -14,6 +14,7 @@ from bosa_core.plugin.plugin import Plugin
|
|
|
14
14
|
from gllm_inference.catalog.catalog import BaseCatalog
|
|
15
15
|
from gllm_pipeline.pipeline.pipeline import Pipeline
|
|
16
16
|
|
|
17
|
+
from glchat_plugin.config.constant import DEFAULT_ORGANIZATION_ID
|
|
17
18
|
from glchat_plugin.pipeline.pipeline_handler import PipelineHandler
|
|
18
19
|
|
|
19
20
|
PipelineState = TypeVar("PipelineState")
|
|
@@ -31,6 +32,7 @@ class PipelineBuilderPlugin(Plugin, Generic[PipelineState, PipelinePresetConfig]
|
|
|
31
32
|
name (str): The name of the plugin.
|
|
32
33
|
description (str): The description of the plugin.
|
|
33
34
|
version (str): The version of the plugin.
|
|
35
|
+
organization_id (str): The organization ID.
|
|
34
36
|
lmrp_catalogs (dict[str, BaseCatalog[Any]] | None): The LM request processor catalogs.
|
|
35
37
|
prompt_builder_catalogs (dict[str, BaseCatalog[Any]] | None): The prompt builder catalogs.
|
|
36
38
|
additional_config_class (Type[PipelineRuntimeConfig] | None): The additional runtime configuration class.
|
|
@@ -40,6 +42,7 @@ class PipelineBuilderPlugin(Plugin, Generic[PipelineState, PipelinePresetConfig]
|
|
|
40
42
|
name: str
|
|
41
43
|
description: str = "Pipeline builder plugin"
|
|
42
44
|
version: str = "0.0.0"
|
|
45
|
+
organization_id: str = DEFAULT_ORGANIZATION_ID
|
|
43
46
|
|
|
44
47
|
lmrp_catalogs: dict[str, BaseCatalog[Any]] | None = None
|
|
45
48
|
prompt_builder_catalogs: dict[str, BaseCatalog[Any]] | None = None
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Authors:
|
|
4
4
|
Immanuel Rhesa (immanuel.rhesa@gdplabs.id)
|
|
5
5
|
Hermes Vincentius Gani (hermes.v.gani@gdplabs.id)
|
|
6
|
-
Ricky Setiawan (ricky.setiawan@gdplabs.id)
|
|
7
6
|
|
|
8
7
|
References:
|
|
9
8
|
NONE
|
|
@@ -31,21 +30,6 @@ class BaseUserService(ABC):
|
|
|
31
30
|
"""
|
|
32
31
|
raise NotImplementedError
|
|
33
32
|
|
|
34
|
-
@abstractmethod
|
|
35
|
-
async def get_user_session(self, **kwargs: Any) -> Any | None:
|
|
36
|
-
"""Abstract method to get the user session.
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
**kwargs (Any): Additional keyword arguments for user session retrieval.
|
|
40
|
-
|
|
41
|
-
Returns:
|
|
42
|
-
Any | None: User session, None if not found.
|
|
43
|
-
|
|
44
|
-
Raises:
|
|
45
|
-
NotImplementedError: If the method is not implemented.
|
|
46
|
-
"""
|
|
47
|
-
raise NotImplementedError
|
|
48
|
-
|
|
49
33
|
@abstractmethod
|
|
50
34
|
async def register(self, **kwargs: Any):
|
|
51
35
|
"""Abstract method to register a new user.
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
glchat_plugin/__init__.py,sha256=SHSBMz7JDU6MecyIrhHu5-3NVs89JkXhyvD3ZGOkWOE,37
|
|
2
2
|
glchat_plugin/config/__init__.py,sha256=DNnX8B_TvAN89oyMgq32zG1DeaezODrihiAXTwOPT5o,39
|
|
3
3
|
glchat_plugin/config/app_config.py,sha256=9_ShYtaQ7Rp14sSkrIFLoOAMlbwVlm13EuCxzOn4NCI,426
|
|
4
|
-
glchat_plugin/config/constant.py,sha256=
|
|
4
|
+
glchat_plugin/config/constant.py,sha256=zZO4WCkozvm6i_rMquTp99Q3alom0SN_P9SNqAHO3ko,3621
|
|
5
5
|
glchat_plugin/context/__init__.py,sha256=3Wx_apMIS6z-m6eRs6hoyOsJFLJfKmMFOkrPDkPQfJI,40
|
|
6
|
-
glchat_plugin/context/context_manager.py,sha256=
|
|
6
|
+
glchat_plugin/context/context_manager.py,sha256=AVTs30Tg5EbPb5HDZfW9RI3lY24Pc0-NhOPFxw5XG5U,1330
|
|
7
7
|
glchat_plugin/handler/__init__.py,sha256=H5DJaAfwwtRsvMcOaEzHfGMQk25H7la0E7uPfksWtoQ,40
|
|
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=1XkTfhmoIViJKVhRbaKisCRSWR5lzQO6aCP6O8-qqOo,34022
|
|
12
|
+
glchat_plugin/pipeline/pipeline_plugin.py,sha256=eBrg4THS0P49Mz4glEjrwqe1pxnvOn_UitJ9gOBVcac,4562
|
|
13
13
|
glchat_plugin/service/__init__.py,sha256=9T4qzyYL052qLqva5el1F575OTRNaaf9tb9UvW-leTc,47
|
|
14
14
|
glchat_plugin/service/base_rate_limiter_service.py,sha256=tgKwdr4EqnGo5iDRVJPnlg8W9q0hiUzfeewAtdW4IjU,1232
|
|
15
15
|
glchat_plugin/service/base_tenant_service.py,sha256=CB-jJWXi87nTcjO1XhPoSgNMf2YA_LfXoHr30ye0VtI,734
|
|
16
|
-
glchat_plugin/service/base_user_service.py,sha256=
|
|
16
|
+
glchat_plugin/service/base_user_service.py,sha256=qnRKl2u1xhGc4wMaOd_h_mAuxM7GduyDbqebj-k3GDE,2211
|
|
17
17
|
glchat_plugin/storage/__init__.py,sha256=VNO7ua2yAOLzXwe6H6zDZz9yXbhQfKqNJzxE3G8IyfA,50
|
|
18
18
|
glchat_plugin/storage/base_anonymizer_storage.py,sha256=oFwovWrsjM7v1YjeN-4p-M3OGnAeo_Y7-9xqlToI180,1969
|
|
19
19
|
glchat_plugin/storage/base_chat_history_storage.py,sha256=YIGM8zv7s5BQ8O7W1LfaLyQW4SF9Bt3aolowsoDaQw8,11257
|
|
20
20
|
glchat_plugin/tools/__init__.py,sha256=OFotHbgQ8mZEbdlvlv5aVMdxfubPvkVWAcTwhIPdIqQ,542
|
|
21
21
|
glchat_plugin/tools/decorators.py,sha256=AvQBV18wzXWdC483RSSmpfh92zsqTyp8SzDLIkreIGU,3925
|
|
22
|
-
glchat_plugin-0.
|
|
23
|
-
glchat_plugin-0.
|
|
24
|
-
glchat_plugin-0.
|
|
25
|
-
glchat_plugin-0.
|
|
22
|
+
glchat_plugin-0.4.1.dist-info/METADATA,sha256=q3Po_AA7fAbEOEMH-EiCgX5VxEOH774fbfnQ_qD8tyc,2063
|
|
23
|
+
glchat_plugin-0.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
24
|
+
glchat_plugin-0.4.1.dist-info/top_level.txt,sha256=fzKSXmct5dY4CAKku4-mkdHX-QPAyQVvo8vpQj8qizY,14
|
|
25
|
+
glchat_plugin-0.4.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|