Skip to content

Instantly share code, notes, and snippets.

@third774
Created January 16, 2024 06:48
Show Gist options
  • Save third774/031ee03124495aed893c45d9f8b2c0fa to your computer and use it in GitHub Desktop.
Save third774/031ee03124495aed893c45d9f8b2c0fa to your computer and use it in GitHub Desktop.
// Name: Fix Spelling and Grammar
// Author: Kevin Kipp
// Email: [email protected]
// 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