shitton
This commit is contained in:
@@ -5,6 +5,9 @@ import path from "node:path";
|
||||
import {AiTool} from "../tool-types";
|
||||
import {Environment} from "../../common/environment";
|
||||
import {randomUUID} from "node:crypto";
|
||||
import {toolsLogger} from "./tool-logger";
|
||||
|
||||
const logger = toolsLogger.child("python-interpreter");
|
||||
|
||||
export const PYTHON_INTERPRETER_TOOL_NAME = "python_interpreter";
|
||||
|
||||
@@ -203,17 +206,17 @@ export async function runPythonInterpreter(
|
||||
};
|
||||
}
|
||||
|
||||
console.time("python.syntax");
|
||||
const syntaxStartedAt = Date.now();
|
||||
const syntax = await validatePythonSyntax(args.code, options);
|
||||
console.timeEnd("python.syntax");
|
||||
logger.debug("syntax.done", {duration: logger.duration(syntaxStartedAt), ok: syntax.ok});
|
||||
|
||||
if (!syntax.ok) {
|
||||
return syntax;
|
||||
}
|
||||
|
||||
console.time("python.execution");
|
||||
const executionStartedAt = Date.now();
|
||||
const result = await executePythonCode(args, options);
|
||||
console.timeEnd("python.execution");
|
||||
logger.debug("execution.done", {duration: logger.duration(executionStartedAt), ok: result.ok, phase: result.phase});
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -293,7 +296,8 @@ async function executePythonCode(
|
||||
args: PythonInterpreterArgs,
|
||||
options: PythonInterpreterOptions = {},
|
||||
): Promise<PythonToolResult> {
|
||||
console.log("EXECUTE_PYTHON_CODE", "ARGS: ", JSON.stringify(args), "; OPTIONS: ", JSON.stringify(options));
|
||||
const startedAt = Date.now();
|
||||
logger.info("execute.start", {args, options});
|
||||
|
||||
const pythonBinary =
|
||||
options.pythonBinary ?? process.env.PYTHON_INTERPRETER_BINARY ?? "C:\\Users\\meloda\\Desktop\\AI_BOT\\.venv\\Scripts\\python.exe";
|
||||
@@ -329,7 +333,7 @@ async function executePythonCode(
|
||||
mode: 0o600,
|
||||
});
|
||||
|
||||
console.log("EXECUTE_PYTHON_CODE", "SCRIPT FILE WRITTEN", new Date());
|
||||
logger.debug("script.written", {tempDir, userScriptPath, runnerPath, duration: logger.duration(startedAt)});
|
||||
|
||||
const result = await runProcess({
|
||||
command: pythonBinary,
|
||||
@@ -346,10 +350,10 @@ async function executePythonCode(
|
||||
},
|
||||
});
|
||||
|
||||
console.log("EXECUTE_PYTHON_CODE", "RESULT ACHIEVED", new Date());
|
||||
logger.debug("process.done", {duration: logger.duration(startedAt), exitCode: result.exitCode, timedOut: result.timedOut, outputTruncated: result.outputTruncated});
|
||||
|
||||
if (result.timedOut) {
|
||||
console.log("EXECUTE_PYTHON_CODE", "RESULT ERROR TIMED OUT", new Date());
|
||||
logger.warn("process.timeout", {duration: logger.duration(startedAt)});
|
||||
return {
|
||||
ok: false,
|
||||
phase: "execution",
|
||||
@@ -365,7 +369,7 @@ async function executePythonCode(
|
||||
}
|
||||
|
||||
if (result.outputTruncated) {
|
||||
console.log("EXECUTE_PYTHON_CODE", "RESULT ERROR TRUNCATED", new Date());
|
||||
logger.warn("process.output_truncated", {duration: logger.duration(startedAt), stdoutChars: result.stdout.length, stderrChars: result.stderr.length});
|
||||
|
||||
return {
|
||||
ok: false,
|
||||
@@ -382,7 +386,7 @@ async function executePythonCode(
|
||||
}
|
||||
|
||||
if (result.exitCode !== 0) {
|
||||
console.log("EXECUTE_PYTHON_CODE", "RESULT ERROR EXIT CODE", new Date(), "\n", JSON.stringify(result, null, 2));
|
||||
logger.warn("process.non_zero_exit", {duration: logger.duration(startedAt), result});
|
||||
|
||||
return {
|
||||
ok: false,
|
||||
@@ -398,7 +402,7 @@ async function executePythonCode(
|
||||
};
|
||||
}
|
||||
|
||||
console.log("EXECUTE_PYTHON_CODE", "RESULT NORMAL", new Date());
|
||||
logger.debug("process.ok", {duration: logger.duration(startedAt)});
|
||||
|
||||
const {
|
||||
artifacts,
|
||||
@@ -420,7 +424,7 @@ async function executePythonCode(
|
||||
skippedArtifacts,
|
||||
};
|
||||
} catch (error) {
|
||||
console.log("EXECUTE_PYTHON_CODE", "RESULT ERROR", new Date());
|
||||
logger.error("execute.failed", {duration: logger.duration(startedAt), error});
|
||||
return {
|
||||
ok: false,
|
||||
phase: "internal",
|
||||
|
||||
Reference in New Issue
Block a user