robert 2.2.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.
- robert/__init__.py +9 -0
- robert/__main__.py +20 -0
- robert/_version.py +3 -0
- robert/api.py +646 -0
- robert/aqme.py +280 -0
- robert/argument_parser.py +98 -0
- robert/checkml.py +433 -0
- robert/checkml_score.py +50 -0
- robert/curate.py +217 -0
- robert/evaluate_bot_retrieval.py +125 -0
- robert/evaluate_bot_support.py +102 -0
- robert/evaluate_workflow_summaries.py +87 -0
- robert/export_bot_docs_knowledge.py +1632 -0
- robert/generate.py +249 -0
- robert/generate_utils.py +311 -0
- robert/gui_easyrob/__init__.py +0 -0
- robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
- robert/gui_easyrob/bot/__init__.py +47 -0
- robert/gui_easyrob/bot/answer_metadata.py +198 -0
- robert/gui_easyrob/bot/bot_context.py +679 -0
- robert/gui_easyrob/bot/bot_engine.py +1100 -0
- robert/gui_easyrob/bot/bot_panel.py +1231 -0
- robert/gui_easyrob/bot/bot_rag.py +1178 -0
- robert/gui_easyrob/bot/bot_window.py +39 -0
- robert/gui_easyrob/bot/bot_worker.py +149 -0
- robert/gui_easyrob/bot/credential_store.py +143 -0
- robert/gui_easyrob/bot/error_parser.py +105 -0
- robert/gui_easyrob/bot/evidence_policy.py +164 -0
- robert/gui_easyrob/bot/heuristics.py +859 -0
- robert/gui_easyrob/bot/icons.py +56 -0
- robert/gui_easyrob/bot/input_csv_audit.py +212 -0
- robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
- robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
- robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
- robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
- robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
- robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
- robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
- robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
- robert/gui_easyrob/bot/llm_providers.py +1573 -0
- robert/gui_easyrob/bot/online_docs.py +105 -0
- robert/gui_easyrob/bot/prompt_policy.py +575 -0
- robert/gui_easyrob/bot/question_intent.py +562 -0
- robert/gui_easyrob/bot/response_quality.py +104 -0
- robert/gui_easyrob/bot/result_insights.py +225 -0
- robert/gui_easyrob/bot/token_usage.py +75 -0
- robert/gui_easyrob/bot/workflow_results.py +1396 -0
- robert/gui_easyrob/checkml_launcher.py +15 -0
- robert/gui_easyrob/easyrob.py +29 -0
- robert/gui_easyrob/easyrob_launcher.py +113 -0
- robert/gui_easyrob/main/__init__.py +9 -0
- robert/gui_easyrob/main/window.py +5152 -0
- robert/gui_easyrob/result_navigation.py +14 -0
- robert/gui_easyrob/tabs/__init__.py +23 -0
- robert/gui_easyrob/tabs/advanced_options.py +370 -0
- robert/gui_easyrob/tabs/aqme.py +1234 -0
- robert/gui_easyrob/tabs/checkml.py +898 -0
- robert/gui_easyrob/tabs/images.py +427 -0
- robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
- robert/gui_easyrob/tabs/molssi.py +447 -0
- robert/gui_easyrob/tabs/predictions.py +484 -0
- robert/gui_easyrob/tabs/result_catalog.py +170 -0
- robert/gui_easyrob/tabs/results.py +490 -0
- robert/gui_easyrob/tabs/results_workspace.py +120 -0
- robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
- robert/gui_easyrob/test_bot_question_routing.py +383 -0
- robert/gui_easyrob/test_bot_result_analysis.py +356 -0
- robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
- robert/gui_easyrob/test_bot_ui_integration.py +278 -0
- robert/gui_easyrob/test_checkml_app_mode.py +124 -0
- robert/gui_easyrob/test_checkml_completion.py +57 -0
- robert/gui_easyrob/test_checkml_defaults.py +37 -0
- robert/gui_easyrob/test_checkml_result_summary.py +113 -0
- robert/gui_easyrob/test_checkml_web_mode.py +57 -0
- robert/gui_easyrob/test_dialog_layout.py +33 -0
- robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
- robert/gui_easyrob/test_molssi_auto.py +569 -0
- robert/gui_easyrob/test_tutorial_view.py +215 -0
- robert/gui_easyrob/tutorials/check_model.md +25 -0
- robert/gui_easyrob/tutorials/chemdraw.md +49 -0
- robert/gui_easyrob/tutorials/csv.md +53 -0
- robert/gui_easyrob/tutorials/descriptors.md +21 -0
- robert/gui_easyrob/tutorials/overview.md +65 -0
- robert/gui_easyrob/tutorials/predictions.md +25 -0
- robert/gui_easyrob/tutorials/robbot.md +29 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
- robert/gui_easyrob/utils/__init__.py +0 -0
- robert/gui_easyrob/utils/aqme_utils.py +238 -0
- robert/gui_easyrob/utils/molssi_utils.py +584 -0
- robert/gui_easyrob/utils/predictions_utils.py +985 -0
- robert/gui_easyrob/utils/utils_gui.py +738 -0
- robert/gui_easyrob/version.py +68 -0
- robert/gui_easyrob/web/app.css +484 -0
- robert/gui_easyrob/web/app.html +134 -0
- robert/gui_easyrob/web/app.js +764 -0
- robert/gui_easyrob/web/checkml_brand.png +0 -0
- robert/gui_easyrob/web/easyrob_background.gif +0 -0
- robert/gui_easyrob/web/easyrob_background.png +0 -0
- robert/gui_easyrob/web/images.css +89 -0
- robert/gui_easyrob/web/images.html +39 -0
- robert/gui_easyrob/web/images.js +101 -0
- robert/gui_easyrob/web/results.js +499 -0
- robert/gui_easyrob/web/robert_brand.png +0 -0
- robert/gui_easyrob/web_dialogs.py +64 -0
- robert/gui_easyrob/web_results.py +253 -0
- robert/gui_easyrob/web_shell.py +684 -0
- robert/gui_easyrob/workflow_progress.py +89 -0
- robert/gui_easyrob/workflow_run_lock.py +27 -0
- robert/icons/CheckML_icon.png +0 -0
- robert/icons/Robert_icon.png +0 -0
- robert/icons/Robert_logo.jpg +0 -0
- robert/icons/Robert_logo_transparent.png +0 -0
- robert/icons/documentation_icon.png +0 -0
- robert/icons/info_icon.png +0 -0
- robert/icons/pdf_icon.png +0 -0
- robert/icons/play_icon.png +0 -0
- robert/icons/stop_icon.png +0 -0
- robert/icons/youtube_icon.ico +0 -0
- robert/predict.py +193 -0
- robert/predict_utils.py +410 -0
- robert/report/CheckML_logo.jpg +0 -0
- robert/report/GENERATE.png +0 -0
- robert/report/Robert_icon.ico +0 -0
- robert/report/Robert_logo.jpg +0 -0
- robert/report/Robert_logo1.jpg +0 -0
- robert/report/abbrev.png +0 -0
- robert/report/adv_anal.png +0 -0
- robert/report/checkml_pass.svg +3 -0
- robert/report/checkml_unclear.svg +3 -0
- robert/report/checkml_warning.svg +3 -0
- robert/report/features.png +0 -0
- robert/report/outliers.png +0 -0
- robert/report/pred.png +0 -0
- robert/report/repro.png +0 -0
- robert/report/robust_x.png +0 -0
- robert/report/robust_y_high.png +0 -0
- robert/report/robust_y_low.png +0 -0
- robert/report/score.png +0 -0
- robert/report/score_0.jpg +0 -0
- robert/report/score_1.jpg +0 -0
- robert/report/score_10.jpg +0 -0
- robert/report/score_2.jpg +0 -0
- robert/report/score_3.jpg +0 -0
- robert/report/score_4.jpg +0 -0
- robert/report/score_5.jpg +0 -0
- robert/report/score_6.jpg +0 -0
- robert/report/score_7.jpg +0 -0
- robert/report/score_8.jpg +0 -0
- robert/report/score_9.jpg +0 -0
- robert/report/score_gray_0.jpg +0 -0
- robert/report/score_gray_1.jpg +0 -0
- robert/report/score_gray_10.jpg +0 -0
- robert/report/score_gray_2.jpg +0 -0
- robert/report/score_gray_3.jpg +0 -0
- robert/report/score_gray_4.jpg +0 -0
- robert/report/score_gray_5.jpg +0 -0
- robert/report/score_gray_6.jpg +0 -0
- robert/report/score_gray_7.jpg +0 -0
- robert/report/score_gray_8.jpg +0 -0
- robert/report/score_gray_9.jpg +0 -0
- robert/report/score_w_1_0.jpg +0 -0
- robert/report/score_w_1_1.jpg +0 -0
- robert/report/score_w_2_0.jpg +0 -0
- robert/report/score_w_2_1.jpg +0 -0
- robert/report/score_w_2_2.jpg +0 -0
- robert/report/score_w_2_gray_0.jpg +0 -0
- robert/report/score_w_2_gray_1.jpg +0 -0
- robert/report/score_w_2_gray_2.jpg +0 -0
- robert/report/score_w_3_0.jpg +0 -0
- robert/report/score_w_3_1.jpg +0 -0
- robert/report/score_w_3_2.jpg +0 -0
- robert/report/score_w_3_3.jpg +0 -0
- robert/report/score_w_4_0.jpg +0 -0
- robert/report/score_w_4_1.JPG +0 -0
- robert/report/score_w_4_2.jpg +0 -0
- robert/report/score_w_4_3.jpg +0 -0
- robert/report/score_w_4_4.jpg +0 -0
- robert/report/transpa.png +0 -0
- robert/report/y_distrib.png +0 -0
- robert/report.py +2880 -0
- robert/report_utils.py +2270 -0
- robert/robert.py +181 -0
- robert/utils.py +4763 -0
- robert/verify.py +606 -0
- robert-2.2.0.dist-info/METADATA +55 -0
- robert-2.2.0.dist-info/RECORD +261 -0
- robert-2.2.0.dist-info/WHEEL +5 -0
- robert-2.2.0.dist-info/entry_points.txt +3 -0
- robert-2.2.0.dist-info/licenses/LICENSE +21 -0
- robert-2.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""Provider-independent answer evidence and citation metadata."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from enum import Enum
|
|
7
|
+
import re
|
|
8
|
+
from urllib.parse import urlsplit
|
|
9
|
+
|
|
10
|
+
from .response_quality import calibrate_validation_guarantees
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"AnswerMetadata",
|
|
14
|
+
"EvidenceOrigin",
|
|
15
|
+
"normalize_provider_answer_text",
|
|
16
|
+
"normalize_provider_citations",
|
|
17
|
+
"SourceCitation",
|
|
18
|
+
"WebSearchMode",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
_MALFORMED_URL_CITATION_RE = re.compile(
|
|
23
|
+
r"【\[(https?://[^\s\]】]+)】\]\((https?://[^\s\)】]+)】\)",
|
|
24
|
+
flags=re.IGNORECASE,
|
|
25
|
+
)
|
|
26
|
+
_INTERNAL_REFERENCE_RE = re.compile(
|
|
27
|
+
r"(?:\[\s*|【\s*)(?:easyrob|robert|aqme)[\-_‐‑‒–—―]"
|
|
28
|
+
r"[A-Za-z0-9_\-‐‑‒–—―.]+(?:\s*\]|】)",
|
|
29
|
+
flags=re.IGNORECASE,
|
|
30
|
+
)
|
|
31
|
+
_EMPTY_MARKDOWN_ARTIFACT_RE = re.compile(
|
|
32
|
+
r"(?m)^[ \t]*(?:(?:[-*+]|\d+[.)])[ \t]*)?\\[ \t]*(?:\n|$)"
|
|
33
|
+
)
|
|
34
|
+
_COMPLETE_SENTENCE_RE = re.compile(r"[.!?](?=\s|$)")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class EvidenceOrigin(str, Enum):
|
|
38
|
+
"""Describe the evidence used to produce a visible answer."""
|
|
39
|
+
|
|
40
|
+
LOCAL_SYSTEM = "local_system"
|
|
41
|
+
LOCAL_DOCUMENTATION = "local_documentation"
|
|
42
|
+
WEB_AND_DOCUMENTATION = "web_and_documentation"
|
|
43
|
+
GENERAL_KNOWLEDGE = "general_knowledge"
|
|
44
|
+
INSUFFICIENT = "insufficient"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class WebSearchMode(str, Enum):
|
|
48
|
+
"""Control whether a provider may perform its native web search."""
|
|
49
|
+
|
|
50
|
+
OFF = "off"
|
|
51
|
+
AUTO = "auto"
|
|
52
|
+
REQUIRED = "required"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass(frozen=True, slots=True)
|
|
56
|
+
class SourceCitation:
|
|
57
|
+
"""A validated, user-visible HTTP source."""
|
|
58
|
+
|
|
59
|
+
title: str
|
|
60
|
+
url: str
|
|
61
|
+
start_index: int | None = None
|
|
62
|
+
end_index: int | None = None
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def create(
|
|
66
|
+
cls,
|
|
67
|
+
title: object,
|
|
68
|
+
url: object,
|
|
69
|
+
**locations: object,
|
|
70
|
+
) -> "SourceCitation | None":
|
|
71
|
+
clean_url = str(url or "").strip()
|
|
72
|
+
try:
|
|
73
|
+
parsed = urlsplit(clean_url)
|
|
74
|
+
except ValueError:
|
|
75
|
+
return None
|
|
76
|
+
if (
|
|
77
|
+
parsed.scheme.lower() not in {"http", "https"}
|
|
78
|
+
or not parsed.hostname
|
|
79
|
+
or parsed.username is not None
|
|
80
|
+
or parsed.password is not None
|
|
81
|
+
):
|
|
82
|
+
return None
|
|
83
|
+
|
|
84
|
+
start = locations.get("start_index")
|
|
85
|
+
end = locations.get("end_index")
|
|
86
|
+
clean_start = start if isinstance(start, int) and start >= 0 else None
|
|
87
|
+
clean_end = end if isinstance(end, int) and end >= 0 else None
|
|
88
|
+
if clean_start is not None and clean_end is not None and clean_end < clean_start:
|
|
89
|
+
clean_start = None
|
|
90
|
+
clean_end = None
|
|
91
|
+
|
|
92
|
+
clean_title = str(title or "").strip() or clean_url
|
|
93
|
+
return cls(
|
|
94
|
+
title=clean_title[:200],
|
|
95
|
+
url=clean_url[:2000],
|
|
96
|
+
start_index=clean_start,
|
|
97
|
+
end_index=clean_end,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def normalize_provider_citations(text: object) -> str:
|
|
102
|
+
"""Repair a known malformed provider URL citation without trusting its target."""
|
|
103
|
+
clean_text = str(text or "")
|
|
104
|
+
|
|
105
|
+
def replace(match: re.Match[str]) -> str:
|
|
106
|
+
visible_url, target_url = match.groups()
|
|
107
|
+
if visible_url.casefold().rstrip("/") != target_url.casefold().rstrip("/"):
|
|
108
|
+
return match.group(0)
|
|
109
|
+
citation = SourceCitation.create(visible_url, target_url)
|
|
110
|
+
if citation is None:
|
|
111
|
+
return match.group(0)
|
|
112
|
+
return f"[{citation.url}]({citation.url})"
|
|
113
|
+
|
|
114
|
+
return _MALFORMED_URL_CITATION_RE.sub(replace, clean_text)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _tables_to_labeled_lists(text: str) -> str:
|
|
118
|
+
"""Flatten pipe tables for the narrow chat renderer without inventing cells."""
|
|
119
|
+
lines = text.splitlines()
|
|
120
|
+
output = []
|
|
121
|
+
index = 0
|
|
122
|
+
def cells(line):
|
|
123
|
+
return [cell.strip() for cell in re.split(r"(?<!\\)\|", line.strip().strip("|"))]
|
|
124
|
+
while index < len(lines):
|
|
125
|
+
headers = cells(lines[index])
|
|
126
|
+
separators = cells(lines[index + 1]) if index + 1 < len(lines) else []
|
|
127
|
+
if len(headers) > 1 and len(headers) == len(separators) and all(
|
|
128
|
+
re.fullmatch(r":?-{3,}:?", cell) for cell in separators
|
|
129
|
+
):
|
|
130
|
+
index += 2
|
|
131
|
+
output.append("")
|
|
132
|
+
while index < len(lines) and "|" in lines[index]:
|
|
133
|
+
values = cells(lines[index])
|
|
134
|
+
if len(values) > len(headers):
|
|
135
|
+
break
|
|
136
|
+
for header, value in zip(headers, values):
|
|
137
|
+
if value:
|
|
138
|
+
output.append(f"- **{header}:** {value}")
|
|
139
|
+
output.append("")
|
|
140
|
+
index += 1
|
|
141
|
+
else:
|
|
142
|
+
output.append(lines[index])
|
|
143
|
+
index += 1
|
|
144
|
+
return "\n".join(output)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def normalize_provider_answer_text(text: object, *, token_limited: bool = False) -> str:
|
|
148
|
+
"""Clean provider formatting while preserving readable Markdown and web links."""
|
|
149
|
+
cleaned = normalize_provider_citations(text).replace("\r\n", "\n").replace("\r", "\n")
|
|
150
|
+
code_blocks: list[str] = []
|
|
151
|
+
def protect_code(match: re.Match[str]) -> str:
|
|
152
|
+
code_blocks.append(match.group(0))
|
|
153
|
+
return f"@@ROBBOTCODE{len(code_blocks) - 1}@@"
|
|
154
|
+
cleaned = re.sub(r"(?m)^```[^\n]*\n[\s\S]*?(?:^```[ \t]*$|\Z)", protect_code, cleaned)
|
|
155
|
+
cleaned = _tables_to_labeled_lists(cleaned)
|
|
156
|
+
cleaned = cleaned.replace(" ", " ").replace(" ", " ")
|
|
157
|
+
cleaned = _INTERNAL_REFERENCE_RE.sub("", cleaned)
|
|
158
|
+
cleaned = _EMPTY_MARKDOWN_ARTIFACT_RE.sub("", cleaned)
|
|
159
|
+
cleaned = re.sub(r"\\[ \t]*\n", "\n", cleaned)
|
|
160
|
+
cleaned = re.sub(r"\\([*_\-])", r"\1", cleaned)
|
|
161
|
+
cleaned = re.sub(r"[ \t]+([,.;:!?])", r"\1", cleaned)
|
|
162
|
+
cleaned = re.sub(r"[ \t]+\n", "\n", cleaned)
|
|
163
|
+
cleaned = re.sub(r"\n{3,}", "\n\n", cleaned).strip()
|
|
164
|
+
lines = cleaned.splitlines()
|
|
165
|
+
next_item_number = 0
|
|
166
|
+
for index, line in enumerate(lines):
|
|
167
|
+
ordered_item = re.match(r"^(\s*)\d+([.)])\s+(.+)$", line)
|
|
168
|
+
if ordered_item:
|
|
169
|
+
next_item_number = next_item_number + 1 if next_item_number else 1
|
|
170
|
+
lines[index] = (
|
|
171
|
+
f"{ordered_item.group(1)}{next_item_number}{ordered_item.group(2)} "
|
|
172
|
+
f"{ordered_item.group(3)}"
|
|
173
|
+
)
|
|
174
|
+
elif line.strip() and not (
|
|
175
|
+
next_item_number and (line[:1].isspace() or re.fullmatch(r"@@ROBBOTCODE\d+@@", line.strip()))
|
|
176
|
+
):
|
|
177
|
+
next_item_number = 0
|
|
178
|
+
cleaned = "\n".join(lines)
|
|
179
|
+
if token_limited:
|
|
180
|
+
cleaned = re.sub(r"(?m)^\s*\d+\\?[.)]\s*$", "", cleaned).rstrip()
|
|
181
|
+
sentence_ends = list(_COMPLETE_SENTENCE_RE.finditer(cleaned))
|
|
182
|
+
if sentence_ends:
|
|
183
|
+
cleaned = cleaned[: sentence_ends[-1].end()].rstrip()
|
|
184
|
+
elif cleaned:
|
|
185
|
+
cleaned = cleaned.rstrip(" .") + "…"
|
|
186
|
+
cleaned = calibrate_validation_guarantees(cleaned)
|
|
187
|
+
for index, block in enumerate(code_blocks):
|
|
188
|
+
cleaned = cleaned.replace(f"@@ROBBOTCODE{index}@@", block)
|
|
189
|
+
return cleaned
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@dataclass(frozen=True, slots=True)
|
|
193
|
+
class AnswerMetadata:
|
|
194
|
+
"""Normalized evidence details returned by any answer backend."""
|
|
195
|
+
|
|
196
|
+
evidence_origin: EvidenceOrigin = EvidenceOrigin.GENERAL_KNOWLEDGE
|
|
197
|
+
sources: tuple[SourceCitation, ...] = ()
|
|
198
|
+
search_error: str = ""
|