tabby-chatgpt-plugin
Version:
32 lines (30 loc) • 1.16 kB
JavaScript
const axios = require("axios");
module.exports = {
name: "ChatGPT Integration",
description: "Send prompts to ChatGPT from the Tabby terminal.",
extendTerminal: (terminal) => {
terminal.onInput(async (input) => {
if (input.startsWith("chatgpt ")) {
const prompt = input.replace("chatgpt ", "");
try {
const response = await axios.post(
"https://api.openai.com/v1/completions",
{
model: "text-davinci-003",
prompt: prompt,
max_tokens: 150
},
{
headers: {
Authorization: `Bearer SUA_API_KEY`
}
}
);
terminal.write("\n" + response.data.choices[0].text.trim() + "\n");
} catch (error) {
terminal.write("\nErro ao conectar ao ChatGPT: " + error.message + "\n");
}
}
});
},
};