Skip to content

Commit

Permalink
chore: deal import, type and error handling suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
paopa committed Jan 9, 2025
1 parent 00d000c commit b165de2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions wren-ai-service/src/pipelines/indexing/sql_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import sys
import uuid
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Set

import orjson
from hamilton import base
Expand Down Expand Up @@ -53,7 +53,7 @@ def run(self, sql_pairs: List[SqlPair], project_id: Optional[str] = ""):
@observe(capture_input=False)
def boilerplates(
mdl_str: str,
) -> List[str]:
) -> Set[str]:
mdl = orjson.loads(mdl_str)

return {
Expand Down Expand Up @@ -129,8 +129,12 @@ def _load_sql_pairs(sql_pairs_path: str) -> Dict[str, Any]:
logger.warning(f"SQL pairs file not found: {sql_pairs_path}")
return {}

with open(sql_pairs_path, "r") as file:
return orjson.loads(file.read())
try:
with open(sql_pairs_path, "r") as file:
return orjson.loads(file.read())
except Exception as e:
logger.error(f"Error loading SQL pairs file: {e}")
return {}


class SqlPairs(BasicPipeline):
Expand Down
4 changes: 2 additions & 2 deletions wren-ai-service/tools/mdl_to_str.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import argparse

import orjson


Expand Down Expand Up @@ -38,8 +40,6 @@ def _args():


if __name__ == "__main__":
import argparse

args = _args()
mdl = orjson.loads(open(args.path).read())
print(to_str(mdl))

0 comments on commit b165de2

Please sign in to comment.