Skip to content

Instantly share code, notes, and snippets.

View trevorstenson's full-sized avatar
🏠
Working from home

Trevor Stenson trevorstenson

🏠
Working from home
View GitHub Profile
@trevorstenson
trevorstenson / gpt3-sw-page-generator.js
Created February 20, 2023 22:21
A service worker that intercepts fetch events, and generates HTML pages on the fly from GPT-3 to return back to the client application.
const API_KEY = "<OPEN_AI_API_KEY_HERE>";
async function openai_request(prompt) {
let engine = "text-davinci-003";
const response = await fetch("https://api.openai.com/v1/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + API_KEY,
},