fixes
Showing
1 changed file
with
20 additions
and
0 deletions
| ... | @@ -64,7 +64,11 @@ function App() { | ... | @@ -64,7 +64,11 @@ function App() { |
| 64 | setChatInput(""); | 64 | setChatInput(""); |
| 65 | setChatLog(chatLogNew) | 65 | setChatLog(chatLogNew) |
| 66 | 66 | ||
| 67 | const userMessage = { user: "gpt", message: "..." }; | ||
| 68 | setChatLog(prevChatLog => [...prevChatLog, userMessage]); | ||
| 69 | |||
| 67 | const messages = chatLogNew.map((message) => message.message).join("\n") | 70 | const messages = chatLogNew.map((message) => message.message).join("\n") |
| 71 | let intervalId = startInterval(); | ||
| 68 | 72 | ||
| 69 | try { | 73 | try { |
| 70 | const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { | 74 | const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { |
| ... | @@ -79,6 +83,7 @@ function App() { | ... | @@ -79,6 +83,7 @@ function App() { |
| 79 | }); | 83 | }); |
| 80 | const data = await response.json(); | 84 | const data = await response.json(); |
| 81 | const parsedData = data.message.trim(); | 85 | const parsedData = data.message.trim(); |
| 86 | clearInterval(intervalId); | ||
| 82 | 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']; |
| 83 | 88 | ||
| 84 | const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); | 89 | const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); |
| ... | @@ -113,6 +118,21 @@ function App() { | ... | @@ -113,6 +118,21 @@ function App() { |
| 113 | const errorMsg = "We apologize for any inconvenience caused due to the delay in the response time. Please try again."; | 118 | const errorMsg = "We apologize for any inconvenience caused due to the delay in the response time. Please try again."; |
| 114 | setChatLog([...chatLogNew, { user: "gpt", message: `<div class="errormsg"><span>i</span><div class="msg">${errorMsg}</div></div>`} ]) | 119 | setChatLog([...chatLogNew, { user: "gpt", message: `<div class="errormsg"><span>i</span><div class="msg">${errorMsg}</div></div>`} ]) |
| 115 | } | 120 | } |
| 121 | |||
| 122 | function startInterval() { | ||
| 123 | return setInterval(function() { | ||
| 124 | if (userMessage.message.length === 3) { | ||
| 125 | userMessage.message = "."; | ||
| 126 | } else if (userMessage.message.length === 1) { | ||
| 127 | userMessage.message = ".."; | ||
| 128 | } else { | ||
| 129 | userMessage.message = "..."; | ||
| 130 | } | ||
| 131 | var thinkingDots = document.getElementsByClassName("message"); | ||
| 132 | var thinkingDot = thinkingDots[thinkingDots.length - 1]; | ||
| 133 | thinkingDot.innerHTML = userMessage.message; | ||
| 134 | }, 500); | ||
| 135 | } | ||
| 116 | } | 136 | } |
| 117 | 137 | ||
| 118 | function handleTemp(temp) { | 138 | function handleTemp(temp) { | ... | ... |
-
Please register or sign in to post a comment