Skip to main content
Glama
by microsoft
code-opt-fn.genai.js2.46 kB
script({ title: "Code Patches", description: "Optimize code to run faster, modified from https://twitter.com/mattshumer_/status/1719403205950349588.", maxTokens: 2000, group: "samples", system: ["system.tools"], }) defTool("check_syntax", "Checks code for syntax errors", { "type": "object", "properties": { "code": { "type": "string", "description": "Code to check.", }, }, "required": ["code"], }, async (args) => { const { code } = args const { stdout } = await host.exec("node", ["genaisrc/check-syntax.js"], { stdin: code }) return stdout }) defTool("update_file", "Describes an update (patch) of a file.", { "type": "object", "properties": { "filename": { "type": "string", "description": "Filename to update.", }, "label": { "type": "string", "description": "Description of the change.", }, "lineStart": { "type": "string", "description": "The line number to start the patch.", }, "lineEnd": { "type": "string", "description": "The line number to end the patch.", }, "content": { "type": "string", "description": "The content to replace the patch with. If not provided, the patch will be deleted.", } }, "required": ["filename", "lineStart", "lineEnd"], }, (args) => { const { filename, lineStart, lineEnd, content, label } = args return { content: `${filename}[${lineStart}-${lineEnd}] ${content || ""} (${label || "no description"})`, edits: [{ type: "replace", filename, range: [parseInt(lineStart) - 1, parseInt(lineEnd) - 1], text: content, }] } }) // Modified from https://twitter.com/mattshumer_/status/1719403205950349588?s=46 def("FILE", env.files, { lineNumbers: true }) $` You are a world expert in making code run faster. You use any resource you can to do so. Given some code in FILE files, identify how long it might take to run. After that, identify which parts are key candidates to speed up. After that, order the candidates by ranking. Take the top-ranked candidate, check the syntax and update the code in the file to be faster. If the syntax is incorrect, try to fix the code. Do not explain your reasoning, just update the code. `

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/microsoft/genaiscript'

If you have feedback or need assistance with the MCP directory API, please join our Discord server