function escapeShellArg(str) { return "'" + str.replace(/'/g, "'\\''") + "'"; } const removeBackticks = (str) => { // remove leading backticks str = str.replace(/^(```\n|```)/g, ""); // remove tailing backticks and everything after const index = str.lastIndexOf("```"); if (index !== -1) { return str.slice(0, index); } return str; }; function run(input, parameters) { const apiEndpoint = "http://localhost:8080/v1/completions"; const prompt = `<|im_start|>system Please correct, polish, or translate the text delimited by triple backticks to standard English.<|im_end|> <|im_start|>user Text=\`\`\`neither 经理或员工 has been informed about the meeting\`\`\`<|im_end|> <|im_start|>assistant Output=Neither the manager nor the employees have been informed about the meeting.<|im_end|> <|im_start|>user Text=\`\`\`${input}\`\`\`<|im_end|> <|im_start|>assistant Output=`; const requestData = { prompt: prompt, temperature: 0.1, stop: ["<|im_end|"], }; const curlCommand = `curl ${apiEndpoint} -X POST -v -H 'Content-Type: application/json' -d ${escapeShellArg( JSON.stringify(requestData) )}`; // Instantiate the Application object const app = Application.currentApplication(); app.includeStandardAdditions = true; const apiResultJSON = app.doShellScript(curlCommand); // Parse the JSON response and extract the result const apiResultObject = JSON.parse(apiResultJSON); const result = apiResultObject.choices[0].text; return result.trim(); }