Created
November 28, 2023 11:19
-
-
Save vladholubiev/d455623e69babe4c92eb880b3bb42c75 to your computer and use it in GitHub Desktop.
Raycast extension to rewrite text from clipboard to sound like a native speaker, and copy it back to clipboard.
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
import { showHUD, Clipboard } from "@raycast/api"; | |
import OpenAI from 'openai'; | |
import dotenv from 'dotenv'; | |
dotenv.config({ path: '~/.zshrc' }); | |
const openai = new OpenAI({ | |
apiKey: process.env.OPENAI_API_KEY ?? '', | |
}); | |
export default async function main() { | |
const currentClipboard = await Clipboard.readText(); | |
const chatCompletion = await openai.chat.completions.create({ | |
messages: [{ role: 'user', content: `\`\`\` | |
${currentClipboard} | |
\`\`\` | |
Rewrite the text above to sound more like a native speaker, while doing minimal modifications to the text.` }], | |
model: 'gpt-4-1106-preview', | |
temperature:0, | |
max_tokens:3000 | |
}); | |
const response = chatCompletion.choices[0].message.content ?? ''; | |
await Clipboard.copy(response); | |
await showHUD(response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment