glchat-plugin 0.4.1__py3-none-any.whl → 0.4.3__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.
@@ -1,6 +1,7 @@
1
1
  """Provides a class for context manager.
2
2
 
3
3
  Authors:
4
+ Ricky Setiawan (ricky.setiawan@gdplabs.id)
4
5
  Ryan Ignatius Hadiwijaya (ryan.i.hadiwijaya@gdplabs.id)
5
6
 
6
7
  References:
@@ -8,6 +9,7 @@ References:
8
9
  """
9
10
 
10
11
  from contextvars import ContextVar
12
+ from typing import Any
11
13
 
12
14
 
13
15
  class ContextManager:
@@ -18,6 +20,7 @@ class ContextManager:
18
20
 
19
21
  _tenant: ContextVar[str | None] = ContextVar("tenant_id", default=None)
20
22
  _user: ContextVar[str | None] = ContextVar("user_id", default=None)
23
+ _user_session: ContextVar[Any | None] = ContextVar("user_session", default=None)
21
24
 
22
25
  @classmethod
23
26
  def set_tenant(cls, tenant_id: str | None) -> None:
@@ -55,3 +58,21 @@ class ContextManager:
55
58
  str | None: The user id.
56
59
  """
57
60
  return cls._user.get()
61
+
62
+ @classmethod
63
+ def set_user_session(cls, user_session: Any | None) -> None:
64
+ """Set the user session in the context.
65
+
66
+ Args:
67
+ user_session (Any | None): The user session.
68
+ """
69
+ cls._user_session.set(user_session)
70
+
71
+ @classmethod
72
+ def get_user_session(cls) -> Any | None:
73
+ """Get the user session from the context.
74
+
75
+ Returns:
76
+ Any | None: The user session.
77
+ """
78
+ return cls._user_session.get()
@@ -166,7 +166,7 @@ class PipelineHandler(PluginHandler):
166
166
  if pipeline_type != instance._chatbot_configs[chatbot_organization_id].pipeline_type:
167
167
  continue
168
168
 
169
- await cls._build_plugin(instance, chatbot_id, preset.supported_models, plugin)
169
+ await cls._build_plugin(instance, chatbot_id, preset.supported_models, plugin, organization_id)
170
170
  except Exception as e:
171
171
  logger.warning(f"Failed when ainit pliugin {traceback.format_exc()}")
172
172
  logger.warning(f"Error initializing plugin for chatbot `{chatbot_id}`: {e}")
@@ -186,7 +186,12 @@ class PipelineHandler(PluginHandler):
186
186
 
187
187
  @classmethod
188
188
  async def _build_plugin(
189
- cls, instance: "PipelineHandler", chatbot_id: str, supported_models: list[dict[str, Any]], plugin: Plugin
189
+ cls,
190
+ instance: "PipelineHandler",
191
+ chatbot_id: str,
192
+ supported_models: list[dict[str, Any]],
193
+ plugin: Plugin,
194
+ organization_id: str = DEFAULT_ORGANIZATION_ID,
190
195
  ) -> None:
191
196
  """Build a plugin for the given chatbot.
192
197
 
@@ -195,8 +200,8 @@ class PipelineHandler(PluginHandler):
195
200
  chatbot_id (str): The chatbot ID.
196
201
  supported_models (list[dict[str, Any]]): List of models (including config).
197
202
  plugin (Plugin): The pipeline builder plugin instance.
203
+ organization_id (str): The organization ID.
198
204
  """
199
- organization_id = plugin.organization_id
200
205
  chatbot_organization_id = (chatbot_id, organization_id)
201
206
  plugin.prompt_builder_catalogs = instance._chatbot_configs[chatbot_organization_id].prompt_builder_catalogs
202
207
  plugin.lmrp_catalogs = instance._chatbot_configs[chatbot_organization_id].lmrp_catalogs
@@ -376,7 +381,7 @@ class PipelineHandler(PluginHandler):
376
381
  return
377
382
 
378
383
  # Use the existing _build_plugin method to rebuild the pipeline
379
- await __class__._build_plugin(self, chatbot_id, [model_config], plugin)
384
+ await __class__._build_plugin(self, chatbot_id, [model_config], plugin, organization_id)
380
385
 
381
386
  logger.info(f"Successfully rebuilt pipeline for chatbot `{chatbot_organization_id}` model `{model_id}`")
382
387
 
@@ -519,7 +524,7 @@ class PipelineHandler(PluginHandler):
519
524
  )
520
525
 
521
526
  supported_models = list(pipeline_info["config"].get("supported_models", {}).values())
522
- await __class__._build_plugin(self, chatbot_id, supported_models, plugin)
527
+ await __class__._build_plugin(self, chatbot_id, supported_models, plugin, organization_id)
523
528
 
524
529
  async def delete_chatbot(self, chatbot_id: str, organization_id: str = DEFAULT_ORGANIZATION_ID) -> None:
525
530
  """Delete a chatbot.
@@ -594,7 +599,7 @@ class PipelineHandler(PluginHandler):
594
599
  self._builders.pop(chatbot_organization_id, None)
595
600
  self._builders[chatbot_organization_id] = plugin
596
601
 
597
- await __class__._build_plugin(self, chatbot_id, supported_models, plugin)
602
+ await __class__._build_plugin(self, chatbot_id, supported_models, plugin, organization_id)
598
603
  except Exception as e:
599
604
  logger.warning(f"Error updating chatbot `{chatbot_id}`: {e}")
600
605
 
@@ -746,7 +751,7 @@ class PipelineHandler(PluginHandler):
746
751
  return
747
752
 
748
753
  # Use the existing _build_plugin method to rebuild the plugin
749
- await __class__._build_plugin(self, chatbot_id, supported_models, plugin)
754
+ await __class__._build_plugin(self, chatbot_id, supported_models, plugin, organization_id)
750
755
 
751
756
  logger.info(f"Successfully rebuilt pipeline builder for chatbot `{chatbot_id}`")
752
757
 
@@ -3,6 +3,7 @@
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)
6
7
 
7
8
  References:
8
9
  NONE
@@ -30,6 +31,21 @@ class BaseUserService(ABC):
30
31
  """
31
32
  raise NotImplementedError
32
33
 
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
+
33
49
  @abstractmethod
34
50
  async def register(self, **kwargs: Any):
35
51
  """Abstract method to register a new user.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: glchat-plugin
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Author-email: GenAI SDK Team <gat-sdk@gdplabs.id>
5
5
  Requires-Python: <3.13,>=3.11
6
6
  Description-Content-Type: text/markdown
@@ -3,23 +3,23 @@ glchat_plugin/config/__init__.py,sha256=DNnX8B_TvAN89oyMgq32zG1DeaezODrihiAXTwOP
3
3
  glchat_plugin/config/app_config.py,sha256=9_ShYtaQ7Rp14sSkrIFLoOAMlbwVlm13EuCxzOn4NCI,426
4
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=AVTs30Tg5EbPb5HDZfW9RI3lY24Pc0-NhOPFxw5XG5U,1330
6
+ glchat_plugin/context/context_manager.py,sha256=dQUbejXUMrYwLo8xPGo1P-QWuMYPahmRddAx8Ig-fJE,1968
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=1XkTfhmoIViJKVhRbaKisCRSWR5lzQO6aCP6O8-qqOo,34022
11
+ glchat_plugin/pipeline/pipeline_handler.py,sha256=Kp2LBqtVHzJ2twLaUvYXnL-1QGkqL_8h21IAR7FxBTI,34203
12
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=qnRKl2u1xhGc4wMaOd_h_mAuxM7GduyDbqebj-k3GDE,2211
16
+ glchat_plugin/service/base_user_service.py,sha256=DlVj0pimzTgvgz2dqpVkfhMK8PWEwQ9LyukzGoVZgYc,2703
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.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,,
22
+ glchat_plugin-0.4.3.dist-info/METADATA,sha256=Annr1O57pSyLVG6niQiTXTZT7A2s9R1QWlo5nqzgur4,2063
23
+ glchat_plugin-0.4.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
+ glchat_plugin-0.4.3.dist-info/top_level.txt,sha256=fzKSXmct5dY4CAKku4-mkdHX-QPAyQVvo8vpQj8qizY,14
25
+ glchat_plugin-0.4.3.dist-info/RECORD,,