Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.
refactor(templates): 将参数配置字段从parameters重命名为options
yifanfeng97699461d823f9
diff --git a/hyperextract/cli/commands/build_index.py b/hyperextract/cli/commands/build_index.pyindex 82f9abb..4022895 100644--- a/hyperextract/cli/commands/build_index.py+++ b/hyperextract/cli/commands/build_index.py@@ -1,11 +1,16 @@"""Build-index command for Hyper-Extract CLI."""-from pathlib import Path-import typerfrom rich.console import Consolefrom rich.progress import Progress, SpinnerColumn, TextColumn+from ..utils import (+ validate_config,+ validate_kb_with_data,+ create_template,+ get_template_from_kb,+)+console = Console()app = typer.Typer(@@ -20,37 +25,9 @@ def main(force: bool = typer.Option(False, "--force", "-f", help="Force rebuild"),):"""Build vector index for knowledge base."""- from ..config import ConfigManager, load_kb_metadata-- path = Path(kb_path)-- if not path.exists():- console.print(f"[red]Error:[/red] Knowledge base not found: {kb_path}")- raise typer.Exit(1)-- if not path.is_dir():- console.print(f"[red]Error:[/red] Not a directory: {kb_path}")- raise typer.Exit(1)-- data_file = path / "data.json"- if not data_file.exists():- console.print(f"[red]Error:[/red] Not a valid knowledge base: {kb_path} (no data.json)")- raise typer.Exit(1)-- metadata = load_kb_metadata(path)- if not metadata:- console.print(f"[yellow]Warning:[/yellow] No metadata found, assuming knowledge_graph")- template = "knowledge_graph"- lang = "zh"- else:- template = metadata.get("template", "knowledge_graph")- lang = metadata.get("lang", "zh")-- config = ConfigManager()- valid, msg = config.validate()- if not valid:- console.print(f"[red]Error:[/red] {msg}")- raise typer.Exit(1)+ validate_config()++ path = validate_kb_with_data(kb_path)index_dir = path / "index"if index_dir.exists() and any(index_dir.iterdir()) and not force:@@ -58,6 +35,8 @@ def main(console.print(f"[dim]Index location: {index_dir}[/dim]")raise typer.Exit(0)+ template, lang = get_template_from_kb(path)+console.print(f"[blue]Template:[/blue] {template}")console.print(f"[blue]Language:[/blue] {lang}")console.print()@@ -66,9 +45,7 @@ def main(task = progress.add_task("Initializing...", total=None)try:- from ..templates import resolve_template-- kb = resolve_template(template, lang)+ kb = create_template(template, lang)progress.update(task, description="Loading knowledge base...")kb.load(path)diff --git a/hyperextract/cli/commands/feed.py b/hyperextract/cli/commands/feed.pyindex 791cb28..f08abc4 100644--- a/hyperextract/cli/commands/feed.py+++ b/hyperextract/cli/commands/feed.py@@ -8,6 +8,15 @@ import typerfrom rich.console import Consolefrom rich.progress import Progress, SpinnerColumn, TextColumn+from ..utils import (+ read_input,+ validate_config,+ validate_kb_path,+ create_template,+ get_template_from_kb,+)+from ..config import load_kb_metadata, save_kb_metadata+console = Console()app = typer.Typer(@@ -16,18 +25,6 @@ app = typer.Typer()-def read_input(input_path: str) -> str:- """Read input from file or stdin."""- import sys- if input_path == "-":- return sys.stdin.read()- path = Path(input_path)- if not path.exists():- raise FileNotFoundError(f"Input file not found: {input_path}")- with open(path, "r", encoding="utf-8") as f:- return f.read()--@app.command()def main(input: str = typer.Argument(..., help="Input file path or '-' for stdin"),@@ -36,20 +33,9 @@ def main(lang: Optional[str] = typer.Option(None, "--lang", "-l", help="Language"),):"""Append knowledge to an existing directory."""- from ..config import ConfigManager, load_kb_metadata, save_kb_metadata- from ..templates import resolve_template-- config = ConfigManager()- valid, msg = config.validate()- if not valid:- console.print(f"[red]Error:[/red] {msg}")- raise typer.Exit(1)-- output_path = Path(output)+ validate_config()- if not output_path.exists():- console.print(f"[red]Error:[/red] Output directory does not exist: {output}")- raise typer.Exit(1)+ output_path = validate_kb_path(output)metadata = load_kb_metadata(output_path)if not metadata:@@ -68,7 +54,7 @@ def main(console.print()try:- kb = resolve_template(template, lang)+ kb = create_template(template, lang)console.print(f"[green]Template loaded:[/green] {template}")except ValueError as e:console.print(f"[red]Error:[/red] {e}")diff --git a/hyperextract/cli/commands/list.py b/hyperextract/cli/commands/list.pyindex 5e36aea..34567bd 100644--- a/hyperextract/cli/commands/list.py+++ b/hyperextract/cli/commands/list.py@@ -5,6 +5,14 @@ from rich.console import Consolefrom rich.table import Tableimport typer+from hyperextract.utils.template_engine import Gallery, Template++from ..utils import (+ get_autotype_description,+ get_domain_description,+ AUTOTYPE_MAP,+)+console = Console()app = typer.Typer(@@ -13,32 +21,6 @@ app = typer.Typer()-AUTOTYPES = [- ("AutoModel", "Extract into a complete data model"),- ("AutoList", "Extract as a list (keywords, items)"),- ("AutoSet", "Extract and deduplicate (entity registry)"),- ("AutoGraph", "Extract as a knowledge graph (relations)"),- ("AutoTemporalGraph", "Extract as timeline (events over time)"),- ("AutoSpatialGraph", "Extract as spatial graph (locations)"),- ("AutoSpatioTemporalGraph", "Extract as spatiotemporal graph (time + space)"),- ("AutoHypergraph", "Extract as hypergraph (multi-party relations)"),-]--DOMAINS = [- ("finance", "Financial documents"),- ("medicine", "Medical documents"),- ("legal", "Legal documents"),- ("history", "Historical documents"),- ("literature", "Literature works"),- ("tcm", "Traditional Chinese Medicine"),- ("news", "News articles"),- ("biology", "Biological documents"),- ("industry", "Industrial documents"),- ("agriculture", "Agricultural documents"),- ("food", "Food and culinary"),- ("general", "General purpose"),-]-METHODS = [("kg_gen", "Knowledge Graph Generation"),("atom", "Atomic Information Extraction"),@@ -50,22 +32,11 @@ METHODS = []-def _get_domains_from_configs() -> list:- """Get domains from configs directory."""- try:- from ..templates import get_domains- return get_domains()- except Exception:- return []--@app.command(name="autotype")def autotype(search: Optional[str] = typer.Option(None, "--search", "-s", help="Search autotypes"),):"""List all available AutoTypes."""- from hyperextract.utils.template_engine import Gallery-autotypes = Gallery.list_autotypes()if search:@@ -76,10 +47,10 @@ def autotype(table.add_column("AutoType", style="cyan", width=25)table.add_column("Description", style="green")- autotype_descriptions = dict(AUTOTYPES)for name in autotypes:- desc = autotype_descriptions.get(name, "")- table.add_row(name, desc)+ display_name = AUTOTYPE_MAP.get(name, name)+ desc = get_autotype_description(display_name)+ table.add_row(display_name, desc)console.print(table)console.print(f"\n[dim]Total: {len(autotypes)} AutoTypes[/dim]")@@ -92,8 +63,6 @@ def template(language: Optional[str] = typer.Option(None, "--lang", "-l", help="Filter by language"),):"""List all available templates."""- from hyperextract.utils.template_engine import Gallery-results = Gallery.search(query=search, autotype=autotype, language=language)templates = []@@ -124,13 +93,11 @@ def domain(search: Optional[str] = typer.Option(None, "--search", "-s", help="Search domains"),):"""List all available domains."""- domains = _get_domains_from_configs()-- domain_descriptions = dict(DOMAINS)+ domains = Template.domains()items = []for name, count in domains:- desc = domain_descriptions.get(name, f"{name} documents")+ desc = get_domain_description(name)items.append((name, f"{desc} ({count} templates)"))if search:diff --git a/hyperextract/cli/commands/parse.py b/hyperextract/cli/commands/parse.pyindex e3edb69..0bfba93 100644--- a/hyperextract/cli/commands/parse.py+++ b/hyperextract/cli/commands/parse.py@@ -1,14 +1,21 @@"""Parse command for Hyper-Extract CLI."""-import sysfrom pathlib import Pathfrom datetime import datetime-from typing import Optionalimport typerfrom rich.console import Consolefrom rich.progress import Progress, SpinnerColumn, TextColumn+from ..utils import (+ read_input,+ validate_config,+ create_template,+ get_template_config,+ get_auto_type_from_config,+)+from ..config import save_kb_metadata+console = Console()app = typer.Typer(@@ -17,17 +24,6 @@ app = typer.Typer()-def read_input(input_path: str) -> str:- """Read input from file or stdin."""- if input_path == "-":- return sys.stdin.read()- path = Path(input_path)- if not path.exists():- raise FileNotFoundError(f"Input file not found: {input_path}")- with open(path, "r", encoding="utf-8") as f:- return f.read()--@app.command()def main(input: str = typer.Argument(..., help="Input file path or '-' for stdin"),@@ -37,14 +33,7 @@ def main(force: bool = typer.Option(False, "--force", "-f", help="Force overwrite"),):"""Extract knowledge from text to a new directory."""- from ..config import ConfigManager, save_kb_metadata- from ..templates import resolve_template, resolve_template_config, get_auto_type_from_template-- config = ConfigManager()- valid, msg = config.validate()- if not valid:- console.print(f"[red]Error:[/red] {msg}")- raise typer.Exit(1)+ validate_config()output_path = Path(output)@@ -62,7 +51,7 @@ def main(console.print()try:- template_config = resolve_template_config(template, lang)+ template_config = get_template_config(template, lang)if template_config is None:raise ValueError(f"Template '{template}' not found")console.print(f"[green]Template resolved:[/green] {template_config.name}")@@ -73,7 +62,7 @@ def main(with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}"), console=console) as progress:task = progress.add_task("Creating template instance...", total=None)- kb = resolve_template(template, lang)+ kb = create_template(template, lang)progress.update(task, description="Reading input...")text = read_input(input)@@ -88,7 +77,7 @@ def main(metadata = {"template": template,"lang": lang,- "auto_type": get_auto_type_from_template(template_config),+ "auto_type": get_auto_type_from_config(template_config),"created_at": datetime.now().isoformat(),"updated_at": datetime.now().isoformat(),}diff --git a/hyperextract/cli/commands/search.py b/hyperextract/cli/commands/search.pyindex 19810ab..b0c10be 100644--- a/hyperextract/cli/commands/search.py+++ b/hyperextract/cli/commands/search.py@@ -1,11 +1,18 @@"""Search command for Hyper-Extract CLI."""-from pathlib import Path+import jsonimport typerfrom rich.console import Consolefrom rich.progress import Progress, SpinnerColumn, TextColumn+from ..utils import (+ validate_config,+ validate_kb_with_index,+ create_template,+ get_template_from_kb,+)+console = Console()app = typer.Typer(@@ -21,38 +28,10 @@ def main(top_k: int = typer.Option(3, "--top-k", "-n", help="Number of results"),):"""Semantic search in knowledge base."""- from ..config import ConfigManager, load_kb_metadata- from ..templates import resolve_template-- path = Path(kb_path)-- if not path.exists():- console.print(f"[red]Error:[/red] Knowledge base not found: {kb_path}")- raise typer.Exit(1)-- if not path.is_dir():- console.print(f"[red]Error:[/red] Not a directory: {kb_path}")- raise typer.Exit(1)-- index_dir = path / "index"- if not index_dir.exists() or not any(index_dir.iterdir()):- console.print(f"[red]Error:[/red] Index not found. Please run 'he build-index {kb_path}' first.")- raise typer.Exit(1)-- metadata = load_kb_metadata(path)- if not metadata:- console.print(f"[yellow]Warning:[/yellow] No metadata found, assuming knowledge_graph")- template = "knowledge_graph"- lang = "zh"- else:- template = metadata.get("template", "knowledge_graph")- lang = metadata.get("lang", "zh")+ validate_config()- config = ConfigManager()- valid, msg = config.validate()- if not valid:- console.print(f"[red]Error:[/red] {msg}")- raise typer.Exit(1)+ path = validate_kb_with_index(kb_path)+ template, lang = get_template_from_kb(path)console.print(f"[blue]Query:[/blue] {query}")console.print(f"[blue]Knowledge base:[/blue] {kb_path}")@@ -63,7 +42,7 @@ def main(task = progress.add_task("Searching...", total=None)try:- kb = resolve_template(template, lang)+ kb = create_template(template, lang)progress.update(task, description="Loading knowledge base...")kb.load(path)@@ -85,10 +64,8 @@ def main(for i, result in enumerate(results, 1):console.print(f"[bold cyan]Result {i}:[/bold cyan]")if hasattr(result, "model_dump"):- import jsonconsole.print_json(json.dumps(result.model_dump(), indent=2, ensure_ascii=False))elif hasattr(result, "dict"):- import jsonconsole.print_json(json.dumps(result.dict(), indent=2, ensure_ascii=False))else:console.print(str(result))diff --git a/hyperextract/cli/commands/show.py b/hyperextract/cli/commands/show.pyindex ad675dd..2f0a509 100644--- a/hyperextract/cli/commands/show.py+++ b/hyperextract/cli/commands/show.py@@ -1,11 +1,17 @@"""Show command for Hyper-Extract CLI."""-from pathlib import Pathimport jsonimport typerfrom rich.console import Console+from ..utils import (+ validate_config,+ validate_kb_with_data,+ create_template,+ get_template_from_kb,+)+console = Console()app = typer.Typer(@@ -20,46 +26,20 @@ def main(build_index: bool = typer.Option(False, "--build-index", "-b", help="Build index"),):"""Show knowledge base visualization."""- from ..config import ConfigManager, load_kb_metadata- from ..templates import resolve_template, resolve_template_config-- path = Path(kb_path)-- if not path.exists():- console.print(f"[red]Error:[/red] Knowledge base not found: {kb_path}")- raise typer.Exit(1)+ path = validate_kb_with_data(kb_path)- if not path.is_dir():- console.print(f"[red]Error:[/red] Not a directory: {kb_path}")- raise typer.Exit(1)-- data_file = path / "data.json"- if not data_file.exists():- console.print(f"[red]Error:[/red] Not a valid knowledge base: {kb_path} (no data.json)")- raise typer.Exit(1)-- metadata = load_kb_metadata(path)- if not metadata:- console.print(f"[yellow]Warning:[/yellow] No metadata found, assuming knowledge_graph")- template = "knowledge_graph"- lang = "zh"- else:- template = metadata.get("template", "knowledge_graph")- lang = metadata.get("lang", "zh")+ template, lang = get_template_from_kb(path)console.print(f"[blue]Template:[/blue] {template}")console.print(f"[blue]Language:[/blue] {lang}")console.print()- config = ConfigManager()- valid, msg = config.validate()- if not valid and build_index:- console.print(f"[red]Error:[/red] {msg}")- raise typer.Exit(1)+ if build_index:+ validate_config()with console.status("[bold blue]Loading knowledge base..."):try:- kb = resolve_template(template, lang)+ kb = create_template(template, lang)kb.load(path)if build_index:@@ -71,6 +51,7 @@ def main(console.print(f"[red]Error loading knowledge base:[/red] {e}")raise typer.Exit(1)+ data_file = path / "data.json"with open(data_file, "r", encoding="utf-8") as f:data = json.load(f)diff --git a/hyperextract/cli/commands/talk.py b/hyperextract/cli/commands/talk.pyindex fb2e545..2a71f3f 100644--- a/hyperextract/cli/commands/talk.py+++ b/hyperextract/cli/commands/talk.py@@ -1,12 +1,18 @@"""Talk command for Hyper-Extract CLI."""-from pathlib import Pathfrom typing import Optionalimport typerfrom rich.console import Consolefrom rich.progress import Progress, SpinnerColumn, TextColumn+from ..utils import (+ validate_config,+ validate_kb_with_index,+ create_template,+ get_template_from_kb,+)+console = Console()app = typer.Typer(@@ -15,7 +21,7 @@ app = typer.Typer()-def chat_loop(kb, config):+def chat_loop(kb):"""Interactive chat loop."""console.print("\n[bold green]Entering interactive mode. Type 'exit' or 'quit' to stop.[/bold green]\n")while True:@@ -45,38 +51,10 @@ def main(interactive: bool = typer.Option(False, "--interactive", "-i", help="Interactive mode"),):"""Chat with knowledge base."""- from ..config import ConfigManager, load_kb_metadata- from ..templates import resolve_template-- path = Path(kb_path)-- if not path.exists():- console.print(f"[red]Error:[/red] Knowledge base not found: {kb_path}")- raise typer.Exit(1)-- if not path.is_dir():- console.print(f"[red]Error:[/red] Not a directory: {kb_path}")- raise typer.Exit(1)+ validate_config()- index_dir = path / "index"- if not index_dir.exists() or not any(index_dir.iterdir()):- console.print(f"[red]Error:[/red] Index not found. Please run 'he build-index {kb_path}' first.")- raise typer.Exit(1)-- metadata = load_kb_metadata(path)- if not metadata:- console.print(f"[yellow]Warning:[/yellow] No metadata found, assuming knowledge_graph")- template = "knowledge_graph"- lang = "zh"- else:- template = metadata.get("template", "knowledge_graph")- lang = metadata.get("lang", "zh")-- config = ConfigManager()- valid, msg = config.validate()- if not valid:- console.print(f"[red]Error:[/red] {msg}")- raise typer.Exit(1)+ path = validate_kb_with_index(kb_path)+ template, lang = get_template_from_kb(path)if interactive:console.print(f"[blue]Knowledge base:[/blue] {kb_path}")@@ -96,7 +74,7 @@ def main(task = progress.add_task("Loading...", total=None)try:- kb = resolve_template(template, lang)+ kb = create_template(template, lang)progress.update(task, description="Loading knowledge base...")kb.load(path)@@ -106,7 +84,7 @@ def main(raise typer.Exit(1)if interactive:- chat_loop(kb, config)+ chat_loop(kb)else:with console.status("[bold blue]Thinking..."):try:diff --git a/hyperextract/cli/templates.py b/hyperextract/cli/templates.pydeleted file mode 100644index 1951336..0000000--- a/hyperextract/cli/templates.py+++ /dev/null@@ -1,58 +0,0 @@-"""Template loading utilities for Hyper-Extract CLI."""--from typing import Optional, Any, Type--from hyperextract.utils.template_engine import Gallery, TemplateConfig---def resolve_template(template_str: str, lang: str = "zh") -> Type:- """Resolve a template string to a template instance.-- Args:- template_str: Template name (e.g., "knowledge_graph", "zh/finance/risk_assessment")- lang: Language (zh/en)-- Returns:- TemplateWrapper instance-- Raises:- ValueError: If template not found- """- return Gallery.create(template_str, lang)---def resolve_template_config(template_str: str, lang: str = "zh") -> Optional[TemplateConfig]:- """Resolve a template string to a TemplateConfig.-- Args:- template_str: Template name- lang: Language (zh/en)-- Returns:- TemplateConfig if found, None otherwise- """- return Gallery._resolve_config(template_str, lang)---def get_auto_type_from_template(template_or_config: Any) -> str:- """Infer AutoType from template class or config."""- if isinstance(template_or_config, TemplateConfig):- autotype = template_or_config.autotype- autotype_map = {- "model": "AutoModel",- "list": "AutoList",- "set": "AutoSet",- "graph": "AutoGraph",- "hypergraph": "AutoHypergraph",- "temporal_graph": "AutoTemporalGraph",- "spatial_graph": "AutoSpatialGraph",- "spatio_temporal_graph": "AutoSpatioTemporalGraph",- }- return autotype_map.get(autotype, "AutoGraph")-- return "AutoGraph"---def get_domains() -> list:- """Get available domains from configs directory."""- return Gallery.list_domains()diff --git a/hyperextract/cli/utils.py b/hyperextract/cli/utils.pynew file mode 100644index 0000000..470fa3b--- /dev/null+++ b/hyperextract/cli/utils.py@@ -0,0 +1,242 @@+"""Common utilities for Hyper-Extract CLI."""++import sys+import typer+from pathlib import Path+from rich.console import Console+from typing import Optional, Tuple++from hyperextract.utils.template_engine import Template, TemplateConfig+from .config import ConfigManager++console = Console()+++AUTOTYPE_MAP = {+ "model": "AutoModel",+ "list": "AutoList",+ "set": "AutoSet",+ "graph": "AutoGraph",+ "hypergraph": "AutoHypergraph",+ "temporal_graph": "AutoTemporalGraph",+ "spatial_graph": "AutoSpatialGraph",+ "spatio_temporal_graph": "AutoSpatioTemporalGraph",+}++AUTOTYPE_DESCRIPTIONS = {+ "AutoModel": "Extract into a complete data model",+ "AutoList": "Extract as a list (keywords, items)",+ "AutoSet": "Extract and deduplicate (entity registry)",+ "AutoGraph": "Extract as a knowledge graph (relations)",+ "AutoTemporalGraph": "Extract as timeline (events over time)",+ "AutoSpatialGraph": "Extract as spatial graph (locations)",+ "AutoSpatioTemporalGraph": "Extract as spatiotemporal graph (time + space)",+ "AutoHypergraph": "Extract as hypergraph (multi-party relations)",+}++DOMAIN_DESCRIPTIONS = {+ "finance": "Financial documents",+ "medicine": "Medical documents",+ "legal": "Legal documents",+ "history": "Historical documents",+ "literature": "Literature works",+ "tcm": "Traditional Chinese Medicine",+ "news": "News articles",+ "biology": "Biological documents",+ "industry": "Industrial documents",+ "agriculture": "Agricultural documents",+ "food": "Food and culinary",+ "general": "General purpose",+}+++def read_input(input_path: str) -> str:+ """Read input from file or stdin."""+ if input_path == "-":+ return sys.stdin.read()+ path = Path(input_path)+ if not path.exists():+ raise FileNotFoundError(f"Input file not found: {input_path}")+ with open(path, "r", encoding="utf-8") as f:+ return f.read()+++def validate_kb_path(kb_path: str) -> Path:+ """Validate knowledge base path.++ Args:+ kb_path: Knowledge base directory path++ Returns:+ Path object++ Raises:+ typer.Exit: If path is invalid+ """+ path = Path(kb_path)++ if not path.exists():+ console.print(f"[red]Error:[/red] Knowledge base not found: {kb_path}")+ raise typer.Exit(1)++ if not path.is_dir():+ console.print(f"[red]Error:[/red] Not a directory: {kb_path}")+ raise typer.Exit(1)++ return path+++def validate_kb_with_data(kb_path: str) -> Path:+ """Validate knowledge base path with data.json.++ Args:+ kb_path: Knowledge base directory path++ Returns:+ Path object++ Raises:+ typer.Exit: If path is invalid or missing data.json+ """+ path = validate_kb_path(kb_path)++ data_file = path / "data.json"+ if not data_file.exists():+ console.print(+ f"[red]Error:[/red] Not a valid knowledge base: {kb_path} (no data.json)"+ )+ raise typer.Exit(1)++ return path+++def validate_kb_with_index(kb_path: str) -> Path:+ """Validate knowledge base path with index.++ Args:+ kb_path: Knowledge base directory path++ Returns:+ Path object++ Raises:+ typer.Exit: If path is invalid or missing index+ """+ path = validate_kb_path(kb_path)++ index_dir = path / "index"+ if not index_dir.exists() or not any(index_dir.iterdir()):+ console.print(+ f"[red]Error:[/red] Index not found. Please run 'he build-index {kb_path}' first."+ )+ raise typer.Exit(1)++ return path+++def get_template_from_kb(kb_path: Path) -> Tuple[str, str]:+ """Get template name and language from knowledge base metadata.++ Args:+ kb_path: Knowledge base directory path++ Returns:+ Tuple of (template_name, language)+ """+ from .config import load_kb_metadata++ metadata = load_kb_metadata(kb_path)++ if not metadata:+ console.print(+ "[yellow]Warning:[/yellow] No metadata found, assuming knowledge_graph"+ )+ return "knowledge_graph", "zh"++ template = metadata.get("template", "knowledge_graph")+ lang = metadata.get("lang", "zh")++ return template, lang+++def validate_config() -> "ConfigManager":+ """Validate configuration.++ Returns:+ ConfigManager instance++ Raises:+ typer.Exit: If configuration is invalid+ """++ config = ConfigManager()+ valid, msg = config.validate()++ if not valid:+ console.print(f"[red]Error:[/red] {msg}")+ raise typer.Exit(1)++ return config+++def create_template(template: str, lang: str = "zh"):+ """Create template instance.++ Args:+ template: Template name+ lang: Language (zh/en)++ Returns:+ TemplateWrapper instance+ """+ return Template.create(template, lang)+++def get_template_config(template: str, lang: str = "zh") -> Optional[TemplateConfig]:+ """Get template config.++ Args:+ template: Template name+ lang: Language (zh/en)++ Returns:+ TemplateConfig if found+ """+ return Template.get(template, lang)+++def get_auto_type_from_config(config: TemplateConfig) -> str:+ """Infer AutoType from template config.++ Args:+ config: TemplateConfig instance++ Returns:+ AutoType string (e.g., "AutoGraph")+ """+ autotype = config.autotype+ return AUTOTYPE_MAP.get(autotype, "AutoGraph")+++def get_autotype_description(autotype: str) -> str:+ """Get description for AutoType.++ Args:+ autotype: AutoType name (e.g., "AutoGraph")++ Returns:+ Description string+ """+ return AUTOTYPE_DESCRIPTIONS.get(autotype, "")+++def get_domain_description(domain: str) -> str:+ """Get description for domain.++ Args:+ domain: Domain name (e.g., "finance")++ Returns:+ Description string+ """+ return DOMAIN_DESCRIPTIONS.get(domain, f"{domain} documents")diff --git a/hyperextract/templates/legacy/presets/agriculture/amendment_plan.yaml b/hyperextract/templates/legacy/presets/agriculture/amendment_plan.yamlindex 6bc4185..ea06063 100644--- a/hyperextract/templates/legacy/presets/agriculture/amendment_plan.yaml+++ b/hyperextract/templates/legacy/presets/agriculture/amendment_plan.yaml@@ -72,7 +72,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/agriculture/crop_growth_cycle.yaml b/hyperextract/templates/legacy/presets/agriculture/crop_growth_cycle.yamlindex cbe6578..ec7a76a 100644--- a/hyperextract/templates/legacy/presets/agriculture/crop_growth_cycle.yaml+++ b/hyperextract/templates/legacy/presets/agriculture/crop_growth_cycle.yaml@@ -85,7 +85,7 @@ identifiers:target: "target"time_field: "time"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/agriculture/pest_control_hypergraph.yaml b/hyperextract/templates/legacy/presets/agriculture/pest_control_hypergraph.yamlindex bba7f4d..5409574 100644--- a/hyperextract/templates/legacy/presets/agriculture/pest_control_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/agriculture/pest_control_hypergraph.yaml@@ -82,7 +82,7 @@ identifiers:source: "crop"target: "pest"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/biology/phylogenetic_relation_graph.yaml b/hyperextract/templates/legacy/presets/biology/phylogenetic_relation_graph.yamlindex 9607cd9..37edd4d 100644--- a/hyperextract/templates/legacy/presets/biology/phylogenetic_relation_graph.yaml+++ b/hyperextract/templates/legacy/presets/biology/phylogenetic_relation_graph.yaml@@ -82,7 +82,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/biology/protein_complex_map.yaml b/hyperextract/templates/legacy/presets/biology/protein_complex_map.yamlindex 5f19a84..0debebf 100644--- a/hyperextract/templates/legacy/presets/biology/protein_complex_map.yaml+++ b/hyperextract/templates/legacy/presets/biology/protein_complex_map.yaml@@ -77,7 +77,7 @@ identifiers:edge_id: "{complex_name}|{members}"edge_members: "members"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/biology/regulatory_network.yaml b/hyperextract/templates/legacy/presets/biology/regulatory_network.yamlindex 36455e7..7cd5cf6 100644--- a/hyperextract/templates/legacy/presets/biology/regulatory_network.yaml+++ b/hyperextract/templates/legacy/presets/biology/regulatory_network.yaml@@ -83,7 +83,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/biology/species_interaction_web.yaml b/hyperextract/templates/legacy/presets/biology/species_interaction_web.yamlindex 115b951..fd628fc 100644--- a/hyperextract/templates/legacy/presets/biology/species_interaction_web.yaml+++ b/hyperextract/templates/legacy/presets/biology/species_interaction_web.yaml@@ -78,7 +78,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/biology/taxonomic_tree.yaml b/hyperextract/templates/legacy/presets/biology/taxonomic_tree.yamlindex 11dc4dc..79a9f87 100644--- a/hyperextract/templates/legacy/presets/biology/taxonomic_tree.yaml+++ b/hyperextract/templates/legacy/presets/biology/taxonomic_tree.yaml@@ -73,7 +73,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/food/ingredient_composition_hypergraph.yaml b/hyperextract/templates/legacy/presets/food/ingredient_composition_hypergraph.yamlindex 211c96f..d5238dc 100644--- a/hyperextract/templates/legacy/presets/food/ingredient_composition_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/food/ingredient_composition_hypergraph.yaml@@ -91,7 +91,7 @@ identifiers:- "auxiliary_ingredients"- "seasonings"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/food/sensory_evaluation_graph.yaml b/hyperextract/templates/legacy/presets/food/sensory_evaluation_graph.yamlindex 49eec98..6cd76b3 100644--- a/hyperextract/templates/legacy/presets/food/sensory_evaluation_graph.yaml+++ b/hyperextract/templates/legacy/presets/food/sensory_evaluation_graph.yaml@@ -89,7 +89,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/history/chronological_event_chain.yaml b/hyperextract/templates/legacy/presets/history/chronological_event_chain.yamlindex 3f09f89..895ea8e 100644--- a/hyperextract/templates/legacy/presets/history/chronological_event_chain.yaml+++ b/hyperextract/templates/legacy/presets/history/chronological_event_chain.yaml@@ -85,7 +85,7 @@ identifiers:target: "target"time_field: "time"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/history/epistolary_knowledge_graph.yaml b/hyperextract/templates/legacy/presets/history/epistolary_knowledge_graph.yamlindex 8e783b4..281a2e4 100644--- a/hyperextract/templates/legacy/presets/history/epistolary_knowledge_graph.yaml+++ b/hyperextract/templates/legacy/presets/history/epistolary_knowledge_graph.yaml@@ -100,7 +100,7 @@ identifiers:target: "target"time_field: "time"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/history/historical_context_graph.yaml b/hyperextract/templates/legacy/presets/history/historical_context_graph.yamlindex 8fe656b..82d735f 100644--- a/hyperextract/templates/legacy/presets/history/historical_context_graph.yaml+++ b/hyperextract/templates/legacy/presets/history/historical_context_graph.yaml@@ -70,7 +70,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/history/historical_knowledge_graph.yaml b/hyperextract/templates/legacy/presets/history/historical_knowledge_graph.yamlindex b7a63ba..c4e6b79 100644--- a/hyperextract/templates/legacy/presets/history/historical_knowledge_graph.yaml+++ b/hyperextract/templates/legacy/presets/history/historical_knowledge_graph.yaml@@ -75,7 +75,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/history/multi_participant_event_map.yaml b/hyperextract/templates/legacy/presets/history/multi_participant_event_map.yamlindex 9c6af56..7a762ff 100644--- a/hyperextract/templates/legacy/presets/history/multi_participant_event_map.yaml+++ b/hyperextract/templates/legacy/presets/history/multi_participant_event_map.yaml@@ -77,7 +77,7 @@ identifiers:edge_id: "eventName"edge_members: "participants"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/history/narrative_relation_graph.yaml b/hyperextract/templates/legacy/presets/history/narrative_relation_graph.yamlindex 3bcd26f..bd13514 100644--- a/hyperextract/templates/legacy/presets/history/narrative_relation_graph.yaml+++ b/hyperextract/templates/legacy/presets/history/narrative_relation_graph.yaml@@ -72,7 +72,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/history/personal_trajectory_hypergraph.yaml b/hyperextract/templates/legacy/presets/history/personal_trajectory_hypergraph.yamlindex 7357daf..f58f700 100644--- a/hyperextract/templates/legacy/presets/history/personal_trajectory_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/history/personal_trajectory_hypergraph.yaml@@ -71,7 +71,7 @@ identifiers:edge_id: "{phase}|{time}|{locations}"edge_members: "companions"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/history/political_struggle_hypergraph.yaml b/hyperextract/templates/legacy/presets/history/political_struggle_hypergraph.yamlindex c9d40c4..0a55b77 100644--- a/hyperextract/templates/legacy/presets/history/political_struggle_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/history/political_struggle_hypergraph.yaml@@ -96,7 +96,7 @@ identifiers:- "planners"- "turncoats"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/literature/character_arc_timeline.yaml b/hyperextract/templates/legacy/presets/literature/character_arc_timeline.yamlindex 217e2d5..53f1e2a 100644--- a/hyperextract/templates/legacy/presets/literature/character_arc_timeline.yaml+++ b/hyperextract/templates/legacy/presets/literature/character_arc_timeline.yaml@@ -79,7 +79,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/literature/complex_character_relation.yaml b/hyperextract/templates/legacy/presets/literature/complex_character_relation.yamlindex 20e15e0..1b42283 100644--- a/hyperextract/templates/legacy/presets/literature/complex_character_relation.yaml+++ b/hyperextract/templates/legacy/presets/literature/complex_character_relation.yaml@@ -77,7 +77,7 @@ identifiers:edge_id: "{relationType}|{participants}"edge_members: "participants"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/literature/critique_argument_hypergraph.yaml b/hyperextract/templates/legacy/presets/literature/critique_argument_hypergraph.yamlindex 341c086..de74587 100644--- a/hyperextract/templates/legacy/presets/literature/critique_argument_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/literature/critique_argument_hypergraph.yaml@@ -78,7 +78,7 @@ identifiers:- "citations"- "conclusion"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/literature/motif_association_net.yaml b/hyperextract/templates/legacy/presets/literature/motif_association_net.yamlindex 5cd99ab..40abbe4 100644--- a/hyperextract/templates/legacy/presets/literature/motif_association_net.yaml+++ b/hyperextract/templates/legacy/presets/literature/motif_association_net.yaml@@ -67,7 +67,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/literature/narrative_event_chain.yaml b/hyperextract/templates/legacy/presets/literature/narrative_event_chain.yamlindex 31009df..6ba28b6 100644--- a/hyperextract/templates/legacy/presets/literature/narrative_event_chain.yaml+++ b/hyperextract/templates/legacy/presets/literature/narrative_event_chain.yaml@@ -73,7 +73,7 @@ identifiers:target: "target"time_field: "time"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/literature/narrative_structure_tree.yaml b/hyperextract/templates/legacy/presets/literature/narrative_structure_tree.yamlindex 195c1e4..930b88a 100644--- a/hyperextract/templates/legacy/presets/literature/narrative_structure_tree.yaml+++ b/hyperextract/templates/legacy/presets/literature/narrative_structure_tree.yaml@@ -74,7 +74,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/literature/scene_event_hypergraph.yaml b/hyperextract/templates/legacy/presets/literature/scene_event_hypergraph.yamlindex 46bf745..d331b3c 100644--- a/hyperextract/templates/legacy/presets/literature/scene_event_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/literature/scene_event_hypergraph.yaml@@ -86,7 +86,7 @@ identifiers:- "actions"- "timeOfDay"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/literature/story_entity_graph.yaml b/hyperextract/templates/legacy/presets/literature/story_entity_graph.yamlindex 34fa693..53e5389 100644--- a/hyperextract/templates/legacy/presets/literature/story_entity_graph.yaml+++ b/hyperextract/templates/legacy/presets/literature/story_entity_graph.yaml@@ -69,7 +69,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/news/complex_relation_net.yaml b/hyperextract/templates/legacy/presets/news/complex_relation_net.yamlindex 72162c2..c042c3f 100644--- a/hyperextract/templates/legacy/presets/news/complex_relation_net.yaml+++ b/hyperextract/templates/legacy/presets/news/complex_relation_net.yaml@@ -81,7 +81,7 @@ identifiers:edge_id: "{relationType}|{participants}"edge_members: "participants"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/news/impact_chain.yaml b/hyperextract/templates/legacy/presets/news/impact_chain.yamlindex f0df671..038ec1f 100644--- a/hyperextract/templates/legacy/presets/news/impact_chain.yaml+++ b/hyperextract/templates/legacy/presets/news/impact_chain.yaml@@ -87,7 +87,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/news/investigative_context_graph.yaml b/hyperextract/templates/legacy/presets/news/investigative_context_graph.yamlindex fd8be49..b782f24 100644--- a/hyperextract/templates/legacy/presets/news/investigative_context_graph.yaml+++ b/hyperextract/templates/legacy/presets/news/investigative_context_graph.yaml@@ -85,7 +85,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/news/key_event_sequence.yaml b/hyperextract/templates/legacy/presets/news/key_event_sequence.yamlindex 1184d6c..f5a88f1 100644--- a/hyperextract/templates/legacy/presets/news/key_event_sequence.yaml+++ b/hyperextract/templates/legacy/presets/news/key_event_sequence.yaml@@ -95,7 +95,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/news/live_update_timeline.yaml b/hyperextract/templates/legacy/presets/news/live_update_timeline.yamlindex 497e7e3..a4a652f 100644--- a/hyperextract/templates/legacy/presets/news/live_update_timeline.yaml+++ b/hyperextract/templates/legacy/presets/news/live_update_timeline.yaml@@ -98,7 +98,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/news/news_entity_graph.yaml b/hyperextract/templates/legacy/presets/news/news_entity_graph.yamlindex 97a3120..816b336 100644--- a/hyperextract/templates/legacy/presets/news/news_entity_graph.yaml+++ b/hyperextract/templates/legacy/presets/news/news_entity_graph.yaml@@ -85,7 +85,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/legacy/presets/news/viewpoint_structure.yaml b/hyperextract/templates/legacy/presets/news/viewpoint_structure.yamlindex 73649c1..5ece582 100644--- a/hyperextract/templates/legacy/presets/news/viewpoint_structure.yaml+++ b/hyperextract/templates/legacy/presets/news/viewpoint_structure.yaml@@ -93,7 +93,7 @@ identifiers:edge_id: "name"edge_members: "participantNames"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/call_sentiment_hypergraph.yaml b/hyperextract/templates/presets/finance/call_sentiment_hypergraph.yamlindex ac16c87..7210a15 100644--- a/hyperextract/templates/presets/finance/call_sentiment_hypergraph.yaml+++ b/hyperextract/templates/presets/finance/call_sentiment_hypergraph.yaml@@ -101,7 +101,7 @@ identifiers:edge_id: "{cluster_name}|{participating_elements}"edge_members: "participating_elements"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/company_history_timeline.yaml b/hyperextract/templates/presets/finance/company_history_timeline.yamlindex 3a6a95c..aea5549 100644--- a/hyperextract/templates/presets/finance/company_history_timeline.yaml+++ b/hyperextract/templates/presets/finance/company_history_timeline.yaml@@ -112,7 +112,7 @@ identifiers:target: "target"time_field: "eventDate"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/discussion_graph.yaml b/hyperextract/templates/presets/finance/discussion_graph.yamlindex eb8b65a..975ec36 100644--- a/hyperextract/templates/presets/finance/discussion_graph.yaml+++ b/hyperextract/templates/presets/finance/discussion_graph.yaml@@ -87,7 +87,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/factor_influence_hypergraph.yaml b/hyperextract/templates/presets/finance/factor_influence_hypergraph.yamlindex 7ce028b..30f78ff 100644--- a/hyperextract/templates/presets/finance/factor_influence_hypergraph.yaml+++ b/hyperextract/templates/presets/finance/factor_influence_hypergraph.yaml@@ -79,7 +79,7 @@ identifiers:edge_id: "{result}_{factors}"edge_members: "factors"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/financial_data_temporal_graph.yaml b/hyperextract/templates/presets/finance/financial_data_temporal_graph.yamlindex 75619c7..a57772f 100644--- a/hyperextract/templates/presets/finance/financial_data_temporal_graph.yaml+++ b/hyperextract/templates/presets/finance/financial_data_temporal_graph.yaml@@ -113,7 +113,7 @@ identifiers:target: "target"time_field: "fiscal_period"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/market_narrative_timeline.yaml b/hyperextract/templates/presets/finance/market_narrative_timeline.yamlindex 05707a2..82c9352 100644--- a/hyperextract/templates/presets/finance/market_narrative_timeline.yaml+++ b/hyperextract/templates/presets/finance/market_narrative_timeline.yaml@@ -107,7 +107,7 @@ identifiers:target: "target"time_field: "timestamp"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/material_event_timeline.yaml b/hyperextract/templates/presets/finance/material_event_timeline.yamlindex b5e86d1..e230aca 100644--- a/hyperextract/templates/presets/finance/material_event_timeline.yaml+++ b/hyperextract/templates/presets/finance/material_event_timeline.yaml@@ -123,7 +123,7 @@ identifiers:target: "target"time_field: "start_timestamp"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/multi_source_sentiment_hypergraph.yaml b/hyperextract/templates/presets/finance/multi_source_sentiment_hypergraph.yamlindex dbedcad..36bc2bd 100644--- a/hyperextract/templates/presets/finance/multi_source_sentiment_hypergraph.yaml+++ b/hyperextract/templates/presets/finance/multi_source_sentiment_hypergraph.yaml@@ -113,7 +113,7 @@ identifiers:edge_id: "fusion_name"edge_members: "participating_sources"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/risk_assessment.yaml b/hyperextract/templates/presets/finance/risk_assessment.yamlindex 19b6b3d..c6bca8e 100644--- a/hyperextract/templates/presets/finance/risk_assessment.yaml+++ b/hyperextract/templates/presets/finance/risk_assessment.yaml@@ -115,7 +115,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/shareholder_structure.yaml b/hyperextract/templates/presets/finance/shareholder_structure.yamlindex 6d6b798..1222ee9 100644--- a/hyperextract/templates/presets/finance/shareholder_structure.yaml+++ b/hyperextract/templates/presets/finance/shareholder_structure.yaml@@ -105,7 +105,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/finance/supply_chain.yaml b/hyperextract/templates/presets/finance/supply_chain.yamlindex f4458f9..db2fed8 100644--- a/hyperextract/templates/presets/finance/supply_chain.yaml+++ b/hyperextract/templates/presets/finance/supply_chain.yaml@@ -89,7 +89,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "one_stage"display:diff --git a/hyperextract/templates/presets/general/compliance_logic.yaml b/hyperextract/templates/presets/general/compliance_logic.yamlindex 8d1fa5f..99a8e14 100644--- a/hyperextract/templates/presets/general/compliance_logic.yaml+++ b/hyperextract/templates/presets/general/compliance_logic.yaml@@ -83,7 +83,7 @@ identifiers:edge_id: "{ruleType}_{action}_{participants}"edge_members: "participants"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/general/concept_hierarchy.yaml b/hyperextract/templates/presets/general/concept_hierarchy.yamlindex 1b54879..95e7e3d 100644--- a/hyperextract/templates/presets/general/concept_hierarchy.yaml+++ b/hyperextract/templates/presets/general/concept_hierarchy.yaml@@ -72,7 +72,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/general/cross_reference_net.yaml b/hyperextract/templates/presets/general/cross_reference_net.yamlindex 86e0862..ef37f91 100644--- a/hyperextract/templates/presets/general/cross_reference_net.yaml+++ b/hyperextract/templates/presets/general/cross_reference_net.yaml@@ -73,7 +73,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/general/knowledge_graph.yaml b/hyperextract/templates/presets/general/knowledge_graph.yamlindex e4d6f3f..3353b23 100644--- a/hyperextract/templates/presets/general/knowledge_graph.yaml+++ b/hyperextract/templates/presets/general/knowledge_graph.yaml@@ -73,7 +73,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/general/life_event_timeline.yaml b/hyperextract/templates/presets/general/life_event_timeline.yamlindex 61e4739..155135c 100644--- a/hyperextract/templates/presets/general/life_event_timeline.yaml+++ b/hyperextract/templates/presets/general/life_event_timeline.yaml@@ -95,7 +95,7 @@ identifiers:target: "target"time_field: "eventDate"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/general/operational_procedure.yaml b/hyperextract/templates/presets/general/operational_procedure.yamlindex 1a2898e..5219aad 100644--- a/hyperextract/templates/presets/general/operational_procedure.yaml+++ b/hyperextract/templates/presets/general/operational_procedure.yaml@@ -90,7 +90,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/general/penalty_mapping.yaml b/hyperextract/templates/presets/general/penalty_mapping.yamlindex 0b48df7..19077d6 100644--- a/hyperextract/templates/presets/general/penalty_mapping.yaml+++ b/hyperextract/templates/presets/general/penalty_mapping.yaml@@ -73,7 +73,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/general/social_network.yaml b/hyperextract/templates/presets/general/social_network.yamlindex fe6e6bd..07d613d 100644--- a/hyperextract/templates/presets/general/social_network.yaml+++ b/hyperextract/templates/presets/general/social_network.yaml@@ -82,7 +82,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/emergency_response_graph.yaml b/hyperextract/templates/presets/industry/emergency_response_graph.yamlindex 298a894..4e52d2e 100644--- a/hyperextract/templates/presets/industry/emergency_response_graph.yaml+++ b/hyperextract/templates/presets/industry/emergency_response_graph.yaml@@ -100,7 +100,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/equipment_topology_graph.yaml b/hyperextract/templates/presets/industry/equipment_topology_graph.yamlindex 972f233..5d6321a 100644--- a/hyperextract/templates/presets/industry/equipment_topology_graph.yaml+++ b/hyperextract/templates/presets/industry/equipment_topology_graph.yaml@@ -111,7 +111,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/failure_case_graph.yaml b/hyperextract/templates/presets/industry/failure_case_graph.yamlindex ed07afc..6215f6a 100644--- a/hyperextract/templates/presets/industry/failure_case_graph.yaml+++ b/hyperextract/templates/presets/industry/failure_case_graph.yaml@@ -100,7 +100,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/failure_knowledge_hypergraph.yaml b/hyperextract/templates/presets/industry/failure_knowledge_hypergraph.yamlindex 6f82a0a..bee3814 100644--- a/hyperextract/templates/presets/industry/failure_knowledge_hypergraph.yaml+++ b/hyperextract/templates/presets/industry/failure_knowledge_hypergraph.yaml@@ -85,7 +85,7 @@ identifiers:edge_id: "{reasoning_type}_{nodes}"edge_members: "nodes"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/incident_causality_map.yaml b/hyperextract/templates/presets/industry/incident_causality_map.yamlindex 99c199a..bb2f861 100644--- a/hyperextract/templates/presets/industry/incident_causality_map.yaml+++ b/hyperextract/templates/presets/industry/incident_causality_map.yaml@@ -94,7 +94,7 @@ identifiers:edge_id: "{causality_type}_{nodes}"edge_members: "nodes"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/inspection_record_graph.yaml b/hyperextract/templates/presets/industry/inspection_record_graph.yamlindex c33501e..5b67fd4 100644--- a/hyperextract/templates/presets/industry/inspection_record_graph.yaml+++ b/hyperextract/templates/presets/industry/inspection_record_graph.yaml@@ -89,7 +89,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/maintenace_operation_map.yaml b/hyperextract/templates/presets/industry/maintenace_operation_map.yamlindex 5a3b523..530f201 100644--- a/hyperextract/templates/presets/industry/maintenace_operation_map.yaml+++ b/hyperextract/templates/presets/industry/maintenace_operation_map.yaml@@ -105,7 +105,7 @@ identifiers:edge_id: "{operation_name}_{nodes}"edge_members: "nodes"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/operating_mode_graph.yaml b/hyperextract/templates/presets/industry/operating_mode_graph.yamlindex cd7cd21..5d6d246 100644--- a/hyperextract/templates/presets/industry/operating_mode_graph.yaml+++ b/hyperextract/templates/presets/industry/operating_mode_graph.yaml@@ -105,7 +105,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/operation_flow_graph.yaml b/hyperextract/templates/presets/industry/operation_flow_graph.yamlindex 6542167..d34311b 100644--- a/hyperextract/templates/presets/industry/operation_flow_graph.yaml+++ b/hyperextract/templates/presets/industry/operation_flow_graph.yaml@@ -111,7 +111,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/safety_control_graph.yaml b/hyperextract/templates/presets/industry/safety_control_graph.yamlindex 07ec21d..a13c028 100644--- a/hyperextract/templates/presets/industry/safety_control_graph.yaml+++ b/hyperextract/templates/presets/industry/safety_control_graph.yaml@@ -110,7 +110,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/safety_timeline.yaml b/hyperextract/templates/presets/industry/safety_timeline.yamlindex 754e79c..caf9e4e 100644--- a/hyperextract/templates/presets/industry/safety_timeline.yaml+++ b/hyperextract/templates/presets/industry/safety_timeline.yaml@@ -112,7 +112,7 @@ identifiers:target: "target"time_field: "timestamp"-parameters:+options:extraction_mode: "two_stage"# observation_time 和 observation_location 由用户在运行时提供# 示例:TemplateFactory.create(config, llm, embedder, observation_time="2024-06-15")diff --git a/hyperextract/templates/presets/industry/system_compatibility_graph.yaml b/hyperextract/templates/presets/industry/system_compatibility_graph.yamlindex 2956f35..a4d42df 100644--- a/hyperextract/templates/presets/industry/system_compatibility_graph.yaml+++ b/hyperextract/templates/presets/industry/system_compatibility_graph.yaml@@ -88,7 +88,7 @@ identifiers:edge_id: "{compatibility_type}_{nodes}"edge_members: "nodes"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/industry/system_topology_graph.yaml b/hyperextract/templates/presets/industry/system_topology_graph.yamlindex 60e12b9..224368f 100644--- a/hyperextract/templates/presets/industry/system_topology_graph.yaml+++ b/hyperextract/templates/presets/industry/system_topology_graph.yaml@@ -94,7 +94,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/legal/adjudication_logic.yaml b/hyperextract/templates/presets/legal/adjudication_logic.yamlindex 200f48b..cab36c9 100644--- a/hyperextract/templates/presets/legal/adjudication_logic.yaml+++ b/hyperextract/templates/presets/legal/adjudication_logic.yaml@@ -93,7 +93,7 @@ identifiers:edge_id: "{logic_type}_{participants}"edge_members: "participants"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/legal/beneficial_ownership_graph.yaml b/hyperextract/templates/presets/legal/beneficial_ownership_graph.yamlindex 78ad3a0..32d1ef9 100644--- a/hyperextract/templates/presets/legal/beneficial_ownership_graph.yaml+++ b/hyperextract/templates/presets/legal/beneficial_ownership_graph.yaml@@ -99,7 +99,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/legal/case_fact_timeline.yaml b/hyperextract/templates/presets/legal/case_fact_timeline.yamlindex 7904ae1..a6a5f71 100644--- a/hyperextract/templates/presets/legal/case_fact_timeline.yaml+++ b/hyperextract/templates/presets/legal/case_fact_timeline.yaml@@ -104,7 +104,7 @@ identifiers:target: "target"time_field: "time_info"-parameters:+options:extraction_mode: "two_stage"# observation_time 和 observation_location 由用户在运行时提供# 示例:TemplateFactory.create(config, llm, embedder, observation_time="2024-06-15")diff --git a/hyperextract/templates/presets/legal/case_law_citation_net.yaml b/hyperextract/templates/presets/legal/case_law_citation_net.yamlindex 7d5abc7..1f38386 100644--- a/hyperextract/templates/presets/legal/case_law_citation_net.yaml+++ b/hyperextract/templates/presets/legal/case_law_citation_net.yaml@@ -98,7 +98,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/legal/contract_obligation_hypergraph.yaml b/hyperextract/templates/presets/legal/contract_obligation_hypergraph.yamlindex bb82a24..442099d 100644--- a/hyperextract/templates/presets/legal/contract_obligation_hypergraph.yaml+++ b/hyperextract/templates/presets/legal/contract_obligation_hypergraph.yaml@@ -99,7 +99,7 @@ identifiers:edge_id: "{obligation_type}_{participants}"edge_members: "participants"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/legal/legal_concept_ontology.yaml b/hyperextract/templates/presets/legal/legal_concept_ontology.yamlindex 81d9f5b..4d81f85 100644--- a/hyperextract/templates/presets/legal/legal_concept_ontology.yaml+++ b/hyperextract/templates/presets/legal/legal_concept_ontology.yaml@@ -91,7 +91,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/legal/litigation_participant_map.yaml b/hyperextract/templates/presets/legal/litigation_participant_map.yamlindex 1562c4a..567f070 100644--- a/hyperextract/templates/presets/legal/litigation_participant_map.yaml+++ b/hyperextract/templates/presets/legal/litigation_participant_map.yaml@@ -85,7 +85,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/medicine/anatomy_hierarchy.yaml b/hyperextract/templates/presets/medicine/anatomy_hierarchy.yamlindex c105ce6..69310ee 100644--- a/hyperextract/templates/presets/medicine/anatomy_hierarchy.yaml+++ b/hyperextract/templates/presets/medicine/anatomy_hierarchy.yaml@@ -72,7 +72,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/medicine/clinical_pathway.yaml b/hyperextract/templates/presets/medicine/clinical_pathway.yamlindex 45f4e3e..22585dc 100644--- a/hyperextract/templates/presets/medicine/clinical_pathway.yaml+++ b/hyperextract/templates/presets/medicine/clinical_pathway.yaml@@ -70,7 +70,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/medicine/complex_interaction_net.yaml b/hyperextract/templates/presets/medicine/complex_interaction_net.yamlindex 88bd7b3..032fdc4 100644--- a/hyperextract/templates/presets/medicine/complex_interaction_net.yaml+++ b/hyperextract/templates/presets/medicine/complex_interaction_net.yaml@@ -69,7 +69,7 @@ identifiers:edge_id: "name"edge_members: "nodes"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/medicine/hospital_course_timeline.yaml b/hyperextract/templates/presets/medicine/hospital_course_timeline.yamlindex 711869b..af31e5d 100644--- a/hyperextract/templates/presets/medicine/hospital_course_timeline.yaml+++ b/hyperextract/templates/presets/medicine/hospital_course_timeline.yaml@@ -89,7 +89,7 @@ identifiers:target: "target"time_field: "eventDate"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/medicine/medical_concept_net.yaml b/hyperextract/templates/presets/medicine/medical_concept_net.yamlindex d58ed57..a243b6d 100644--- a/hyperextract/templates/presets/medicine/medical_concept_net.yaml+++ b/hyperextract/templates/presets/medicine/medical_concept_net.yaml@@ -76,7 +76,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/medicine/pathology_hypergraph.yaml b/hyperextract/templates/presets/medicine/pathology_hypergraph.yamlindex 44d1940..114ffc5 100644--- a/hyperextract/templates/presets/medicine/pathology_hypergraph.yaml+++ b/hyperextract/templates/presets/medicine/pathology_hypergraph.yaml@@ -74,7 +74,7 @@ identifiers:edge_id: "mechanism_name"edge_members: "participating_entities"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/medicine/pharmacology_graph.yaml b/hyperextract/templates/presets/medicine/pharmacology_graph.yamlindex fa6c406..af2dfc8 100644--- a/hyperextract/templates/presets/medicine/pharmacology_graph.yaml+++ b/hyperextract/templates/presets/medicine/pharmacology_graph.yaml@@ -75,7 +75,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/medicine/surgical_event_graph.yaml b/hyperextract/templates/presets/medicine/surgical_event_graph.yamlindex 8a2a443..211a37c 100644--- a/hyperextract/templates/presets/medicine/surgical_event_graph.yaml+++ b/hyperextract/templates/presets/medicine/surgical_event_graph.yaml@@ -75,7 +75,7 @@ identifiers:edge_id: "name"edge_members: "nodes"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/medicine/treatment_regimen_map.yaml b/hyperextract/templates/presets/medicine/treatment_regimen_map.yamlindex 371c525..68bbbf1 100644--- a/hyperextract/templates/presets/medicine/treatment_regimen_map.yaml+++ b/hyperextract/templates/presets/medicine/treatment_regimen_map.yaml@@ -68,7 +68,7 @@ identifiers:edge_id: "name"edge_members: "nodes"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/tcm/acupoint_location_map.yaml b/hyperextract/templates/presets/tcm/acupoint_location_map.yamlindex 604b14a..480eae4 100644--- a/hyperextract/templates/presets/tcm/acupoint_location_map.yaml+++ b/hyperextract/templates/presets/tcm/acupoint_location_map.yaml@@ -91,7 +91,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/tcm/compatibility_net.yaml b/hyperextract/templates/presets/tcm/compatibility_net.yamlindex a45734e..93903d6 100644--- a/hyperextract/templates/presets/tcm/compatibility_net.yaml+++ b/hyperextract/templates/presets/tcm/compatibility_net.yaml@@ -77,7 +77,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/tcm/formula_composition.yaml b/hyperextract/templates/presets/tcm/formula_composition.yamlindex b9232c8..28d2ad0 100644--- a/hyperextract/templates/presets/tcm/formula_composition.yaml+++ b/hyperextract/templates/presets/tcm/formula_composition.yaml@@ -121,7 +121,7 @@ identifiers:- "zuoHerbs"- "shiHerbs"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/tcm/function_indication_map.yaml b/hyperextract/templates/presets/tcm/function_indication_map.yamlindex 403af2b..143ffb0 100644--- a/hyperextract/templates/presets/tcm/function_indication_map.yaml+++ b/hyperextract/templates/presets/tcm/function_indication_map.yaml@@ -88,7 +88,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/tcm/meridian_flow_graph.yaml b/hyperextract/templates/presets/tcm/meridian_flow_graph.yamlindex a13101b..218d311 100644--- a/hyperextract/templates/presets/tcm/meridian_flow_graph.yaml+++ b/hyperextract/templates/presets/tcm/meridian_flow_graph.yaml@@ -98,7 +98,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/tcm/prescription_modification.yaml b/hyperextract/templates/presets/tcm/prescription_modification.yamlindex 71ea76d..4d1376b 100644--- a/hyperextract/templates/presets/tcm/prescription_modification.yaml+++ b/hyperextract/templates/presets/tcm/prescription_modification.yaml@@ -94,7 +94,7 @@ identifiers:- "baseFormula"- "herbs"-parameters:+options:extraction_mode: "two_stage"display:diff --git a/hyperextract/templates/presets/tcm/syndrome_reasoning_graph.yaml b/hyperextract/templates/presets/tcm/syndrome_reasoning_graph.yamlindex 50e8572..e282208 100644--- a/hyperextract/templates/presets/tcm/syndrome_reasoning_graph.yaml+++ b/hyperextract/templates/presets/tcm/syndrome_reasoning_graph.yaml@@ -90,7 +90,7 @@ identifiers:edge_id: "{reasoningType}|{nodes}"edge_members: "nodes"-parameters:+options:extraction_mode: "two_stage"display:diff --git "a/hyperextract/templates/\347\237\245\350\257\206\346\250\241\346\235\277\350\256\276\350\256\241\346\214\207\345\215\227.md" "b/hyperextract/templates/\347\237\245\350\257\206\346\250\241\346\235\277\350\256\276\350\256\241\346\214\207\345\215\227.md"index dc83373..8448ebe 100644--- "a/hyperextract/templates/\347\237\245\350\257\206\346\250\241\346\235\277\350\256\276\350\256\241\346\214\207\345\215\227.md"+++ "b/hyperextract/templates/\347\237\245\350\257\206\346\250\241\346\235\277\350\256\276\350\256\241\346\214\207\345\215\227.md"@@ -187,7 +187,7 @@ identifiers:source: "source"target: "target"-parameters:+options:extraction_mode: two_stagedisplay:@@ -220,10 +220,68 @@ display:| `schema` / `item_schema` / `node_schema` / `edge_schema` | 数据结构定义 || `guide` | 提取指南 || `identifiers` | 标识配置 |-| `parameters` | 运行时参数 |+| `options` | 运行时参数 || `display` | 展示配置 |-### 3.3 Rules 字段格式说明+### 3.4 Options 配置说明++`options` 字段用于配置运行时参数,支持以下配置项:++#### 3.4.1 Merge Strategy 配置++合并策略用于定义当检测到重复实体时如何处理。有以下预定义策略可供选择:++| 策略 | YAML值 | 说明 |+|------|--------|------|+| MERGE_FIELD | `merge_field` | 非空值覆盖,列表追加(默认) |+| KEEP_INCOMING | `keep_incoming` | 最新数据胜出 |+| KEEP_EXISTING | `keep_existing` | 保留首次数据 |+| LLM.BALANCED | `llm_balanced` | LLM智能平衡(默认) |+| LLM.PREFER_INCOMING | `llm_prefer_incoming` | 偏向新数据 |+| LLM.PREFER_EXISTING | `llm_prefer_existing` | 偏向旧数据 |++**不同 AutoType 的策略参数名**:++| AutoType | 参数名 | 示例 |+|----------|--------|------|+| AutoModel | `merge_strategy` | `merge_strategy: llm_balanced` |+| AutoList | - | 无(列表类型不需要合并) |+| AutoSet | `merge_strategy` | `merge_strategy: keep_incoming` |+| AutoGraph/AutoHypergraph | `node_merge_strategy` + `edge_merge_strategy` | `node_merge_strategy: llm_balanced`<br>`edge_merge_strategy: merge_field` |+| AutoTemporalGraph | `node_merge_strategy` + `edge_merge_strategy` | 同上 |+| AutoSpatialGraph | `node_merge_strategy` + `edge_merge_strategy` | 同上 |+| AutoSpatioTemporalGraph | `node_merge_strategy` + `edge_merge_strategy` | 同上 |++**示例配置**:++```yaml+# Model/Set 类型+options:+ merge_strategy: llm_balanced++# Graph 类型+options:+ node_merge_strategy: llm_balanced+ edge_merge_strategy: merge_field+```++#### 3.4.2 其他 Options 配置++| 参数 | 类型 | 默认值 | 说明 |+|------|------|--------|------|+| `extraction_mode` | str | `two_stage` | 提取模式:`one_stage` 或 `two_stage` |+| `chunk_size` | int | `2048` | 文本分块大小 |+| `chunk_overlap` | int | `256` | 分块重叠大小 |+| `max_workers` | int | `10` | 最大工作线程数 |+| `verbose` | bool | `false` | 是否输出详细信息 |++**时序图专用参数**:+| `observation_time` | str | - | 观察时间点 |++**空间图专用参数**:+| `observation_location` | str | - | 观察位置 |++### 3.5 Rules 字段格式说明`guide` 中的 `rules`、`rules_for_nodes`、`rules_for_edges`、`rules_for_time`、`rules_for_location` 等字段使用 List 格式:@@ -585,9 +643,9 @@ guide:- "'去年' → {observation_time} 的前一年"```-**特有 parameters 配置**:+**特有 options 配置**:```yaml-parameters:+options:extraction_mode: "two_stage"observation_time: "2024-01-01"```@@ -610,9 +668,9 @@ guide:- "'这里' → {observation_location}"```-**特有 parameters 配置**:+**特有 options 配置**:```yaml-parameters:+options:observation_location: "北京"```diff --git a/hyperextract/utils/template_engine/builder/__init__.py b/hyperextract/utils/template_engine/builder/__init__.pyindex 97ca9de..47b44ca 100644--- a/hyperextract/utils/template_engine/builder/__init__.py+++ b/hyperextract/utils/template_engine/builder/__init__.py@@ -1,36 +1,21 @@"""Builder module - Configuration models, loaders and builders."""-from .loader import TemplateConfig, ConfigLoader, Parameters, Display-from .schema import (- FieldDescription,- SchemaField,- BaseSchema,- ModelSchema,- ItemSchema,- NodeSchema,- EdgeSchema,- SchemaBuilder,+from .schema import SchemaBuilder+from .prompt import PromptBuilder+from .identifiers import IdentifierResolver+from .loader import TemplateConfig, ConfigLoader+from .options import (+ Options,+ OptionsBuilder,)-from .extraction import GuideTarget, Guide, PromptBuilder-from .identifiers import Identifiers, IdentifierResolver__all__ = ["TemplateConfig","ConfigLoader",- "Parameters",- "Display",- "FieldDescription",- "SchemaField",- "BaseSchema",- "ModelSchema",- "ItemSchema",- "NodeSchema",- "EdgeSchema",+ "Options","SchemaBuilder",- "GuideTarget",- "Guide","PromptBuilder",- "Identifiers","IdentifierResolver",+ "OptionsBuilder",]diff --git a/hyperextract/utils/template_engine/builder/loader.py b/hyperextract/utils/template_engine/builder/loader.pyindex c600bfc..d477691 100644--- a/hyperextract/utils/template_engine/builder/loader.py+++ b/hyperextract/utils/template_engine/builder/loader.py@@ -1,49 +1,14 @@-"""Config loader, parameters and display models."""+"""Config loader and template configuration models."""-from typing import Any, Dict, List, Literal, Optional, Union+import yamlfrom pathlib import Path+from typing import Any, Dict, List, Literal, Optional, Unionfrom pydantic import BaseModel, Field, field_validator, ConfigDict-import yaml-from .schema import ModelSchema, ItemSchema, NodeSchema, EdgeSchema-from .extraction import Guide+from .prompt import Guidefrom .identifiers import Identifiers---class Parameters(BaseModel):- """Runtime parameters configuration."""-- merge_strategy: Optional[str] = None- custom_merge_rule: Optional[Union[str, Dict[str, str]]] = None- node_merge_strategy: Optional[str] = None- node_custom_merge_rule: Optional[Union[str, Dict[str, str]]] = None- edge_merge_strategy: Optional[str] = None- edge_custom_merge_rule: Optional[Union[str, Dict[str, str]]] = None- extraction_mode: Optional[str] = None- observation_time: Optional[str] = None- observation_location: Optional[str] = None- chunk_size: int = 2048- chunk_overlap: int = 256- max_workers: int = 10- verbose: bool = False- search_fields: Optional[List[str]] = None- node_search_fields: Optional[List[str]] = None- edge_search_fields: Optional[List[str]] = None-- def get_merge_strategy(self) -> Optional[str]:- """Get merge strategy."""- return self.merge_strategy or self.node_merge_strategy-- def get_custom_merge_rule(self, language: str = "zh") -> Optional[str]:- """Get custom merge rule."""- rule = self.custom_merge_rule or self.node_custom_merge_rule- if rule is None:- return None- if isinstance(rule, str):- return rule- if isinstance(rule, dict):- return rule.get(language) or rule.get("zh") or ""- return None+from .schema import ModelSchema, ItemSchema, NodeSchema, EdgeSchema+from .options import Optionsclass Display(BaseModel):@@ -71,7 +36,7 @@ class TemplateConfig(BaseModel):edge_schema: Optional[EdgeSchema] = Noneguide: Optional[Guide] = Noneidentifiers: Optional[Identifiers] = None- parameters: Optional[Parameters] = None+ options: Optional[Options] = Nonedisplay: Optional[Display] = Nonemodel_config = ConfigDict(populate_by_name=True)@@ -136,7 +101,6 @@ class ConfigLoader:__all__ = [- "Parameters","Display","TemplateConfig","ConfigLoader",diff --git a/hyperextract/utils/template_engine/builder/options.py b/hyperextract/utils/template_engine/builder/options.pynew file mode 100644index 0000000..34ca285--- /dev/null+++ b/hyperextract/utils/template_engine/builder/options.py@@ -0,0 +1,526 @@+"""Options models and builder."""++from typing import Any, Callable, List, Optional, Type+from pydantic import BaseModel, Field++from ontomem.merger import MergeStrategy++from .schema import SchemaBuilder+from .identifiers import IdentifierResolver+++class Options(BaseModel):+ """运行时选项配置 - 排除 LLM、Embedder、Schema、Prompt 之外的所有配置"""++ merge_strategy: Optional[str] = None+ node_merge_strategy: Optional[str] = None+ edge_merge_strategy: Optional[str] = None+ extraction_mode: Optional[str] = None+ observation_time: Optional[str] = None+ observation_location: Optional[str] = None+ chunk_size: int = 2048+ chunk_overlap: int = 256+ max_workers: int = 10+ verbose: bool = False+ search_fields: Optional[List[str]] = None+ node_search_fields: Optional[List[str]] = None+ edge_search_fields: Optional[List[str]] = None++ def get_merge_strategy(self) -> Optional[str]:+ """Get merge strategy."""+ return self.merge_strategy or self.node_merge_strategy+++class ModelOptions:+ """Options for AutoModel."""++ def __init__(+ self,+ merge_strategy: str = "llm_balanced",+ chunk_size: int = 2048,+ chunk_overlap: int = 256,+ max_workers: int = 10,+ verbose: bool = False,+ ):+ self.merge_strategy = merge_strategy+ self.chunk_size = chunk_size+ self.chunk_overlap = chunk_overlap+ self.max_workers = max_workers+ self.verbose = verbose+++class ListOptions:+ """Options for AutoList."""++ def __init__(+ self,+ chunk_size: int = 2048,+ chunk_overlap: int = 256,+ max_workers: int = 10,+ verbose: bool = False,+ ):+ self.chunk_size = chunk_size+ self.chunk_overlap = chunk_overlap+ self.max_workers = max_workers+ self.verbose = verbose+++class SetOptions:+ """Options for AutoSet."""++ def __init__(+ self,+ merge_strategy: str = "llm_balanced",+ chunk_size: int = 2048,+ chunk_overlap: int = 256,+ max_workers: int = 10,+ verbose: bool = False,+ ):+ self.merge_strategy = merge_strategy+ self.chunk_size = chunk_size+ self.chunk_overlap = chunk_overlap+ self.max_workers = max_workers+ self.verbose = verbose+++class GraphOptions:+ """Options for AutoGraph/AutoHypergraph."""++ def __init__(+ self,+ extraction_mode: str = "two_stage",+ node_merge_strategy: str = "llm_balanced",+ edge_merge_strategy: str = "llm_balanced",+ chunk_size: int = 2048,+ chunk_overlap: int = 256,+ max_workers: int = 10,+ verbose: bool = False,+ node_search_fields: Optional[List[str]] = None,+ edge_search_fields: Optional[List[str]] = None,+ ):+ self.extraction_mode = extraction_mode+ self.node_merge_strategy = node_merge_strategy+ self.edge_merge_strategy = edge_merge_strategy+ self.chunk_size = chunk_size+ self.chunk_overlap = chunk_overlap+ self.max_workers = max_workers+ self.verbose = verbose+ self.node_search_fields = node_search_fields+ self.edge_search_fields = edge_search_fields+++class TemporalGraphOptions(GraphOptions):+ """Options for AutoTemporalGraph."""++ def __init__(+ self,+ extraction_mode: str = "two_stage",+ node_merge_strategy: str = "llm_balanced",+ edge_merge_strategy: str = "llm_balanced",+ observation_time: Optional[str] = None,+ chunk_size: int = 2048,+ chunk_overlap: int = 256,+ max_workers: int = 10,+ verbose: bool = False,+ node_search_fields: Optional[List[str]] = None,+ edge_search_fields: Optional[List[str]] = None,+ ):+ super().__init__(+ extraction_mode=extraction_mode,+ node_merge_strategy=node_merge_strategy,+ edge_merge_strategy=edge_merge_strategy,+ chunk_size=chunk_size,+ chunk_overlap=chunk_overlap,+ max_workers=max_workers,+ verbose=verbose,+ node_search_fields=node_search_fields,+ edge_search_fields=edge_search_fields,+ )+ self.observation_time = observation_time+++class SpatialGraphOptions(GraphOptions):+ """Options for AutoSpatialGraph."""++ def __init__(+ self,+ extraction_mode: str = "two_stage",+ node_merge_strategy: str = "llm_balanced",+ edge_merge_strategy: str = "llm_balanced",+ observation_location: Optional[str] = None,+ chunk_size: int = 2048,+ chunk_overlap: int = 256,+ max_workers: int = 10,+ verbose: bool = False,+ node_search_fields: Optional[List[str]] = None,+ edge_search_fields: Optional[List[str]] = None,+ ):+ super().__init__(+ extraction_mode=extraction_mode,+ node_merge_strategy=node_merge_strategy,+ edge_merge_strategy=edge_merge_strategy,+ chunk_size=chunk_size,+ chunk_overlap=chunk_overlap,+ max_workers=max_workers,+ verbose=verbose,+ node_search_fields=node_search_fields,+ edge_search_fields=edge_search_fields,+ )+ self.observation_location = observation_location+++class SpatioTemporalGraphOptions(TemporalGraphOptions):+ """Options for AutoSpatioTemporalGraph."""++ def __init__(+ self,+ extraction_mode: str = "two_stage",+ node_merge_strategy: str = "llm_balanced",+ edge_merge_strategy: str = "llm_balanced",+ observation_time: Optional[str] = None,+ observation_location: Optional[str] = None,+ chunk_size: int = 2048,+ chunk_overlap: int = 256,+ max_workers: int = 10,+ verbose: bool = False,+ node_search_fields: Optional[List[str]] = None,+ edge_search_fields: Optional[List[str]] = None,+ ):+ super().__init__(+ extraction_mode=extraction_mode,+ node_merge_strategy=node_merge_strategy,+ edge_merge_strategy=edge_merge_strategy,+ observation_time=observation_time,+ chunk_size=chunk_size,+ chunk_overlap=chunk_overlap,+ max_workers=max_workers,+ verbose=verbose,+ node_search_fields=node_search_fields,+ edge_search_fields=edge_search_fields,+ )+ self.observation_location = observation_location+++class OptionsBuilder:+ """Options Builder - 负责选项解析、验证、merge strategy 解析"""++ @staticmethod+ def get_language(config) -> str:+ """Get language setting."""+ lang = config.language+ if isinstance(lang, list):+ return lang[0] if lang else "zh"+ return lang or "zh"++ @staticmethod+ def get_extraction_mode(config) -> str:+ """Get extraction mode."""+ return config.options.extraction_mode if config.options else "two_stage"++ VALID_MERGE_STRATEGIES = {+ "merge_field",+ "keep_incoming",+ "keep_existing",+ "llm_balanced",+ "llm_prefer_incoming",+ "llm_prefer_existing",+ }++ @staticmethod+ def resolve_merge_strategy(+ strategy_name: Optional[str],+ key_extractor: Callable,+ llm_client,+ item_schema: Type,+ ):+ """Resolve merge strategy."""+ if strategy_name:+ strategy_name = strategy_name.lower()+ if strategy_name not in OptionsBuilder.VALID_MERGE_STRATEGIES:+ raise ValueError(+ f"Invalid merge strategy '{strategy_name}'. "+ f"Valid options: {OptionsBuilder.VALID_MERGE_STRATEGIES}"+ )+ if '.' in strategy_name:+ parts = strategy_name.split('.')+ return getattr(getattr(MergeStrategy, parts[0].upper()), parts[1].upper())+ else:+ return MergeStrategy[strategy_name.upper()]+ return MergeStrategy.LLM.BALANCED++ @classmethod+ def build_model_options(cls, config, language: str = "zh"):+ """Build options for AutoModel."""+ options = config.options or Options()+ return ModelOptions(+ merge_strategy=options.merge_strategy or "llm_balanced",+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ )++ @classmethod+ def build_list_options(cls, config):+ """Build options for AutoList."""+ options = config.options or Options()+ return ListOptions(+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ )++ @classmethod+ def build_set_options(cls, config, language: str = "zh"):+ """Build options for AutoSet."""+ options = config.options or Options()+ return SetOptions(+ merge_strategy=options.merge_strategy or "llm_balanced",+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ )++ @classmethod+ def build_graph_options(cls, config, language: str = "zh"):+ """Build options for AutoGraph/AutoHypergraph."""+ options = config.options or Options()+ extraction_mode = cls.get_extraction_mode(config)+ return GraphOptions(+ extraction_mode=extraction_mode,+ node_merge_strategy=options.node_merge_strategy or "llm_balanced",+ edge_merge_strategy=options.edge_merge_strategy or "llm_balanced",+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ node_search_fields=options.node_search_fields,+ edge_search_fields=options.edge_search_fields,+ )++ @classmethod+ def build_temporal_graph_options(cls, config, language: str = "zh"):+ """Build options for AutoTemporalGraph."""+ options = config.options or Options()+ extraction_mode = cls.get_extraction_mode(config)+ return TemporalGraphOptions(+ extraction_mode=extraction_mode,+ node_merge_strategy=options.node_merge_strategy or "llm_balanced",+ edge_merge_strategy=options.edge_merge_strategy or "llm_balanced",+ observation_time=options.observation_time,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ node_search_fields=options.node_search_fields,+ edge_search_fields=options.edge_search_fields,+ )++ @classmethod+ def build_spatial_graph_options(cls, config, language: str = "zh"):+ """Build options for AutoSpatialGraph."""+ options = config.options or Options()+ extraction_mode = cls.get_extraction_mode(config)+ return SpatialGraphOptions(+ extraction_mode=extraction_mode,+ node_merge_strategy=options.node_merge_strategy or "llm_balanced",+ edge_merge_strategy=options.edge_merge_strategy or "llm_balanced",+ observation_location=options.observation_location,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ node_search_fields=options.node_search_fields,+ edge_search_fields=options.edge_search_fields,+ )++ @classmethod+ def build_spatio_temporal_graph_options(cls, config, language: str = "zh"):+ """Build options for AutoSpatioTemporalGraph."""+ options = config.options or Options()+ extraction_mode = cls.get_extraction_mode(config)+ return SpatioTemporalGraphOptions(+ extraction_mode=extraction_mode,+ node_merge_strategy=options.node_merge_strategy or "llm_balanced",+ edge_merge_strategy=options.edge_merge_strategy or "llm_balanced",+ observation_time=options.observation_time,+ observation_location=options.observation_location,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ node_search_fields=options.node_search_fields,+ edge_search_fields=options.edge_search_fields,+ )++ @classmethod+ def build_prompts(cls, config, prompt_builder, extraction_mode: str = None):+ """Build prompts based on extraction mode and autotype."""+ if extraction_mode is None:+ extraction_mode = cls.get_extraction_mode(config)++ guide = config.guide+ autotype = config.autotype++ if autotype in ("model", "list", "set"):+ return prompt_builder.build_model_prompt(guide), "", ""++ if autotype == "graph":+ if extraction_mode == "one_stage":+ return (+ prompt_builder.build_graph_main_prompt(guide),+ "",+ "",+ )+ else:+ return (+ "",+ prompt_builder.build_graph_node_prompt(guide),+ prompt_builder.build_graph_edge_prompt(guide),+ )++ if autotype in ("hypergraph",):+ if extraction_mode == "one_stage":+ return (+ prompt_builder.build_graph_main_prompt(guide),+ "",+ "",+ )+ else:+ return (+ "",+ prompt_builder.build_graph_node_prompt(guide),+ prompt_builder.build_graph_edge_prompt(guide),+ )++ if autotype == "temporal_graph":+ if extraction_mode == "one_stage":+ return (+ prompt_builder.build_graph_main_prompt(guide),+ "",+ "",+ )+ else:+ return (+ "",+ prompt_builder.build_temporal_graph_node_prompt(guide),+ prompt_builder.build_graph_edge_prompt(guide),+ )++ if autotype == "spatial_graph":+ if extraction_mode == "one_stage":+ return (+ prompt_builder.build_graph_main_prompt(guide),+ "",+ "",+ )+ else:+ return (+ "",+ prompt_builder.build_spatial_graph_node_prompt(guide),+ prompt_builder.build_graph_edge_prompt(guide),+ )++ if autotype == "spatio_temporal_graph":+ if extraction_mode == "one_stage":+ return (+ prompt_builder.build_graph_main_prompt(guide),+ "",+ "",+ )+ else:+ return (+ "",+ prompt_builder.build_spatio_temporal_graph_node_prompt(guide),+ prompt_builder.build_graph_edge_prompt(guide),+ )++ return "", "", ""++ @classmethod+ def validate_model_config(cls, config):+ """验证 AutoModel 配置"""+ schema_dict = SchemaBuilder.build_schema(config)+ if schema_dict.get("schema") is None:+ raise ValueError(f"AutoModel requires schema definition: {config.name}")+ return schema_dict++ @classmethod+ def validate_list_config(cls, config):+ """验证 AutoList 配置"""+ schema_dict = SchemaBuilder.build_schema(config)+ if schema_dict.get("item_schema") is None:+ raise ValueError(f"AutoList requires item_schema definition: {config.name}")+ return schema_dict++ @classmethod+ def validate_set_config(cls, config):+ """验证 AutoSet 配置"""+ schema_dict = SchemaBuilder.build_schema(config)+ if schema_dict.get("item_schema") is None:+ raise ValueError(f"AutoSet requires item_schema definition: {config.name}")++ identifiers = IdentifierResolver.resolve_all(config)+ if identifiers.get("item_id_extractor") is None:+ raise ValueError(f"AutoSet requires item_id configuration: {config.name}")++ return schema_dict, identifiers++ @classmethod+ def validate_graph_config(cls, config):+ """验证 AutoGraph/AutoHypergraph 配置"""+ schema_dict = SchemaBuilder.build_schema(config)+ if schema_dict.get("node_schema") is None or schema_dict.get("edge_schema") is None:+ raise ValueError(f"AutoGraph requires node_schema and edge_schema definition: {config.name}")++ identifiers = IdentifierResolver.resolve_all(config)+ required = ["node_key_extractor", "edge_key_extractor", "nodes_in_edge_extractor"]+ if not all(identifiers.get(k) for k in required):+ raise ValueError(f"AutoGraph requires complete identifiers configuration: {config.name}")++ return schema_dict, identifiers++ @classmethod+ def validate_temporal_graph_config(cls, config):+ """验证 AutoTemporalGraph 配置"""+ schema_dict, identifiers = cls.validate_graph_config(config)++ if identifiers.get("time_in_edge_extractor") is None:+ raise ValueError(f"AutoTemporalGraph requires time_field in identifiers: {config.name}")++ return schema_dict, identifiers++ @classmethod+ def validate_spatial_graph_config(cls, config):+ """验证 AutoSpatialGraph 配置"""+ schema_dict, identifiers = cls.validate_graph_config(config)++ if identifiers.get("location_extractor") is None:+ raise ValueError(f"AutoSpatialGraph requires location_field in identifiers: {config.name}")++ return schema_dict, identifiers++ @classmethod+ def validate_spatio_temporal_graph_config(cls, config):+ """验证 AutoSpatioTemporalGraph 配置"""+ schema_dict, identifiers = cls.validate_graph_config(config)++ if not identifiers.get("time_extractor") or not identifiers.get("location_extractor"):+ raise ValueError(f"AutoSpatioTemporalGraph requires time_field and location_field in identifiers: {config.name}")++ return schema_dict, identifiers+++__all__ = [+ "Options",+ "ModelOptions",+ "ListOptions",+ "SetOptions",+ "GraphOptions",+ "TemporalGraphOptions",+ "SpatialGraphOptions",+ "SpatioTemporalGraphOptions",+ "OptionsBuilder",+]diff --git a/hyperextract/utils/template_engine/builder/extraction.py b/hyperextract/utils/template_engine/builder/prompt.pysimilarity index 91%rename from hyperextract/utils/template_engine/builder/extraction.pyrename to hyperextract/utils/template_engine/builder/prompt.pyindex d5c0ca0..fe89d9a 100644--- a/hyperextract/utils/template_engine/builder/extraction.py+++ b/hyperextract/utils/template_engine/builder/prompt.py@@ -30,23 +30,27 @@ class Guide(BaseModel):"""Guide configuration."""target: Optional[Union[str, List[str], Dict[str, Union[str, List[str]]]]] = None- rules: Optional[Union[List[str], Dict[str, List[str]]]] = None- rules_for_nodes: Optional[Union[List[str], Dict[str, List[str]]]] = None- rules_for_edges: Optional[Union[List[str], Dict[str, List[str]]]] = None- rules_for_time: Optional[Union[List[str], Dict[str, List[str]]]] = None- rules_for_location: Optional[Union[List[str], Dict[str, List[str]]]] = None+ rules: Optional[Union[str, List[str], Dict[str, Union[str, List[str]]]]] = None+ rules_for_nodes: Optional[Union[str, List[str], Dict[str, Union[str, List[str]]]]] = None+ rules_for_edges: Optional[Union[str, List[str], Dict[str, Union[str, List[str]]]]] = None+ rules_for_time: Optional[Union[str, List[str], Dict[str, Union[str, List[str]]]]] = None+ rules_for_location: Optional[Union[str, List[str], Dict[str, Union[str, List[str]]]]] = Nonedef get_field(self, field_name: str, language: str = "zh") -> Optional[str]:"""Get specified field content for specified language."""value = getattr(self, field_name, None)if value is None:return None+ if isinstance(value, str):+ return valueif isinstance(value, list):return "\n".join(f"{i+1}. {item}" for i, item in enumerate(value))if isinstance(value, dict):dict_value = value.get(language) or value.get("zh")if dict_value is None:return None+ if isinstance(dict_value, str):+ return dict_valueif isinstance(dict_value, list):return "\n".join(f"{i+1}. {item}" for i, item in enumerate(dict_value))return None@@ -85,16 +89,20 @@ class PromptBuilder:self.labels = LABEL_MAPPING.get(language, LABEL_MAPPING["zh"])@staticmethod- def _get_text(value: Optional[Union[List[str], Dict[str, List[str]]]], language: str = "zh") -> Optional[str]:+ def _get_text(value: Optional[Union[str, List[str], Dict[str, Union[str, List[str]]]]], language: str = "zh") -> Optional[str]:"""Get multilingual text value, supports list format."""if value is None:return None+ if isinstance(value, str):+ return valueif isinstance(value, list):return "\n".join(f"{i+1}. {item}" for i, item in enumerate(value))if isinstance(value, dict):dict_value = value.get(language) or value.get("zh")if dict_value is None:return None+ if isinstance(dict_value, str):+ return dict_valueif isinstance(dict_value, list):return "\n".join(f"{i+1}. {item}" for i, item in enumerate(dict_value))return Nonediff --git a/hyperextract/utils/template_engine/factory.py b/hyperextract/utils/template_engine/factory.pyindex 3e886e2..c314d3b 100644--- a/hyperextract/utils/template_engine/factory.py+++ b/hyperextract/utils/template_engine/factory.py@@ -3,42 +3,36 @@Supports all 8 AutoType dynamic generation."""-from typing import Any, Callable, Dict, List, Optional, Type, Union-from pathlib import Path+from typing import TYPE_CHECKING-from ontomem.merger import MergeStrategy, create_merger, BaseMergerfrom langchain_core.language_models import BaseChatModelfrom langchain_core.embeddings import Embeddings-from hyperextract.types import (- AutoModel,- AutoList,- AutoSet,- AutoGraph,- AutoHypergraph,- AutoTemporalGraph,- AutoSpatialGraph,- AutoSpatioTemporalGraph,-)-from .builder import (TemplateConfig,- Parameters,- SchemaBuilder,- IdentifierResolver,PromptBuilder,+ OptionsBuilder,+ Options,)+if TYPE_CHECKING:+ from hyperextract.types import (+ AutoModel,+ AutoList,+ AutoSet,+ AutoGraph,+ AutoHypergraph,+ AutoTemporalGraph,+ AutoSpatialGraph,+ AutoSpatioTemporalGraph,+ )-class TemplateFactory:+class TemplateFactory:@staticmethoddef get_language(config: TemplateConfig) -> str:"""Get language setting."""- lang = config.language- if isinstance(lang, list):- return lang[0] if lang else "zh"- return lang or "zh"+ return OptionsBuilder.get_language(config)@staticmethoddef resolve_display_extractors(config: TemplateConfig, schema_dict: dict):@@ -49,277 +43,222 @@ class TemplateFactory:result = {}autotype = config.autotype- display_dict = display.model_dump() if hasattr(display, 'model_dump') else display+ display_dict = (+ display.model_dump() if hasattr(display, "model_dump") else display+ )if autotype in ("model", "list", "set"):label_field = display_dict.get("label")if label_field:result["label_extractor"] = lambda x: str(getattr(x, label_field, ""))- elif autotype in ("graph", "hypergraph", "temporal_graph", "spatial_graph", "spatio_temporal_graph"):+ elif autotype in (+ "graph",+ "hypergraph",+ "temporal_graph",+ "spatial_graph",+ "spatio_temporal_graph",+ ):node_label_field = display_dict.get("node_label")if node_label_field:- result["node_label_extractor"] = lambda x: str(getattr(x, node_label_field, ""))+ result["node_label_extractor"] = lambda x: str(+ getattr(x, node_label_field, "")+ )edge_label_field = display_dict.get("edge_label")if edge_label_field:- result["edge_label_extractor"] = lambda x: str(getattr(x, edge_label_field, ""))+ result["edge_label_extractor"] = lambda x: str(+ getattr(x, edge_label_field, "")+ )return result- @staticmethod- def resolve_merge_strategy(- strategy_name: Optional[str],- custom_rule: Optional[str],- key_extractor: Callable,- llm_client: BaseChatModel,- item_schema: Type,- ) -> Union[MergeStrategy, BaseMerger]:- """Resolve merge strategy."""- if custom_rule:- return MergeStrategy.LLM.BALANCED- if strategy_name:- strategy_name = strategy_name.lower()- if '.' in strategy_name:- parts = strategy_name.split('.')- return getattr(getattr(MergeStrategy, parts[0].upper()), parts[1].upper())- else:- try:- return MergeStrategy[strategy_name.upper()]- except KeyError:- return MergeStrategy.LLM.BALANCED- return MergeStrategy.LLM.BALANCED-@classmethod- def create_model(cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings) -> AutoModel:+ def create_model(+ cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings+ ) -> "AutoModel":"""Create AutoModel template."""+ from hyperextract.types import AutoModel+language = cls.get_language(config)- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict = OptionsBuilder.validate_model_config(config)schema_class = schema_dict.get("schema")- if schema_class is None:- raise ValueError(f"AutoModel requires schema definition: {config.name}")-- guide = config.guideprompt_builder = PromptBuilder(language)- prompt = prompt_builder.build_model_prompt(guide)+ prompt = prompt_builder.build_model_prompt(config.guide)- parameters = config.parameters or Parameters()- merge_strategy = parameters.merge_strategy or "llm_balanced"- custom_merge_rule = parameters.get_custom_merge_rule(language)+ options = OptionsBuilder.build_model_options(config, language)return AutoModel(data_schema=schema_class,llm_client=llm_client,embedder=embedder,- strategy_or_merger=cls.resolve_merge_strategy(- merge_strategy,- custom_merge_rule,+ strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.merge_strategy,lambda x: str(x),llm_client,schema_class,),prompt=prompt,- chunk_size=parameters.chunk_size,- chunk_overlap=parameters.chunk_overlap,- max_workers=parameters.max_workers,- verbose=parameters.verbose,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,)@classmethod- def create_list(cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings) -> AutoList:+ def create_list(+ cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings+ ) -> "AutoList":"""Create AutoList template."""+ from hyperextract.types import AutoList+language = cls.get_language(config)- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict = OptionsBuilder.validate_list_config(config)item_schema_class = schema_dict.get("item_schema")- if item_schema_class is None:- raise ValueError(f"AutoList requires item_schema definition: {config.name}")-- guide = config.guideprompt_builder = PromptBuilder(language)- prompt = prompt_builder.build_model_prompt(guide)+ prompt = prompt_builder.build_model_prompt(config.guide)- parameters = config.parameters or Parameters()+ options = OptionsBuilder.build_list_options(config)return AutoList(item_schema=item_schema_class,llm_client=llm_client,embedder=embedder,prompt=prompt,- chunk_size=parameters.chunk_size,- chunk_overlap=parameters.chunk_overlap,- max_workers=parameters.max_workers,- verbose=parameters.verbose,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,)@classmethod- def create_set(cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings) -> AutoSet:+ def create_set(+ cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings+ ) -> "AutoSet":"""Create AutoSet template."""+ from hyperextract.types import AutoSet+language = cls.get_language(config)- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict, identifiers = OptionsBuilder.validate_set_config(config)item_schema_class = schema_dict.get("item_schema")-- if item_schema_class is None:- raise ValueError(f"AutoSet requires item_schema definition: {config.name}")-- identifiers = IdentifierResolver.resolve_all(config)item_id_extractor = identifiers.get("item_id_extractor")- if item_id_extractor is None:- raise ValueError(f"AutoSet requires item_id configuration: {config.name}")-- guide = config.guideprompt_builder = PromptBuilder(language)- prompt = prompt_builder.build_model_prompt(guide)+ prompt = prompt_builder.build_model_prompt(config.guide)- parameters = config.parameters or Parameters()- merge_strategy = parameters.merge_strategy or "llm_balanced"- custom_merge_rule = parameters.get_custom_merge_rule(language)+ options = OptionsBuilder.build_set_options(config, language)return AutoSet(item_schema=item_schema_class,item_key_extractor=item_id_extractor,llm_client=llm_client,embedder=embedder,- strategy_or_merger=cls.resolve_merge_strategy(- merge_strategy,- custom_merge_rule,+ strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.merge_strategy,item_id_extractor,llm_client,item_schema_class,),prompt=prompt,- chunk_size=parameters.chunk_size,- chunk_overlap=parameters.chunk_overlap,- max_workers=parameters.max_workers,- verbose=parameters.verbose,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,)@classmethod- def create_graph(cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings) -> AutoGraph:- """Create AutoGraph template."""+ def create_graph(+ cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings+ ) -> "AutoGraph":+ from hyperextract.types import AutoGraph+language = cls.get_language(config)- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict, identifiers = OptionsBuilder.validate_graph_config(config)node_schema_class = schema_dict.get("node_schema")edge_schema_class = schema_dict.get("edge_schema")-- if node_schema_class is None or edge_schema_class is None:- raise ValueError(f"AutoGraph requires node_schema and edge_schema definition: {config.name}")-- identifiers = IdentifierResolver.resolve_all(config)node_key_extractor = identifiers.get("node_key_extractor")edge_key_extractor = identifiers.get("edge_key_extractor")nodes_in_edge_extractor = identifiers.get("nodes_in_edge_extractor")- if not all([node_key_extractor, edge_key_extractor, nodes_in_edge_extractor]):- raise ValueError(f"AutoGraph requires complete identifiers configuration: {config.name}")-- guide = config.guideprompt_builder = PromptBuilder(language)+ options = OptionsBuilder.build_graph_options(config, language)- extraction_mode = config.parameters.extraction_mode if config.parameters else "two_stage"-- if extraction_mode == "one_stage":- prompt = prompt_builder.build_graph_main_prompt(guide)- prompt_for_node_extraction = ""- prompt_for_edge_extraction = ""- else:- prompt = ""- prompt_for_node_extraction = prompt_builder.build_graph_node_prompt(guide)- prompt_for_edge_extraction = prompt_builder.build_graph_edge_prompt(guide)-- parameters = config.parameters or Parameters()-- node_merge_strategy = parameters.node_merge_strategy or "llm_balanced"- node_custom_merge_rule = parameters.node_custom_merge_rule- edge_merge_strategy = parameters.edge_merge_strategy or "llm_balanced"- edge_custom_merge_rule = parameters.edge_custom_merge_rule+ prompt, prompt_for_node_extraction, prompt_for_edge_extraction = (+ OptionsBuilder.build_prompts(+ config, prompt_builder, options.extraction_mode+ )+ )return AutoGraph(node_schema=node_schema_class,edge_schema=edge_schema_class,- node_key_extractor=node_key_extractor,- edge_key_extractor=edge_key_extractor,- nodes_in_edge_extractor=nodes_in_edge_extractor,- llm_client=llm_client,- embedder=embedder,- extraction_mode=extraction_mode,- node_strategy_or_merger=cls.resolve_merge_strategy(- node_merge_strategy,- node_custom_merge_rule,- node_key_extractor,- llm_client,- node_schema_class,- ),- edge_strategy_or_merger=cls.resolve_merge_strategy(- edge_merge_strategy,- edge_custom_merge_rule,- edge_key_extractor,- llm_client,- edge_schema_class,- ),- prompt=prompt,- prompt_for_node_extraction=prompt_for_node_extraction,- prompt_for_edge_extraction=prompt_for_edge_extraction,- chunk_size=parameters.chunk_size,- chunk_overlap=parameters.chunk_overlap,- max_workers=parameters.max_workers,- verbose=parameters.verbose,- node_fields_for_index=parameters.node_search_fields,- edge_fields_for_index=parameters.edge_search_fields,- )+ node_key_extractor=node_key_extractor,+ edge_key_extractor=edge_key_extractor,+ nodes_in_edge_extractor=nodes_in_edge_extractor,+ llm_client=llm_client,+ embedder=embedder,+ extraction_mode=options.extraction_mode,+ node_strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.node_merge_strategy,+ node_key_extractor,+ llm_client,+ node_schema_class,+ ),+ edge_strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.edge_merge_strategy,+ edge_key_extractor,+ llm_client,+ edge_schema_class,+ ),+ prompt=prompt,+ prompt_for_node_extraction=prompt_for_node_extraction,+ prompt_for_edge_extraction=prompt_for_edge_extraction,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ node_fields_for_index=options.node_search_fields,+ edge_fields_for_index=options.edge_search_fields,+ )@classmethod- def create_hypergraph(cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings) -> AutoHypergraph:- """Create AutoHypergraph template."""+ def create_hypergraph(+ cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings+ ) -> "AutoHypergraph":return cls.create_graph(config, llm_client, embedder)@classmethod- def create_temporal_graph(cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings) -> AutoTemporalGraph:- """Create AutoTemporalGraph template."""+ def create_temporal_graph(+ cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings+ ) -> "AutoTemporalGraph":+ from hyperextract.types import AutoTemporalGraph+language = cls.get_language(config)- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict, identifiers = OptionsBuilder.validate_temporal_graph_config(+ config+ )node_schema_class = schema_dict.get("node_schema")edge_schema_class = schema_dict.get("edge_schema")-- if node_schema_class is None or edge_schema_class is None:- raise ValueError(f"AutoTemporalGraph requires node_schema and edge_schema definition: {config.name}")-- identifiers = IdentifierResolver.resolve_all(config)node_key_extractor = identifiers.get("node_key_extractor")edge_key_extractor = identifiers.get("edge_key_extractor")nodes_in_edge_extractor = identifiers.get("nodes_in_edge_extractor")time_in_edge_extractor = identifiers.get("time_in_edge_extractor")- if not all([node_key_extractor, edge_key_extractor, nodes_in_edge_extractor]):- raise ValueError(f"AutoTemporalGraph requires complete identifiers configuration: {config.name}")-- guide = config.guideprompt_builder = PromptBuilder(language)+ options = OptionsBuilder.build_temporal_graph_options(config, language)- extraction_mode = config.parameters.extraction_mode if config.parameters else "two_stage"-- if extraction_mode == "one_stage":- prompt = prompt_builder.build_graph_main_prompt(guide)- prompt_for_node_extraction = ""- prompt_for_edge_extraction = ""- else:- prompt = ""- prompt_for_node_extraction = prompt_builder.build_temporal_graph_node_prompt(guide)- prompt_for_edge_extraction = prompt_builder.build_graph_edge_prompt(guide)-- parameters = config.parameters or Parameters()-- node_merge_strategy = parameters.node_merge_strategy or "llm_balanced"- node_custom_merge_rule = parameters.node_custom_merge_rule- edge_merge_strategy = parameters.edge_merge_strategy or "llm_balanced"- edge_custom_merge_rule = parameters.edge_custom_merge_rule+ prompt, prompt_for_node_extraction, prompt_for_edge_extraction = (+ OptionsBuilder.build_prompts(+ config, prompt_builder, options.extraction_mode+ )+ )return AutoTemporalGraph(node_schema=node_schema_class,@@ -328,20 +267,18 @@ class TemplateFactory:edge_key_extractor=edge_key_extractor,nodes_in_edge_extractor=nodes_in_edge_extractor,time_in_edge_extractor=time_in_edge_extractor,- observation_time=parameters.observation_time,+ observation_time=options.observation_time,llm_client=llm_client,embedder=embedder,- extraction_mode=extraction_mode,- node_strategy_or_merger=cls.resolve_merge_strategy(- node_merge_strategy,- node_custom_merge_rule,+ extraction_mode=options.extraction_mode,+ node_strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.node_merge_strategy,node_key_extractor,llm_client,node_schema_class,),- edge_strategy_or_merger=cls.resolve_merge_strategy(- edge_merge_strategy,- edge_custom_merge_rule,+ edge_strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.edge_merge_strategy,edge_key_extractor,llm_client,edge_schema_class,@@ -349,55 +286,40 @@ class TemplateFactory:prompt=prompt,prompt_for_node_extraction=prompt_for_node_extraction,prompt_for_edge_extraction=prompt_for_edge_extraction,- chunk_size=parameters.chunk_size,- chunk_overlap=parameters.chunk_overlap,- max_workers=parameters.max_workers,- verbose=parameters.verbose,- node_fields_for_index=parameters.node_search_fields,- edge_fields_for_index=parameters.edge_search_fields,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ node_fields_for_index=options.node_search_fields,+ edge_fields_for_index=options.edge_search_fields,)@classmethod- def create_spatial_graph(cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings) -> AutoSpatialGraph:- """Create AutoSpatialGraph template."""+ def create_spatial_graph(+ cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings+ ) -> "AutoSpatialGraph":+ from hyperextract.types import AutoSpatialGraph+language = cls.get_language(config)- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict, identifiers = OptionsBuilder.validate_spatial_graph_config(+ config+ )node_schema_class = schema_dict.get("node_schema")edge_schema_class = schema_dict.get("edge_schema")-- if node_schema_class is None or edge_schema_class is None:- raise ValueError(f"AutoSpatialGraph requires node_schema and edge_schema definition: {config.name}")-- identifiers = IdentifierResolver.resolve_all(config)node_key_extractor = identifiers.get("node_key_extractor")edge_key_extractor = identifiers.get("edge_key_extractor")nodes_in_edge_extractor = identifiers.get("nodes_in_edge_extractor")location_extractor = identifiers.get("location_extractor")- if not all([node_key_extractor, edge_key_extractor, nodes_in_edge_extractor]):- raise ValueError(f"AutoSpatialGraph requires complete identifiers configuration: {config.name}")-- guide = config.guideprompt_builder = PromptBuilder(language)+ options = OptionsBuilder.build_spatial_options(config, language)- extraction_mode = config.parameters.extraction_mode if config.parameters else "two_stage"-- if extraction_mode == "one_stage":- prompt = prompt_builder.build_graph_main_prompt(guide)- prompt_for_node_extraction = ""- prompt_for_edge_extraction = ""- else:- prompt = ""- prompt_for_node_extraction = prompt_builder.build_spatial_graph_node_prompt(guide)- prompt_for_edge_extraction = prompt_builder.build_graph_edge_prompt(guide)-- parameters = config.parameters or Parameters()-- node_merge_strategy = parameters.node_merge_strategy or "llm_balanced"- node_custom_merge_rule = parameters.node_custom_merge_rule- edge_merge_strategy = parameters.edge_merge_strategy or "llm_balanced"- edge_custom_merge_rule = parameters.edge_custom_merge_rule+ prompt, prompt_for_node_extraction, prompt_for_edge_extraction = (+ OptionsBuilder.build_prompts(+ config, prompt_builder, options.extraction_mode+ )+ )return AutoSpatialGraph(node_schema=node_schema_class,@@ -406,20 +328,18 @@ class TemplateFactory:edge_key_extractor=edge_key_extractor,nodes_in_edge_extractor=nodes_in_edge_extractor,location_extractor=location_extractor,- observation_location=parameters.observation_location,+ observation_location=options.observation_location,llm_client=llm_client,embedder=embedder,- extraction_mode=extraction_mode,- node_strategy_or_merger=cls.resolve_merge_strategy(- node_merge_strategy,- node_custom_merge_rule,+ extraction_mode=options.extraction_mode,+ node_strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.node_merge_strategy,node_key_extractor,llm_client,node_schema_class,),- edge_strategy_or_merger=cls.resolve_merge_strategy(- edge_merge_strategy,- edge_custom_merge_rule,+ edge_strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.edge_merge_strategy,edge_key_extractor,llm_client,edge_schema_class,@@ -427,56 +347,43 @@ class TemplateFactory:prompt=prompt,prompt_for_node_extraction=prompt_for_node_extraction,prompt_for_edge_extraction=prompt_for_edge_extraction,- chunk_size=parameters.chunk_size,- chunk_overlap=parameters.chunk_overlap,- max_workers=parameters.max_workers,- verbose=parameters.verbose,- node_fields_for_index=parameters.node_search_fields,- edge_fields_for_index=parameters.edge_search_fields,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ node_fields_for_index=options.node_search_fields,+ edge_fields_for_index=options.edge_search_fields,)@classmethod- def create_spatio_temporal_graph(cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings) -> AutoSpatioTemporalGraph:- """Create AutoSpatioTemporalGraph template."""+ def create_spatio_temporal_graph(+ cls, config: TemplateConfig, llm_client: BaseChatModel, embedder: Embeddings+ ) -> "AutoSpatioTemporalGraph":+ from hyperextract.types import AutoSpatioTemporalGraph+language = cls.get_language(config)- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict, identifiers = (+ OptionsBuilder.validate_spatio_temporal_graph_config(config)+ )node_schema_class = schema_dict.get("node_schema")edge_schema_class = schema_dict.get("edge_schema")-- if node_schema_class is None or edge_schema_class is None:- raise ValueError(f"AutoSpatioTemporalGraph requires node_schema and edge_schema definition: {config.name}")-- identifiers = IdentifierResolver.resolve_all(config)node_key_extractor = identifiers.get("node_key_extractor")edge_key_extractor = identifiers.get("edge_key_extractor")nodes_in_edge_extractor = identifiers.get("nodes_in_edge_extractor")time_extractor = identifiers.get("time_extractor")location_extractor = identifiers.get("location_extractor")- if not all([node_key_extractor, edge_key_extractor, nodes_in_edge_extractor]):- raise ValueError(f"AutoSpatioTemporalGraph requires complete identifiers configuration: {config.name}")-- guide = config.guideprompt_builder = PromptBuilder(language)+ options = OptionsBuilder.build_spatio_temporal_graph_options(+ config, language+ )- extraction_mode = config.parameters.extraction_mode if config.parameters else "two_stage"-- if extraction_mode == "one_stage":- prompt = prompt_builder.build_graph_main_prompt(guide)- prompt_for_node_extraction = ""- prompt_for_edge_extraction = ""- else:- prompt = ""- prompt_for_node_extraction = prompt_builder.build_spatio_temporal_graph_node_prompt(guide)- prompt_for_edge_extraction = prompt_builder.build_graph_edge_prompt(guide)-- parameters = config.parameters or Parameters()-- node_merge_strategy = parameters.node_merge_strategy or "llm_balanced"- node_custom_merge_rule = parameters.node_custom_merge_rule- edge_merge_strategy = parameters.edge_merge_strategy or "llm_balanced"- edge_custom_merge_rule = parameters.edge_custom_merge_rule+ prompt, prompt_for_node_extraction, prompt_for_edge_extraction = (+ OptionsBuilder.build_prompts(+ config, prompt_builder, options.extraction_mode+ )+ )return AutoSpatioTemporalGraph(node_schema=node_schema_class,@@ -486,34 +393,32 @@ class TemplateFactory:nodes_in_edge_extractor=nodes_in_edge_extractor,time_extractor=time_extractor,location_extractor=location_extractor,- observation_time=parameters.observation_time,- observation_location=parameters.observation_location,+ observation_time=options.observation_time,+ observation_location=options.observation_location,llm_client=llm_client,embedder=embedder,- extraction_mode=extraction_mode,- node_strategy_or_merger=cls.resolve_merge_strategy(- node_merge_strategy,- node_custom_merge_rule,- node_key_extractor,- llm_client,- node_schema_class,- ),- edge_strategy_or_merger=cls.resolve_merge_strategy(- edge_merge_strategy,- edge_custom_merge_rule,- edge_key_extractor,- llm_client,- edge_schema_class,- ),+ extraction_mode=options.extraction_mode,+ node_strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.node_merge_strategy,+ node_key_extractor,+ llm_client,+ node_schema_class,+ ),+ edge_strategy_or_merger=OptionsBuilder.resolve_merge_strategy(+ options.edge_merge_strategy,+ edge_key_extractor,+ llm_client,+ edge_schema_class,+ ),prompt=prompt,prompt_for_node_extraction=prompt_for_node_extraction,prompt_for_edge_extraction=prompt_for_edge_extraction,- chunk_size=parameters.chunk_size,- chunk_overlap=parameters.chunk_overlap,- max_workers=parameters.max_workers,- verbose=parameters.verbose,- node_fields_for_index=parameters.node_search_fields,- edge_fields_for_index=parameters.edge_search_fields,+ chunk_size=options.chunk_size,+ chunk_overlap=options.chunk_overlap,+ max_workers=options.max_workers,+ verbose=options.verbose,+ node_fields_for_index=options.node_search_fields,+ edge_fields_for_index=options.edge_search_fields,)@classmethod@@ -522,7 +427,7 @@ class TemplateFactory:config: TemplateConfig,llm_client: BaseChatModel,embedder: Embeddings,- **kwargs+ **kwargs,):"""Create template instance based on configuration.@@ -558,12 +463,11 @@ class TemplateFactory:max_workers=20)"""- # Merge parameters: user-provided kwargs have highest priorityif kwargs:- base_params = config.parameters or Parameters()- params_dict = base_params.model_dump()- params_dict.update(kwargs)- config.parameters = Parameters(**params_dict)+ base_options = config.options or Options()+ options_dict = base_options.model_dump()+ options_dict.update(kwargs)+ config.options = Options(**options_dict)autotype_map = {"model": cls.create_model,@@ -611,7 +515,13 @@ class TemplateWrapper:def show(self, **kwargs):"""Automatically pass label_extractor parameters."""- if self._autotype in ("graph", "hypergraph", "temporal_graph", "spatial_graph", "spatio_temporal_graph"):+ if self._autotype in (+ "graph",+ "hypergraph",+ "temporal_graph",+ "spatial_graph",+ "spatio_temporal_graph",+ ):if self._node_label_extractor and self._edge_label_extractor:kwargs.setdefault("node_label_extractor", self._node_label_extractor)kwargs.setdefault("edge_label_extractor", self._edge_label_extractor)