Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.
Merge PR #100: wire AutoDocument as YAML type and public export
yifanfeng978565598c459a
diff --cc hyperextract/utils/template_engine/factory.pyindex 050f6ed,16f51a9..df20a03--- a/hyperextract/utils/template_engine/factory.py+++ b/hyperextract/utils/template_engine/factory.py@@@ -1,8 -1,7 +1,8 @@@"""Template Factory - Dynamically creates template instances from configuration.- `create()` currently wires: model, list, set, graph, hypergraph,- temporal_graph, spatial_graph, spatio_temporal_graph.- Unknown `type` values raise ValueError (document is not wired here).+ Supports AutoType generation for model, list, set, document, graph,+ hypergraph, temporal_graph, spatial_graph, and spatio_temporal_graph.++Unknown `type` values raise ValueError listing the allowed types."""from pathlib import Pathdiff --cc tests/template_engine/test_factory.pyindex 15bc7a2,47b9d6b..f8f7f87--- a/tests/template_engine/test_factory.py+++ b/tests/template_engine/test_factory.py@@@ -130,33 -127,48 +130,80 @@@ class TestTemplateFactoryCreateAllTypesassert result.metadata.get("type") == "graph"+class TestTemplateFactoryUnknownType:+ """Unknown AutoType must fail closed with ValueError, not UnboundLocalError."""++ def test_unknown_type_yaml_raises_valueerror(self, tmp_path, llm_client, embedder):+ repo_root = Path(__file__).resolve().parents[2]+ src = (repo_root / "hyperextract/templates/presets/general/base_model.yaml").read_text(+ encoding="utf-8"+ )+ yaml_path = tmp_path / "not_a_type.yaml"+ yaml_path.write_text(+ src.replace("\ntype: model\n", "\ntype: not_a_type\n"),+ encoding="utf-8",+ )+ raw_type = yaml.safe_load(yaml_path.read_text(encoding="utf-8"))["type"]+ assert raw_type == "not_a_type"++ # Parser Literal rejects unknown types at load; assignment reaches the+ # factory match the same way an unbound type would after a looser schema.+ cfg = Gallery.get("general/model").model_copy(deep=True)+ cfg.type = raw_type++ with pytest.raises(ValueError, match="not_a_type") as exc_info:+ TemplateFactory.create(cfg, "en", llm_client, embedder)++ assert not isinstance(exc_info.value, UnboundLocalError)+ message = str(exc_info.value)+ assert "Allowed types:" in message+ assert "model" in message+ assert "graph" in message+ assert "hypergraph" in message+++++ _DOCUMENT_YAML = """+ language: en+ name: document_fixture+ type: document+ tags: [test]+ description: Minimal AutoDocument fixture (chunk corpus, no LLM extraction).+ output:+ description: Unused; AutoDocument stores raw chunks.+ fields:+ - name: content+ type: str+ description: Placeholder required by TemplateCfg.+ guideline:+ target: Unused; AutoDocument does not extract.+ rules:+ - Chunk text only; do not invent graph schema.+ display:+ label: '{content}'+ """+++ class TestTemplateFactoryDocumentType:+ def test_create_document_yaml_type(self, tmp_path, llm_client, embedder):+ yaml_path = tmp_path / "document.yaml"+ yaml_path.write_text(_DOCUMENT_YAML, encoding="utf-8")++ from hyperextract.utils.template_engine import Template++ result = Template.create(+ str(yaml_path),+ "en",+ llm_client,+ embedder,+ )++ from hyperextract import AutoDocument++ assert isinstance(result, AutoDocument)+ assert result.metadata["type"] == "document"++ def test_public_import_autodocument(self):+ from hyperextract import AutoDocument as Exported+ from hyperextract.types import AutoDocument as Canonical++ assert Exported is Canonical