|
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 |
|
@@ -462,96 +463,12 @@ def _create_error_result(self, question: str, error_message: str) -> QueryResult |
462 | 463 | def generate_suggestions( |
463 | 464 | self, project_id: str, user_id: str |
464 | 465 | ) -> List[Dict[str, Any]]: |
465 | | - """Generate query suggestions based on project data.""" |
| 466 | + """Generate query suggestions using the dedicated suggestions service.""" |
466 | 467 | try: |
467 | | - # Use mock project data for now |
468 | | - project = { |
469 | | - "columns_metadata": [ |
470 | | - {"name": "sales_amount", "type": "number"}, |
471 | | - {"name": "category", "type": "string"}, |
472 | | - {"name": "date", "type": "date"}, |
473 | | - ] |
474 | | - } |
475 | | - |
476 | | - # Generate suggestions based on column types |
477 | | - suggestions = [] |
478 | | - metadata = project.get("columns_metadata", []) |
479 | | - |
480 | | - # Find numeric columns for aggregation suggestions |
481 | | - numeric_cols = [ |
482 | | - col["name"] |
483 | | - for col in metadata |
484 | | - if col.get("type") in ["number", "integer", "float"] |
485 | | - ] |
486 | | - categorical_cols = [ |
487 | | - col["name"] for col in metadata if col.get("type") == "string" |
488 | | - ] |
489 | | - date_cols = [ |
490 | | - col["name"] |
491 | | - for col in metadata |
492 | | - if col.get("type") in ["date", "datetime"] |
493 | | - ] |
494 | | - |
495 | | - if numeric_cols: |
496 | | - suggestions.append( |
497 | | - { |
498 | | - "id": f"sug_sum_{numeric_cols[0]}", |
499 | | - "text": f"Show me the total {numeric_cols[0]}", |
500 | | - "category": "analysis", |
501 | | - "complexity": "beginner", |
502 | | - } |
503 | | - ) |
504 | | - |
505 | | - if categorical_cols: |
506 | | - suggestions.append( |
507 | | - { |
508 | | - "id": f"sug_group_{categorical_cols[0]}", |
509 | | - "text": f"Break down {numeric_cols[0]} by {categorical_cols[0]}", |
510 | | - "category": "analysis", |
511 | | - "complexity": "intermediate", |
512 | | - } |
513 | | - ) |
514 | | - |
515 | | - suggestions.append( |
516 | | - { |
517 | | - "id": f"sug_chart_{categorical_cols[0]}", |
518 | | - "text": f"Create a bar chart of {numeric_cols[0]} by {categorical_cols[0]}", |
519 | | - "category": "visualization", |
520 | | - "complexity": "intermediate", |
521 | | - } |
522 | | - ) |
523 | | - |
524 | | - if date_cols and numeric_cols: |
525 | | - suggestions.append( |
526 | | - { |
527 | | - "id": f"sug_trend_{date_cols[0]}", |
528 | | - "text": f"Show {numeric_cols[0]} trend over {date_cols[0]}", |
529 | | - "category": "visualization", |
530 | | - "complexity": "intermediate", |
531 | | - } |
532 | | - ) |
533 | | - |
534 | | - # Add general suggestions |
535 | | - suggestions.extend( |
536 | | - [ |
537 | | - { |
538 | | - "id": "sug_overview", |
539 | | - "text": "Give me an overview of this dataset", |
540 | | - "category": "summary", |
541 | | - "complexity": "beginner", |
542 | | - }, |
543 | | - { |
544 | | - "id": "sug_top_values", |
545 | | - "text": "Show me the top 10 rows", |
546 | | - "category": "analysis", |
547 | | - "complexity": "beginner", |
548 | | - }, |
549 | | - ] |
550 | | - ) |
551 | | - |
552 | | - return suggestions[:5] # Return top 5 suggestions |
553 | | - |
| 468 | + suggestions_service = get_suggestions_service() |
| 469 | + return suggestions_service.generate_suggestions(project_id, user_id) |
554 | 470 | except Exception as e: |
| 471 | + logger.error(f"Error generating suggestions via service: {str(e)}") |
555 | 472 | return [] |
556 | 473 |
|
557 | 474 | def _ensure_project_embeddings(self, project_id: str, user_id: str): |
|
0 commit comments