Skip to content

Instantly share code, notes, and snippets.

@mzbac
Created July 26, 2025 13:14
Show Gist options
  • Save mzbac/754829a569f57232d2bcac3eb91a44df to your computer and use it in GitHub Desktop.
Save mzbac/754829a569f57232d2bcac3eb91a44df to your computer and use it in GitHub Desktop.
automator grammar check
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
<think>
</think>
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment