Skip to content

Commit 4a5ee3c

Browse files
committed
merge with main
1 parent ecf7e96 commit 4a5ee3c

File tree

7 files changed

+81
-41
lines changed

7 files changed

+81
-41
lines changed

py-src/data_formulator/agents/agent_data_rec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def process_gpt_response(self, input_tables, messages, response):
137137
#log = {'messages': messages, 'response': response.model_dump(mode='json')}
138138

139139
if isinstance(response, Exception):
140-
result = {'status': 'other error', 'content': response.body}
140+
result = {'status': 'other error', 'content': str(response.body)}
141141
return [result]
142142

143143
candidates = []

py-src/data_formulator/agents/agent_data_transform_v2.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def process_gpt_response(self, input_tables, messages, response):
205205
#logger.info(response.prompt_filter_results)
206206

207207
if isinstance(response, Exception):
208-
result = {'status': 'other error', 'content': response.body}
208+
result = {'status': 'other error', 'content': str(response.body)}
209209
return [result]
210210

211211
candidates = []
@@ -233,10 +233,11 @@ def process_gpt_response(self, input_tables, messages, response):
233233
logger.info(result['content'])
234234
result['code'] = code_str
235235
except Exception as e:
236-
logger.warning('other error:')
237-
error_message = traceback.format_exc()
236+
logger.warning('Error occurred during code execution:')
237+
error_message = str(e)
238238
logger.warning(error_message)
239-
result = {'status': 'other error', 'content': error_message}
239+
print(error_message)
240+
result = {'status': 'other error', 'content': f"An error occurred while executing the transformation: {error_message}"}
240241
else:
241242
result = {'status': 'no transformation', 'content': input_tables[0]['rows']}
242243

py-src/data_formulator/app.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,18 @@ def test_model():
147147
"endpoint": endpoint,
148148
"key": key,
149149
"model": model,
150-
"status": 'ok'
150+
"status": 'ok',
151+
"message": ""
151152
}
152153
except Exception as e:
153-
print(e)
154+
print(f"Error: {e}")
155+
error_message = str(e)
154156
result = {
155157
"endpoint": endpoint,
156158
"key": key,
157159
"model": model,
158-
"status": 'error'
160+
"status": 'error',
161+
"message": error_message,
159162
}
160163
else:
161164
{'status': 'error'}
@@ -423,7 +426,7 @@ def refine_data():
423426
new_instruction = content["new_instruction"]
424427

425428
print("previous dialog")
426-
print(dialog[0]['content'])
429+
print(dialog)
427430

428431
# always resort to the data transform agent
429432
agent = DataTransformationAgentV2(client, model=model)
@@ -434,10 +437,7 @@ def refine_data():
434437
error_message = results[0]['content']
435438
new_instruction = f"We run into the following problem executing the code, please fix it:\n\n{error_message}\n\nPlease think step by step, reflect why the error happens and fix the code so that no more errors would occur."
436439

437-
response_message = dialog['response']['choices'][0]['message']
438-
prev_dialog = [*dialog['messages'], {"role": response_message['role'], 'content': response_message['content']}]
439-
440-
results = agent.followup(input_tables, prev_dialog, [field['name'] for field in output_fields], new_instruction)
440+
results = agent.followup(input_tables, dialog, [field['name'] for field in output_fields], new_instruction)
441441
repair_attempts += 1
442442

443443
response = flask.jsonify({ "status": "ok", "token": token, "results": results})

py-src/data_formulator/py_sandbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def block_mischief(event,arg):
3838
try:
3939
exec(code, allowed_objects)
4040
except Exception as err:
41-
error_message = traceback.format_exc()
41+
error_message = f"Error: {type(err).__name__} - {str(err)}"
4242
conn.send({'status': 'error', 'content': error_message})
4343
conn.close()
4444
return allowed_objects

src/app/dfSlice.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface DataFormulatorState {
3030

3131
oaiModels: {endpoint: string, key: string, model: string }[];
3232
selectedModel: {endpoint: string, model: string} | undefined;
33-
testedModels: {endpoint: string, model: string, status: 'ok' | 'error' | 'testing' | 'unknown'}[];
33+
testedModels: {endpoint: string, model: string, status: 'ok' | 'error' | 'testing' | 'unknown', message: string}[];
3434

3535
tables : DictTable[];
3636
charts: Chart[];
@@ -278,12 +278,13 @@ export const dataFormulatorSlice = createSlice({
278278
state.oaiModels = state.oaiModels.filter(oaiModel => oaiModel.model != model || oaiModel.endpoint != endpoint );
279279
state.testedModels = state.testedModels.filter(m => !(m.model == model && m.endpoint == endpoint));
280280
},
281-
updateModelStatus: (state, action: PayloadAction<{model: string, endpoint: string, status: 'ok' | 'error' | 'testing' | 'unknown'}>) => {
281+
updateModelStatus: (state, action: PayloadAction<{model: string, endpoint: string, status: 'ok' | 'error' | 'testing' | 'unknown', message: string}>) => {
282282
let model = action.payload.model;
283283
let endpoint = action.payload.endpoint;
284284
let status = action.payload.status;
285-
286-
state.testedModels = [...state.testedModels.filter(t => !(t.model == model && t.endpoint == endpoint)), {model, endpoint, status} ]
285+
let message = action.payload.message;
286+
287+
state.testedModels = [...state.testedModels.filter(t => !(t.model == model && t.endpoint == endpoint)), {model, endpoint, status, message} ]
287288
},
288289
addTable: (state, action: PayloadAction<DictTable>) => {
289290
let table = action.payload;

src/views/EncodingShelfCard.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,25 @@ export const EncodingShelfCard: FC<EncodingShelfCardProps> = function ({ chartId
314314
if (data["status"] == "ok") {
315315
if (data["token"] == token) {
316316
let candidates = data["results"].filter((item: any) => {
317-
return item["content"].length > 0
317+
return item["status"] == "ok" && item["content"].length > 0
318318
});
319+
console.log(data)
320+
console.log(data.results[0])
319321
if (candidates.length == 0) {
320-
dispatch(dfActions.addMessages({
321-
"timestamp": Date.now(),
322-
"type": "error",
323-
"value": "Unable to find a data transformation for the chart, please check concepts, encodings and clarification questions."
324-
}));
322+
try {
323+
let errorMessage = data.results[0].content;
324+
dispatch(dfActions.addMessages({
325+
"timestamp": Date.now(),
326+
"type": "error",
327+
"value": `Unable to find a data transformation for the chart, please check concepts, encodings and clarification questions. Details: "${errorMessage}"`
328+
}));
329+
} catch (e) {
330+
dispatch(dfActions.addMessages({
331+
"timestamp": Date.now(),
332+
"type": "error",
333+
"value": `Unable to find a data transformation for the chart, please check concepts, encodings and clarification questions.`
334+
}));
335+
}
325336
} else {
326337

327338
// PART 1: handle triggers
@@ -462,7 +473,7 @@ export const EncodingShelfCard: FC<EncodingShelfCardProps> = function ({ chartId
462473
dispatch(dfActions.addMessages({
463474
"timestamp": Date.now(),
464475
"type": "error",
465-
"value": `Data formulation for ${fieldNamesStr} fails, maybe try something differently?`
476+
"value": `Data formulation for ${fieldNamesStr} fails, maybe try something differently? Error: ${error.message}`
466477
}));
467478
});
468479
}

src/views/ModelSelectionDialog.tsx

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
7676
const [showKeys, setShowKeys] = useState<boolean>(false);
7777
const [tempSelectedModel, setTempSelectedMode] = useState<{model: string, endpoint: string} | undefined >(selectedModel);
7878

79-
let updateModelStatus = (model: string, endpoint: string, status: 'ok' | 'error' | 'testing' | 'unknown') => {
80-
dispatch(dfActions.updateModelStatus({endpoint, model, status}));
79+
let updateModelStatus = (model: string, endpoint: string, status: 'ok' | 'error' | 'testing' | 'unknown', message: string) => {
80+
dispatch(dfActions.updateModelStatus({endpoint, model, status, message}));
8181
}
8282
let getStatus = (model: string, endpoint: string) => {
8383
return testedModels.find(t => t.model == model && t.endpoint == endpoint)?.status || 'unknown';
@@ -92,7 +92,7 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
9292
let modelExists = oaiModels.some(m => m.endpoint == newEndpoint && m.model == newModel);
9393

9494
let testModel = (endpoint: string, key: string, model: string) => {
95-
updateModelStatus(model, endpoint, 'testing');
95+
updateModelStatus(model, endpoint, 'testing', "");
9696
let message = {
9797
method: 'POST',
9898
headers: { 'Content-Type': 'application/json', },
@@ -106,9 +106,9 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
106106
.then((response) => response.json())
107107
.then((data) => {
108108
let status = data["status"] || 'error';
109-
updateModelStatus(model, endpoint, status)
109+
updateModelStatus(model, endpoint, status, data["message"] || "");
110110
}).catch((error) => {
111-
updateModelStatus(model, endpoint, 'error')
111+
updateModelStatus(model, endpoint, 'error', error.message)
112112
});
113113
}
114114

@@ -231,37 +231,45 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
231231
let status = getStatus(oaiModel.model, oaiModel.endpoint);
232232
let statusIcon = status == "unknown" ? <HelpOutlineIcon color="warning" /> : ( status == 'testing' ? <CircularProgress size={24} />:
233233
(status == "ok" ? <CheckCircleOutlineIcon color="success"/> : <ErrorOutlineIcon color="error"/> ))
234+
235+
const borderStyle = ['error', 'unknown'].includes(status) ? '1px dashed lightgray' : undefined;
236+
const noBorderStyle = ['error', 'unknown'].includes(status) ? 'none' : undefined;
234237

235238
return (
239+
<>
236240
<TableRow
237-
hover
241+
238242
role="checkbox"
239243
aria-checked={isItemSelected}
240244
selected={isItemSelected}
241245
key={`${oaiModel.endpoint}-${oaiModel.model}`}
242246
onClick={() => { setTempSelectedMode({model: oaiModel.model, endpoint: oaiModel.endpoint}) }}
243247
sx={{ cursor: 'pointer'}}
244248
>
245-
<TableCell align="right">
249+
<TableCell align="right" sx={{ borderBottom: noBorderStyle }}>
246250
<Radio checked={isItemSelected} name="radio-buttons" />
247251
</TableCell>
248-
<TableCell align="left">
252+
<TableCell align="left" sx={{ borderBottom: noBorderStyle }}>
249253
{oaiModel.endpoint == 'openai' ? 'openai' : 'azure openai'}
250254
</TableCell>
251-
<TableCell component="th" scope="row">
255+
<TableCell component="th" scope="row" sx={{ borderBottom: borderStyle }}>
252256
{oaiModel.endpoint}
253257
</TableCell>
254-
<TableCell align="left">
258+
<TableCell align="left" sx={{ borderBottom: borderStyle }}>
255259
{oaiModel.key != "" ?
256260
(showKeys ? (oaiModel.key || <Typography sx={{color: "lightgray"}} fontSize='inherit'>N/A</Typography>) : "************") :
257261
<Typography sx={{color: "lightgray"}} fontSize='inherit'>N/A</Typography>
258262
}
259263
</TableCell>
260-
<TableCell align="left">{oaiModel.model}</TableCell>
261-
<TableCell sx={{fontWeight: 'bold'}} align="right"><IconButton
262-
onClick ={() => { testModel(oaiModel.endpoint, oaiModel.key, oaiModel.model) }}
263-
>{statusIcon}</IconButton></TableCell>
264-
<TableCell align="right">
264+
<TableCell align="left" sx={{ borderBottom: borderStyle }}>{oaiModel.model}</TableCell>
265+
<TableCell sx={{fontWeight: 'bold', borderBottom: borderStyle}} align="right">
266+
<IconButton
267+
onClick ={() => { testModel(oaiModel.endpoint, oaiModel.key, oaiModel.model) }}
268+
>
269+
{statusIcon}
270+
</IconButton>
271+
</TableCell>
272+
<TableCell sx={{ borderBottom: borderStyle }} align="right">
265273
<IconButton disabled={oaiModel.endpoint=="default"}
266274
onClick={()=>{
267275
dispatch(dfActions.removeModel({model: oaiModel.model, endpoint: oaiModel.endpoint}));
@@ -282,11 +290,30 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
282290
</IconButton>
283291
</TableCell>
284292
</TableRow>
293+
{['error', 'unknown'].includes(status) && (
294+
<TableRow
295+
selected={isItemSelected}
296+
onClick={() => { setTempSelectedMode({model: oaiModel.model, endpoint: oaiModel.endpoint}) }}
297+
sx={{
298+
cursor: 'pointer',
299+
'&:hover': {
300+
backgroundColor: 'rgba(0, 0, 0, 0.04)',
301+
},
302+
}}
303+
>
304+
<TableCell colSpan={2} align="right" ></TableCell>
305+
<TableCell colSpan={5}>
306+
<Typography variant="caption" color="error">
307+
{testedModels.find(m => m.model === oaiModel.model && m.endpoint === oaiModel.endpoint)?.message || "Unknown error"}
308+
</Typography>
309+
</TableCell>
310+
</TableRow>
311+
)}
312+
</>
285313
)
286314
})}
287315
{newModelEntry}
288316
</TableBody>
289-
{/* <caption style={{textAlign: 'right', padding: '0 16px'}}><Typography fontSize="small" color="error">{modelExists ? "endpoint and model exists" : ""}</Typography></caption> */}
290317
</Table>
291318
</TableContainer>
292319

0 commit comments

Comments
 (0)