Skip to content

Instantly share code, notes, and snippets.

@third774
Created January 16, 2024 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save third774/6e781f5d9c3cbccb7326aef7bc640cee to your computer and use it in GitHub Desktop.
Save third774/6e781f5d9c3cbccb7326aef7bc640cee to your computer and use it in GitHub Desktop.
// Name: Fix Spelling and Grammar
// Author: Kevin Kipp
// Email: kevin.kipp@gmail.com
// Twitter: https://twitter.com/kevin_kipp
// Github: https://github.com/third774
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 openai.chat.completions.create({
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:
${text}
---
The corrected text is:`,
},
],
model: 'gpt-3.5-turbo',
temperature: 0,
});
const insertText = await editor(completion.choices[0].message.content);
await setSelectedText(insertText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment