glchat-plugin 0.2.0__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/__init__.py +1 -0
- glchat_plugin/config/__init__.py +1 -0
- glchat_plugin/config/app_config.py +22 -0
- glchat_plugin/config/constant.py +26 -0
- glchat_plugin/pipeline/__init__.py +1 -0
- glchat_plugin/pipeline/base_pipeline_preset_config.py +36 -0
- glchat_plugin/pipeline/pipeline_handler.py +602 -0
- glchat_plugin/pipeline/pipeline_plugin.py +126 -0
- glchat_plugin/service/__init__.py +1 -0
- glchat_plugin/service/base_user_service.py +82 -0
- glchat_plugin/storage/__init__.py +1 -0
- glchat_plugin/storage/base_anonymizer_storage.py +58 -0
- glchat_plugin/storage/base_chat_history_storage.py +356 -0
- glchat_plugin/tools/__init__.py +21 -0
- glchat_plugin/tools/decorators.py +115 -0
- glchat_plugin-0.2.0.dist-info/METADATA +62 -0
- glchat_plugin-0.2.0.dist-info/RECORD +19 -0
- glchat_plugin-0.2.0.dist-info/WHEEL +5 -0
- glchat_plugin-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Tool Plugin Decorators for External Use.
|
|
2
|
+
|
|
3
|
+
This module provides utilities for marking and preparing tool plugins using a decorator-based approach.
|
|
4
|
+
The decorators and utilities can be used independently in external repositories, as they only add
|
|
5
|
+
metadata to tool classes without creating any connections to a plugin registration system.
|
|
6
|
+
|
|
7
|
+
Authors:
|
|
8
|
+
Raymond Christopher (raymond.christopher@gdplabs.id)
|
|
9
|
+
Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import inspect
|
|
13
|
+
from typing import Any, Callable, Type
|
|
14
|
+
|
|
15
|
+
from gllm_core.utils import LoggerManager
|
|
16
|
+
from langchain_core.tools import BaseTool
|
|
17
|
+
|
|
18
|
+
logger = LoggerManager().get_logger()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def tool_plugin(
|
|
22
|
+
version: str = "1.0.0",
|
|
23
|
+
) -> Callable[[Type[BaseTool]], Type[BaseTool]]:
|
|
24
|
+
"""Decorator to mark a BaseTool class as a tool plugin.
|
|
25
|
+
|
|
26
|
+
This decorator adds metadata to the tool class that will be used by the
|
|
27
|
+
plugin system when the tool is loaded. It doesn't directly register
|
|
28
|
+
the tool with any system, allowing for use in external repositories.
|
|
29
|
+
The actual tool name and description are intended to be retrieved
|
|
30
|
+
from the tool instance at runtime.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
version (str): Version of the plugin. Defaults to "1.0.0".
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
Callable[[Type[BaseTool]], Type[BaseTool]]: A decorator function that wraps the tool class.
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
```python
|
|
40
|
+
@tool_plugin(version="1.0.0")
|
|
41
|
+
class MyAwesomeTool(BaseTool):
|
|
42
|
+
name = "my_awesome_tool"
|
|
43
|
+
description = "Does something awesome"
|
|
44
|
+
|
|
45
|
+
def _run(self, **kwargs):
|
|
46
|
+
return "Awesome result!"
|
|
47
|
+
```
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def decorator(tool_class: Type[BaseTool]) -> Type[BaseTool]:
|
|
51
|
+
"""Marks a BaseTool class as a plugin by adding metadata for discovery.
|
|
52
|
+
|
|
53
|
+
This decorator adds plugin metadata to the tool class and marks it for later discovery.
|
|
54
|
+
It validates that the decorated class is a subclass of BaseTool.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
tool_class (Type[BaseTool]): The BaseTool class to be decorated with plugin metadata.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
Type[BaseTool]: The decorated BaseTool class with added plugin metadata.
|
|
61
|
+
"""
|
|
62
|
+
if not issubclass(tool_class, BaseTool):
|
|
63
|
+
raise TypeError(f"{tool_class.__name__} is not a subclass of BaseTool")
|
|
64
|
+
|
|
65
|
+
# Store basic plugin metadata as class attributes for later discovery
|
|
66
|
+
tool_class._plugin_metadata = {
|
|
67
|
+
"version": version,
|
|
68
|
+
"tool_class": tool_class.__name__,
|
|
69
|
+
"module": tool_class.__module__,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# Mark the class as a decorated tool plugin for easy discovery
|
|
73
|
+
tool_class._is_tool_plugin = True
|
|
74
|
+
|
|
75
|
+
# Log the preparation (but don't require any specific logger)
|
|
76
|
+
try:
|
|
77
|
+
# Simplified logging message
|
|
78
|
+
logger.info(f"Marked tool class {tool_class.__name__} as plugin with version {version}")
|
|
79
|
+
except Exception:
|
|
80
|
+
# Ignore logging errors in standalone mode
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
return tool_class
|
|
84
|
+
|
|
85
|
+
return decorator
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def is_tool_plugin(obj: Any) -> bool:
|
|
89
|
+
"""Check if an object is a tool plugin.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
obj (Any): The object to check.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
bool: True if the object is a decorated tool plugin, False otherwise.
|
|
96
|
+
"""
|
|
97
|
+
return inspect.isclass(obj) and getattr(obj, "_is_tool_plugin", False) is True
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def get_plugin_metadata(tool_class: Type[BaseTool]) -> dict[str, Any]:
|
|
101
|
+
"""Get the plugin metadata from a decorated tool class.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
tool_class (Type[BaseTool]): The tool class to get metadata from.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
dict[str, Any]: A dictionary of plugin metadata.
|
|
108
|
+
|
|
109
|
+
Raises:
|
|
110
|
+
ValueError: If the tool class is not a decorated tool plugin.
|
|
111
|
+
"""
|
|
112
|
+
if not is_tool_plugin(tool_class):
|
|
113
|
+
raise ValueError(f"{tool_class.__name__} is not a decorated tool plugin")
|
|
114
|
+
|
|
115
|
+
return getattr(tool_class, "_plugin_metadata", {})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: glchat-plugin
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Author-email: GenAI SDK Team <gat-sdk@gdplabs.id>
|
|
5
|
+
Requires-Python: <3.13,>=3.11
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: poetry>=2.1.3
|
|
8
|
+
Requires-Dist: bosa-core-binary>=0.5.0
|
|
9
|
+
Requires-Dist: gllm-core-binary>=0.3.0
|
|
10
|
+
Requires-Dist: gllm-inference-binary>=0.4.0
|
|
11
|
+
Requires-Dist: gllm-pipeline-binary>=0.4.0
|
|
12
|
+
Requires-Dist: langchain>=0.3.0
|
|
13
|
+
Requires-Dist: langchain-core>=0.3.0
|
|
14
|
+
Requires-Dist: semver>=3.0.4
|
|
15
|
+
Provides-Extra: flair
|
|
16
|
+
Requires-Dist: flair; extra == "flair"
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: coverage>=7.4.4; extra == "dev"
|
|
19
|
+
Requires-Dist: mypy>=1.15.0; extra == "dev"
|
|
20
|
+
Requires-Dist: pre-commit>=3.7.0; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest>=8.1.1; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-asyncio>=0.23.6; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.6.7; extra == "dev"
|
|
25
|
+
|
|
26
|
+
# GDP Labs GenAI Plugin
|
|
27
|
+
|
|
28
|
+
## Description
|
|
29
|
+
|
|
30
|
+
A library to implement Plugin architecture and integrate with existing pipelines.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
### Prerequisites
|
|
35
|
+
- Python 3.11+ - [Install here](https://www.python.org/downloads/)
|
|
36
|
+
- Pip (if using Pip) - [Install here](https://pip.pypa.io/en/stable/installation/)
|
|
37
|
+
- Poetry 1.8.1+ (if using Poetry) - [Install here](https://python-poetry.org/docs/#installation)
|
|
38
|
+
- Git (if using Git) - [Install here](https://git-scm.com/downloads)
|
|
39
|
+
- For git installation:
|
|
40
|
+
- Access to the [GDP Labs SDK github repository](https://github.com/GDP-ADMIN/glchat-sdk)
|
|
41
|
+
|
|
42
|
+
### 1. Installation from Pypi
|
|
43
|
+
Choose one of the following methods to install the package:
|
|
44
|
+
|
|
45
|
+
#### Using pip
|
|
46
|
+
```bash
|
|
47
|
+
pip install glchat-plugin-binary
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Using Poetry
|
|
51
|
+
```bash
|
|
52
|
+
poetry add glchat-plugin-binary
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 2. Development Installation (Git)
|
|
56
|
+
For development purposes, you can install directly from the Git repository:
|
|
57
|
+
```bash
|
|
58
|
+
poetry add "git+ssh://git@github.com/GDP-ADMIN/glchat-sdk.git#subdirectory=python/glchat-plugin"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
For more information, please refer to the [PIPELINE.md](https://github.com/GDP-ADMIN/glchat-sdk/blob/main/python/glchat-plugin/PIPELINE.md).
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
glchat_plugin/__init__.py,sha256=SHSBMz7JDU6MecyIrhHu5-3NVs89JkXhyvD3ZGOkWOE,37
|
|
2
|
+
glchat_plugin/config/__init__.py,sha256=DNnX8B_TvAN89oyMgq32zG1DeaezODrihiAXTwOPT5o,39
|
|
3
|
+
glchat_plugin/config/app_config.py,sha256=9_ShYtaQ7Rp14sSkrIFLoOAMlbwVlm13EuCxzOn4NCI,426
|
|
4
|
+
glchat_plugin/config/constant.py,sha256=hdTXG5mIULV86DepClE97VGhn9E-HtsjZ9PyLKKEdmc,689
|
|
5
|
+
glchat_plugin/pipeline/__init__.py,sha256=Sk-NfIGyA9VKIg0Bt5OHatNUYyWVPh9i5xhE5DFAfbo,41
|
|
6
|
+
glchat_plugin/pipeline/base_pipeline_preset_config.py,sha256=2DxJlroZ_tvVO6DYo1R07cjhWgKQJpysw1GsJ3BNRnw,1100
|
|
7
|
+
glchat_plugin/pipeline/pipeline_handler.py,sha256=vDvIPI7Y39K_DI3jvQZsXC9YzQLUI4TuC-boyasdey8,24405
|
|
8
|
+
glchat_plugin/pipeline/pipeline_plugin.py,sha256=1i7w7WepM5gON4Kx10SjL7NV7-SYVAmRE1EW2m_dOYg,4028
|
|
9
|
+
glchat_plugin/service/__init__.py,sha256=eVyDgTcbOG0slfGT2GSUnUM9MHC2Wh3aU6fcLV_JHs4,45
|
|
10
|
+
glchat_plugin/service/base_user_service.py,sha256=agpziGm7ua2wIv-rrrnTOiYlyUjp6L6dArWY2q0m63g,2178
|
|
11
|
+
glchat_plugin/storage/__init__.py,sha256=VNO7ua2yAOLzXwe6H6zDZz9yXbhQfKqNJzxE3G8IyfA,50
|
|
12
|
+
glchat_plugin/storage/base_anonymizer_storage.py,sha256=oFwovWrsjM7v1YjeN-4p-M3OGnAeo_Y7-9xqlToI180,1969
|
|
13
|
+
glchat_plugin/storage/base_chat_history_storage.py,sha256=JvUUFMu_9jRBQ9yug_x7S4rQjZEA1vM5ombDvz-7zCE,11095
|
|
14
|
+
glchat_plugin/tools/__init__.py,sha256=OFotHbgQ8mZEbdlvlv5aVMdxfubPvkVWAcTwhIPdIqQ,542
|
|
15
|
+
glchat_plugin/tools/decorators.py,sha256=AvQBV18wzXWdC483RSSmpfh92zsqTyp8SzDLIkreIGU,3925
|
|
16
|
+
glchat_plugin-0.2.0.dist-info/METADATA,sha256=Vhjz_PklkL2HzLFrJBi27NPAox_4ytlLDX137ltMKLg,2063
|
|
17
|
+
glchat_plugin-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
18
|
+
glchat_plugin-0.2.0.dist-info/top_level.txt,sha256=fzKSXmct5dY4CAKku4-mkdHX-QPAyQVvo8vpQj8qizY,14
|
|
19
|
+
glchat_plugin-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
glchat_plugin
|