langparse 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langparse/__init__.py +55 -0
- langparse/autoparser.py +25 -0
- langparse/chunkers/__init__.py +12 -0
- langparse/chunkers/blocks.py +151 -0
- langparse/chunkers/profiles.py +53 -0
- langparse/chunkers/registry.py +38 -0
- langparse/chunkers/semantic.py +242 -0
- langparse/chunkers/text.py +96 -0
- langparse/chunkers/workbook.py +942 -0
- langparse/cli.py +329 -0
- langparse/config.py +169 -0
- langparse/core/__init__.py +0 -0
- langparse/core/chunker.py +16 -0
- langparse/core/engine.py +37 -0
- langparse/core/parser.py +35 -0
- langparse/core/rendering.py +49 -0
- langparse/engines/__init__.py +1 -0
- langparse/engines/pdf/__init__.py +1 -0
- langparse/engines/pdf/deepdoc/__init__.py +55 -0
- langparse/engines/pdf/deepdoc/layout_recognizer.py +235 -0
- langparse/engines/pdf/deepdoc/model_loader.py +101 -0
- langparse/engines/pdf/deepdoc/ocr.py +641 -0
- langparse/engines/pdf/deepdoc/operators.py +684 -0
- langparse/engines/pdf/deepdoc/pdf_parser.py +1894 -0
- langparse/engines/pdf/deepdoc/postprocess.py +339 -0
- langparse/engines/pdf/deepdoc/recognizer.py +418 -0
- langparse/engines/pdf/deepdoc/rendering.py +210 -0
- langparse/engines/pdf/deepdoc/table_structure_recognizer.py +559 -0
- langparse/engines/pdf/deepdoc/tokenizer.py +30 -0
- langparse/engines/pdf/deepdoc/utils.py +36 -0
- langparse/engines/pdf/deepdoc_engine.py +164 -0
- langparse/engines/pdf/mineru.py +259 -0
- langparse/engines/pdf/mineru_client.py +318 -0
- langparse/engines/pdf/mineru_service.py +225 -0
- langparse/engines/pdf/ocr.py +101 -0
- langparse/engines/pdf/other.py +20 -0
- langparse/engines/pdf/simple.py +134 -0
- langparse/engines/pdf/vision_llm.py +27 -0
- langparse/errors.py +70 -0
- langparse/logging.py +27 -0
- langparse/metrics.py +129 -0
- langparse/parsers/__init__.py +0 -0
- langparse/parsers/docx_parser.py +114 -0
- langparse/parsers/excel_parser.py +220 -0
- langparse/parsers/markdown_parser.py +34 -0
- langparse/parsers/pdf_parser.py +31 -0
- langparse/parsers/registry.py +48 -0
- langparse/parsers/sniff.py +72 -0
- langparse/progress.py +77 -0
- langparse/py.typed +0 -0
- langparse/services/__init__.py +11 -0
- langparse/services/batch_service.py +339 -0
- langparse/services/benchmark_service.py +202 -0
- langparse/services/fidelity.py +154 -0
- langparse/services/output_paths.py +86 -0
- langparse/services/parse_service.py +523 -0
- langparse/services/quality.py +65 -0
- langparse/services/workbook_ambiguity_benchmark.py +563 -0
- langparse/services/workbook_quality_benchmark.py +230 -0
- langparse/types.py +97 -0
- langparse/workbooks/__init__.py +103 -0
- langparse/workbooks/adapters.py +474 -0
- langparse/workbooks/assembly.py +993 -0
- langparse/workbooks/blocks.py +209 -0
- langparse/workbooks/bundle-v1.schema.json +71 -0
- langparse/workbooks/bundle.py +341 -0
- langparse/workbooks/classification.py +393 -0
- langparse/workbooks/continuation.py +577 -0
- langparse/workbooks/evaluation/__init__.py +45 -0
- langparse/workbooks/evaluation/evaluator.py +381 -0
- langparse/workbooks/evaluation/schema.py +419 -0
- langparse/workbooks/labels.py +14 -0
- langparse/workbooks/lineage.py +117 -0
- langparse/workbooks/modeling/__init__.py +52 -0
- langparse/workbooks/modeling/cache.py +20 -0
- langparse/workbooks/modeling/config.py +87 -0
- langparse/workbooks/modeling/contract.py +628 -0
- langparse/workbooks/modeling/disambiguation.py +800 -0
- langparse/workbooks/modeling/openai_adapter.py +192 -0
- langparse/workbooks/modeling/policy.py +79 -0
- langparse/workbooks/modeling/ports.py +44 -0
- langparse/workbooks/modeling/pricing.py +17 -0
- langparse/workbooks/modeling/types.py +251 -0
- langparse/workbooks/objects.py +229 -0
- langparse/workbooks/quality/__init__.py +23 -0
- langparse/workbooks/quality/bundle.py +53 -0
- langparse/workbooks/quality/evaluator.py +266 -0
- langparse/workbooks/quality/facts.py +142 -0
- langparse/workbooks/quality/schema.py +462 -0
- langparse/workbooks/reference_types.py +73 -0
- langparse/workbooks/references.py +178 -0
- langparse/workbooks/regions.py +932 -0
- langparse/workbooks/rendering.py +222 -0
- langparse/workbooks/tables.py +477 -0
- langparse/workbooks/types.py +257 -0
- langparse-0.1.0.dist-info/METADATA +790 -0
- langparse-0.1.0.dist-info/RECORD +101 -0
- langparse-0.1.0.dist-info/WHEEL +5 -0
- langparse-0.1.0.dist-info/entry_points.txt +2 -0
- langparse-0.1.0.dist-info/licenses/LICENSE +192 -0
- langparse-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
import os
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from numbers import Real
|
|
7
|
+
|
|
8
|
+
from .ports import WorkbookModelConfigurationError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class WorkbookModelConfig:
|
|
13
|
+
api_key: str
|
|
14
|
+
model: str
|
|
15
|
+
base_url: str | None = None
|
|
16
|
+
timeout_seconds: float = 20.0
|
|
17
|
+
|
|
18
|
+
def __post_init__(self) -> None:
|
|
19
|
+
api_key = self.api_key.strip() if isinstance(self.api_key, str) else ""
|
|
20
|
+
model = self.model.strip() if isinstance(self.model, str) else ""
|
|
21
|
+
if not api_key:
|
|
22
|
+
raise WorkbookModelConfigurationError("api_key must be a non-empty string")
|
|
23
|
+
if not model:
|
|
24
|
+
raise WorkbookModelConfigurationError("model must be a non-empty string")
|
|
25
|
+
if (
|
|
26
|
+
isinstance(self.timeout_seconds, bool)
|
|
27
|
+
or not isinstance(self.timeout_seconds, Real)
|
|
28
|
+
or not math.isfinite(self.timeout_seconds)
|
|
29
|
+
or self.timeout_seconds <= 0
|
|
30
|
+
):
|
|
31
|
+
raise WorkbookModelConfigurationError("timeout_seconds must be a finite positive real")
|
|
32
|
+
base_url = self.base_url.strip() if isinstance(self.base_url, str) else self.base_url
|
|
33
|
+
object.__setattr__(self, "api_key", api_key)
|
|
34
|
+
object.__setattr__(self, "model", model)
|
|
35
|
+
object.__setattr__(self, "base_url", base_url or None)
|
|
36
|
+
|
|
37
|
+
def __repr__(self) -> str:
|
|
38
|
+
return (
|
|
39
|
+
f"WorkbookModelConfig(model={self.model!r}, "
|
|
40
|
+
"api_key='***', "
|
|
41
|
+
f"base_url={self.base_url!r}, "
|
|
42
|
+
f"timeout_seconds={self.timeout_seconds})"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def resolve_workbook_model_config(
|
|
47
|
+
*,
|
|
48
|
+
cli_model: str | None = None,
|
|
49
|
+
cli_api_key: str | None = None,
|
|
50
|
+
cli_base_url: str | None = None,
|
|
51
|
+
cli_timeout_seconds: float | None = None,
|
|
52
|
+
from_env: bool = True,
|
|
53
|
+
) -> WorkbookModelConfig:
|
|
54
|
+
"""Resolve workbook model configuration with CLI args taking precedence over environment variables."""
|
|
55
|
+
|
|
56
|
+
api_key_candidate = (
|
|
57
|
+
cli_api_key
|
|
58
|
+
if cli_api_key is not None
|
|
59
|
+
else (os.environ.get("OPENAI_API_KEY") if from_env else None)
|
|
60
|
+
)
|
|
61
|
+
api_key = api_key_candidate.strip() if isinstance(api_key_candidate, str) else ""
|
|
62
|
+
if not api_key:
|
|
63
|
+
raise WorkbookModelConfigurationError(
|
|
64
|
+
"OPENAI_API_KEY is required for model disambiguation. "
|
|
65
|
+
"Set it via the environment or inject WorkbookModelConfig programmatically."
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
model_candidate = cli_model.strip() if cli_model is not None else ""
|
|
69
|
+
model = model_candidate or (os.environ.get("OPENAI_MODEL", "").strip() if from_env else "")
|
|
70
|
+
if not model:
|
|
71
|
+
raise WorkbookModelConfigurationError(
|
|
72
|
+
"OPENAI_MODEL is required for model disambiguation. "
|
|
73
|
+
"Set it via environment variable or pass --model <name>."
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
base_url = cli_base_url or (os.environ.get("OPENAI_BASE_URL") if from_env else None)
|
|
77
|
+
if base_url:
|
|
78
|
+
base_url = base_url.strip() or None
|
|
79
|
+
|
|
80
|
+
timeout_seconds = cli_timeout_seconds if cli_timeout_seconds is not None else 20.0
|
|
81
|
+
|
|
82
|
+
return WorkbookModelConfig(
|
|
83
|
+
api_key=api_key,
|
|
84
|
+
model=model,
|
|
85
|
+
base_url=base_url,
|
|
86
|
+
timeout_seconds=timeout_seconds,
|
|
87
|
+
)
|