Fix Spelling and Grammar (using OpenAI)

Open fix-spelling-and-grammar in Script Kit

// Name: Fix Spelling and Grammar
// Author: Kevin Kipp
// Email:
// Twitter:
// Github:
import '@johnlindquist/kit';
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: await env('OPENAI_API_KEY', {
secret: true,
const text = await getSelectedText();
const completion = await{
messages: [
role: 'user',
content: `You are an editor and you are tasked with fixing the spelling and grammar of the following text:
Text to fix:
The corrected text is:`,
model: 'gpt-3.5-turbo',
temperature: 0,
const insertText = await editor(completion.choices[0].message.content);
await setSelectedText(insertText);