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

updated_functionality #27

Merged
merged 5 commits into from
Apr 27, 2023
Merged
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
80 changes: 63 additions & 17 deletions client/src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import Header from "../Components/Header";
import Footer from "../Components/Footer";
import MainContent from "../Components/MainContent";
// import Button from "react-bootstrap/Button";
//import Button from "react-bootstrap/Button";
//import App from "../App";

import "./Home.css";
// import logo from "./logo.svg";
// import logo from "./logo.svg"; //import for a logo

export function Home() {
// const [val, setVal] = useState("");
/* const [val, setVal] = useState("");
const [content, setContent] = useState("");*/
/*const [message, setMessage] = useState("Loading...");

useEffect(() => {
Expand All @@ -28,24 +30,68 @@ export function Home() {
console.error(err);
});
}, []);*/
/*const onSubmit = (e) => {
e.preventDefault(content);

if (!content) {
alert("Add some text");
return;
} else if (val === content) {
alert("update text please");
} else {
onAdd(content);
console.log(onAdd);
console.log(content);
setContent(content);
setVal(content);
}
};*/

/*const onAdd = async ({ content }) => {
const result = await (
await fetch("http://localhost:3100/api/corrections", {
//const result = await(await fetch(`${ api }/corrections`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
content,
}),
//body: JSON.stringify(item),
})
).json();

if (!result.error) {
console.log(result);
//navigate("/About");
//window.location.reload();
} else {
console.log(result.error);
}
};*/

return (
<div>
<Header />
{/* <p>Hello World</p> */}
{/* this the label */}
{/* <label htmlFor="review">Review</label> */}
{/*textarea with spellcheck function*/}
{/* <textarea
value={val}
onChange={(e) => setVal(e.target.value)}
spellCheck={true}
id="review"
name="review"
placeholder="write your message here"
rows="10"
cols="50"
></textarea>
{/* <p>Hello World</p>
this the label
<form id="inputForm" onSubmit={onSubmit}>
<div>
<label htmlFor="review">Review</label>
<textarea
//spellCheck={true}
id="review"
name="review"
placeholder="write your message here"
rows="10"
cols="50"
value={content}
onChange={(e) => setContent(e.target.value)}
></textarea>
<input type="submit" value="Submit" />
</div>
</form>
<Button variant="primary">BootstrapButton</Button> */}
<MainContent />

Expand Down
25 changes: 18 additions & 7 deletions server/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Router } from "express";
import { Configuration, OpenAIApi } from "openai";

// import db from "./db";
//import db from "./db";

import logger from "./utils/logger";

Expand All @@ -11,7 +11,7 @@ router.get("/", (_, res) => {
logger.debug("Welcoming everyone...");
res.json({ message: "Hello, world!" });
});

//get corrections route
router.get("/corrections", async (req, res) => {
const apiKey = process.env.OPENAI_KEY;
const configuration = new Configuration({
Expand All @@ -21,14 +21,25 @@ router.get("/corrections", async (req, res) => {
// const responseGPT = await openai.listEngines();
// eslint-disable-next-line no-console
// console.log(responseGPT.data);
const text = "I iz v good et coding fam..";
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: `Can you correct this sentence for grammatical issues and make it sound like a nerd: ${text}`,
const text = "I iz v good et coding..";
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{
role: "user",
content: `Can you correct this sentence for grammatical issues and give it three options: ${text}`,
},
],
});
/*const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: `Can you correct this sentence for grammatical issues and make it old school : ${text}`,
});*/
// eslint-disable-next-line no-console
console.log(completion.data.choices[0].text);
console.log(completion.data.choices[0].message);
//console.log(completion.data.choices[0].text);
res.json({ msg: completion.data });
});
//"text-davinci-003" "gpt-3.5-turbo-0301"

export default router;