|
13 | 13 | from models.response_schemas import QueryResult |
14 | 14 | from services.duckdb_service import duckdb_service |
15 | 15 | from services.embeddings_service import get_embeddings_service |
| 16 | +from services.suggestions_service import get_suggestions_service |
16 | 17 | from services.project_service import get_project_service |
17 | 18 | from services.storage_service import storage_service |
18 | 19 |
|
@@ -1073,96 +1074,12 @@ def _create_error_result(self, question: str, error_message: str) -> QueryResult |
1073 | 1074 | def generate_suggestions( |
1074 | 1075 | self, project_id: str, user_id: str |
1075 | 1076 | ) -> List[Dict[str, Any]]: |
1076 | | - """Generate query suggestions based on project data.""" |
| 1077 | + """Generate query suggestions using the dedicated suggestions service.""" |
1077 | 1078 | try: |
1078 | | - # Use mock project data for now |
1079 | | - project = { |
1080 | | - "columns_metadata": [ |
1081 | | - {"name": "sales_amount", "type": "number"}, |
1082 | | - {"name": "category", "type": "string"}, |
1083 | | - {"name": "date", "type": "date"}, |
1084 | | - ] |
1085 | | - } |
1086 | | - |
1087 | | - # Generate suggestions based on column types |
1088 | | - suggestions = [] |
1089 | | - metadata = project.get("columns_metadata", []) |
1090 | | - |
1091 | | - # Find numeric columns for aggregation suggestions |
1092 | | - numeric_cols = [ |
1093 | | - col["name"] |
1094 | | - for col in metadata |
1095 | | - if col.get("type") in ["number", "integer", "float"] |
1096 | | - ] |
1097 | | - categorical_cols = [ |
1098 | | - col["name"] for col in metadata if col.get("type") == "string" |
1099 | | - ] |
1100 | | - date_cols = [ |
1101 | | - col["name"] |
1102 | | - for col in metadata |
1103 | | - if col.get("type") in ["date", "datetime"] |
1104 | | - ] |
1105 | | - |
1106 | | - if numeric_cols: |
1107 | | - suggestions.append( |
1108 | | - { |
1109 | | - "id": f"sug_sum_{numeric_cols[0]}", |
1110 | | - "text": f"Show me the total {numeric_cols[0]}", |
1111 | | - "category": "analysis", |
1112 | | - "complexity": "beginner", |
1113 | | - } |
1114 | | - ) |
1115 | | - |
1116 | | - if categorical_cols: |
1117 | | - suggestions.append( |
1118 | | - { |
1119 | | - "id": f"sug_group_{categorical_cols[0]}", |
1120 | | - "text": f"Break down {numeric_cols[0]} by {categorical_cols[0]}", |
1121 | | - "category": "analysis", |
1122 | | - "complexity": "intermediate", |
1123 | | - } |
1124 | | - ) |
1125 | | - |
1126 | | - suggestions.append( |
1127 | | - { |
1128 | | - "id": f"sug_chart_{categorical_cols[0]}", |
1129 | | - "text": f"Create a bar chart of {numeric_cols[0]} by {categorical_cols[0]}", |
1130 | | - "category": "visualization", |
1131 | | - "complexity": "intermediate", |
1132 | | - } |
1133 | | - ) |
1134 | | - |
1135 | | - if date_cols and numeric_cols: |
1136 | | - suggestions.append( |
1137 | | - { |
1138 | | - "id": f"sug_trend_{date_cols[0]}", |
1139 | | - "text": f"Show {numeric_cols[0]} trend over {date_cols[0]}", |
1140 | | - "category": "visualization", |
1141 | | - "complexity": "intermediate", |
1142 | | - } |
1143 | | - ) |
1144 | | - |
1145 | | - # Add general suggestions |
1146 | | - suggestions.extend( |
1147 | | - [ |
1148 | | - { |
1149 | | - "id": "sug_overview", |
1150 | | - "text": "Give me an overview of this dataset", |
1151 | | - "category": "summary", |
1152 | | - "complexity": "beginner", |
1153 | | - }, |
1154 | | - { |
1155 | | - "id": "sug_top_values", |
1156 | | - "text": "Show me the top 10 rows", |
1157 | | - "category": "analysis", |
1158 | | - "complexity": "beginner", |
1159 | | - }, |
1160 | | - ] |
1161 | | - ) |
1162 | | - |
1163 | | - return suggestions[:5] # Return top 5 suggestions |
1164 | | - |
| 1079 | + suggestions_service = get_suggestions_service() |
| 1080 | + return suggestions_service.generate_suggestions(project_id, user_id) |
1165 | 1081 | except Exception as e: |
| 1082 | + logger.error(f"Error generating suggestions via service: {str(e)}") |
1166 | 1083 | return [] |
1167 | 1084 |
|
1168 | 1085 | def _ensure_project_embeddings(self, project_id: str, user_id: str): |
|
0 commit comments