fix conflict
Showing
2 changed files
with
59 additions
and
30 deletions
| ... | @@ -42,7 +42,6 @@ function App() { | ... | @@ -42,7 +42,6 @@ function App() { |
| 42 | 42 | ||
| 43 | async function handleSubmit(e){ | 43 | async function handleSubmit(e){ |
| 44 | e.preventDefault(); | 44 | e.preventDefault(); |
| 45 | console.log(chatInput) | ||
| 46 | const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who', 'hey']; | 45 | const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who', 'hey']; |
| 47 | const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi'); | 46 | const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi'); |
| 48 | const inputMatches = chatInput.match(userInputRegex); | 47 | const inputMatches = chatInput.match(userInputRegex); |
| ... | @@ -51,16 +50,13 @@ function App() { | ... | @@ -51,16 +50,13 @@ function App() { |
| 51 | const userPunctuationRegex = new RegExp(`[${userPunctuation.join('')}]$`); | 50 | const userPunctuationRegex = new RegExp(`[${userPunctuation.join('')}]$`); |
| 52 | const punctuationMatches = chatInput.match(userPunctuationRegex); | 51 | const punctuationMatches = chatInput.match(userPunctuationRegex); |
| 53 | 52 | ||
| 54 | console.log(punctuationMatches) | ||
| 55 | var userModifiedInput = chatInput | 53 | var userModifiedInput = chatInput |
| 56 | 54 | ||
| 57 | if (!punctuationMatches) { | 55 | if (!punctuationMatches) { |
| 58 | if (!inputMatches) { | 56 | if (!inputMatches) { |
| 59 | userModifiedInput = chatInput + "."; | 57 | userModifiedInput = chatInput + "."; |
| 60 | console.log("not a question!") | ||
| 61 | } else { | 58 | } else { |
| 62 | userModifiedInput = chatInput + "?"; | 59 | userModifiedInput = chatInput + "?"; |
| 63 | console.log("its a question!") | ||
| 64 | } | 60 | } |
| 65 | } | 61 | } |
| 66 | 62 | ||
| ... | @@ -71,34 +67,36 @@ function App() { | ... | @@ -71,34 +67,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 | 67 | // 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") | 68 | const messages = chatLogNew.map((message) => message.message).join("\n") |
| 73 | 69 | ||
| 74 | const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { | 70 | try { |
| 75 | method: "POST", | 71 | const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { |
| 76 | headers: { | 72 | method: "POST", |
| 77 | "Content-Type": "application/json" | 73 | headers: { |
| 78 | }, | 74 | "Content-Type": "application/json" |
| 79 | body: JSON.stringify({ | 75 | }, |
| 80 | message: messages, | 76 | body: JSON.stringify({ |
| 81 | currentModel, | 77 | message: messages, |
| 82 | }) | 78 | currentModel, |
| 79 | }) | ||
| 83 | }); | 80 | }); |
| 84 | const data = await response.json(); | 81 | const data = await response.json(); |
| 85 | const parsedData = data.message.trim(); | 82 | const parsedData = data.message.trim(); |
| 86 | const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table']; | 83 | const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table']; |
| 87 | 84 | ||
| 88 | const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); | 85 | const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); |
| 89 | // console.log(regex) | 86 | const matches = parsedData.match(regex); |
| 90 | const matches = parsedData.match(regex); | 87 | if (!matches) { |
| 91 | console.log(matches); | 88 | var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. ')) |
| 92 | if (!matches) { | 89 | } else { |
| 93 | var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. ')) | 90 | replaceTags = (parsedData.replace(':',':<code>').replace('<?','<?').replace('?>','?>').replace(/\n/g, '<br>')) |
| 94 | console.log("not programming!") | 91 | } |
| 95 | } else { | 92 | setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ]) |
| 96 | replaceTags = (parsedData.replace(':',':<code>').replace('<?','<?').replace('?>','?>').replace(/\n/g, '<br>')) | 93 | |
| 97 | console.log("programming!") | 94 | var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; |
| 95 | scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; | ||
| 96 | } catch (error) { | ||
| 97 | const errorMsg = "We apologize for any inconvenience caused due to the delay in the response time. Please try again."; | ||
| 98 | setChatLog([...chatLogNew, { user: "gpt", message: `<div class="errormsg"><span>i</span><div class="msg">${errorMsg}</div></div>`} ]) | ||
| 98 | } | 99 | } |
| 99 | setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ]) | ||
| 100 | var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; | ||
| 101 | scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; | ||
| 102 | } | 100 | } |
| 103 | 101 | ||
| 104 | function handleTemp(temp) { | 102 | function handleTemp(temp) { | ... | ... |
| ... | @@ -2,6 +2,33 @@ | ... | @@ -2,6 +2,33 @@ |
| 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 | font-weight: 600; | ||
| 16 | } | ||
| 17 | .errormsg span { | ||
| 18 | background: #008BF5; | ||
| 19 | padding: 1px 11px; | ||
| 20 | border-radius: 50px; | ||
| 21 | width: 25px; | ||
| 22 | height: 25px; | ||
| 23 | margin-right: 10px; | ||
| 24 | color: #fff; | ||
| 25 | font-weight: 900; | ||
| 26 | display: inline-block; | ||
| 27 | vertical-align: top; | ||
| 28 | font-family: auto; | ||
| 29 | font-size: 15px; | ||
| 30 | } | ||
| 31 | |||
| 5 | .side-menu-button { | 32 | .side-menu-button { |
| 6 | border:0 solid white; | 33 | 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 */ | 34 | /* 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 */ |
| ... | @@ -175,6 +202,10 @@ code br:nth-child(-n+2) { | ... | @@ -175,6 +202,10 @@ code br:nth-child(-n+2) { |
| 175 | .message { | 202 | .message { |
| 176 | font-size: 14px; | 203 | font-size: 14px; |
| 177 | } | 204 | } |
| 205 | .errormsg { | ||
| 206 | padding: 10px; | ||
| 207 | width: 80%; | ||
| 208 | } | ||
| 178 | .chat-message-center { | 209 | .chat-message-center { |
| 179 | padding: 20px 5vw !important; | 210 | padding: 20px 5vw !important; |
| 180 | } | 211 | } | ... | ... |
-
Please register or sign in to post a comment