datahub-describer 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DataHub Describer contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: datahub-describer
3
+ Version: 0.1.0
4
+ Summary: Hierarchical LLM-generated descriptions for DataHub
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: acryl-datahub[datahub-rest]>=1.7.0
10
+ Requires-Dist: openai>=1.40.0
11
+ Provides-Extra: dev
12
+ Requires-Dist: pytest; extra == "dev"
13
+ Dynamic: license-file
14
+
15
+ # DataHub Describer
16
+
17
+ Generate missing DataHub descriptions with an OpenAI-compatible LLM.
18
+
19
+ The connector works from fields upward:
20
+
21
+ ```text
22
+ fields → datasets → parent containers
23
+ ```
24
+
25
+ Field prompts use field metadata. Parent prompts use the names and descriptions
26
+ of their immediate children. Existing descriptions are preserved by default.
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ pip install datahub-describer
32
+ ```
33
+
34
+ ## Configure
35
+
36
+ Use the registered DataHub source type:
37
+
38
+ ```yaml
39
+ source:
40
+ type: datahub-describer
41
+ config:
42
+ llm_model: "${LLM_MODEL}"
43
+ llm_base_url: "${LLM_BASE_URL}"
44
+ llm_api_key: "${LLM_API_KEY}"
45
+
46
+ sink:
47
+ type: datahub-rest
48
+ config:
49
+ server: "${DATAHUB_GMS_URL}"
50
+ ```
51
+
52
+ See `datahub_describer.example.yml` for all settings.
53
+
54
+ ## Development
55
+
56
+ ```bash
57
+ pip install -e '.[dev]'
58
+ pytest
59
+ ```
@@ -0,0 +1,45 @@
1
+ # DataHub Describer
2
+
3
+ Generate missing DataHub descriptions with an OpenAI-compatible LLM.
4
+
5
+ The connector works from fields upward:
6
+
7
+ ```text
8
+ fields → datasets → parent containers
9
+ ```
10
+
11
+ Field prompts use field metadata. Parent prompts use the names and descriptions
12
+ of their immediate children. Existing descriptions are preserved by default.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ pip install datahub-describer
18
+ ```
19
+
20
+ ## Configure
21
+
22
+ Use the registered DataHub source type:
23
+
24
+ ```yaml
25
+ source:
26
+ type: datahub-describer
27
+ config:
28
+ llm_model: "${LLM_MODEL}"
29
+ llm_base_url: "${LLM_BASE_URL}"
30
+ llm_api_key: "${LLM_API_KEY}"
31
+
32
+ sink:
33
+ type: datahub-rest
34
+ config:
35
+ server: "${DATAHUB_GMS_URL}"
36
+ ```
37
+
38
+ See `datahub_describer.example.yml` for all settings.
39
+
40
+ ## Development
41
+
42
+ ```bash
43
+ pip install -e '.[dev]'
44
+ pytest
45
+ ```
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "datahub-describer"
7
+ version = "0.1.0"
8
+ description = "Hierarchical LLM-generated descriptions for DataHub"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ dependencies = [
13
+ "acryl-datahub[datahub-rest]>=1.7.0",
14
+ "openai>=1.40.0",
15
+ ]
16
+
17
+ [project.entry-points."datahub.ingestion.source.plugins"]
18
+ datahub-describer = "datahub_describer.source:HierarchicalDocumentationSource"
19
+
20
+ [project.optional-dependencies]
21
+ dev = ["pytest"]
22
+
23
+ [tool.setuptools.packages.find]
24
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ from datahub_describer.source import (
2
+ HierarchicalDocumentationSource,
3
+ )
4
+
5
+ __all__ = ["HierarchicalDocumentationSource"]
6
+ __version__ = "0.1.0"
@@ -0,0 +1,93 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import logging
5
+ import re
6
+ from typing import Any, Dict, Optional
7
+
8
+ from openai import OpenAI
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ def _json_object(content: str) -> Dict[str, Any]:
14
+ parsed = json.loads(content)
15
+ if not isinstance(parsed, dict):
16
+ raise ValueError("LLM response must be a JSON object")
17
+ return parsed
18
+
19
+
20
+ def get_llm_client(
21
+ api_key: str,
22
+ base_url: str,
23
+ *,
24
+ timeout: float,
25
+ max_retries: int,
26
+ ) -> OpenAI:
27
+ return OpenAI(
28
+ api_key=api_key or "not-required",
29
+ base_url=base_url,
30
+ timeout=timeout,
31
+ max_retries=max_retries,
32
+ )
33
+
34
+
35
+ def chat_json(
36
+ client: OpenAI,
37
+ *,
38
+ system: str,
39
+ user: str,
40
+ model: str,
41
+ temperature: Optional[float] = 0.1,
42
+ ) -> Dict[str, Any]:
43
+ messages = [
44
+ {"role": "system", "content": system},
45
+ {"role": "user", "content": user},
46
+ ]
47
+ kwargs: Dict[str, Any] = {
48
+ "model": model,
49
+ "response_format": {"type": "json_object"},
50
+ "messages": messages,
51
+ }
52
+ if temperature is not None:
53
+ kwargs["temperature"] = temperature
54
+
55
+ while True:
56
+ try:
57
+ response = client.chat.completions.create(**kwargs)
58
+ break
59
+ except Exception as exc:
60
+ message = str(exc).lower()
61
+ if "temperature" in kwargs and "temperature" in message:
62
+ logger.warning(
63
+ "Model %s rejected temperature=%s; retrying without it",
64
+ model,
65
+ kwargs["temperature"],
66
+ )
67
+ kwargs.pop("temperature")
68
+ continue
69
+ if "response_format" in kwargs and (
70
+ "response_format" in message
71
+ or "response format" in message
72
+ or "json_object" in message
73
+ ):
74
+ logger.warning(
75
+ "Model %s rejected JSON response format; retrying without it",
76
+ model,
77
+ )
78
+ kwargs.pop("response_format")
79
+ continue
80
+ raise
81
+
82
+ content = response.choices[0].message.content or "{}"
83
+ try:
84
+ return _json_object(content)
85
+ except json.JSONDecodeError:
86
+ match = re.search(r"\{.*\}", content, re.DOTALL)
87
+ if not match:
88
+ logger.warning(
89
+ "Failed to parse LLM JSON response: %s",
90
+ content[:500],
91
+ )
92
+ return {}
93
+ return _json_object(match.group(0))