Skip to content

Commit d303bac

Browse files
Merge pull request #25 from semiotic-ai/table-desc
Table desc
2 parents 6cfb015 + 129c7a8 commit d303bac

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed

graphdoc/docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@
7979
def setup(app):
8080
# Create static directory if it doesn't exist to avoid the warning
8181
if not os.path.exists(os.path.join(os.path.dirname(__file__), "_static")):
82-
os.makedirs(os.path.join(os.path.dirname(__file__), "_static"))
82+
os.makedirs(os.path.join(os.path.dirname(__file__), "_static"))

graphdoc/graphdoc/data/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
check_directory_path,
1212
check_file_path,
1313
load_yaml_config,
14+
load_yaml_config_redacted,
1415
setup_logging,
1516
)
1617
from graphdoc.data.local import LocalDataHelper
@@ -45,4 +46,5 @@
4546
"SchemaRating",
4647
"SchemaType",
4748
"schema_objects_to_dataset",
49+
"load_yaml_config_redacted",
4850
]

graphdoc/graphdoc/data/helper.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,36 @@ def load_yaml_config(file_path: Union[str, Path], use_env: bool = True) -> dict:
9797
return yaml.load(file, Loader=SafeLoader)
9898

9999

100+
def load_yaml_config_redacted(
101+
file_path: Union[str, Path], replace_value: str = "redacted"
102+
) -> dict:
103+
"""Load a YAML configuration file with environment variables redacted.
104+
105+
:param file_path: The path to the YAML file.
106+
:type file_path: Union[str, Path]
107+
:param replace_value: The value to replace the environment variables with.
108+
:type replace_value: str
109+
:return: The YAML configuration with env vars replaced by "redacted".
110+
:rtype: dict
111+
:raises ValueError: If the path does not resolve to a valid file.
112+
113+
"""
114+
115+
def _redacted_env_constructor(loader, node):
116+
return replace_value
117+
118+
SafeLoader.add_constructor("!env", _redacted_env_constructor)
119+
120+
_file_path = Path(file_path).resolve()
121+
if not _file_path.is_file():
122+
raise ValueError(
123+
f"The provided path does not resolve to a valid file: {file_path}"
124+
)
125+
126+
with open(_file_path, "r") as file:
127+
return yaml.load(file, Loader=SafeLoader)
128+
129+
100130
def setup_logging(
101131
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
102132
):

graphdoc/graphdoc/modules/doc_generator_module.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,13 @@ def _predict(self, database_schema: str) -> dspy.Prediction:
222222
if self.fill_empty_descriptions:
223223
updated_ast = self.par.fill_empty_descriptions(database_ast)
224224
database_schema = print_ast(updated_ast)
225+
else:
226+
database_schema = print_ast(database_ast)
225227

226228
# try to generate the schema
227229
try:
228230
prediction = self.prompt.infer(database_schema=database_schema)
231+
log.info("Generated schema: " + str(prediction.documented_schema))
229232
except Exception as e:
230233
log.warning("Error generating schema: " + str(e))
231234
return dspy.Prediction(documented_schema=database_schema)
@@ -367,7 +370,7 @@ def document_full_schema(
367370
updated_ast = self.par.fill_empty_descriptions(document_ast)
368371
return_schema = print_ast(updated_ast)
369372
else:
370-
return_schema = database_schema
373+
return_schema = print_ast(document_ast)
371374
status = "ERROR"
372375

373376
if trace:

graphdoc/graphdoc/prompts/schema_doc_generation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class DocGeneratorSignature(dspy.Signature):
3131
- Descriptions should be factual, straightforward, and avoid any speculative language.
3232
- Refrain from using the phrase "in the { table } table" within your descriptions.
3333
- Ensure that the documentation adheres to standard schema formatting without modifying the underlying schema structure.
34+
- Make sure that the entities themselves are documented.
3435
3536
### Formatting:
3637
- Maintain consistency with the existing documentation style and structure.

graphdoc/tests/test_confest.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Copyright 2025-, Semiotic AI, Inc.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
# system packages
45
import logging
56

7+
# external packages
8+
from dotenv import load_dotenv
9+
610
# internal packages
711
from graphdoc import (
812
DocGeneratorPrompt,
@@ -17,13 +21,12 @@
1721
OverwriteSchemaRating,
1822
)
1923

20-
# system packages
21-
22-
# external packages
23-
2424
# logging
2525
log = logging.getLogger(__name__)
2626

27+
# load the environment variables
28+
load_dotenv("../.env")
29+
2730

2831
class TestFixtures:
2932
def test_parser(self, par: Parser):
@@ -44,10 +47,6 @@ def test_overwrite_ldh(self, overwrite_ldh: LocalDataHelper):
4447
== OverwriteSchemaCategoryRatingMapping.get_rating
4548
)
4649

47-
# def test_gd(self, gd: GraphDoc):
48-
# assert gd is not None
49-
# assert isinstance(gd, GraphDoc)
50-
5150
def test_dqp(self, dqp):
5251
assert isinstance(dqp, DocQualityPrompt)
5352
assert dqp.prompt_type == "predict"

0 commit comments

Comments
 (0)