This is a chrome extension to show the sentiment of each tweet on your timeline :)
This is build with GPT-3 by Open AI.
For demonstration, it shows below in the demo video.
https://user-images.githubusercontent.com/980588/201276868-290e7c8f-5bd0-4eb1-b270-24b26600dfab.mp4
You need to build an API to call GPT-3 and put it here.
I quickly made it on Deno Deploy (I really wanna use Kuiq, but Supabase Edge Functions (Kuiq uses it behind the scene) currently doesn't recognize XMLHttpRequest
even with import "https://deno.land/x/[email protected]/mod.ts"
, so I can't use it ).
This is my code for your reference.
import "https://deno.land/x/[email protected]/mod.ts";
import { Configuration, OpenAIApi } from "https://esm.sh/[email protected]"
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import { oakCors } from "https://deno.land/x/cors/mod.ts";
const router = new Router();
router.get('/', async (context) => {
const configuration = new Configuration({
apiKey: "YOUR OPEN AI API KEY"
});
const openai = new OpenAIApi(configuration);
const u = new URL(context.request.url);
const tweet = u.searchParams.get('tweet')
if (!tweet) {
context.response.body = 'no query'
return
}
try {
const response = await openai.createCompletion({
model: "text-davinci-002",
prompt: `Decide whether a Tweet's sentiment is positive, neutral, or negative.\n\nTweet: \"${tweet}\"\nSentiment:`,
temperature: 0,
max_tokens: 60,
top_p: 1,
frequency_penalty: 0.5,
presence_penalty: 0,
});
context.response.body = response
} catch(err) {
context.response.body = {status: 'error', detail: err.message}
}
})
const app = new Application();
app.use(oakCors()); // Enable CORS for All Routes
app.use(router.routes());
console.info("CORS-enabled web server listening on port 8000");
await app.listen({ port: 8000 });