From f884154a64b22d5cd8f18dc7a248d93da71257f8 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:01:16 -0500 Subject: [PATCH 001/125] Delete .env --- .env | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index fddcbcdc1..000000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -REACT_APP_API_KEY=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 -REACT_APP_API_KEY=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 From 3e1b4d7f92a280d97e967eade1ff656fc38ee711 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:53:21 -0500 Subject: [PATCH 002/125] Update generate.js --- pages/api/generate.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pages/api/generate.js b/pages/api/generate.js index 8eba30734..45a1ed15c 100644 --- a/pages/api/generate.js +++ b/pages/api/generate.js @@ -1,15 +1,23 @@ +// Imports the Configuration and OpenAIApi classes from the openai library import { Configuration, OpenAIApi } from 'openai'; +// Creates a Configuration instance with the OpenAI API key from the environment variable const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); +// Creates an OpenAIApi instance using the Configuration instance const openai = new OpenAIApi(configuration); + +// Define the prefix for the API prompt const basePromptPrefix = ""; + +// Define the generateAction function const generateAction = async (req, res) => { - // Run first prompt + // Log the API request console.log(`API: ${basePromptPrefix}${req.body.userInput}`) + // Call the OpenAI API to generate a response to the prompt const baseCompletion = await openai.createCompletion({ model: 'text-davinci-003', prompt: `${basePromptPrefix}${req.body.userInput}`, @@ -17,9 +25,12 @@ const generateAction = async (req, res) => { max_tokens: 250, }); + // Get the response from the API call const basePromptOutput = baseCompletion.data.choices.pop(); + // Return the response to the client res.status(200).json({ output: basePromptOutput }); }; -export default generateAction; \ No newline at end of file +// Export the generateAction function +export default generateAction; From 082d2f5640a3132e1d461bb743029d812b4e9396 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:01:00 -0500 Subject: [PATCH 003/125] Create .env --- .env | 1 + 1 file changed, 1 insertion(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 000000000..18f4d861d --- /dev/null +++ b/.env @@ -0,0 +1 @@ +API_KEY=${process.env.API_KEY} From 11d8b64335f3c3a03e993e5620e90cf5d0847c7b Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:04:56 -0500 Subject: [PATCH 004/125] Create secrets-managers --- secrets-managers | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 secrets-managers diff --git a/secrets-managers b/secrets-managers new file mode 100644 index 000000000..150e4a651 --- /dev/null +++ b/secrets-managers @@ -0,0 +1,23 @@ +require('dotenv').config(); + +const { Octokit } = require("@octokit/rest"); +const octokit = new Octokit(); + +async function getSecret(secretName) { + const result = await octokit.actions.getSecret({ + owner: process.env.GITHUB_REPOSITORY_OWNER, + repo: process.env.GITHUB_REPOSITORY_NAME, + name: secretName + }); + return result.data.value; +} + +async function main() { + const apiKey = await getSecret("OPENAI_API_KEY"); + + console.log(`Your OpenAI API key is: ${apiKey}`); +} + +main().catch(error => { + console.error(error); +}); From e3d948c5859584ac5c8dbe207e886265b2a7e8a1 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:10:11 -0500 Subject: [PATCH 005/125] Delete secrets-managers --- secrets-managers | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 secrets-managers diff --git a/secrets-managers b/secrets-managers deleted file mode 100644 index 150e4a651..000000000 --- a/secrets-managers +++ /dev/null @@ -1,23 +0,0 @@ -require('dotenv').config(); - -const { Octokit } = require("@octokit/rest"); -const octokit = new Octokit(); - -async function getSecret(secretName) { - const result = await octokit.actions.getSecret({ - owner: process.env.GITHUB_REPOSITORY_OWNER, - repo: process.env.GITHUB_REPOSITORY_NAME, - name: secretName - }); - return result.data.value; -} - -async function main() { - const apiKey = await getSecret("OPENAI_API_KEY"); - - console.log(`Your OpenAI API key is: ${apiKey}`); -} - -main().catch(error => { - console.error(error); -}); From 14137594ed74087b27eebc7b618936953f26830a Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:20:35 -0500 Subject: [PATCH 006/125] Update index.js --- pages/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pages/index.js b/pages/index.js index 944b24d92..caaec58f4 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,4 +1,5 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect} from 'react'; +import axios from "axios"; const Home = () => { const [userInput, setUserInput] = useState(''); @@ -28,6 +29,17 @@ const Home = () => { setApiOutput(`${output.text}`); setIsGenerating(false); } + const baseCompletion = await openai.createCompletion({ + model: 'text-davinci-003', + prompt: `${basePromptPrefix}${req.body.userInput}`, + temperature: 0.7, + max_tokens: 250, + }); + + const basePromptOutput = baseCompletion.data.choices.pop(); + + res.status(200).json({ output: basePromptOutput }); +}; return (
From 298c7ac2ecf87eac21b23da590280e0b7213000c Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:22:14 -0500 Subject: [PATCH 007/125] Update index.js --- pages/index.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pages/index.js b/pages/index.js index caaec58f4..22c921004 100644 --- a/pages/index.js +++ b/pages/index.js @@ -21,20 +21,6 @@ const Home = () => { }, body: JSON.stringify({ userInput }), }); - - const data = await response.json(); - const { output } = data; - console.log("OpenAI replied...", output.text) - - setApiOutput(`${output.text}`); - setIsGenerating(false); - } - const baseCompletion = await openai.createCompletion({ - model: 'text-davinci-003', - prompt: `${basePromptPrefix}${req.body.userInput}`, - temperature: 0.7, - max_tokens: 250, - }); const basePromptOutput = baseCompletion.data.choices.pop(); From e957b56d2678fde210414143ba62a503c78a8e87 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:35:09 -0500 Subject: [PATCH 008/125] Update index.js --- pages/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pages/index.js b/pages/index.js index 22c921004..050bc4505 100644 --- a/pages/index.js +++ b/pages/index.js @@ -3,6 +3,10 @@ import axios from "axios"; const Home = () => { const [userInput, setUserInput] = useState(''); + const onUserChangedText = (event) => { + console.log(event.target.value); + setUserInput(event.target.value); +}; const [apiOutput, setApiOutput] = useState(''); const [isGenerating, setIsGenerating] = useState(false); From 5bce52d11a3808bf0fd165e4c180eba6ed8ed879 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:38:02 -0500 Subject: [PATCH 009/125] Update index.js --- pages/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/index.js b/pages/index.js index 050bc4505..9f32cf3f4 100644 --- a/pages/index.js +++ b/pages/index.js @@ -3,10 +3,10 @@ import axios from "axios"; const Home = () => { const [userInput, setUserInput] = useState(''); - const onUserChangedText = (event) => { +}; +const onUserChangedText = (event) => { console.log(event.target.value); setUserInput(event.target.value); -}; const [apiOutput, setApiOutput] = useState(''); const [isGenerating, setIsGenerating] = useState(false); From f1ed38103cedd5821dd232055b4a4cbe7674c627 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:41:56 -0500 Subject: [PATCH 010/125] Update index.js --- pages/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pages/index.js b/pages/index.js index 9f32cf3f4..973a24c80 100644 --- a/pages/index.js +++ b/pages/index.js @@ -4,9 +4,6 @@ import axios from "axios"; const Home = () => { const [userInput, setUserInput] = useState(''); }; -const onUserChangedText = (event) => { - console.log(event.target.value); - setUserInput(event.target.value); const [apiOutput, setApiOutput] = useState(''); const [isGenerating, setIsGenerating] = useState(false); @@ -25,7 +22,9 @@ const onUserChangedText = (event) => { }, body: JSON.stringify({ userInput }), }); - + const onUserChangedText = (event) => { + console.log(event.target.value); + setUserInput(event.target.value); const basePromptOutput = baseCompletion.data.choices.pop(); res.status(200).json({ output: basePromptOutput }); From 77fe85de7f2ab4cac759f6056721cdbd930ff93d Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:45:33 -0500 Subject: [PATCH 011/125] Update index.js --- pages/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pages/index.js b/pages/index.js index 973a24c80..1651cd008 100644 --- a/pages/index.js +++ b/pages/index.js @@ -2,7 +2,9 @@ import React, { useState, useEffect} from 'react'; import axios from "axios"; const Home = () => { - const [userInput, setUserInput] = useState(''); + const [userInput, setUserInput] = useState(''); const onUserChangedText = (event) => { + console.log(event.target.value); + setUserInput(event.target.value); }; const [apiOutput, setApiOutput] = useState(''); const [isGenerating, setIsGenerating] = useState(false); @@ -22,9 +24,7 @@ const Home = () => { }, body: JSON.stringify({ userInput }), }); - const onUserChangedText = (event) => { - console.log(event.target.value); - setUserInput(event.target.value); + const basePromptOutput = baseCompletion.data.choices.pop(); res.status(200).json({ output: basePromptOutput }); From 5af3efd0695dd40de983e7f188169b2485056131 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:50:23 -0500 Subject: [PATCH 012/125] Update index.js --- pages/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pages/index.js b/pages/index.js index 1651cd008..c8cf4cce9 100644 --- a/pages/index.js +++ b/pages/index.js @@ -2,9 +2,7 @@ import React, { useState, useEffect} from 'react'; import axios from "axios"; const Home = () => { - const [userInput, setUserInput] = useState(''); const onUserChangedText = (event) => { - console.log(event.target.value); - setUserInput(event.target.value); + const [userInput, setUserInput] = useState(''); }; const [apiOutput, setApiOutput] = useState(''); const [isGenerating, setIsGenerating] = useState(false); From 0cecdafc09bb6aa3fb3616605c9a12afa9b4f760 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:54:13 -0500 Subject: [PATCH 013/125] Update index.js --- pages/index.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pages/index.js b/pages/index.js index c8cf4cce9..63a9419f2 100644 --- a/pages/index.js +++ b/pages/index.js @@ -3,7 +3,6 @@ import axios from "axios"; const Home = () => { const [userInput, setUserInput] = useState(''); -}; const [apiOutput, setApiOutput] = useState(''); const [isGenerating, setIsGenerating] = useState(false); @@ -22,10 +21,6 @@ const Home = () => { }, body: JSON.stringify({ userInput }), }); - - const basePromptOutput = baseCompletion.data.choices.pop(); - - res.status(200).json({ output: basePromptOutput }); }; return ( From aacc22ab4891f6409b3417cf519775490340ce39 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 17:10:41 -0500 Subject: [PATCH 014/125] Update index.js --- pages/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pages/index.js b/pages/index.js index 63a9419f2..3fcc8a141 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,6 +1,3 @@ -import React, { useState, useEffect} from 'react'; -import axios from "axios"; - const Home = () => { const [userInput, setUserInput] = useState(''); const [apiOutput, setApiOutput] = useState(''); @@ -14,14 +11,17 @@ const Home = () => { setIsGenerating(true); console.log("Calling OpenAI...") - const response = await fetch('/api/generate', { + const response = await fetch(`/api/generate?apiKey=${process.env.API_KEY}`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ userInput }), }); -}; + const responseJson = await response.json(); + setApiOutput(responseJson.output); + setIsGenerating(false); + }; return (
@@ -56,3 +56,5 @@ const Home = () => { export default Home; + + From 88a3a1be41128c4b7f74c899f0685663af5a5415 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 17:17:12 -0500 Subject: [PATCH 015/125] Update index.js --- pages/index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pages/index.js b/pages/index.js index 3fcc8a141..3ed28573a 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,3 +1,6 @@ +import React, { useState, useEffect} from 'react'; +import axios from "axios"; + const Home = () => { const [userInput, setUserInput] = useState(''); const [apiOutput, setApiOutput] = useState(''); @@ -11,16 +14,20 @@ const Home = () => { setIsGenerating(true); console.log("Calling OpenAI...") - const response = await fetch(`/api/generate?apiKey=${process.env.API_KEY}`, { + const response = await fetch('/api/generate', { method: 'POST', headers: { 'Content-Type': 'application/json', + 'Authorization': `Bearer ${process.env.API_KEY}` }, body: JSON.stringify({ userInput }), }); - const responseJson = await response.json(); - setApiOutput(responseJson.output); - setIsGenerating(false); + + if (response.ok) { + const json = await response.json(); + setApiOutput(json.text); + setIsGenerating(false); + } }; return ( @@ -49,6 +56,9 @@ const Home = () => {
+
+

{apiOutput}

+
); @@ -58,3 +68,4 @@ export default Home; + From f357d988e6c5d212155b6f2eacfeb82e0af502d3 Mon Sep 17 00:00:00 2001 From: David Fisher <123786348+alfrencho@users.noreply.github.com> Date: Mon, 30 Jan 2023 17:51:57 -0500 Subject: [PATCH 016/125] Update index.js --- pages/index.js | 83 +++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 61 deletions(-) diff --git a/pages/index.js b/pages/index.js index 3ed28573a..8564ed680 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,70 +1,31 @@ -import React, { useState, useEffect} from 'react'; -import axios from "axios"; - -const Home = () => { - const [userInput, setUserInput] = useState(''); - const [apiOutput, setApiOutput] = useState(''); - const [isGenerating, setIsGenerating] = useState(false); - - const onUserChangedText = (event) => { - setUserInput(event.target.value); - }; - - const callGenerateEndpoint = async () => { - setIsGenerating(true); - - console.log("Calling OpenAI...") - const response = await fetch('/api/generate', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${process.env.API_KEY}` - }, - body: JSON.stringify({ userInput }), - }); - - if (response.ok) { - const json = await response.json(); - setApiOutput(json.text); - setIsGenerating(false); +import React, { useState, useEffect } from 'react'; + +function MyComponent() { + const [isMounted, setIsMounted] = useState(false); + const [myState, setMyState] = useState(initialValue); + + useEffect(() => { + setIsMounted(true); + return () => { + setIsMounted(false); + }; + }, []); + + function handleClick() { + if (isMounted) { + setMyState(newValue); } - }; + } return ( -
-
-
-
-

574WARD Marketing Assistant

-
-
-

Build The Bend

-
-
-
-