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.
Files changed (261) hide show
  1. robert/__init__.py +9 -0
  2. robert/__main__.py +20 -0
  3. robert/_version.py +3 -0
  4. robert/api.py +646 -0
  5. robert/aqme.py +280 -0
  6. robert/argument_parser.py +98 -0
  7. robert/checkml.py +433 -0
  8. robert/checkml_score.py +50 -0
  9. robert/curate.py +217 -0
  10. robert/evaluate_bot_retrieval.py +125 -0
  11. robert/evaluate_bot_support.py +102 -0
  12. robert/evaluate_workflow_summaries.py +87 -0
  13. robert/export_bot_docs_knowledge.py +1632 -0
  14. robert/generate.py +249 -0
  15. robert/generate_utils.py +311 -0
  16. robert/gui_easyrob/__init__.py +0 -0
  17. robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
  18. robert/gui_easyrob/bot/__init__.py +47 -0
  19. robert/gui_easyrob/bot/answer_metadata.py +198 -0
  20. robert/gui_easyrob/bot/bot_context.py +679 -0
  21. robert/gui_easyrob/bot/bot_engine.py +1100 -0
  22. robert/gui_easyrob/bot/bot_panel.py +1231 -0
  23. robert/gui_easyrob/bot/bot_rag.py +1178 -0
  24. robert/gui_easyrob/bot/bot_window.py +39 -0
  25. robert/gui_easyrob/bot/bot_worker.py +149 -0
  26. robert/gui_easyrob/bot/credential_store.py +143 -0
  27. robert/gui_easyrob/bot/error_parser.py +105 -0
  28. robert/gui_easyrob/bot/evidence_policy.py +164 -0
  29. robert/gui_easyrob/bot/heuristics.py +859 -0
  30. robert/gui_easyrob/bot/icons.py +56 -0
  31. robert/gui_easyrob/bot/input_csv_audit.py +212 -0
  32. robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
  33. robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
  34. robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
  35. robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
  36. robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
  37. robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
  38. robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
  39. robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
  40. robert/gui_easyrob/bot/llm_providers.py +1573 -0
  41. robert/gui_easyrob/bot/online_docs.py +105 -0
  42. robert/gui_easyrob/bot/prompt_policy.py +575 -0
  43. robert/gui_easyrob/bot/question_intent.py +562 -0
  44. robert/gui_easyrob/bot/response_quality.py +104 -0
  45. robert/gui_easyrob/bot/result_insights.py +225 -0
  46. robert/gui_easyrob/bot/token_usage.py +75 -0
  47. robert/gui_easyrob/bot/workflow_results.py +1396 -0
  48. robert/gui_easyrob/checkml_launcher.py +15 -0
  49. robert/gui_easyrob/easyrob.py +29 -0
  50. robert/gui_easyrob/easyrob_launcher.py +113 -0
  51. robert/gui_easyrob/main/__init__.py +9 -0
  52. robert/gui_easyrob/main/window.py +5152 -0
  53. robert/gui_easyrob/result_navigation.py +14 -0
  54. robert/gui_easyrob/tabs/__init__.py +23 -0
  55. robert/gui_easyrob/tabs/advanced_options.py +370 -0
  56. robert/gui_easyrob/tabs/aqme.py +1234 -0
  57. robert/gui_easyrob/tabs/checkml.py +898 -0
  58. robert/gui_easyrob/tabs/images.py +427 -0
  59. robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
  60. robert/gui_easyrob/tabs/molssi.py +447 -0
  61. robert/gui_easyrob/tabs/predictions.py +484 -0
  62. robert/gui_easyrob/tabs/result_catalog.py +170 -0
  63. robert/gui_easyrob/tabs/results.py +490 -0
  64. robert/gui_easyrob/tabs/results_workspace.py +120 -0
  65. robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
  66. robert/gui_easyrob/test_bot_question_routing.py +383 -0
  67. robert/gui_easyrob/test_bot_result_analysis.py +356 -0
  68. robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
  69. robert/gui_easyrob/test_bot_ui_integration.py +278 -0
  70. robert/gui_easyrob/test_checkml_app_mode.py +124 -0
  71. robert/gui_easyrob/test_checkml_completion.py +57 -0
  72. robert/gui_easyrob/test_checkml_defaults.py +37 -0
  73. robert/gui_easyrob/test_checkml_result_summary.py +113 -0
  74. robert/gui_easyrob/test_checkml_web_mode.py +57 -0
  75. robert/gui_easyrob/test_dialog_layout.py +33 -0
  76. robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
  77. robert/gui_easyrob/test_molssi_auto.py +569 -0
  78. robert/gui_easyrob/test_tutorial_view.py +215 -0
  79. robert/gui_easyrob/tutorials/check_model.md +25 -0
  80. robert/gui_easyrob/tutorials/chemdraw.md +49 -0
  81. robert/gui_easyrob/tutorials/csv.md +53 -0
  82. robert/gui_easyrob/tutorials/descriptors.md +21 -0
  83. robert/gui_easyrob/tutorials/overview.md +65 -0
  84. robert/gui_easyrob/tutorials/predictions.md +25 -0
  85. robert/gui_easyrob/tutorials/robbot.md +29 -0
  86. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
  87. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
  88. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
  89. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
  90. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
  91. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
  92. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
  93. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
  94. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
  95. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
  96. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
  97. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
  98. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
  99. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
  100. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
  101. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
  102. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
  103. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
  104. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
  105. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
  106. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
  107. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
  108. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
  109. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
  110. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
  111. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
  112. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
  113. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
  114. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
  115. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
  116. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
  117. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
  118. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
  119. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
  120. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
  121. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
  122. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
  123. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
  124. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
  125. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
  126. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
  127. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
  128. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
  129. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
  130. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
  131. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
  132. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
  133. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
  134. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
  135. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
  136. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
  137. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
  138. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
  139. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
  140. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
  141. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
  142. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
  143. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
  144. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
  145. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
  146. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
  147. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
  148. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
  149. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
  150. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
  151. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
  152. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
  153. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
  154. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
  155. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
  156. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
  157. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
  158. robert/gui_easyrob/utils/__init__.py +0 -0
  159. robert/gui_easyrob/utils/aqme_utils.py +238 -0
  160. robert/gui_easyrob/utils/molssi_utils.py +584 -0
  161. robert/gui_easyrob/utils/predictions_utils.py +985 -0
  162. robert/gui_easyrob/utils/utils_gui.py +738 -0
  163. robert/gui_easyrob/version.py +68 -0
  164. robert/gui_easyrob/web/app.css +484 -0
  165. robert/gui_easyrob/web/app.html +134 -0
  166. robert/gui_easyrob/web/app.js +764 -0
  167. robert/gui_easyrob/web/checkml_brand.png +0 -0
  168. robert/gui_easyrob/web/easyrob_background.gif +0 -0
  169. robert/gui_easyrob/web/easyrob_background.png +0 -0
  170. robert/gui_easyrob/web/images.css +89 -0
  171. robert/gui_easyrob/web/images.html +39 -0
  172. robert/gui_easyrob/web/images.js +101 -0
  173. robert/gui_easyrob/web/results.js +499 -0
  174. robert/gui_easyrob/web/robert_brand.png +0 -0
  175. robert/gui_easyrob/web_dialogs.py +64 -0
  176. robert/gui_easyrob/web_results.py +253 -0
  177. robert/gui_easyrob/web_shell.py +684 -0
  178. robert/gui_easyrob/workflow_progress.py +89 -0
  179. robert/gui_easyrob/workflow_run_lock.py +27 -0
  180. robert/icons/CheckML_icon.png +0 -0
  181. robert/icons/Robert_icon.png +0 -0
  182. robert/icons/Robert_logo.jpg +0 -0
  183. robert/icons/Robert_logo_transparent.png +0 -0
  184. robert/icons/documentation_icon.png +0 -0
  185. robert/icons/info_icon.png +0 -0
  186. robert/icons/pdf_icon.png +0 -0
  187. robert/icons/play_icon.png +0 -0
  188. robert/icons/stop_icon.png +0 -0
  189. robert/icons/youtube_icon.ico +0 -0
  190. robert/predict.py +193 -0
  191. robert/predict_utils.py +410 -0
  192. robert/report/CheckML_logo.jpg +0 -0
  193. robert/report/GENERATE.png +0 -0
  194. robert/report/Robert_icon.ico +0 -0
  195. robert/report/Robert_logo.jpg +0 -0
  196. robert/report/Robert_logo1.jpg +0 -0
  197. robert/report/abbrev.png +0 -0
  198. robert/report/adv_anal.png +0 -0
  199. robert/report/checkml_pass.svg +3 -0
  200. robert/report/checkml_unclear.svg +3 -0
  201. robert/report/checkml_warning.svg +3 -0
  202. robert/report/features.png +0 -0
  203. robert/report/outliers.png +0 -0
  204. robert/report/pred.png +0 -0
  205. robert/report/repro.png +0 -0
  206. robert/report/robust_x.png +0 -0
  207. robert/report/robust_y_high.png +0 -0
  208. robert/report/robust_y_low.png +0 -0
  209. robert/report/score.png +0 -0
  210. robert/report/score_0.jpg +0 -0
  211. robert/report/score_1.jpg +0 -0
  212. robert/report/score_10.jpg +0 -0
  213. robert/report/score_2.jpg +0 -0
  214. robert/report/score_3.jpg +0 -0
  215. robert/report/score_4.jpg +0 -0
  216. robert/report/score_5.jpg +0 -0
  217. robert/report/score_6.jpg +0 -0
  218. robert/report/score_7.jpg +0 -0
  219. robert/report/score_8.jpg +0 -0
  220. robert/report/score_9.jpg +0 -0
  221. robert/report/score_gray_0.jpg +0 -0
  222. robert/report/score_gray_1.jpg +0 -0
  223. robert/report/score_gray_10.jpg +0 -0
  224. robert/report/score_gray_2.jpg +0 -0
  225. robert/report/score_gray_3.jpg +0 -0
  226. robert/report/score_gray_4.jpg +0 -0
  227. robert/report/score_gray_5.jpg +0 -0
  228. robert/report/score_gray_6.jpg +0 -0
  229. robert/report/score_gray_7.jpg +0 -0
  230. robert/report/score_gray_8.jpg +0 -0
  231. robert/report/score_gray_9.jpg +0 -0
  232. robert/report/score_w_1_0.jpg +0 -0
  233. robert/report/score_w_1_1.jpg +0 -0
  234. robert/report/score_w_2_0.jpg +0 -0
  235. robert/report/score_w_2_1.jpg +0 -0
  236. robert/report/score_w_2_2.jpg +0 -0
  237. robert/report/score_w_2_gray_0.jpg +0 -0
  238. robert/report/score_w_2_gray_1.jpg +0 -0
  239. robert/report/score_w_2_gray_2.jpg +0 -0
  240. robert/report/score_w_3_0.jpg +0 -0
  241. robert/report/score_w_3_1.jpg +0 -0
  242. robert/report/score_w_3_2.jpg +0 -0
  243. robert/report/score_w_3_3.jpg +0 -0
  244. robert/report/score_w_4_0.jpg +0 -0
  245. robert/report/score_w_4_1.JPG +0 -0
  246. robert/report/score_w_4_2.jpg +0 -0
  247. robert/report/score_w_4_3.jpg +0 -0
  248. robert/report/score_w_4_4.jpg +0 -0
  249. robert/report/transpa.png +0 -0
  250. robert/report/y_distrib.png +0 -0
  251. robert/report.py +2880 -0
  252. robert/report_utils.py +2270 -0
  253. robert/robert.py +181 -0
  254. robert/utils.py +4763 -0
  255. robert/verify.py +606 -0
  256. robert-2.2.0.dist-info/METADATA +55 -0
  257. robert-2.2.0.dist-info/RECORD +261 -0
  258. robert-2.2.0.dist-info/WHEEL +5 -0
  259. robert-2.2.0.dist-info/entry_points.txt +3 -0
  260. robert-2.2.0.dist-info/licenses/LICENSE +21 -0
  261. robert-2.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,39 @@
1
+ """Floating top-level window that hosts the robBOT panel."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from PySide6.QtCore import Qt, Signal
6
+ from PySide6.QtGui import QCloseEvent, QHideEvent, QShowEvent
7
+ from PySide6.QtWidgets import QSizePolicy, QVBoxLayout, QWidget
8
+
9
+ from .bot_panel import BotPanel
10
+
11
+ __all__ = ["BotWindow"]
12
+
13
+
14
+ class BotWindow(QWidget):
15
+ visibility_changed = Signal(bool)
16
+
17
+ def __init__(self, parent=None) -> None:
18
+ super().__init__(parent, Qt.Window)
19
+ self.setWindowTitle("robBOT")
20
+ self.resize(700, 820)
21
+ self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
22
+
23
+ layout = QVBoxLayout(self)
24
+ layout.setContentsMargins(0, 0, 0, 0)
25
+
26
+ self.panel = BotPanel(self)
27
+ self.panel.close_requested.connect(self.hide)
28
+ layout.addWidget(self.panel)
29
+
30
+ def showEvent(self, event: QShowEvent) -> None:
31
+ super().showEvent(event)
32
+ self.visibility_changed.emit(True)
33
+
34
+ def hideEvent(self, event: QHideEvent) -> None:
35
+ super().hideEvent(event)
36
+ self.visibility_changed.emit(False)
37
+
38
+ def closeEvent(self, event: QCloseEvent) -> None:
39
+ super().closeEvent(event)
@@ -0,0 +1,149 @@
1
+ """Background worker for non-blocking EasyROB bot replies."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Mapping, Sequence
6
+
7
+ from PySide6.QtCore import QThread, Signal
8
+
9
+ from .bot_context import GuiSnapshot
10
+ from .answer_metadata import AnswerMetadata
11
+ from .token_usage import TokenUsage
12
+
13
+ __all__ = ["BotReplyWorker"]
14
+
15
+
16
+ class BotReplyWorker(QThread):
17
+ succeeded = Signal(int, int, str, bool, bool, object, object)
18
+ failed = Signal(int, int, str)
19
+ progressed = Signal(int, int, str)
20
+
21
+ def __init__(
22
+ self,
23
+ engine,
24
+ *,
25
+ request_id: int,
26
+ generation: int,
27
+ question: str,
28
+ snapshot: GuiSnapshot,
29
+ mode: str,
30
+ provider: str,
31
+ api_key: str,
32
+ model: str | None = None,
33
+ conversation_history: Sequence[Mapping[str, object]] | None = None,
34
+ tutorial_id: str | None = None,
35
+ web_search_enabled: bool = True,
36
+ parent=None,
37
+ ) -> None:
38
+ super().__init__(parent)
39
+ self.engine = engine
40
+ self._interruption_requested = False
41
+ self.request_id = request_id if type(request_id) is int else 0
42
+ self.generation = generation if type(generation) is int else 0
43
+ self.question = question if type(question) is str else ""
44
+ self.snapshot = snapshot
45
+ self.mode = mode
46
+ self.provider = provider
47
+ self.api_key = api_key if type(api_key) is str else ""
48
+ self.model = model
49
+ self.tutorial_id = tutorial_id.strip() if type(tutorial_id) is str else ""
50
+ self.web_search_enabled = web_search_enabled is True
51
+ records = conversation_history if type(conversation_history) in {list, tuple} else ()
52
+ self.conversation_history = tuple(
53
+ {"role": record["role"], "content": record["content"], **(
54
+ {"memory_eligible": record["memory_eligible"]}
55
+ if "memory_eligible" in record else {}
56
+ )}
57
+ for record in records
58
+ if type(record) is dict
59
+ and type(record.get("role")) is str
60
+ and type(record.get("content")) is str
61
+ )
62
+
63
+ def requestInterruption(self) -> None:
64
+ self._interruption_requested = True
65
+ super().requestInterruption()
66
+
67
+ def _is_interrupted(self) -> bool:
68
+ return self._interruption_requested or self.isInterruptionRequested()
69
+
70
+ def run(self) -> None:
71
+ try:
72
+ if self._is_interrupted():
73
+ return
74
+ if hasattr(self.engine, "answer_with_metadata"):
75
+ answer_kwargs = dict(
76
+ question=self.question,
77
+ snapshot=self.snapshot,
78
+ mode=self.mode,
79
+ provider=self.provider,
80
+ api_key=self.api_key,
81
+ model=self.model,
82
+ conversation_history=self.conversation_history,
83
+ web_search_enabled=self.web_search_enabled,
84
+ progress_callback=self._report_progress,
85
+ )
86
+ if self.tutorial_id:
87
+ answer_kwargs["tutorial_id"] = self.tutorial_id
88
+ answer_result = self.engine.answer_with_metadata(**answer_kwargs)
89
+ if type(answer_result) is dict:
90
+ raw_answer = answer_result.get("text", "")
91
+ answer = raw_answer if type(raw_answer) is str else ""
92
+ auto_reset_context = answer_result.get("auto_reset_context", False) is True
93
+ memory_eligible = answer_result.get("memory_eligible", True) is True
94
+ raw_usage = answer_result.get("usage")
95
+ raw_metadata = answer_result.get("metadata")
96
+ else:
97
+ raw_answer = getattr(answer_result, "text", "")
98
+ answer = raw_answer if type(raw_answer) is str else ""
99
+ auto_reset_context = getattr(answer_result, "auto_reset_context", False) is True
100
+ memory_eligible = getattr(answer_result, "memory_eligible", True) is True
101
+ raw_usage = getattr(answer_result, "usage", None)
102
+ raw_metadata = getattr(answer_result, "metadata", None)
103
+ usage = raw_usage if isinstance(raw_usage, TokenUsage) else TokenUsage()
104
+ metadata = raw_metadata if isinstance(raw_metadata, AnswerMetadata) else AnswerMetadata()
105
+ else:
106
+ answer_kwargs = dict(
107
+ question=self.question,
108
+ snapshot=self.snapshot,
109
+ mode=self.mode,
110
+ provider=self.provider,
111
+ api_key=self.api_key,
112
+ model=self.model,
113
+ conversation_history=self.conversation_history,
114
+ )
115
+ if self.tutorial_id:
116
+ answer_kwargs["tutorial_id"] = self.tutorial_id
117
+ raw_answer = self.engine.answer(**answer_kwargs)
118
+ answer = raw_answer if type(raw_answer) is str else ""
119
+ auto_reset_context = False
120
+ memory_eligible = True
121
+ usage = TokenUsage()
122
+ metadata = AnswerMetadata()
123
+ except Exception:
124
+ if not self._is_interrupted():
125
+ self.failed.emit(
126
+ self.request_id,
127
+ self.generation,
128
+ "The bot could not complete the request.",
129
+ )
130
+ return
131
+ finally:
132
+ self.api_key = ""
133
+
134
+ if self._is_interrupted():
135
+ return
136
+ self.succeeded.emit(
137
+ self.request_id,
138
+ self.generation,
139
+ answer,
140
+ auto_reset_context,
141
+ memory_eligible,
142
+ usage,
143
+ metadata,
144
+ )
145
+
146
+ def _report_progress(self, stage: str) -> None:
147
+ if self._is_interrupted() or type(stage) is not str:
148
+ return
149
+ self.progressed.emit(self.request_id, self.generation, stage)
@@ -0,0 +1,143 @@
1
+ """Protect saved cloud API keys with the operating system's credential service."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ import ctypes
7
+ from ctypes import wintypes
8
+ import sys
9
+
10
+ from PySide6.QtCore import QSettings
11
+
12
+
13
+ class CredentialStoreError(RuntimeError):
14
+ """A credential could not be saved or recovered securely."""
15
+
16
+ def __init__(self, message: str, temporary_secret: str = "") -> None:
17
+ super().__init__(message)
18
+ self.temporary_secret = temporary_secret
19
+
20
+
21
+ class _DataBlob(ctypes.Structure):
22
+ _fields_ = [
23
+ ("size", wintypes.DWORD),
24
+ ("data", ctypes.POINTER(ctypes.c_byte)),
25
+ ]
26
+
27
+
28
+ def _windows_crypt(data: bytes, *, decrypt: bool) -> bytes:
29
+ source_buffer = ctypes.create_string_buffer(data)
30
+ source = _DataBlob(len(data), ctypes.cast(source_buffer, ctypes.POINTER(ctypes.c_byte)))
31
+ result = _DataBlob()
32
+ crypt32 = ctypes.windll.crypt32
33
+ operation = crypt32.CryptUnprotectData if decrypt else crypt32.CryptProtectData
34
+ operation.argtypes = (
35
+ ctypes.POINTER(_DataBlob),
36
+ ctypes.c_void_p if decrypt else wintypes.LPCWSTR,
37
+ ctypes.POINTER(_DataBlob),
38
+ ctypes.c_void_p,
39
+ ctypes.c_void_p,
40
+ wintypes.DWORD,
41
+ ctypes.POINTER(_DataBlob),
42
+ )
43
+ operation.restype = wintypes.BOOL
44
+ if not operation(ctypes.byref(source), None, None, None, None, 1, ctypes.byref(result)):
45
+ raise ctypes.WinError()
46
+ try:
47
+ return ctypes.string_at(result.data, result.size)
48
+ finally:
49
+ ctypes.windll.kernel32.LocalFree(ctypes.cast(result.data, ctypes.c_void_p))
50
+
51
+
52
+ class CredentialStore:
53
+ """Store a single robBOT key without keeping plaintext in QSettings."""
54
+
55
+ LEGACY_KEY = "bot/api_key"
56
+ PROTECTED_KEY = "bot/api_key_protected"
57
+ SERVICE = "easyROB.robBOT"
58
+ ACCOUNT = "cloud_api_key"
59
+
60
+ def __init__(self, settings) -> None:
61
+ self.settings = settings
62
+
63
+ def _check_settings_write(self) -> None:
64
+ status = getattr(self.settings, "status", lambda: QSettings.NoError)()
65
+ if status != QSettings.NoError:
66
+ raise CredentialStoreError("The API key settings could not be written.")
67
+
68
+ @staticmethod
69
+ def _keyring():
70
+ try:
71
+ import keyring
72
+ except ImportError as exc:
73
+ raise CredentialStoreError(
74
+ "Secure API key storage is unavailable on this system. Install the keyring package."
75
+ ) from exc
76
+ return keyring
77
+
78
+ def save(self, secret: str) -> None:
79
+ if not secret:
80
+ raise CredentialStoreError("The API key is empty.")
81
+ try:
82
+ if sys.platform == "win32":
83
+ protected = _windows_crypt(secret.encode("utf-8"), decrypt=False)
84
+ self.settings.setValue(self.PROTECTED_KEY, base64.b64encode(protected).decode("ascii"))
85
+ else:
86
+ self._keyring().set_password(self.SERVICE, self.ACCOUNT, secret)
87
+ self.settings.remove(self.LEGACY_KEY)
88
+ self.settings.sync()
89
+ self._check_settings_write()
90
+ except CredentialStoreError:
91
+ raise
92
+ except Exception as exc:
93
+ raise CredentialStoreError("The API key could not be saved securely.") from exc
94
+
95
+ def load(self) -> str:
96
+ protected = str(self.settings.value(self.PROTECTED_KEY, "") or "")
97
+ try:
98
+ if sys.platform == "win32":
99
+ secret = (
100
+ _windows_crypt(base64.b64decode(protected, validate=True), decrypt=True).decode("utf-8")
101
+ if protected else ""
102
+ )
103
+ else:
104
+ secret = self._keyring().get_password(self.SERVICE, self.ACCOUNT) or ""
105
+ except CredentialStoreError:
106
+ secret = ""
107
+ except Exception as exc:
108
+ raise CredentialStoreError("The saved API key could not be read securely.") from exc
109
+ if secret:
110
+ if self.settings.value(self.LEGACY_KEY, None) is not None:
111
+ self.settings.remove(self.LEGACY_KEY)
112
+ self.settings.sync()
113
+ self._check_settings_write()
114
+ return secret
115
+
116
+ legacy = str(self.settings.value(self.LEGACY_KEY, "") or "")
117
+ if not legacy:
118
+ return ""
119
+ try:
120
+ self.save(legacy)
121
+ except CredentialStoreError as exc:
122
+ self.settings.remove(self.LEGACY_KEY)
123
+ self.settings.sync()
124
+ raise CredentialStoreError(
125
+ "The old API key could not be migrated to secure storage. It is available for this session only.",
126
+ temporary_secret=legacy,
127
+ ) from exc
128
+ return legacy
129
+
130
+ def delete(self) -> None:
131
+ try:
132
+ if sys.platform != "win32":
133
+ keyring = self._keyring()
134
+ if keyring.get_password(self.SERVICE, self.ACCOUNT):
135
+ keyring.delete_password(self.SERVICE, self.ACCOUNT)
136
+ self.settings.remove(self.PROTECTED_KEY)
137
+ self.settings.remove(self.LEGACY_KEY)
138
+ self.settings.sync()
139
+ self._check_settings_write()
140
+ except CredentialStoreError:
141
+ raise
142
+ except Exception as exc:
143
+ raise CredentialStoreError("The saved API key could not be deleted.") from exc
@@ -0,0 +1,105 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ import re
5
+
6
+ __all__ = ["ParsedFailure", "infer_target_column_failure_hint", "parse_python_failure"]
7
+
8
+
9
+ _TRACEBACK_RE = re.compile(r'^File "([^"]+)", line (\d+), in (.+)$')
10
+ _EXCEPTION_RE = re.compile(r"^([A-Za-z_][A-Za-z0-9_]*(?:Error|Exception)):\s*(.+)$")
11
+
12
+
13
+ @dataclass(frozen=True, slots=True)
14
+ class ParsedFailure:
15
+ failure_type: str = ""
16
+ failure_message: str = ""
17
+ failure_location: str = ""
18
+ failure_function: str = ""
19
+ failure_operation: str = ""
20
+ likely_cause: str = ""
21
+
22
+
23
+ def _likely_cause(failure_type: str, failure_message: str, failure_operation: str) -> str:
24
+ lowered_message = failure_message.lower()
25
+ lowered_operation = failure_operation.lower()
26
+ if failure_type == "TypeError" and "not supported for the input types" in lowered_message:
27
+ if "linregress" in lowered_operation:
28
+ return "one or both inputs to the regression step are not numeric or have incompatible dtypes"
29
+ return "the operation received values with incompatible Python or NumPy types"
30
+ return ""
31
+
32
+
33
+ def infer_target_column_failure_hint(
34
+ target_column: str,
35
+ prediction_type: str,
36
+ failure_type: str,
37
+ failure_operation: str,
38
+ likely_cause: str,
39
+ ) -> str:
40
+ target = str(target_column or "").strip()
41
+ prediction = str(prediction_type or "").strip().lower()
42
+ operation = str(failure_operation or "").lower()
43
+ cause = str(likely_cause or "").lower()
44
+ if not target:
45
+ return ""
46
+ if failure_type != "TypeError":
47
+ return ""
48
+ if "linregress" not in operation:
49
+ return ""
50
+ if "not numeric" not in cause and "incompatible dtypes" not in cause:
51
+ return ""
52
+
53
+ target_lower = target.lower()
54
+ if target_lower == "smiles" or "smiles" in target_lower:
55
+ return (
56
+ f"The selected target column is `{target}`, which is text structure data rather than a numeric response. "
57
+ f"For {prediction or 'this'} modelling, the target should be the property you want to predict, not the SMILES column."
58
+ )
59
+ if target_lower in {"code_name", "name"} or "name" in target_lower:
60
+ return (
61
+ f"The selected target column is `{target}`, which looks like an identifier/text column rather than a numeric response. "
62
+ f"For {prediction or 'this'} modelling, the target should be the property you want to predict."
63
+ )
64
+ return ""
65
+
66
+
67
+ def parse_python_failure(console_text: str) -> ParsedFailure:
68
+ lines = [line.strip() for line in str(console_text or "").splitlines() if line.strip()]
69
+ if not lines:
70
+ return ParsedFailure()
71
+
72
+ failure_type = ""
73
+ failure_message = ""
74
+ failure_location = ""
75
+ failure_function = ""
76
+ failure_operation = ""
77
+
78
+ for line in reversed(lines):
79
+ exception_match = _EXCEPTION_RE.match(line)
80
+ if exception_match:
81
+ failure_type = exception_match.group(1).strip()
82
+ failure_message = exception_match.group(2).strip()
83
+ break
84
+
85
+ for index, line in enumerate(lines):
86
+ traceback_match = _TRACEBACK_RE.match(line)
87
+ if traceback_match:
88
+ file_name = traceback_match.group(1).strip()
89
+ line_number = traceback_match.group(2).strip()
90
+ function_name = traceback_match.group(3).strip()
91
+ failure_location = f"{file_name}:{line_number}"
92
+ failure_function = function_name
93
+ if index + 1 < len(lines):
94
+ next_line = lines[index + 1].strip()
95
+ if next_line and not next_line.startswith("^") and not next_line.startswith('File "'):
96
+ failure_operation = next_line
97
+
98
+ return ParsedFailure(
99
+ failure_type=failure_type,
100
+ failure_message=failure_message,
101
+ failure_location=failure_location,
102
+ failure_function=failure_function,
103
+ failure_operation=failure_operation,
104
+ likely_cause=_likely_cause(failure_type, failure_message, failure_operation),
105
+ )
@@ -0,0 +1,164 @@
1
+ """Deterministic evidence routing and privacy-safe search query policy."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from enum import Enum
7
+ import re
8
+ import unicodedata
9
+ from typing import Sequence
10
+
11
+ from .bot_rag import SearchResult, normalize_terms
12
+ from .prompt_policy import anonymize_paths, redact_sensitive_text
13
+ from .question_intent import is_explicit_web_request, requires_fresh_information
14
+
15
+ __all__ = [
16
+ "EvidenceAssessment",
17
+ "EvidenceDecision",
18
+ "assess_evidence",
19
+ "sanitize_search_query",
20
+ ]
21
+
22
+
23
+ STRONG_LOCAL_SCORE = 4.0
24
+ STRONG_LOCAL_COVERAGE = 0.6
25
+ MAX_SEARCH_QUERY_CHARS = 500
26
+
27
+
28
+ def official_documentation_domains(question: str) -> tuple[str, ...]:
29
+ """Select program documentation from explicit program or distinctive module names."""
30
+ domains = []
31
+ if re.search(r"\b(?:aqme|qdescp|csearch|cmin|qcorr|qprep)\b", question, re.I):
32
+ domains.append("aqme.readthedocs.io")
33
+ if re.search(r"\b(?:robert|easyrob|y[- ]shuffle|y[- ]mean)\b", question, re.I):
34
+ domains.append("robert.readthedocs.io")
35
+ return tuple(domains)
36
+
37
+
38
+ def _deep_program_question(question: str) -> bool:
39
+ folded = unicodedata.normalize("NFKD", question.casefold())
40
+ folded = "".join(char for char in folded if not unicodedata.combining(char))
41
+ if re.search(r"\b(?:popup|dialog|button|tab|displayed|boton|pestana|ventana)\b", folded):
42
+ return False
43
+ return bool(official_documentation_domains(question) and re.search(
44
+ r"\b(?:why|how does|calculat(?:e|ed|ion)|compare|difference|parameters?|defaults?|thresholds?|"
45
+ r"boltzmann|cross.validation|y[- ]shuffle|conformer|solvent|explain|criteria|read.?the.?docs|por que|como calcula|como funciona|"
46
+ r"diferencia|parametros?|umbrales?|validacion cruzada)\b", folded,
47
+ ))
48
+
49
+ _ROLE_MARKER_RE = re.compile(
50
+ r"(?i)(?:^|\s)(?:system|assistant|developer|tool|user)(?:\s*\(data\))?\s*:\s*"
51
+ )
52
+ _TEMPLATE_MARKER_RE = re.compile(
53
+ r"(?i)<\|/?(?:im_start|im_end|system|assistant|user|developer|tool)\|>|\[/?INST\]"
54
+ )
55
+ _URL_RE = re.compile(r"(?i)\b(?:https?|ftp)://[^\s]+")
56
+ _WINDOWS_PATH_RE = re.compile(r"(?i)(?:[A-Z]:[\\/]|\\\\)[^\s,;]+")
57
+ _POSIX_FILE_PATH_RE = re.compile(r"(?<!\w)/(?:[^\s/]+/)+[^\s,;]+")
58
+ _REDACTION_RE = re.compile(r"(?i)\[(?:redacted|path|home)\]|<path>(?:[/\\][^\s]+)?")
59
+ _SPACE_RE = re.compile(r"\s+")
60
+ _FOUNDATIONAL_RE = re.compile(
61
+ r"(?i)\b(?:what is|what are|explain|difference between|how does)\b.*\b(?:"
62
+ r"machine learning|random forest|neural network|regression|classification|"
63
+ r"cross validation|descriptor|molecule|chemistry|reaction|catalyst|overfitting|"
64
+ r"feature importance|principal component|clustering|software testing|unit test|"
65
+ r"integration test|one[- ]?shot|zero[- ]?shot|few[- ]?shot|coding|programming|"
66
+ r"algorithm|data structure)\b"
67
+ )
68
+
69
+
70
+ class EvidenceDecision(str, Enum):
71
+ """Select the least expensive evidence path that can answer safely."""
72
+
73
+ LOCAL_ENOUGH = "local_enough"
74
+ GENERAL_ENOUGH = "general_enough"
75
+ WEB_OPTIONAL = "web_optional"
76
+ WEB_REQUIRED = "web_required"
77
+ INSUFFICIENT = "insufficient"
78
+
79
+
80
+ @dataclass(frozen=True, slots=True)
81
+ class EvidenceAssessment:
82
+ decision: EvidenceDecision
83
+ reason: str
84
+ query_coverage: float = 0.0
85
+ top_score: float = 0.0
86
+
87
+
88
+ def _coverage(results: Sequence[SearchResult], question: str) -> float:
89
+ if not results:
90
+ return 0.0
91
+ first = results[0]
92
+ query_terms = set(first.query_terms or normalize_terms(question))
93
+ if not query_terms:
94
+ return 0.0
95
+ return min(1.0, len(set(first.matched_terms) & query_terms) / len(query_terms))
96
+
97
+
98
+ def assess_evidence(
99
+ question: object,
100
+ results: Sequence[SearchResult],
101
+ *,
102
+ intent: str = "tutorial",
103
+ ) -> EvidenceAssessment:
104
+ """Classify evidence sufficiency without making a paid model request."""
105
+ if type(question) is not str or not normalize_terms(question):
106
+ return EvidenceAssessment(EvidenceDecision.INSUFFICIENT, "empty_or_unsafe_question")
107
+ if _TEMPLATE_MARKER_RE.search(question):
108
+ return EvidenceAssessment(EvidenceDecision.INSUFFICIENT, "prompt_protocol_marker")
109
+ if is_explicit_web_request(question) or requires_fresh_information(question):
110
+ return EvidenceAssessment(EvidenceDecision.WEB_REQUIRED, "current_or_explicit_web")
111
+ if _deep_program_question(question):
112
+ return EvidenceAssessment(EvidenceDecision.WEB_REQUIRED, "advanced_official_documentation")
113
+
114
+ ordered = sorted(results, key=lambda item: item.score, reverse=True)
115
+ top_score = ordered[0].score if ordered else 0.0
116
+ coverage = _coverage(ordered, question)
117
+ if top_score >= STRONG_LOCAL_SCORE and coverage >= STRONG_LOCAL_COVERAGE:
118
+ return EvidenceAssessment(
119
+ EvidenceDecision.LOCAL_ENOUGH,
120
+ "strong_local_evidence",
121
+ query_coverage=coverage,
122
+ top_score=top_score,
123
+ )
124
+ if _FOUNDATIONAL_RE.search(question):
125
+ return EvidenceAssessment(
126
+ EvidenceDecision.GENERAL_ENOUGH,
127
+ "stable_foundational_question",
128
+ query_coverage=coverage,
129
+ top_score=top_score,
130
+ )
131
+ return EvidenceAssessment(
132
+ EvidenceDecision.WEB_OPTIONAL,
133
+ f"borderline_{str(intent or 'unknown').strip().lower()}",
134
+ query_coverage=coverage,
135
+ top_score=top_score,
136
+ )
137
+
138
+
139
+ def sanitize_search_query(
140
+ question: object,
141
+ secret_values: Sequence[str] = (),
142
+ ) -> str:
143
+ """Return a bounded query with private and prompt-control data removed."""
144
+ if type(question) is not str:
145
+ return ""
146
+ value = redact_sensitive_text(question, secret_values)
147
+ value = _URL_RE.sub(" ", value)
148
+ value = _WINDOWS_PATH_RE.sub(" ", value)
149
+ value = _POSIX_FILE_PATH_RE.sub(" ", value)
150
+ value = anonymize_paths(value)
151
+ value = _TEMPLATE_MARKER_RE.sub(" ", value)
152
+ value = _ROLE_MARKER_RE.sub(" ", value)
153
+ value = _REDACTION_RE.sub(" ", value)
154
+ value = _SPACE_RE.sub(" ", value).strip(" \t\r\n,;:-")
155
+ if not normalize_terms(value):
156
+ return ""
157
+ domains = official_documentation_domains(value)
158
+ if domains:
159
+ scope = " OR ".join(f"site:{domain}" for domain in domains)
160
+ value = f"({scope}) {value}"
161
+ if len(value) <= MAX_SEARCH_QUERY_CHARS:
162
+ return value
163
+ bounded = value[:MAX_SEARCH_QUERY_CHARS].rsplit(" ", 1)[0].strip()
164
+ return bounded or value[:MAX_SEARCH_QUERY_CHARS]