Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 126 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"homepage": "https://github.com/InboxSDK/hello-world#readme",
"dependencies": {
"@inboxsdk/core": "^0.2.20"
"@inboxsdk/core": "^0.2.20",
"openai": "^3.1.0"
},
"devDependencies": {
"copy-webpack-plugin": "^11.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_KEY = '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';
78 changes: 72 additions & 6 deletions src/content.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,82 @@
import * as InboxSDK from '@inboxsdk/core';
import { Configuration, OpenAIApi } from "openai";

InboxSDK.load(2, "Hello World!").then((sdk) => {
// the SDK has been loaded, now do something with it!

//envVariables= process.env
//const {API_OPEN} = envVariables
const apiKey = "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"
//const apiKey = API_OPEN;
console.log(apiKey)

async function generateText(prompt) {


// Make the API request
const response = await fetch('https://api.openai.com/v1/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
'Access-Control-Allow-Origin': '*'
},
body: JSON.stringify({
"model": "text-davinci-002",
"prompt": prompt,
"max_tokens": 2048
})
});
const json = await response.json();
console.log(json)
console.log(json.choices.text)

console.log(json.choices)
console.log(json.choices["0"].text)


return json.choices["0"].text;

}

InboxSDK.load(2, "Hello World!", { timeout: 30000 }).then((sdk) => {
sdk.Compose.registerComposeViewHandler((composeView) => {
// a compose view has come into existence, do something with it!
composeView.addButton({
title: "My Nifty Button!",
title: "Generate Email Response",
iconUrl:
"https://lh5.googleusercontent.com/itq66nh65lfCick8cJ-OPuqZ8OUDTIxjCc25dkc4WUT1JG8XG3z6-eboCu63_uDXSqMnLRdlvQ=s128-h128-e365",
onClick(event) {
event.composeView.insertTextIntoBodyAtCursor("Hello World!");
},
// Create a form element
const form = document.createElement('form');
form.innerHTML = `
<label for="prompt">What is the email about?</label><br>
<input type="text" id="prompt" name="prompt"><br>
<input type="submit" value="Generate Email">
`;
// Add the form to the compose view
event.composeView.insertHTMLIntoBodyAtCursor(form);

// Add a submit event listener to the form
form.addEventListener('submit', async (e) => {
e.preventDefault();
// Get the value of the prompt input field
const prompt = form.querySelector('#prompt').value;

console.log(prompt)

// Declare the response variable
let response;
// Generate the email response
response = await generateText(prompt);
console.log("m")
console.log(response)
console.log("i")

// Insert the email response into the compose view
event.composeView.setBodyText(response);
console.log("mmmmm")
console.log(response)
form.remove();
});
}
});
});
});
2 changes: 1 addition & 1 deletion static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"host_permissions": [
"https://mail.google.com/"
],
"manifest_version": 3
"manifest_version": 4
}