Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple call #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -7,12 +7,14 @@

# testing
/coverage
/.history

# production
/build

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
37 changes: 28 additions & 9 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
]
},
"dependencies": {
"dotenv": "^16.3.1",
"express": "^4.17.3"
},
"devDependencies": {
27 changes: 27 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@
const express = require('express')
const path = require("path");
const app = express()
require('dotenv').config()

let bearerToken = process.env.OPEN_AI_KEY;
// #############################################################################
// This configures static hosting for files in /public that have the extensions
// listed in the array.
@@ -18,6 +20,31 @@ app.use(express.static('build', options))

const port = process.env.PORT || 3000

app.post("/generateBlog", async (req, response)=>{
console.log(req.body)

await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Authorization" : "Bearer " + bearerToken,
"Content-Type": "application/json"
},
body: JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Say whadup doc!"}],
"temperature": 0.7
})
}).then(res=>{
console.log(res.body)
response.send(res.body)
}).catch((err)=>{
response.send("error")
})
});

app.listen(port, () => {
console.log(`React app listening at http://localhost:${port}`)
})
55 changes: 37 additions & 18 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -2,24 +2,43 @@ import logo from './logo.svg';
import './App.css';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);

let generateText = async () => {
console.log("generate logo");

fetch("/generateBlog", {
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"hey":"yo"
})
}).then(res=>{
console.log("Response", res)
})
}

// let generateLogo = async () => {

// }

return (
<div className="App">
<header className="App-header">

<button onClick={generateText}>Generate Blog</button>



{/* <button onClick={generateLogo}>Generate Logo</button> */}

</header>
</div>
);
}

export default App;