Created
January 16, 2024 06:48
-
-
Save third774/6e781f5d9c3cbccb7326aef7bc640cee to your computer and use it in GitHub Desktop.
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
// 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