Skip to content

Commit 97ad9fc

Browse files
committed
improve error message in case a smaller model failed on the task
1 parent ccb6a08 commit 97ad9fc

File tree

5 files changed

+41
-33
lines changed

5 files changed

+41
-33
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
@@ -170,7 +170,7 @@ def process_gpt_response(self, input_tables, messages, response):
170170
logger.warning(error_message)
171171
result = {'status': 'other error', 'code': code_str, 'content': f"Unexpected error: {error_message}"}
172172
else:
173-
result = {'status': 'no transformation', 'code': "", 'content': input_tables[0]['rows']}
173+
result = {'status': 'error', 'code': "", 'content': "No code block found in the response. The model is unable to generate code to complete the task."}
174174

175175
result['dialog'] = [*messages, {"role": choice.message.role, "content": choice.message.content}]
176176
result['agent'] = 'DataRecAgent'

py-src/data_formulator/agents/agent_data_transform_v2.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ def process_gpt_response(self, input_tables, messages, response):
207207

208208
candidates = []
209209
for choice in response.choices:
210-
# logger.info("\n=== Data transformation result ===>\n")
211-
# logger.info(choice.message.content + "\n")
210+
print("\n=== Data transformation result ===>\n")
211+
print(choice.message.content + "\n")
212212

213213
json_blocks = extract_json_objects(choice.message.content + "\n")
214214
if len(json_blocks) > 0:
@@ -218,6 +218,9 @@ def process_gpt_response(self, input_tables, messages, response):
218218

219219
code_blocks = extract_code_from_gpt_response(choice.message.content + "\n", "python")
220220

221+
print("\n=== Code blocks ===>\n")
222+
print(code_blocks)
223+
221224
if len(code_blocks) > 0:
222225
code_str = code_blocks[-1]
223226

@@ -234,15 +237,18 @@ def process_gpt_response(self, input_tables, messages, response):
234237
logger.warning('Error occurred during code execution:')
235238
error_message = f"An error occurred during code execution. Error type: {type(e).__name__}"
236239
logger.warning(error_message)
237-
result = {'status': 'other error', 'code': code_str, 'content': error_message}
240+
result = {'status': 'error', 'code': code_str, 'content': error_message}
238241
else:
239-
result = {'status': 'no transformation', 'code': "", 'content': input_tables[0]['rows']}
242+
result = {'status': 'error', 'code': "", 'content': "No code block found in the response. The model is unable to generate code to complete the task."}
240243

241244
result['dialog'] = [*messages, {"role": choice.message.role, "content": choice.message.content}]
242245
result['agent'] = 'DataTransformationAgent'
243246
result['refined_goal'] = refined_goal
244247
candidates.append(result)
245248

249+
print("\n=== Candidates ===>\n")
250+
print(candidates)
251+
246252
return candidates
247253

248254

src/views/EncodingShelfCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export const EncodingShelfCard: FC<EncodingShelfCardProps> = function ({ chartId
328328
dispatch(dfActions.addMessages({
329329
"timestamp": Date.now(),
330330
"type": "error",
331-
"value": `Data formulation failed, please retry.`,
331+
"value": `Data formulation failed, please try again.`,
332332
"code": code,
333333
"detail": errorMessage
334334
}));

src/views/MessageSnackbar.tsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import IconButton from '@mui/material/IconButton';
88
import CloseIcon from '@mui/icons-material/Close';
99
import { DataFormulatorState, dfActions } from '../app/dfSlice';
1010
import { useDispatch, useSelector } from 'react-redux';
11-
import { Alert, alpha, Box, Paper, Tooltip, Typography } from '@mui/material';
11+
import { Alert, alpha, Box, Divider, Paper, Tooltip, Typography } from '@mui/material';
1212
import InfoIcon from '@mui/icons-material/Info';
1313
import AssignmentIcon from '@mui/icons-material/Assignment';
1414

@@ -156,38 +156,38 @@ export function MessageSnackbar() {
156156
</Snackbar> : ""}
157157
{message != undefined ? <Snackbar
158158
open={open && message != undefined}
159-
autoHideDuration={message?.type == "error" ? 15000 : 5000}
159+
autoHideDuration={message?.type == "error" ? 20000 : 10000}
160160
anchorOrigin={{vertical: 'bottom', horizontal: 'right'}}
161161
onClose={handleClose}
162162
action={action}
163163
>
164-
<Alert onClose={handleClose} severity={message?.type} sx={{ maxWidth: '400px' }}>
164+
<Alert icon={false} onClose={handleClose} severity={message?.type} sx={{ maxWidth: '400px' }}>
165165
<Typography fontSize={10} component="span" sx={{margin: "auto", opacity: 0.7}}>[{timestamp}]</Typography> &nbsp;
166-
{message?.value}
166+
<Typography fontSize={12} component="span" sx={{margin: "auto", fontWeight: 'bold'}}>{message?.value}</Typography>
167167
{message?.detail ?
168-
<>
169-
<br />
170-
<Typography fontSize={12} component="span" sx={{marginBottom: 0, fontWeight: 'bold'}}>
171-
[error details]
172-
</Typography>
173-
<br />
174-
<Typography fontSize={12} component="span" sx={{margin: "auto", opacity: 0.7}}>
175-
{message?.detail}
168+
<Divider textAlign="left" sx={{my: 1, fontSize: 12, opacity: 0.7}} > [details] </Divider>
169+
: ""}
170+
{message?.detail ?
171+
<Box
172+
sx={{
173+
borderRadius: 1,
174+
position: 'relative'
175+
}}
176+
>
177+
<Typography fontSize={12} >
178+
{message?.detail}
176179
</Typography>
177-
</>
180+
</Box>
178181
: ""}
179182
{message?.code ?
180-
<>
181-
<br />
182-
<Typography fontSize={12} component="span" sx={{marginBottom: 0, fontWeight: 'bold'}}>
183-
[generated code]
184-
</Typography>
185-
<Typography fontSize={10} component="span" sx={{margin: "auto", opacity: 0.7}}>
186-
<pre style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word', marginTop: 1 }}>
187-
{message?.code?.split('\n').filter(line => line.trim() !== '').join('\n')}
188-
</pre>
189-
</Typography>
190-
</>
183+
<Divider textAlign="left" sx={{my: 1, fontSize: 12, opacity: 0.7}} > [generated code] </Divider>
184+
: ""}
185+
{message?.code ?
186+
<Typography fontSize={10} component="span" sx={{margin: "auto", opacity: 0.7}}>
187+
<pre style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word', marginTop: 1 }}>
188+
{message?.code?.split('\n').filter(line => line.trim() !== '').join('\n')}
189+
</pre>
190+
</Typography>
191191
: ""}
192192
</Alert>
193193
</Snackbar> : ""}

src/views/ModelSelectionDialog.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
114114
}
115115
}, [newEndpoint]);
116116

117-
let modelExists = models.some(m => m.endpoint == newEndpoint && m.model == newModel && m.api_base == newApiBase && m.api_key == newApiKey && m.api_version == newApiVersion);
117+
let modelExists = models.some(m =>
118+
m.endpoint == newEndpoint && m.model == newModel && m.api_base == newApiBase
119+
&& m.api_key == newApiKey && m.api_version == newApiVersion);
118120

119121
let testModel = (model: ModelConfig) => {
120122
updateModelStatus(model, 'testing', "");
@@ -158,7 +160,7 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
158160
setNewApiVersion("2024-02-15");
159161
}
160162
}}
161-
options={['openai', 'azure', 'ollama', 'gemini', 'anthropic']}
163+
options={['openai', 'azure', 'ollama', 'anthropic', 'gemini']}
162164
renderOption={(props, option) => (
163165
<Typography {...props} onClick={() => setNewEndpoint(option)} sx={{fontSize: "0.875rem"}}>
164166
{option}
@@ -193,7 +195,7 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
193195
<TextField fullWidth size="small" type={showKeys ? "text" : "password"}
194196
InputProps={{ style: { fontSize: "0.875rem" } }}
195197
placeholder='leave blank if using keyless access'
196-
error={newEndpoint != "azure" && !newApiKey}
198+
error={!(newEndpoint == "azure" || newEndpoint == "ollama") && !newApiKey}
197199
value={newApiKey} onChange={(event: any) => { setNewApiKey(event.target.value); }}
198200
autoComplete='off'
199201
/>

0 commit comments

Comments
 (0)