Skip to content

Commit 81a3cc0

Browse files
committed
thanks copilot reviewer, I'm addressing my logger issues...
1 parent 77ae246 commit 81a3cc0

File tree

4 files changed

+63
-27
lines changed

4 files changed

+63
-27
lines changed

py-src/data_formulator/agents/agent_data_rec.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ def process_gpt_response(self, input_tables, messages, response):
181181
result['refined_goal'] = refined_goal
182182
candidates.append(result)
183183

184+
logger.info("=== Recommendation Candidates ===>")
185+
for candidate in candidates:
186+
for key, value in candidate.items():
187+
if key in ['dialog', 'content']:
188+
logger.info(f"##{key}:\n{str(value)[:1000]}...")
189+
else:
190+
logger.info(f"## {key}:\n{value}")
191+
184192
return candidates
185193

186194

py-src/data_formulator/agents/agent_data_transform_v2.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,9 @@ def process_gpt_response(self, input_tables, messages, response):
224224

225225
code_blocks = extract_code_from_gpt_response(choice.message.content + "\n", "python")
226226

227-
logger.info("=== Code blocks ===>")
228-
logger.info(code_blocks)
229-
230227
if len(code_blocks) > 0:
231228
code_str = code_blocks[-1]
232229

233-
for table in input_tables:
234-
logger.info(f"Table: {table['name']}")
235-
logger.info(table['rows'])
236-
237230
try:
238231
result = py_sandbox.run_transform_in_sandbox2020(code_str, [t['rows'] for t in input_tables])
239232
result['code'] = code_str
@@ -256,8 +249,13 @@ def process_gpt_response(self, input_tables, messages, response):
256249
result['refined_goal'] = refined_goal
257250
candidates.append(result)
258251

259-
logger.info("=== Candidates ===>")
260-
logger.info(candidates)
252+
logger.info("=== Transform Candidates ===>")
253+
for candidate in candidates:
254+
for key, value in candidate.items():
255+
if key in ['dialog', 'content']:
256+
logger.info(f"##{key}:\n{str(value)[:1000]}...")
257+
else:
258+
logger.info(f"## {key}:\n{value}")
261259

262260
return candidates
263261

py-src/data_formulator/app.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ def test_model():
213213
content = request.get_json()
214214

215215
# contains endpoint, key, model, api_base, api_version
216-
print("content------------------------------")
217-
print(content)
216+
logger.info("content------------------------------")
217+
logger.info(content)
218218

219219
client = get_client(content['model'])
220220

@@ -226,8 +226,8 @@ def test_model():
226226
]
227227
)
228228

229-
print(f"model: {content['model']}")
230-
print(f"welcome message: {response.choices[0].message.content}")
229+
logger.info(f"model: {content['model']}")
230+
logger.info(f"welcome message: {response.choices[0].message.content}")
231231

232232
if "I can hear you." in response.choices[0].message.content:
233233
result = {
@@ -236,7 +236,7 @@ def test_model():
236236
"message": ""
237237
}
238238
except Exception as e:
239-
print(f"Error: {e}")
239+
logger.info(f"Error: {e}")
240240
error_message = str(e)
241241
result = {
242242
"model": content['model'],
@@ -250,13 +250,13 @@ def test_model():
250250

251251
@app.route("/", defaults={"path": ""})
252252
def index_alt(path):
253-
print(app.static_folder)
253+
logger.info(app.static_folder)
254254
return send_from_directory(app.static_folder, "index.html")
255255

256256
@app.errorhandler(404)
257257
def page_not_found(e):
258258
# your processing here
259-
print(app.static_folder)
259+
logger.info(app.static_folder)
260260
return send_from_directory(app.static_folder, "index.html") #'Hello 404!' #send_from_directory(app.static_folder, "index.html")
261261

262262
###### test functions ######
@@ -432,9 +432,14 @@ def derive_data():
432432
else:
433433
prev_messages = []
434434

435-
print("spec------------------------------")
436-
print(new_fields)
437-
print(instruction)
435+
logger.info("== input tables ===>")
436+
for table in input_tables:
437+
logger.info(f"===> Table: {table['name']} (first 5 rows)")
438+
logger.info(table['rows'][:5])
439+
440+
logger.info("== user spec ===")
441+
logger.info(new_fields)
442+
logger.info(instruction)
438443

439444
mode = "transform"
440445
if len(new_fields) == 0:
@@ -485,11 +490,15 @@ def refine_data():
485490
dialog = content["dialog"]
486491
new_instruction = content["new_instruction"]
487492
max_repair_attempts = content["max_repair_attempts"] if "max_repair_attempts" in content else 1
488-
489-
print("max_repair_attempts")
490-
print(max_repair_attempts)
491-
print("previous dialog")
492-
print(dialog)
493+
494+
logger.info("== input tables ===>")
495+
for table in input_tables:
496+
logger.info(f"===> Table: {table['name']} (first 5 rows)")
497+
logger.info(table['rows'][:5])
498+
499+
logger.info("== user spec ===>")
500+
logger.info(output_fields)
501+
logger.info(new_instruction)
493502

494503
# always resort to the data transform agent
495504
agent = DataTransformationAgentV2(client=client)

src/app/App.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,17 @@ const ConfigDialog: React.FC = () => {
334334
type="number"
335335
variant="outlined"
336336
value={formulateTimeoutSeconds}
337-
onChange={(e) => setFormulateTimeoutSeconds(parseInt(e.target.value))}
337+
onChange={(e) => {
338+
const value = parseInt(e.target.value);
339+
setFormulateTimeoutSeconds(value);
340+
}}
341+
inputProps={{
342+
min: 0,
343+
max: 3600,
344+
}}
345+
error={formulateTimeoutSeconds <= 0 || formulateTimeoutSeconds > 3600}
346+
helperText={formulateTimeoutSeconds <= 0 || formulateTimeoutSeconds > 3600 ?
347+
"Value must be between 1 and 3600 seconds" : ""}
338348
fullWidth
339349
/>
340350
<Typography variant="caption" color="text.secondary" sx={{ mt: 1, display: 'block' }}>
@@ -352,14 +362,24 @@ const ConfigDialog: React.FC = () => {
352362
type="number"
353363
variant="outlined"
354364
value={maxRepairAttempts}
355-
onChange={(e) => setMaxRepairAttempts(parseInt(e.target.value))}
365+
onChange={(e) => {
366+
const value = parseInt(e.target.value);
367+
setMaxRepairAttempts(value);
368+
}}
356369
fullWidth
370+
inputProps={{
371+
min: 1,
372+
max: 5,
373+
}}
374+
error={maxRepairAttempts <= 0 || maxRepairAttempts > 5}
375+
helperText={maxRepairAttempts <= 0 || maxRepairAttempts > 5 ?
376+
"Value must be between 1 and 5" : ""}
357377
/>
358378
<Typography variant="caption" color="text.secondary" sx={{ mt: 1, display: 'block' }}>
359379
Maximum number of times the LLM will attempt to repair code if generated code fails to execute (recommended = 1).
360380
</Typography>
361381
<Typography variant="caption" color="text.secondary" sx={{ mt: 1, display: 'block' }}>
362-
Higher values <span style={{fontStyle: 'italic'}}>might</span> increase chances of success but may take longer. Repair time is considered as part of the formulate timeout.
382+
Higher values might slightly increase the chance of success but can crash the backend. Repair time is as part of the formulate timeout.
363383
</Typography>
364384
</Box>
365385
</Box>
@@ -374,6 +394,7 @@ const ConfigDialog: React.FC = () => {
374394
<Button onClick={() => setOpen(false)}>Cancel</Button>
375395
<Button
376396
variant={hasChanges ? "contained" : "text"}
397+
disabled={!hasChanges || isNaN(maxRepairAttempts) || maxRepairAttempts <= 0 || maxRepairAttempts > 5 || isNaN(formulateTimeoutSeconds) || formulateTimeoutSeconds <= 0 || formulateTimeoutSeconds > 3600}
377398
onClick={() => {
378399
dispatch(dfActions.setConfig({formulateTimeoutSeconds, maxRepairAttempts}));
379400
setOpen(false);

0 commit comments

Comments
 (0)