Created
October 14, 2023 10:00
-
-
Save mzbac/3a2bbca2a7219442de0e2372ea627776 to your computer and use it in GitHub Desktop.
mac automator script for local llama
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/completion"; | |
const prompt = `[INST] Corrects and rephrase user text grammar errors delimited by triple backticks to standard English. | |
Text=\`\`\`she no went to market\`\`\` [/INST] | |
[INST] Output: She didn’t go the market. [/INST] | |
[INST] Text=\`\`\`${input}\`\`\` [/INST] | |
[INST] Output:`; | |
const requestData = { | |
prompt: prompt, | |
temperature: 0.1, | |
stop: ["[/INST]"], | |
}; | |
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.content; | |
return result.trim(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment