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,152 @@
1
+ """Checks for request-local inspection of selected user CSV files."""
2
+
3
+ from gui_easyrob.bot.input_csv_audit import inspect_selected_csvs
4
+ from gui_easyrob.bot.bot_context import GuiSnapshot
5
+ from gui_easyrob.bot.bot_engine import BotEngine
6
+ from gui_easyrob.bot.bot_rag import KnowledgeBase
7
+ from gui_easyrob.bot.llm_providers import ProviderAnswer, TokenUsage, build_llm_prompts
8
+ from types import SimpleNamespace
9
+
10
+
11
+ def test_selected_main_csv_reports_concrete_data_problems(tmp_path):
12
+ main = tmp_path / "input.csv"
13
+ main.write_text(
14
+ "SMILES,code_name,target,charge,empty\n"
15
+ "CCO,a,1,0.1,\n"
16
+ "CCO,a,2,invalid,\n"
17
+ "CCC,c,,0.3,\n",
18
+ encoding="utf-8",
19
+ )
20
+
21
+ insights = inspect_selected_csvs(
22
+ str(main), target_column="target", name_column="code_name", prediction_type="regression"
23
+ )
24
+
25
+ assert len(insights) == 1
26
+ summary = insights[0].summary
27
+ assert insights[0].source == "input.csv"
28
+ assert "3 rows scanned" in summary
29
+ assert "1 missing target value" in summary
30
+ assert "1 nonnumeric value in descriptor charge" in summary
31
+ assert "1 repeated exact SMILES" in summary
32
+ assert "1 repeated code_name" in summary
33
+ assert "empty: 3/3 missing" in summary
34
+
35
+
36
+ def test_external_csv_can_lack_target_but_missing_features_are_reported(tmp_path):
37
+ main = tmp_path / "train.csv"
38
+ external = tmp_path / "new.csv"
39
+ main.write_text("SMILES,code_name,target,charge,dipole\nCCO,a,1,0.1,2\n", encoding="utf-8")
40
+ external.write_text("SMILES,code_name,charge\nCCC,b,0.2\n", encoding="utf-8")
41
+
42
+ insights = inspect_selected_csvs(
43
+ str(main), str(external), target_column="target", name_column="code_name",
44
+ prediction_type="regression",
45
+ )
46
+
47
+ assert "observed target column absent" in insights[1].summary
48
+ assert "missing descriptor column: dipole" in insights[1].summary
49
+ assert "target column missing" not in insights[1].summary
50
+
51
+
52
+ def test_malformed_rows_and_duplicate_headers_are_bounded_findings(tmp_path):
53
+ main = tmp_path / "broken.csv"
54
+ main.write_text("code_name,target,target\na,1,2\nb,3\n", encoding="utf-8")
55
+
56
+ insight = inspect_selected_csvs(str(main), target_column="target")[0]
57
+
58
+ assert "duplicate header: target" in insight.summary
59
+ assert "1 row with a different column count" in insight.summary
60
+
61
+
62
+ def test_csv_scan_limit_is_explicit(tmp_path, monkeypatch):
63
+ from gui_easyrob.bot import input_csv_audit
64
+
65
+ monkeypatch.setattr(input_csv_audit, "_MAX_SCAN_ROWS", 2)
66
+ main = tmp_path / "long.csv"
67
+ main.write_text("target,desc\n1,1\n2,2\n3,3\n", encoding="utf-8")
68
+
69
+ insight = inspect_selected_csvs(str(main), target_column="target")[0]
70
+
71
+ assert "2 rows scanned" in insight.summary
72
+ assert "scan limited to first 2 rows" in insight.summary
73
+
74
+
75
+ def test_unreadable_external_csv_does_not_generate_schema_claims(tmp_path):
76
+ main = tmp_path / "train.csv"
77
+ main.write_text("code_name,target,charge\na,1,0.1\n", encoding="utf-8")
78
+
79
+ insights = inspect_selected_csvs(str(main), str(tmp_path / "missing.csv"), target_column="target")
80
+
81
+ assert "not readable" in insights[1].summary
82
+ assert "missing descriptor column" not in insights[1].summary
83
+
84
+
85
+ def test_semicolon_csv_and_empty_csv_have_explicit_profiles(tmp_path):
86
+ semicolon = tmp_path / "semicolon.csv"
87
+ empty = tmp_path / "empty.csv"
88
+ semicolon.write_text("code_name;target;charge\na;1;0.1\n", encoding="utf-8")
89
+ empty.write_text("", encoding="utf-8")
90
+
91
+ assert "1 rows scanned, 3 columns" in inspect_selected_csvs(str(semicolon), target_column="target")[0].summary
92
+ assert "is empty" in inspect_selected_csvs(str(empty))[0].summary
93
+
94
+
95
+ def _gui_snapshot(csv_path):
96
+ return GuiSnapshot(
97
+ "Input", "Full Workflow", str(csv_path), "", "target", "regression",
98
+ False, True, False, "", [], name_column="code_name",
99
+ )
100
+
101
+
102
+ def test_heuristic_bot_inspects_selected_csv_before_workflow(tmp_path):
103
+ main = tmp_path / "input.csv"
104
+ main.write_text("code_name,target,charge\na,1,0.1\nb,,invalid\n", encoding="utf-8")
105
+ engine = BotEngine(knowledge_base=KnowledgeBase([]))
106
+
107
+ answer = engine.answer("¿Qué problemas hay en mi CSV?", _gui_snapshot(main), "Heuristic", "", "")
108
+
109
+ assert "1 missing target value" in answer
110
+ assert "1 nonnumeric value in descriptor charge" in answer
111
+ assert "input.csv" in answer
112
+ assert "Workflow result" not in answer
113
+
114
+
115
+ def test_cloud_bot_receives_selected_csv_facts_without_workflow(tmp_path):
116
+ class RecordingProvider:
117
+ spec = SimpleNamespace(supports_web_search=True)
118
+
119
+ def __init__(self):
120
+ self.calls = []
121
+
122
+ def generate_answer_with_usage(self, **kwargs):
123
+ self.calls.append(kwargs)
124
+ return ProviderAnswer("The selected CSV has a missing target value.", TokenUsage())
125
+
126
+ main = tmp_path / "input.csv"
127
+ main.write_text("code_name,target,charge\na,1,0.1\nb,,0.2\n", encoding="utf-8")
128
+ provider = RecordingProvider()
129
+ engine = BotEngine(knowledge_base=KnowledgeBase([]), provider_registry={"Test": provider})
130
+
131
+ engine.answer_with_metadata("Analiza mi CSV antes de entrenar", _gui_snapshot(main), "Cloud AI", "Test", "test-key")
132
+
133
+ assert len(provider.calls) == 1
134
+ call = provider.calls[0]
135
+ assert call["question_intent"] == "results"
136
+ assert call["gui_context"].workflow_results.kind == "INPUT CSV"
137
+ system_prompt, user_prompt = build_llm_prompts(
138
+ "Analiza mi CSV antes de entrenar", call["gui_context"], [], question_intent="results"
139
+ )
140
+ assert "1 missing target value" in user_prompt
141
+ assert "before a workflow run" in system_prompt
142
+
143
+
144
+ def test_generic_question_does_not_expose_selected_csv(tmp_path):
145
+ main = tmp_path / "input.csv"
146
+ main.write_text("code_name,target\na,\n", encoding="utf-8")
147
+ engine = BotEngine(knowledge_base=KnowledgeBase([]))
148
+
149
+ answer = engine.answer("What is RMSE?", _gui_snapshot(main), "Heuristic", "", "")
150
+
151
+ assert "missing target" not in answer
152
+ assert "input.csv" not in answer
@@ -0,0 +1,383 @@
1
+ """Regression tests for routing user-specific model questions."""
2
+
3
+ from dataclasses import replace
4
+ from types import SimpleNamespace
5
+
6
+ import pytest
7
+
8
+ from gui_easyrob.bot.answer_metadata import EvidenceOrigin, WebSearchMode
9
+ from gui_easyrob.bot.bot_context import GuiSnapshot
10
+ from gui_easyrob.bot.bot_engine import BotEngine
11
+ from gui_easyrob.bot.bot_rag import KnowledgeBase
12
+ from gui_easyrob.bot.llm_providers import ProviderAnswer, build_llm_prompts, build_provider_registry
13
+ from gui_easyrob.bot.question_intent import (
14
+ classify_question_intent,
15
+ is_follow_up_question,
16
+ is_generic_question,
17
+ select_inference_history,
18
+ )
19
+ from gui_easyrob.bot.token_usage import TokenUsage
20
+ from gui_easyrob.bot.workflow_results import (
21
+ WorkflowReportAssessment,
22
+ WorkflowResultSnapshot,
23
+ render_workflow_answer,
24
+ )
25
+
26
+
27
+ @pytest.mark.parametrize(
28
+ "question",
29
+ (
30
+ "¿Cuál de mis modelos es mejor?",
31
+ "¿Cuál es el mejor modelo de mis resultados?",
32
+ "¿Puedo confiar en este modelo?",
33
+ "Which of my models is best?",
34
+ ),
35
+ )
36
+ def test_personal_model_questions_use_results_context(question):
37
+ assert classify_question_intent(question) == "results"
38
+ assert not is_generic_question(question)
39
+
40
+
41
+ def test_general_model_definition_does_not_use_current_results():
42
+ assert is_generic_question("What is a machine learning model?")
43
+
44
+
45
+ def test_generic_metric_definition_omits_current_workflow_evidence():
46
+ question = "What is RMSE?"
47
+ assert is_generic_question(question)
48
+
49
+ system_prompt, user_prompt = build_llm_prompts(
50
+ question, _result_snapshot(), (), question_intent="results",
51
+ )
52
+
53
+ assert "<WORKFLOW_RESULTS_DATA>" not in user_prompt
54
+ assert "only from supplied workflow evidence" not in system_prompt
55
+
56
+
57
+ @pytest.mark.parametrize("question", ("What was the test R2?", "¿Cuál fue el RMSE del test?"))
58
+ def test_past_run_metric_question_uses_current_results(question):
59
+ assert not is_generic_question(question)
60
+
61
+
62
+ def test_personal_model_question_includes_current_workflow_evidence():
63
+ _, user_prompt = build_llm_prompts(
64
+ "¿Cuál de mis modelos es mejor?", _result_snapshot(), (), question_intent="results",
65
+ )
66
+
67
+ assert "RMSE=4.2" in user_prompt
68
+
69
+
70
+ @pytest.mark.parametrize(
71
+ "question",
72
+ ("¿Qué es un modelo de ML?", "¿Cómo entreno un modelo en EasyROB?"),
73
+ )
74
+ def test_general_spanish_model_questions_are_not_result_questions(question):
75
+ assert classify_question_intent(question) == "tutorial"
76
+
77
+
78
+ def test_spanish_explanation_request_is_a_follow_up():
79
+ assert is_follow_up_question("¿Puedes explicarlo más?")
80
+
81
+
82
+ def test_long_demonstrative_question_is_a_follow_up():
83
+ assert is_follow_up_question("Why does that matter for my model?")
84
+
85
+
86
+ def test_follow_up_chain_retains_original_question_for_retrieval():
87
+ history = [
88
+ {"role": "user", "content": "What does VERIFY check in ROBERT?"},
89
+ {"role": "assistant", "content": "VERIFY checks predictive ability."},
90
+ {"role": "user", "content": "Why is that important?"},
91
+ {"role": "assistant", "content": "It gives validation evidence."},
92
+ {"role": "user", "content": "Can you explain it further?"},
93
+ {"role": "assistant", "content": "It checks whether performance is robust."},
94
+ ]
95
+
96
+ selected = select_inference_history("And what should I check next?", history)
97
+
98
+ assert selected[0]["content"] == "What does VERIFY check in ROBERT?"
99
+
100
+
101
+ def test_follow_up_does_not_cross_an_ineligible_exchange():
102
+ history = [
103
+ {"role": "user", "content": "What does VERIFY check in ROBERT?"},
104
+ {"role": "assistant", "content": "VERIFY checks predictive ability."},
105
+ {"role": "user", "content": "What is the RMSE of my model?"},
106
+ {"role": "assistant", "content": "No result is available.", "memory_eligible": False},
107
+ ]
108
+
109
+ assert select_inference_history("Why is that important?", history) == ()
110
+
111
+
112
+ @pytest.mark.parametrize(
113
+ "question",
114
+ ("And what does CSEARCH do in AQME?", "¿Y qué hace CSEARCH en AQME?"),
115
+ )
116
+ def test_explicit_new_subject_does_not_inherit_previous_module(question):
117
+ history = [
118
+ {"role": "user", "content": "What does VERIFY check in ROBERT?"},
119
+ {"role": "assistant", "content": "VERIFY checks predictive ability."},
120
+ ]
121
+
122
+ assert not is_follow_up_question(question)
123
+ assert select_inference_history(question, history) == ()
124
+
125
+
126
+ @pytest.mark.parametrize("question", ("Why is that important?", "¿Y por qué importa?"))
127
+ def test_verify_explanation_follow_up_answers_the_module(question):
128
+ history = [
129
+ {"role": "user", "content": "What does VERIFY check in ROBERT?"},
130
+ {"role": "assistant", "content": "VERIFY checks predictive ability."},
131
+ ]
132
+ snapshot = GuiSnapshot(
133
+ "ROBERT", "Full Workflow", "example.csv", "", "yield", "regression",
134
+ False, True, False, "", [],
135
+ )
136
+
137
+ answer = BotEngine().answer(
138
+ question, snapshot, "Heuristic", "Test", "", conversation_history=history,
139
+ )
140
+
141
+ assert "VERIFY" in answer
142
+ assert "robustness" in answer
143
+
144
+
145
+ def test_spanish_verify_chain_does_not_answer_about_the_target_column():
146
+ history = [
147
+ {"role": "user", "content": "¿Qué comprueba VERIFY en ROBERT?"},
148
+ {"role": "assistant", "content": "VERIFY comprueba la capacidad predictiva."},
149
+ {"role": "user", "content": "¿Y por qué importa?"},
150
+ {"role": "assistant", "content": "Aporta evidencia de validación."},
151
+ {"role": "user", "content": "¿Puedes explicarlo más?"},
152
+ {"role": "assistant", "content": "Revisa si el rendimiento es robusto."},
153
+ ]
154
+ snapshot = GuiSnapshot(
155
+ "ROBERT", "Full Workflow", "example.csv", "", "yield", "regression",
156
+ False, True, False, "", [],
157
+ )
158
+
159
+ answer = BotEngine().answer(
160
+ "¿Y qué reviso después?", snapshot, "Heuristic", "Test", "",
161
+ conversation_history=history,
162
+ )
163
+
164
+ assert "VERIFY" in answer
165
+ assert "target" not in answer.lower()
166
+
167
+
168
+ def test_error_follow_up_keeps_diagnostic_intent():
169
+ history = (
170
+ {"role": "user", "content": "What does VERIFY check in ROBERT?"},
171
+ {"role": "assistant", "content": "VERIFY checks predictive ability."},
172
+ )
173
+
174
+ assert classify_question_intent("Why is that error important?", history) == "diagnostic"
175
+
176
+
177
+ class _RecordingProvider:
178
+ spec = SimpleNamespace(supports_web_search=True)
179
+
180
+ def __init__(self):
181
+ self.search_modes = []
182
+
183
+ def generate_answer_with_usage(self, **kwargs):
184
+ self.search_modes.append(kwargs["web_search_mode"])
185
+ return ProviderAnswer("The recorded metric needs context.", TokenUsage())
186
+
187
+
188
+ def _result_snapshot():
189
+ workflow = WorkflowResultSnapshot(
190
+ kind="ROBERT",
191
+ status="completed",
192
+ root_name="example",
193
+ summary_available=True,
194
+ metrics=(("RMSE", "4.2", "Test", "PREDICT/PREDICT_data.dat"),),
195
+ )
196
+ return GuiSnapshot(
197
+ "Results", "Full Workflow", "example.csv", "", "yield", "regression",
198
+ False, True, False, "", [], workflow_results=workflow,
199
+ )
200
+
201
+
202
+ @pytest.mark.parametrize(
203
+ ("question", "context"),
204
+ (
205
+ ("what is PFI", "general"),
206
+ ("¿Qué es PFI?", "general"),
207
+ ("What's the difference between PFI and No PFI?", "general"),
208
+ ("What does AQME do?", "general"),
209
+ ("What does VERIFY do in ROBERT?", "general"),
210
+ ("How many descriptors does AQME generate?", "general"),
211
+ ("How do I interpret SHAP?", "general"),
212
+ ("Can you explain overfitting?", "general"),
213
+ ("What does the Run AQME button do?", "gui"),
214
+ ("Why is the Predictions tab disabled?", "gui"),
215
+ ("¿Qué significa esta advertencia?", "gui"),
216
+ ("How do I run this workflow?", "gui"),
217
+ ("What was the test RMSE in my run?", "results"),
218
+ ("What is the test RMSE?", "results"),
219
+ ("Did VERIFY pass?", "results"),
220
+ ("How many descriptors did AQME generate?", "results"),
221
+ ("What warnings are in my report?", "results"),
222
+ ("Summarize my results", "results"),
223
+ ),
224
+ )
225
+ def test_groq_routes_questions_with_a_report_loaded(question, context):
226
+ payloads = []
227
+
228
+ def transport(method, url, **kwargs):
229
+ payloads.append(kwargs["json"])
230
+ return SimpleNamespace(status_code=200, json=lambda: {
231
+ "choices": [{"message": {"content": "Here is the explanation."}}],
232
+ })
233
+
234
+ snapshot = replace(
235
+ _result_snapshot(),
236
+ result_model="Best models",
237
+ result_models=("RF",),
238
+ result_selected_variants=(("No_PFI", "RF"),),
239
+ result_root_reports=("ROBERT_report_No_PFI.pdf",),
240
+ disabled_tabs=("Predictions",),
241
+ popup_active=True,
242
+ popup_text="Select a target column before running.",
243
+ )
244
+ provider = build_provider_registry(transport)["Groq"]
245
+ engine = BotEngine(knowledge_base=KnowledgeBase([]), provider_registry={"Groq": provider})
246
+ answer = engine.answer_with_metadata(
247
+ question, snapshot, "Cloud AI", "Groq", "test-key", web_search_enabled=False,
248
+ )
249
+
250
+ assert payloads, answer.text
251
+ system_prompt, user_prompt = (message["content"] for message in payloads[0]["messages"])
252
+ assert ("<WORKFLOW_RESULTS_DATA>" in user_prompt) == (context == "results")
253
+ if context == "general":
254
+ assert "<GUI_STATE_DATA>" not in user_prompt
255
+ assert "only from supplied workflow evidence" not in system_prompt
256
+ if context == "gui":
257
+ assert "Disabled tabs: Predictions" in user_prompt
258
+ if "advertencia" in question:
259
+ assert "Select a target column before running." in user_prompt
260
+ if "test RMSE" in question:
261
+ assert "RMSE=4.2" in user_prompt
262
+
263
+
264
+ def test_pfi_definition_in_heuristic_mode_with_only_no_pfi_selected():
265
+ snapshot = replace(
266
+ _result_snapshot(), result_models=("RF",),
267
+ result_selected_variants=(("No_PFI", "RF"),),
268
+ )
269
+
270
+ answer = BotEngine().answer("what is PFI", snapshot, "Heuristic", "", "")
271
+
272
+ assert "permutation feature importance" in answer.lower()
273
+ assert "current Results selection" not in answer
274
+
275
+
276
+ def test_general_follow_up_keeps_the_conversation_without_loading_results():
277
+ question = "Why does that matter?"
278
+ history = [
279
+ {"role": "user", "content": "What is PFI?"},
280
+ {"role": "assistant", "content": "PFI measures the effect of shuffling a feature."},
281
+ ]
282
+
283
+ _, user_prompt = build_llm_prompts(
284
+ question, _result_snapshot(), (), conversation_history=history, question_intent="parameter",
285
+ )
286
+
287
+ assert "history-user: What is PFI?" in user_prompt
288
+ assert "<GUI_STATE_DATA>" not in user_prompt
289
+ assert "<WORKFLOW_RESULTS_DATA>" not in user_prompt
290
+
291
+
292
+ def test_local_model_result_question_does_not_trigger_optional_web_search():
293
+ provider = _RecordingProvider()
294
+ engine = BotEngine(knowledge_base=KnowledgeBase([]), provider_registry={"Test": provider})
295
+
296
+ result = engine.answer_with_metadata(
297
+ "¿Cuál de mis modelos es mejor?", _result_snapshot(), "Cloud AI", "Test", "test-key",
298
+ )
299
+
300
+ assert provider.search_modes == [WebSearchMode.OFF]
301
+ assert result.metadata.evidence_origin == EvidenceOrigin.LOCAL_SYSTEM
302
+
303
+
304
+ def test_generic_metric_definition_is_not_labeled_as_local_result():
305
+ provider = _RecordingProvider()
306
+ engine = BotEngine(knowledge_base=KnowledgeBase([]), provider_registry={"Test": provider})
307
+
308
+ result = engine.answer_with_metadata(
309
+ "What is RMSE?", _result_snapshot(), "Cloud AI", "Test", "test-key",
310
+ )
311
+
312
+ assert provider.search_modes == [WebSearchMode.AUTO]
313
+ assert result.metadata.evidence_origin == EvidenceOrigin.GENERAL_KNOWLEDGE
314
+
315
+
316
+ def test_explicit_web_request_keeps_web_search_for_model_question():
317
+ provider = _RecordingProvider()
318
+ engine = BotEngine(knowledge_base=KnowledgeBase([]), provider_registry={"Test": provider})
319
+
320
+ engine.answer_with_metadata(
321
+ "Busca en internet si este modelo es fiable", _result_snapshot(),
322
+ "Cloud AI", "Test", "test-key",
323
+ )
324
+
325
+ assert provider.search_modes == [WebSearchMode.REQUIRED]
326
+
327
+
328
+ @pytest.mark.parametrize("question", ("Can I trust this model?", "¿Puedo confiar en este modelo?"))
329
+ def test_model_trust_question_explains_limits_of_recorded_scores(question):
330
+ workflow = WorkflowResultSnapshot(
331
+ kind="ROBERT",
332
+ status="completed",
333
+ root_name="example",
334
+ summary_available=True,
335
+ report_assessments=(WorkflowReportAssessment(
336
+ variant="PFI", model="RF", prediction_type="regression",
337
+ interpolation_score=7, boundary_score=5,
338
+ ),),
339
+ )
340
+
341
+ answer = render_workflow_answer(workflow, question)
342
+
343
+ assert "Prediction suitability" in answer
344
+ assert "acceptable for your use" in answer
345
+
346
+
347
+ def test_metric_followups_keep_the_original_topic_and_answer_the_new_question():
348
+ engine = BotEngine()
349
+ snapshot = GuiSnapshot(
350
+ "ROBERT", "Full Workflow", "example.csv", "", "yield", "regression",
351
+ False, True, False, "", [],
352
+ )
353
+ first_question = "What does RMSE mean?"
354
+ first_answer = engine.answer(first_question, snapshot, "Heuristic", "Test", "")
355
+ history = [
356
+ {"role": "user", "content": first_question},
357
+ {"role": "assistant", "content": first_answer},
358
+ ]
359
+
360
+ second_question = "Is a lower value always better?"
361
+ second_answer = engine.answer(
362
+ second_question, snapshot, "Heuristic", "Test", "", conversation_history=history,
363
+ )
364
+ assert "RMSE" in second_answer
365
+ assert "lower" in second_answer.lower()
366
+ assert "same target" in second_answer.lower()
367
+ assert "QCORR" not in second_answer
368
+
369
+ history.extend((
370
+ {"role": "user", "content": second_question},
371
+ {"role": "assistant", "content": second_answer},
372
+ ))
373
+ example_answer = engine.answer(
374
+ "Explain it with a short example.", snapshot, "Heuristic", "Test", "",
375
+ conversation_history=history,
376
+ )
377
+ assert "RMSE" in example_answer
378
+ assert "5" in example_answer
379
+ assert "percentage points" in example_answer
380
+
381
+
382
+ def test_named_metric_comparison_does_not_inherit_an_unrelated_topic():
383
+ assert not is_follow_up_question("Is a lower RMSE value always better?")