5630aded by Ryan

Merge branch '26988_chatgpt_look_and_feel' into 'master'

26988 chatgpt look and feel

See merge request !37
2 parents 94593dd1 376c7f7c
...@@ -247,6 +247,7 @@ ...@@ -247,6 +247,7 @@
247 padding: 10px; 247 padding: 10px;
248 border-radius: 5px; 248 border-radius: 5px;
249 margin: 0 0 10px; 249 margin: 0 0 10px;
250 font-size: 14px;
250 } 251 }
251 252
252 ul.suggested-options { 253 ul.suggested-options {
......
...@@ -20,7 +20,6 @@ function App() { ...@@ -20,7 +20,6 @@ function App() {
20 message: "Welcome to AI-PRO... How can I help you?" 20 message: "Welcome to AI-PRO... How can I help you?"
21 }]); 21 }]);
22 22
23 // clear chats
24 function clearChat(){ 23 function clearChat(){
25 setChatLog([]); 24 setChatLog([]);
26 setChatInput(""); 25 setChatInput("");
...@@ -31,8 +30,6 @@ function App() { ...@@ -31,8 +30,6 @@ function App() {
31 fetch(process.env.REACT_APP_SERVER_URL + "/models") 30 fetch(process.env.REACT_APP_SERVER_URL + "/models")
32 .then(res => res.json()) 31 .then(res => res.json())
33 .then(data => { 32 .then(data => {
34 // console.log(data.models.data)
35 // set models in order alpahbetically
36 data.models.data.sort((a, b) => { 33 data.models.data.sort((a, b) => {
37 if(a.id < b.id) { return -1; } 34 if(a.id < b.id) { return -1; }
38 if(a.id > b.id) { return 1; } 35 if(a.id > b.id) { return 1; }
...@@ -44,7 +41,7 @@ function App() { ...@@ -44,7 +41,7 @@ function App() {
44 41
45 async function handleSubmit(e){ 42 async function handleSubmit(e){
46 e.preventDefault(); 43 e.preventDefault();
47 // console.log(chatInput) 44
48 const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who']; 45 const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who'];
49 const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi'); 46 const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi');
50 const inputMatches = chatInput.match(userInputRegex); 47 const inputMatches = chatInput.match(userInputRegex);
...@@ -53,16 +50,13 @@ function App() { ...@@ -53,16 +50,13 @@ function App() {
53 const userPunctuationRegex = new RegExp(`[${userPunctuation.join('')}]$`); 50 const userPunctuationRegex = new RegExp(`[${userPunctuation.join('')}]$`);
54 const punctuationMatches = chatInput.match(userPunctuationRegex); 51 const punctuationMatches = chatInput.match(userPunctuationRegex);
55 52
56 // console.log(punctuationMatches)
57 var userModifiedInput = chatInput 53 var userModifiedInput = chatInput
58 54
59 if (!punctuationMatches) { 55 if (!punctuationMatches) {
60 if (!inputMatches) { 56 if (!inputMatches) {
61 userModifiedInput = chatInput + "."; 57 userModifiedInput = chatInput + ".";
62 // console.log("not a question!")
63 } else { 58 } else {
64 userModifiedInput = chatInput + "?"; 59 userModifiedInput = chatInput + "?";
65 // console.log("its a question!")
66 } 60 }
67 } 61 }
68 62
...@@ -70,8 +64,11 @@ function App() { ...@@ -70,8 +64,11 @@ function App() {
70 setChatInput(""); 64 setChatInput("");
71 setChatLog(chatLogNew) 65 setChatLog(chatLogNew)
72 66
73 // 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 const userMessage = { user: "gpt", message: "..." };
68 setChatLog(prevChatLog => [...prevChatLog, userMessage]);
69
74 const messages = chatLogNew.map((message) => message.message).join("\n") 70 const messages = chatLogNew.map((message) => message.message).join("\n")
71 let intervalId = startInterval();
75 72
76 try { 73 try {
77 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { 74 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
...@@ -86,6 +83,7 @@ function App() { ...@@ -86,6 +83,7 @@ function App() {
86 }); 83 });
87 const data = await response.json(); 84 const data = await response.json();
88 const parsedData = data.message.trim(); 85 const parsedData = data.message.trim();
86 clearInterval(intervalId);
89 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'];
90 88
91 const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); 89 const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi');
...@@ -95,14 +93,46 @@ function App() { ...@@ -95,14 +93,46 @@ function App() {
95 } else { 93 } else {
96 replaceTags = (parsedData.replace(':',':<code>').replace('<?','&#60;?').replace('?>','?&#62;').replace(/\n/g, '<br>')) 94 replaceTags = (parsedData.replace(':',':<code>').replace('<?','&#60;?').replace('?>','?&#62;').replace(/\n/g, '<br>'))
97 } 95 }
98 setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ])
99 96
100 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; 97 for (let i = 0; i < replaceTags.length; i++) {
101 scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; 98 setTimeout(() => {
99 const parsedMsg = replaceTags.slice(0, i + 1);
100 updateLastMessage(parsedMsg);
101 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0];
102 scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight;
103 }, i * 5);
104 }
105
106 function updateLastMessage(parsedMsg) {
107 setChatLog(prevChatLog => {
108 const lastMsg = prevChatLog[prevChatLog.length - 1];
109 if (lastMsg && lastMsg.user === "gpt") {
110 return [...prevChatLog.slice(0, prevChatLog.length - 1), { user: lastMsg.user, message: parsedMsg }];
111 } else {
112 return [...prevChatLog, { user: "gpt", message: parsedMsg }];
113 }
114 });
115 }
116
102 } catch (error) { 117 } catch (error) {
103 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.";
104 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>`} ])
105 } 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 }
106 } 136 }
107 137
108 function handleTemp(temp) { 138 function handleTemp(temp) {
......
1 @import url('https://fonts.googleapis.com/css2?family=Alegreya+Sans:ital,wght@0,400;0,500;1,400&display=swap');
2
3 body {
4 -webkit-font-smoothing: antialiased;
5 -moz-osx-font-smoothing: grayscale;
6 font-family: "Alegreya Sans", sans-serif;
7 }
1 .sidemenu { 8 .sidemenu {
2 background-color: #101827 !important; 9 background-color: #101827 !important;
3 } 10 }
...@@ -7,11 +14,12 @@ ...@@ -7,11 +14,12 @@
7 padding: 15px 25px; 14 padding: 15px 25px;
8 border-radius: 10px; 15 border-radius: 10px;
9 background: rgb(0 139 245 / 6%); 16 background: rgb(0 139 245 / 6%);
17 font-size: 16px;
10 } 18 }
11 19
12 .errormsg .msg { 20 .errormsg .msg {
13 display: inline-block; 21 display: inline-block;
14 width: 90%; 22 width: 85%;
15 } 23 }
16 .errormsg span { 24 .errormsg span {
17 background: #008BF5; 25 background: #008BF5;
...@@ -117,10 +125,10 @@ span.info { ...@@ -117,10 +125,10 @@ span.info {
117 } 125 }
118 126
119 .message { 127 .message {
128 font-size: 20px;
120 padding: 7px 20px !important; 129 padding: 7px 20px !important;
121 line-height: 25px; 130 line-height: 25px;
122 font-size: 14px; 131 font-size: 14px;
123 font-family: "Poppins", "Karla", sans-serif;
124 color: #353b4f; 132 color: #353b4f;
125 -moz-osx-font-smoothing: grayscale; 133 -moz-osx-font-smoothing: grayscale;
126 -webkit-font-smoothing: antialiased !important; 134 -webkit-font-smoothing: antialiased !important;
...@@ -209,19 +217,22 @@ code br:nth-child(-n+2) { ...@@ -209,19 +217,22 @@ code br:nth-child(-n+2) {
209 217
210 @media (min-width: 1280px) { 218 @media (min-width: 1280px) {
211 .message { 219 .message {
212 font-size: 18px; 220 font-size: 20px;
213 } 221 }
214 } 222 }
215 223
216 @media (max-width: 1279px) { 224 @media (max-width: 1279px) {
217 .message { 225 .message {
218 font-size: 16px; 226 font-size: 18px;
219 } 227 }
220 } 228 }
221 229
222 @media (max-width: 991px) { 230 @media (max-width: 991px) {
231 .errormsg .msg {
232 width: 75%;
233 }
223 .message { 234 .message {
224 font-size: 14px; 235 font-size: 16px;
225 } 236 }
226 .chat-message-center { 237 .chat-message-center {
227 padding: 20px 5vw !important; 238 padding: 20px 5vw !important;
...@@ -233,7 +244,7 @@ code br:nth-child(-n+2) { ...@@ -233,7 +244,7 @@ code br:nth-child(-n+2) {
233 width: 80%; 244 width: 80%;
234 } 245 }
235 .message { 246 .message {
236 font-size: 14px; 247 font-size: 16px;
237 } 248 }
238 .errormsg { 249 .errormsg {
239 padding: 10px; 250 padding: 10px;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!