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,65 @@
1
+ #
2
+ # Copyright IBM Corp. 2025 - 2026
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ #
5
+
6
+ import argparse
7
+ from text2sql_eval_toolkit.utils import get_available_benchmarks
8
+
9
+ DEFAULT_MODEL_NAMES = [
10
+ "wxai:meta-llama/llama-3-3-70b-instruct",
11
+ "wxai:ibm/granite-4-h-small",
12
+ "wxai:meta-llama/llama-4-maverick-17b-128e-instruct-fp8",
13
+ "wxai:openai/gpt-oss-120b",
14
+ # "vllm:Qwen/Qwen2.5-1.5B-Instruct",
15
+ # "rits:microsoft/Phi-4-reasoning",
16
+ # "anthropic:claude-opus-4-1-20250805"
17
+ ]
18
+
19
+ # Default models for agentic baselines (single model to reduce runtime)
20
+ DEFAULT_AGENTIC_MODELS = ["wxai:openai/gpt-oss-120b"]
21
+
22
+
23
+ def add_common_arguments(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
24
+ parser.add_argument(
25
+ "benchmark_id",
26
+ help="Benchmark ID. Available benchmarks: "
27
+ + ", ".join(get_available_benchmarks()),
28
+ )
29
+ parser.add_argument(
30
+ "--model_names",
31
+ nargs="+",
32
+ default=DEFAULT_MODEL_NAMES,
33
+ help=F"Optional list of model names. Defaults to {DEFAULT_MODEL_NAMES}.",
34
+ )
35
+ parser.add_argument(
36
+ "--decoding_method",
37
+ type=str,
38
+ default="greedy",
39
+ help="Decoding method (e.g., greedy, sampling). Default: greedy. "
40
+ "Note: Only supported by WatsonX legacy API; ignored by Chat APIs (WatsonX Chat, Claude, VLLM).",
41
+ )
42
+ parser.add_argument(
43
+ "--max_new_tokens",
44
+ type=int,
45
+ default=256,
46
+ help="Maximum number of new tokens to generate. Default: 256. "
47
+ "Automatically converted to 'max_tokens' for Chat APIs.",
48
+ )
49
+ parser.add_argument(
50
+ "--stop_sequences",
51
+ nargs="+",
52
+ default=[],
53
+ help="Stop sequences. Pass each one as a separate string. Default: []. "
54
+ "Note: Supported by Claude and VLLM, but not by WatsonX Chat API.",
55
+ )
56
+ parser.add_argument(
57
+ "--agentic_models",
58
+ nargs="+",
59
+ default=None,
60
+ help=f"List of models to use for agentic baselines when using --run_all_baselines or --pipeline_type agentic. "
61
+ f"Defaults to: {', '.join(DEFAULT_AGENTIC_MODELS)}. "
62
+ "If not specified, uses all models from --model_names for run_experiment.py, "
63
+ f"or DEFAULT_AGENTIC_MODELS for run_all_benchmarks.py.",
64
+ )
65
+ return parser
@@ -0,0 +1,4 @@
1
+ #
2
+ # Package data for text2sql_eval_toolkit.
3
+ #
4
+
@@ -0,0 +1,69 @@
1
+ {
2
+ "bird_mini_dev_sqlite": {
3
+ "name": "bird_mini_dev_sqlite",
4
+ "description": "BIRD-SQL Mini-Dev in SQLite https://github.com/bird-bench/mini_dev",
5
+ "data": "benchmarks/bird_mini_dev_sqlite.json",
6
+ "schema": "benchmarks/bird_mini_dev_sqlite-schema.json",
7
+ "predictions": "results/bird_mini_dev_sqlite-predictions.json",
8
+ "db_engine": {
9
+ "db_type": "sqlite",
10
+ "db_folder": "benchmarks/dbs/bird/dev_databases"
11
+ }
12
+ },
13
+ "bird_mini_dev_postgres": {
14
+ "name": "bird_mini_dev_postgres",
15
+ "description": "BIRD-SQL Mini-Dev in PostgreSQL https://github.com/bird-bench/mini_dev",
16
+ "data": "benchmarks/bird_mini_dev_postgres.json",
17
+ "schema": "benchmarks/bird_mini_dev_postgres-schema.json",
18
+ "predictions": "results/bird_mini_dev_postgres-predictions.json",
19
+ "db_engine": {
20
+ "db_type": "postgres",
21
+ "schema_name": "public",
22
+ "connection_string_env_var": "POSTGRES_CONNECTION_STRING"
23
+ }
24
+ },
25
+ "beaver": {
26
+ "name": "beaver",
27
+ "description": "Beaver benchmark https://peterbaile.github.io/beaver/",
28
+ "data": "benchmarks/beaver.json",
29
+ "schema": "benchmarks/beaver-schema.json",
30
+ "predictions": "results/beaver-predictions.json",
31
+ "db_engine": {
32
+ "db_type": "mysql",
33
+ "connection_string_env_var": "MYSQL_CONNECTION_STRING"
34
+ }
35
+ },
36
+ "archer_en_dev": {
37
+ "name": "archer_en_dev",
38
+ "description": "Archer English Dev Set https://sig4kg.github.io/archer-bench/",
39
+ "data": "benchmarks/archer_en_dev.json",
40
+ "schema": "benchmarks/archer-schema.json",
41
+ "predictions": "results/archer_en_dev-predictions.json",
42
+ "db_engine": {
43
+ "db_type": "sqlite",
44
+ "db_folder": "benchmarks/dbs/archer/database"
45
+ }
46
+ },
47
+ "spider_dev": {
48
+ "name": "spider_dev",
49
+ "description": "Spider Dev Set - Full 1,034 questions https://yale-lily.github.io/spider",
50
+ "data": "benchmarks/spider-dev-converted.json",
51
+ "schema": "benchmarks/spider-dev-schema.json",
52
+ "predictions": "results/spider_dev-predictions.json",
53
+ "db_engine": {
54
+ "db_type": "sqlite",
55
+ "db_folder": "benchmarks/dbs/spider/database"
56
+ }
57
+ },
58
+ "spider_realistic": {
59
+ "name": "spider_realistic",
60
+ "description": "Spider Realistic Dataset In Structure-Grounded Pretraining for Text-to-SQL https://zenodo.org/records/5205322",
61
+ "data": "benchmarks/spider-realistic.json",
62
+ "schema": "benchmarks/spider-dev-schema.json",
63
+ "predictions": "results/spider_realistic-predictions.json",
64
+ "db_engine": {
65
+ "db_type": "sqlite",
66
+ "db_folder": "benchmarks/dbs/spider/database"
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,69 @@
1
+ {
2
+ "bird_mini_dev_sqlite_test_50": {
3
+ "name": "bird_mini_dev_sqlite_test_50",
4
+ "description": "Test sample of 50 BIRD-SQL Mini-Dev in SQLite https://github.com/bird-bench/mini_dev",
5
+ "data": "benchmarks/test_benchmarks/bird_mini_dev_sqlite_test_50.json",
6
+ "schema": "benchmarks/bird_mini_dev_sqlite-schema.json",
7
+ "predictions": "benchmarks/test_benchmarks/results/bird_mini_dev_sqlite_test_50-predictions.json",
8
+ "db_engine": {
9
+ "db_type": "sqlite",
10
+ "db_folder": "benchmarks/dbs/bird/dev_databases"
11
+ }
12
+ },
13
+ "bird_mini_dev_postgres_test_50": {
14
+ "name": "bird_mini_dev_postgres_test_50",
15
+ "description": "Test sample of 50 BIRD-SQL Mini-Dev in PostgreSQL https://github.com/bird-bench/mini_dev",
16
+ "data": "benchmarks/test_benchmarks/bird_mini_dev_postgres_test_50.json",
17
+ "schema": "benchmarks/bird_mini_dev_postgres-schema.json",
18
+ "predictions": "benchmarks/test_benchmarks/results/bird_mini_dev_postgres_test_50-predictions.json",
19
+ "db_engine": {
20
+ "db_type": "postgres",
21
+ "schema_name": "public",
22
+ "connection_string_env_var": "POSTGRES_CONNECTION_STRING"
23
+ }
24
+ },
25
+ "spider_dev_test_50": {
26
+ "name": "spider_dev_test_50",
27
+ "description": "Test sample of 50 Spider Dev questions https://yale-lily.github.io/spider",
28
+ "data": "benchmarks/test_benchmarks/spider_dev_test_50.json",
29
+ "schema": "benchmarks/spider-dev-schema.json",
30
+ "predictions": "benchmarks/test_benchmarks/results/spider_dev_test_50-predictions.json",
31
+ "db_engine": {
32
+ "db_type": "sqlite",
33
+ "db_folder": "benchmarks/dbs/spider/database"
34
+ }
35
+ },
36
+ "beaver_test_10": {
37
+ "name": "beaver_test_10",
38
+ "description": "Test sample of 10 Beaver benchmark questions https://peterbaile.github.io/beaver/",
39
+ "data": "benchmarks/test_benchmarks/beaver_test_10.json",
40
+ "schema": "benchmarks/beaver-schema.json",
41
+ "predictions": "benchmarks/test_benchmarks/results/beaver_test_10-predictions.json",
42
+ "db_engine": {
43
+ "db_type": "mysql",
44
+ "connection_string_env_var": "MYSQL_CONNECTION_STRING"
45
+ }
46
+ },
47
+ "archer_en_dev_test_10": {
48
+ "name": "archer_en_dev_test_10",
49
+ "description": "Test sample of 10 Archer English Dev questions https://sig4kg.github.io/archer-bench/",
50
+ "data": "benchmarks/test_benchmarks/archer_en_dev_test_10.json",
51
+ "schema": "benchmarks/archer-schema.json",
52
+ "predictions": "benchmarks/test_benchmarks/results/archer_en_dev_test_10-predictions.json",
53
+ "db_engine": {
54
+ "db_type": "sqlite",
55
+ "db_folder": "benchmarks/dbs/archer/database"
56
+ }
57
+ },
58
+ "bird_sqlite_test_benchmark": {
59
+ "name": "bird_sqlite_test_benchmark",
60
+ "description": "3 records from BIRD mini-dev used for testing this code base",
61
+ "data": "benchmarks/test_benchmarks/bird_sqlite_test_benchmark.json",
62
+ "schema": "benchmarks/test_benchmarks/bird_sqlite_test_benchmark-schema.json",
63
+ "predictions": "benchmarks/test_benchmarks/results/bird_sqlite_test_benchmark-predictions.json",
64
+ "db_engine": {
65
+ "db_type": "sqlite",
66
+ "db_folder": "benchmarks/test_benchmarks/db"
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,55 @@
1
+ #
2
+ # Copyright IBM Corp. 2025 - 2026
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ #
5
+
6
+ """
7
+ Environment variable loader for text2sql-eval-toolkit.
8
+
9
+ Automatically loads environment variables from .env file in project root.
10
+ """
11
+
12
+ import os
13
+ from pathlib import Path
14
+ from dotenv import load_dotenv
15
+
16
+
17
+ def load_env():
18
+ """
19
+ Load environment variables from .env file in the project root.
20
+
21
+ This function looks for .env starting from the current working directory
22
+ and searches upwards through parent directories. This allows it to work
23
+ correctly when the toolkit is used as a dependency in other projects.
24
+
25
+ Returns:
26
+ bool: True if .env file was found and loaded, False otherwise
27
+ """
28
+ # Start from current working directory and search upwards
29
+ current_dir = Path.cwd()
30
+
31
+ # Search upwards for .env file (max 10 levels)
32
+ for _ in range(10):
33
+ env_path = current_dir / ".env"
34
+ if env_path.exists():
35
+ load_dotenv(env_path, override=False) # Don't override existing env vars
36
+ return True
37
+
38
+ # Move to parent directory
39
+ parent = current_dir.parent
40
+ if parent == current_dir: # Reached root
41
+ break
42
+ current_dir = parent
43
+
44
+ # Try to load from ~/.env as fallback
45
+ home_env = Path.home() / ".env"
46
+ if home_env.exists():
47
+ load_dotenv(home_env, override=False)
48
+ return True
49
+
50
+ return False
51
+
52
+
53
+ # Auto-load on import
54
+ load_env()
55
+
@@ -0,0 +1,26 @@
1
+ #
2
+ # Evaluation subpackage public API for text2sql_eval_toolkit.
3
+ #
4
+
5
+ from unitxt.text2sql_utils import (
6
+ compare_result_dfs,
7
+ compare_dfs_bird_eval_logic,
8
+ is_sqlglot_parsable,
9
+ is_sqlparse_parsable,
10
+ sqlglot_parsed_queries_equivalent,
11
+ sqlglot_optimized_equivalence,
12
+ sqlparse_queries_equivalent,
13
+ sql_exact_match,
14
+ )
15
+
16
+ __all__ = [
17
+ "compare_result_dfs",
18
+ "compare_dfs_bird_eval_logic",
19
+ "is_sqlglot_parsable",
20
+ "is_sqlparse_parsable",
21
+ "sqlglot_parsed_queries_equivalent",
22
+ "sqlglot_optimized_equivalence",
23
+ "sqlparse_queries_equivalent",
24
+ "sql_exact_match",
25
+ ]
26
+