Forked from soumyajit7038/python-tools
Project Files
src / tools / runPython.ts
import { tool } from "@lmstudio/sdk";
import { z } from "zod";
import { runPythonCode } from "../utils/pythonRunner";
import { getToolDefinition } from "../utils/toolRegistry";
const TOOL_DEFINITION = getToolDefinition("run_python");
export const runPythonTool = tool({
name: TOOL_DEFINITION.name,
description: TOOL_DEFINITION.description,
parameters: {
code: z.string().min(1).max(20000).describe("Python source code to execute."),
timeoutSeconds: z
.number()
.int()
.min(1)
.max(20)
.optional()
.describe("Optional timeout in seconds. Defaults to 5. Maximum is 20."),
},
implementation: async ({ code, timeoutSeconds }) => {
return await runPythonCode(code, timeoutSeconds ?? 5);
},
});