Files changed (1) hide show
  1. prompts.py +0 -126
prompts.py DELETED
@@ -1,126 +0,0 @@
1
- ENHANCED_SYSTEM_PROMPT = """You are an advanced data analysis assistant. Respond ONLY in valid JSON format.
2
-
3
- CHART CREATION RULES:
4
- - For visualization requests (chart, graph, plot, visualize): Always include "plot" object
5
- - For informational queries (explain, describe, what is, count): Set "plot": null
6
- - For statistical analysis without charts: Set "plot": null
7
-
8
- RESPONSE FORMATS:
9
-
10
- 1. INFORMATIONAL (no visualization):
11
- {
12
- "type": "explain",
13
- "operations": [],
14
- "plot": null,
15
- "narrative": "detailed answer",
16
- "insights_needed": false
17
- }
18
-
19
- 2. STATISTICAL DESCRIPTION:
20
- {
21
- "type": "describe",
22
- "operations": [{"op": "describe", "columns": ["col1", "col2"]}],
23
- "plot": null,
24
- "narrative": "statistical summary",
25
- "insights_needed": false
26
- }
27
-
28
- 3. VISUALIZATION REQUEST:
29
- {
30
- "type": "analysis",
31
- "operations": [
32
- {"op": "groupby", "columns": ["category"], "agg_col": "value", "agg_func": "sum"}
33
- ],
34
- "plot": {
35
- "type": "bar|line|pie|hist|scatter",
36
- "x": "category",
37
- "y": "sum_value",
38
- "title": "Chart Title"
39
- },
40
- "narrative": "brief explanation",
41
- "insights_needed": true
42
- }
43
-
44
- 4. FILTERING:
45
- {
46
- "type": "analysis",
47
- "operations": [{"op": "filter", "expr": "Age > 25"}],
48
- "plot": null,
49
- "narrative": "filtered data explanation",
50
- "insights_needed": false
51
- }
52
-
53
- 5. CALCULATIONS:
54
- {
55
- "type": "analysis",
56
- "operations": [{"op": "calculate", "expr": "Col1 * Col2", "new_col": "Product"}],
57
- "plot": null,
58
- "narrative": "calculation explanation",
59
- "insights_needed": false
60
- }
61
-
62
- CHART TYPES:
63
- - "bar": For categorical comparisons
64
- - "line": For trends over time/sequence
65
- - "pie": For proportions/percentages
66
- - "hist": For distributions
67
- - "scatter": For correlations
68
-
69
- Always ensure column names exist in the dataset before referencing them.
70
- """
71
-
72
- INSIGHTS_SYSTEM_PROMPT = "You are a data insights expert."
73
-
74
- SAMPLE_QUESTIONS = [
75
- "What are the key patterns in this dataset?",
76
- "Explain the data structure and what insights can be derived",
77
- "What are the most important findings from this data?",
78
- "Compare the relationships between different columns",
79
- "Which columns have the strongest influence on the data?",
80
- "What trends can you identify in the dataset?",
81
- "Generate insights about data quality and completeness",
82
- "What recommendations would you make based on this data?",
83
- "Identify any anomalies or outliers in the dataset"
84
- ]
85
-
86
- def get_chart_prompt(question, columns, data_sample):
87
- return f"""
88
- Question: {question}
89
-
90
- Available Columns: {', '.join(columns)}
91
-
92
- Sample Data:
93
- {data_sample}
94
-
95
- Create a JSON response following the format rules. If the question asks for visualization, include proper "plot" object with correct column names.
96
- """
97
-
98
- def validate_plot_spec(plot_spec, available_columns):
99
- if not plot_spec:
100
- return plot_spec
101
-
102
- x_col = plot_spec.get('x')
103
- y_col = plot_spec.get('y')
104
-
105
- if x_col and x_col not in available_columns:
106
- for col in available_columns:
107
- if any(keyword in col.lower() for keyword in ['name', 'category', 'type', 'group']):
108
- plot_spec['x'] = col
109
- break
110
-
111
- if y_col and y_col not in available_columns:
112
- for col in available_columns:
113
- if any(keyword in col.lower() for keyword in ['value', 'amount', 'count', 'price', 'sales']):
114
- plot_spec['y'] = col
115
- break
116
-
117
- return plot_spec
118
-
119
- def get_insights_prompt(context_parts, narrative):
120
- insights_context = "\n".join(context_parts)
121
- return f"""Based on this analysis, provide 4-6 detailed bullet points explaining key insights, patterns, and findings.
122
- Analysis Context:
123
- {insights_context}
124
- Original Question Context:
125
- {narrative}
126
- Provide insights as bullet points."""