fix
Showing
2 changed files
with
61 additions
and
26 deletions
| ... | @@ -71,34 +71,36 @@ function App() { | ... | @@ -71,34 +71,36 @@ function App() { |
| 71 | // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post | 71 | // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post |
| 72 | const messages = chatLogNew.map((message) => message.message).join("\n") | 72 | const messages = chatLogNew.map((message) => message.message).join("\n") |
| 73 | 73 | ||
| 74 | const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { | 74 | try { |
| 75 | method: "POST", | 75 | const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { |
| 76 | headers: { | 76 | method: "POST", |
| 77 | "Content-Type": "application/json" | 77 | headers: { |
| 78 | }, | 78 | "Content-Type": "application/json" |
| 79 | body: JSON.stringify({ | 79 | }, |
| 80 | message: messages, | 80 | body: JSON.stringify({ |
| 81 | currentModel, | 81 | message: messages, |
| 82 | }) | 82 | currentModel, |
| 83 | }) | ||
| 83 | }); | 84 | }); |
| 84 | const data = await response.json(); | 85 | const data = await response.json(); |
| 85 | const parsedData = data.message.trim(); | 86 | const parsedData = data.message.trim(); |
| 86 | const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table']; | 87 | const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table']; |
| 87 | 88 | ||
| 88 | const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); | 89 | const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); |
| 89 | // console.log(regex) | 90 | const matches = parsedData.match(regex); |
| 90 | const matches = parsedData.match(regex); | 91 | if (!matches) { |
| 91 | // console.log(matches); | 92 | var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. ')) |
| 92 | if (!matches) { | 93 | } else { |
| 93 | var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. ')) | 94 | replaceTags = (parsedData.replace(':',':<code>').replace('<?','<?').replace('?>','?>').replace(/\n/g, '<br>')) |
| 94 | // console.log("not programming!") | 95 | } |
| 95 | } else { | 96 | setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ]) |
| 96 | replaceTags = (parsedData.replace(':',':<code>').replace('<?','<?').replace('?>','?>').replace(/\n/g, '<br>')) | 97 | |
| 97 | // console.log("programming!") | 98 | var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; |
| 99 | scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; | ||
| 100 | } catch (error) { | ||
| 101 | const errorMsg = "We apologize for any inconvenience caused due to the delay in the response time. Please try again."; | ||
| 102 | setChatLog([...chatLogNew, { user: "gpt", message: `<div class="errormsg"><span>i</span><div class="msg">${errorMsg}</div></div>`} ]) | ||
| 98 | } | 103 | } |
| 99 | setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ]) | ||
| 100 | var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; | ||
| 101 | scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; | ||
| 102 | } | 104 | } |
| 103 | 105 | ||
| 104 | function handleTemp(temp) { | 106 | function handleTemp(temp) { | ... | ... |
| ... | @@ -2,6 +2,32 @@ | ... | @@ -2,6 +2,32 @@ |
| 2 | background-color: #101827 !important; | 2 | background-color: #101827 !important; |
| 3 | } | 3 | } |
| 4 | 4 | ||
| 5 | .errormsg { | ||
| 6 | border: 1px solid #7ac5ff; | ||
| 7 | padding: 15px 25px; | ||
| 8 | border-radius: 10px; | ||
| 9 | background: rgb(0 139 245 / 6%); | ||
| 10 | } | ||
| 11 | |||
| 12 | .errormsg .msg { | ||
| 13 | display: inline-block; | ||
| 14 | width: 90%; | ||
| 15 | } | ||
| 16 | .errormsg span { | ||
| 17 | background: #008BF5; | ||
| 18 | padding: 1px 11px; | ||
| 19 | border-radius: 50px; | ||
| 20 | width: 25px; | ||
| 21 | height: 25px; | ||
| 22 | margin-right: 10px; | ||
| 23 | color: #fff; | ||
| 24 | font-weight: 900; | ||
| 25 | display: inline-block; | ||
| 26 | vertical-align: top; | ||
| 27 | font-family: auto; | ||
| 28 | font-size: 15px; | ||
| 29 | } | ||
| 30 | |||
| 5 | .side-menu-button { | 31 | .side-menu-button { |
| 6 | border:0 solid white; | 32 | border:0 solid white; |
| 7 | /* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#cedbe9+0,aac5de+17,6199c7+50,3a84c3+51,419ad6+59,4bb8f0+71,3a8bc2+84,26558b+100;Blue+Gloss */ | 33 | /* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#cedbe9+0,aac5de+17,6199c7+50,3a84c3+51,419ad6+59,4bb8f0+71,3a8bc2+84,26558b+100;Blue+Gloss */ |
| ... | @@ -172,9 +198,16 @@ code br:nth-child(-n+2) { | ... | @@ -172,9 +198,16 @@ code br:nth-child(-n+2) { |
| 172 | } | 198 | } |
| 173 | 199 | ||
| 174 | @media (max-width: 414px) { | 200 | @media (max-width: 414px) { |
| 201 | .errormsg .msg { | ||
| 202 | width: 80%; | ||
| 203 | } | ||
| 175 | .message { | 204 | .message { |
| 176 | font-size: 14px; | 205 | font-size: 14px; |
| 177 | } | 206 | } |
| 207 | .errormsg { | ||
| 208 | padding: 10px; | ||
| 209 | width: 100%; | ||
| 210 | } | ||
| 178 | .chat-message-center { | 211 | .chat-message-center { |
| 179 | padding: 20px 5vw !important; | 212 | padding: 20px 5vw !important; |
| 180 | } | 213 | } | ... | ... |
-
Please register or sign in to post a comment