text2sql-eval-toolkit 1.0.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 (28) hide show
  1. text2sql_eval_toolkit/__init__.py +107 -0
  2. text2sql_eval_toolkit/analysis/__init__.py +5 -0
  3. text2sql_eval_toolkit/analysis/error_analysis.py +335 -0
  4. text2sql_eval_toolkit/analysis/report_tools.py +719 -0
  5. text2sql_eval_toolkit/config_args.py +65 -0
  6. text2sql_eval_toolkit/data/__init__.py +4 -0
  7. text2sql_eval_toolkit/data/benchmarks.json +69 -0
  8. text2sql_eval_toolkit/data/test-benchmarks.json +69 -0
  9. text2sql_eval_toolkit/env_loader.py +55 -0
  10. text2sql_eval_toolkit/evaluation/__init__.py +26 -0
  11. text2sql_eval_toolkit/evaluation/evaluation_tools.py +759 -0
  12. text2sql_eval_toolkit/evaluation/llm_as_judge.py +90 -0
  13. text2sql_eval_toolkit/execution/__init__.py +5 -0
  14. text2sql_eval_toolkit/execution/execution_tools.py +1448 -0
  15. text2sql_eval_toolkit/execution/replace_select_tool.py +114 -0
  16. text2sql_eval_toolkit/inference/__init__.py +5 -0
  17. text2sql_eval_toolkit/inference/agentic_pipeline.py +2335 -0
  18. text2sql_eval_toolkit/inference/base_pipeline.py +11 -0
  19. text2sql_eval_toolkit/inference/baseline_llm_pipeline.py +372 -0
  20. text2sql_eval_toolkit/inference/inference_tools.py +769 -0
  21. text2sql_eval_toolkit/logging.py +54 -0
  22. text2sql_eval_toolkit/profiling/profiling_tools.py +185 -0
  23. text2sql_eval_toolkit/utils.py +302 -0
  24. text2sql_eval_toolkit-1.0.0.dist-info/METADATA +382 -0
  25. text2sql_eval_toolkit-1.0.0.dist-info/RECORD +28 -0
  26. text2sql_eval_toolkit-1.0.0.dist-info/WHEEL +5 -0
  27. text2sql_eval_toolkit-1.0.0.dist-info/licenses/LICENSE +201 -0
  28. text2sql_eval_toolkit-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,90 @@
1
+ #
2
+ # Copyright IBM Corp. 2025 - 2026
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ #
5
+
6
+ from pathlib import Path
7
+ import yaml
8
+ from text2sql_eval_toolkit.logging import get_logger
9
+ from typing import Dict, Any, Optional
10
+ from text2sql_eval_toolkit.inference.inference_tools import WXAIClient
11
+
12
+ logger = get_logger(__name__)
13
+
14
+
15
+ def load_llm_judge_config(config_path: Optional[str] = None) -> Dict[str, Any]:
16
+ if config_path is None:
17
+ config_path = (
18
+ Path(__file__).parent / "llm_judge_config" / "llm_judge_default_config.yaml"
19
+ )
20
+ else:
21
+ config_path = Path(config_path)
22
+ if not config_path.exists():
23
+ raise FileNotFoundError(f"LLM judge config file not found: {config_path}")
24
+ with config_path.open("r", encoding="utf-8") as f:
25
+ return yaml.safe_load(f)
26
+
27
+
28
+ def evaluate_sql_prediction_with_llm(
29
+ question: str,
30
+ ground_truth_sql: str,
31
+ ground_truth_df: Any,
32
+ predicted_sql: str,
33
+ predicted_df: Any,
34
+ generation_prompt: str,
35
+ llm_judge_config: dict,
36
+ ) -> Dict[str, Any]:
37
+ # Extract model config
38
+ model_config = llm_judge_config.get("model", {})
39
+ evaluator_model = model_config.get("id", "")
40
+
41
+ # Extract all other model parameters except "id"
42
+ model_parameters = {k: v for k, v in model_config.items() if k != "id"}
43
+
44
+ # Initialize client
45
+ if evaluator_model.startswith("wxai:"):
46
+ client = WXAIClient(
47
+ model_name=evaluator_model[5:], # Strip "wxai:"
48
+ model_parameters=model_parameters,
49
+ )
50
+ else:
51
+ raise NotImplementedError(
52
+ f"Model '{evaluator_model}' is not supported. Only 'wxai:' models are currently implemented."
53
+ )
54
+
55
+ # Format prompt
56
+ prompt_template = llm_judge_config.get("prompt_template", "")
57
+ prompt = prompt_template.format(
58
+ question=question,
59
+ generation_prompt=generation_prompt,
60
+ ground_truth_sql=ground_truth_sql,
61
+ ground_truth_df=ground_truth_df,
62
+ predicted_sql=predicted_sql,
63
+ predicted_df=predicted_df,
64
+ )
65
+
66
+ verdict = "N/A"
67
+ score = 0.0
68
+ explanation = "N/A"
69
+
70
+ # Run inference
71
+ logger.debug("Running LLM-as-a-judge inference...")
72
+ response = client.model.generate(prompt)
73
+ answer = response.get("results", [{}])[0].get("generated_text", "").strip()
74
+ if not answer:
75
+ logger.error(f"LLM judge inference failed with response: {response}")
76
+ raise ValueError(f"LLM judge inference failed with response: {response}")
77
+ elif answer.lower().startswith("yes"):
78
+ verdict = "Yes"
79
+ score = 1.0
80
+ explanation = answer
81
+ elif answer.lower().startswith("no"):
82
+ verdict = "No"
83
+ score = 0.0
84
+ explanation = answer
85
+ elif answer.lower().startswith("maybe"):
86
+ verdict = "Maybe"
87
+ score = 0.5
88
+ explanation = answer
89
+
90
+ return {"verdict": verdict, "score": score, "explanation": explanation}
@@ -0,0 +1,5 @@
1
+ #
2
+ # Copyright IBM Corp. 2025 - 2026
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ #
5
+