Skip to content

Commit a3d8d95

Browse files
committed
fix-any-usage
1 parent 6aeb699 commit a3d8d95

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

api/utils.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,49 @@
11
"""Utility functions for the text2sql API."""
22
import json
3-
from typing import Any, Dict, List
3+
from typing import Dict, List, Optional, TypedDict
44

55
from litellm import completion, batch_completion
66

77
from api.config import Config
88

99

10-
def create_combined_description(
11-
table_info: Dict[str, Dict[str, Any]], batch_size: int = 10
12-
) -> Dict[str, Dict[str, Any]]:
10+
class ForeignKeyInfo(TypedDict):
11+
"""Foreign key constraint information."""
12+
constraint_name: str
13+
column: str
14+
referenced_table: str
15+
referenced_column: str
16+
17+
18+
class ColumnInfo(TypedDict):
19+
"""Column metadata information."""
20+
type: str
21+
null: str
22+
key: str
23+
description: str
24+
default: Optional[str]
25+
sample_values: List[str]
26+
27+
28+
class TableInfo(TypedDict):
29+
"""Table metadata information."""
30+
description: str
31+
columns: Dict[str, ColumnInfo]
32+
foreign_keys: List[ForeignKeyInfo]
33+
col_descriptions: List[str]
34+
35+
36+
def create_combined_description( # pylint: disable=too-many-locals
37+
table_info: Dict[str, TableInfo], batch_size: int = 10
38+
) -> Dict[str, TableInfo]:
1339
"""
1440
Create a combined description from a dictionary of table descriptions.
1541
1642
Args:
17-
table_info (Dict[str, Dict[str, Any]]): Mapping of table names to their metadata.
43+
table_info (Dict[str, TableInfo]): Mapping of table names to their metadata.
1844
batch_size (int): Number of tables to process per batch when calling the LLM (default: 10).
1945
Returns:
20-
Dict[str, Dict[str, Any]]: Updated mapping containing descriptions.
46+
Dict[str, TableInfo]: Updated mapping containing descriptions.
2147
"""
2248
if not isinstance(table_info, dict):
2349
raise TypeError("table_info must be a dictionary keyed by table name.")

0 commit comments

Comments
 (0)