Skip to content

Commit fc96597

Browse files
authored
Merge pull request #58 from dasmy/dev/improve_prompt
Add some information in the data to the prompt
2 parents 6bdc463 + c1dc9f5 commit fc96597

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

frontend/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ function App() {
155155
});
156156
}
157157

158-
function completeUpload(filename: string) {
158+
function completeUpload(message: string) {
159159
addMessage({
160-
text: `File ${filename} was uploaded successfully.`,
160+
text: message,
161161
type: "message",
162162
role: "system",
163163
});
@@ -171,7 +171,7 @@ function App() {
171171
"Content-Type": "application/json",
172172
},
173173
body: JSON.stringify({
174-
prompt: `File ${filename} was uploaded successfully.`,
174+
prompt: message,
175175
}),
176176
})
177177
.then(() => {})

frontend/src/components/Input.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ export default function Input(props: { onSendMessage: any, onStartUpload: any, o
4343
body: formData,
4444
});
4545

46-
props.onCompletedUpload(file.name);
47-
4846
if (!response.ok) {
4947
throw new Error("Network response was not ok");
5048
}
49+
50+
const json = await response.json();
51+
props.onCompletedUpload(json["message"]);
52+
5153
} catch (error) {
5254
console.error("Error:", error);
5355
}

gpt_code_ui/webapp/main.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import logging
88
import sys
9+
import pandas as pd
910

1011
from collections import deque
1112

@@ -56,6 +57,33 @@ def allowed_file(filename):
5657
return True
5758

5859

60+
def inspect_file(filename: str) -> str:
61+
READER_MAP = {
62+
'.csv': pd.read_csv,
63+
'.tsv': pd.read_csv,
64+
'.xlsx': pd.read_excel,
65+
'.xls': pd.read_excel,
66+
'.xml': pd.read_xml,
67+
'.json': pd.read_json,
68+
'.hdf': pd.read_hdf,
69+
'.hdf5': pd.read_hdf,
70+
'.feather': pd.read_feather,
71+
'.parquet': pd.read_parquet,
72+
'.pkl': pd.read_pickle,
73+
'.sql': pd.read_sql,
74+
}
75+
76+
_, ext = os.path.splitext(filename)
77+
78+
try:
79+
df = READER_MAP[ext.lower()](filename)
80+
return f'The file contains the following columns: {", ".join(df.columns)}'
81+
except KeyError:
82+
return '' # unsupported file type
83+
except Exception:
84+
return '' # file reading failed. - Don't want to know why.
85+
86+
5987
async def get_code(user_prompt, user_openai_key=None, model="gpt-3.5-turbo"):
6088

6189
prompt = f"""First, here is a history of what I asked you to do earlier.
@@ -253,8 +281,10 @@ def upload_file():
253281
if file.filename == '':
254282
return jsonify({'error': 'No selected file'}), 400
255283
if file and allowed_file(file.filename):
256-
file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
257-
return jsonify({'message': 'File successfully uploaded'}), 200
284+
file_target = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
285+
file.save(file_target)
286+
file_info = inspect_file(file_target)
287+
return jsonify({'message': f'File {file.filename} uploaded successfully.\n{file_info}'}), 200
258288
else:
259289
return jsonify({'error': 'File type not allowed'}), 400
260290

0 commit comments

Comments
 (0)