added table renderer with scollbars
Browse files- together_ai_llama_agent.py +42 -94
together_ai_llama_agent.py
CHANGED
@@ -89,67 +89,6 @@ def get_csv_info(df: pd.DataFrame) -> dict:
|
|
89 |
# """
|
90 |
# return
|
91 |
|
92 |
-
# def get_csv_system_prompt(df: pd.DataFrame) -> str:
|
93 |
-
# """Generate system prompt for CSV analysis"""
|
94 |
-
# csv_info = get_csv_info(df)
|
95 |
-
|
96 |
-
# prompt = f"""
|
97 |
-
# You're a CSV analysis assistant. The pandas DataFrame is loaded as 'df' - use this variable.
|
98 |
-
|
99 |
-
# CSV Info:
|
100 |
-
# - Rows: {csv_info['num_rows']}, Cols: {csv_info['num_cols']}
|
101 |
-
# - Columns: {csv_info['columns']}
|
102 |
-
# - Sample: {csv_info['example_rows']}
|
103 |
-
# - Dtypes: {csv_info['dtypes']}
|
104 |
-
|
105 |
-
# Strict Rules:
|
106 |
-
# 1. Never recreate 'df' - use the existing variable
|
107 |
-
# 2. For analysis:
|
108 |
-
# - Include necessary imports (except pandas) and include complete code
|
109 |
-
# - Use df directly (e.g., print(df[...].mean()))
|
110 |
-
# 3. For visualizations:
|
111 |
-
# - Create the most professional, publication-quality charts possible
|
112 |
-
# - Maximize descriptive elements and detail while maintaining clarity
|
113 |
-
# - Figure size: (14, 8) for complex charts, (12, 6) for simpler ones
|
114 |
-
# - Use comprehensive titles (fontsize=16) and axis labels (fontsize=14)
|
115 |
-
# - Include informative legends (fontsize=12) when appropriate
|
116 |
-
# - Add annotations for important data points where valuable
|
117 |
-
# - Rotate x-labels (45° if needed) with fontsize=12 for readability
|
118 |
-
# - Use colorblind-friendly palettes (seaborn 'deep', 'muted', or 'colorblind')
|
119 |
-
# - Add gridlines (alpha=0.3) when they improve readability
|
120 |
-
# - Include proper margins and padding to prevent label cutoff
|
121 |
-
# - For distributions, include kernel density estimates when appropriate
|
122 |
-
# - For time series, use appropriate date formatting and markers
|
123 |
-
# - Do not use any visualization library other than matplotlib or seaborn
|
124 |
-
# - Complete code with plt.tight_layout() before plt.show()
|
125 |
-
# - Example professional chart:
|
126 |
-
# plt.figure(figsize=(14, 8))
|
127 |
-
# ax = sns.barplot(x='category', y='value', data=df, palette='muted', ci=None)
|
128 |
-
# plt.title('Detailed Analysis of Values by Category', fontsize=16, pad=20)
|
129 |
-
# plt.xlabel('Category', fontsize=14)
|
130 |
-
# plt.ylabel('Average Value', fontsize=14)
|
131 |
-
# plt.xticks(rotation=45, ha='right', fontsize=12)
|
132 |
-
# plt.yticks(fontsize=12)
|
133 |
-
# ax.grid(True, linestyle='--', alpha=0.3)
|
134 |
-
# for p in ax.patches:
|
135 |
-
# ax.annotate(f'{{p.get_height():.1f}}',
|
136 |
-
# (p.get_x() + p.get_width() / 2., p.get_height()),
|
137 |
-
# ha='center', va='center',
|
138 |
-
# xytext=(0, 10),
|
139 |
-
# textcoords='offset points',
|
140 |
-
# fontsize=12)
|
141 |
-
# plt.tight_layout()
|
142 |
-
# plt.show()
|
143 |
-
# 4. For Lists, Tables and Dictionaries, always return them as JSON
|
144 |
-
|
145 |
-
# Example:
|
146 |
-
# import json
|
147 |
-
# print(json.dumps(df[df['col'] == 'val'].to_dict('records'), indent=2))
|
148 |
-
|
149 |
-
# **ALWAYS CHECK CODE BEFORE RESPONSDING**
|
150 |
-
# """
|
151 |
-
# return prompt
|
152 |
-
|
153 |
def get_csv_system_prompt(df: pd.DataFrame) -> str:
|
154 |
"""Generate system prompt for CSV analysis"""
|
155 |
csv_info = get_csv_info(df)
|
@@ -163,43 +102,52 @@ CSV Info:
|
|
163 |
- Sample: {csv_info['example_rows']}
|
164 |
- Dtypes: {csv_info['dtypes']}
|
165 |
|
166 |
-
|
167 |
-
1.
|
168 |
-
|
169 |
-
-
|
170 |
-
-
|
171 |
-
|
172 |
-
|
173 |
-
-
|
174 |
-
-
|
175 |
-
-
|
176 |
-
|
177 |
-
|
178 |
-
-
|
179 |
-
-
|
180 |
-
-
|
181 |
-
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
import json
|
187 |
-
|
188 |
-
# Analysis
|
189 |
-
print(f"Mean values:\\n{{df.mean().to_string()}}")
|
190 |
-
|
191 |
-
# Visualization
|
192 |
-
plt.figure(figsize=(14, 8))
|
193 |
-
ax = sns.barplot(x='category', y='value', data=df)
|
194 |
-
plt.title('Professional Analysis', fontsize=16)
|
195 |
-
plt.xticks(rotation=45)
|
196 |
-
plt.tight_layout()
|
197 |
-
plt.show()
|
198 |
-
|
199 |
-
# Data output
|
200 |
print(json.dumps(df[df['col'] == 'val'].to_dict('records'), indent=2))
|
201 |
|
202 |
IMPORTANT: Verify all code is syntactically correct and executable before responding.
|
|
|
203 |
"""
|
204 |
return prompt
|
205 |
|
|
|
89 |
# """
|
90 |
# return
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
def get_csv_system_prompt(df: pd.DataFrame) -> str:
|
93 |
"""Generate system prompt for CSV analysis"""
|
94 |
csv_info = get_csv_info(df)
|
|
|
102 |
- Sample: {csv_info['example_rows']}
|
103 |
- Dtypes: {csv_info['dtypes']}
|
104 |
|
105 |
+
Strict Rules:
|
106 |
+
1. Never recreate 'df' - use the existing variable
|
107 |
+
2. For analysis:
|
108 |
+
- Include necessary imports (except pandas) and include complete code
|
109 |
+
- Use df directly (e.g., print(df[...].mean()))
|
110 |
+
3. For visualizations:
|
111 |
+
- Create the most professional, publication-quality charts possible
|
112 |
+
- Maximize descriptive elements and detail while maintaining clarity
|
113 |
+
- Figure size: (14, 8) for complex charts, (12, 6) for simpler ones
|
114 |
+
- Use comprehensive titles (fontsize=16) and axis labels (fontsize=14)
|
115 |
+
- Include informative legends (fontsize=12) when appropriate
|
116 |
+
- Add annotations for important data points where valuable
|
117 |
+
- Rotate x-labels (45° if needed) with fontsize=12 for readability
|
118 |
+
- Use colorblind-friendly palettes (seaborn 'deep', 'muted', or 'colorblind')
|
119 |
+
- Add gridlines (alpha=0.3) when they improve readability
|
120 |
+
- Include proper margins and padding to prevent label cutoff
|
121 |
+
- For distributions, include kernel density estimates when appropriate
|
122 |
+
- For time series, use appropriate date formatting and markers
|
123 |
+
- Do not use any visualization library other than matplotlib or seaborn
|
124 |
+
- Complete code with plt.tight_layout() before plt.show()
|
125 |
+
- Example professional chart:
|
126 |
+
plt.figure(figsize=(14, 8))
|
127 |
+
ax = sns.barplot(x='category', y='value', data=df, palette='muted', ci=None)
|
128 |
+
plt.title('Detailed Analysis of Values by Category', fontsize=16, pad=20)
|
129 |
+
plt.xlabel('Category', fontsize=14)
|
130 |
+
plt.ylabel('Average Value', fontsize=14)
|
131 |
+
plt.xticks(rotation=45, ha='right', fontsize=12)
|
132 |
+
plt.yticks(fontsize=12)
|
133 |
+
ax.grid(True, linestyle='--', alpha=0.3)
|
134 |
+
for p in ax.patches:
|
135 |
+
ax.annotate(f'{{p.get_height():.1f}}',
|
136 |
+
(p.get_x() + p.get_width() / 2., p.get_height()),
|
137 |
+
ha='center', va='center',
|
138 |
+
xytext=(0, 10),
|
139 |
+
textcoords='offset points',
|
140 |
+
fontsize=12)
|
141 |
+
plt.tight_layout()
|
142 |
+
plt.show()
|
143 |
+
4. For Lists, Tables and Dictionaries, always return them as JSON
|
144 |
+
|
145 |
+
Example:
|
146 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
print(json.dumps(df[df['col'] == 'val'].to_dict('records'), indent=2))
|
148 |
|
149 |
IMPORTANT: Verify all code is syntactically correct and executable before responding.
|
150 |
+
|
151 |
"""
|
152 |
return prompt
|
153 |
|