From 4c94060068c880e1d259f7b16962c7aa4747e8ae Mon Sep 17 00:00:00 2001 From: Roman-hal <85693082+Roman-Hal@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:34:18 +0100 Subject: [PATCH 1/4] upadated_functionality updated of the functionality of the textarea and backend --- client/src/pages/Home.js | 70 +++++++++++++++++++++++++++++++++------- server/api.js | 18 +++++++---- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/client/src/pages/Home.js b/client/src/pages/Home.js index 55f715c..c341a3b 100644 --- a/client/src/pages/Home.js +++ b/client/src/pages/Home.js @@ -4,12 +4,14 @@ import { useState } from "react"; import Header from "../Components/Header"; import Footer from "../Components/Footer"; import Button from "react-bootstrap/Button"; +//import App from "../App"; import "./Home.css"; // import logo from "./logo.svg"; export function Home() { const [val, setVal] = useState(""); + const [content, setContent] = useState(""); /*const [message, setMessage] = useState("Loading..."); useEffect(() => { @@ -27,24 +29,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("/Loginmain"); + //window.location.reload(); + } else { + console.log(result.error); + } + }; return (
Hello World
{/* this the label */} - - {/*textarea with spellcheck function*/} - + diff --git a/server/api.js b/server/api.js index 32bb66f..df16ae8 100644 --- a/server/api.js +++ b/server/api.js @@ -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"; @@ -21,14 +21,20 @@ 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; From c0367da68a358a15c70c94ef61ac086c018e3313 Mon Sep 17 00:00:00 2001 From: Roman-hal <85693082+Roman-Hal@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:39:15 +0100 Subject: [PATCH 2/4] updated_api_for_prettier updated file for prettier check --- server/api.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/api.js b/server/api.js index df16ae8..72a4939 100644 --- a/server/api.js +++ b/server/api.js @@ -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({ @@ -24,7 +24,12 @@ router.get("/corrections", async (req, res) => { 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}` }], + 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", From f34f2c772c26c6ae5ed4243ce3d66c277bdcdc63 Mon Sep 17 00:00:00 2001 From: Roman-hal <85693082+Roman-Hal@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:49:09 +0100 Subject: [PATCH 3/4] updated_main_for_merge merge conflicts sort out --- client/src/pages/Home.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/client/src/pages/Home.js b/client/src/pages/Home.js index c341a3b..0ed9d3a 100644 --- a/client/src/pages/Home.js +++ b/client/src/pages/Home.js @@ -1,5 +1,5 @@ //import { useEffect, useState } from "react"; -import { useState } from "react"; +//import { useState } from "react"; //import { Link } from "react-router-dom"; import Header from "../Components/Header"; import Footer from "../Components/Footer"; @@ -10,8 +10,8 @@ import "./Home.css"; // import logo from "./logo.svg"; export function Home() { - const [val, setVal] = useState(""); - const [content, setContent] = useState(""); + /*const [val, setVal] = useState(""); + const [content, setContent] = useState("");*/ /*const [message, setMessage] = useState("Loading..."); useEffect(() => { @@ -29,7 +29,7 @@ export function Home() { console.error(err); }); }, []);*/ - const onSubmit = (e) => { + /*const onSubmit = (e) => { e.preventDefault(content); if (!content) { @@ -44,9 +44,9 @@ export function Home() { setContent(content); setVal(content); } - }; + };*/ - const onAdd = async ({ content }) => { + /*const onAdd = async ({ content }) => { const result = await ( await fetch("http://localhost:3100/api/corrections", { //const result = await(await fetch(`${ api }/corrections`, { @@ -68,13 +68,13 @@ export function Home() { } else { console.log(result.error); } - }; + };*/ return (Hello World
- {/* this the label */} + {/*Hello World
+ this the label - + */} +