7fd3de54 by RSA

fix conflict

2 parents 3e99a7b9 376c7f7c
...@@ -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; }
...@@ -66,8 +63,11 @@ function App() { ...@@ -66,8 +63,11 @@ function App() {
66 setChatInput(""); 63 setChatInput("");
67 setChatLog(chatLogNew) 64 setChatLog(chatLogNew)
68 65
69 // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post 66 const userMessage = { user: "gpt", message: "..." };
67 setChatLog(prevChatLog => [...prevChatLog, userMessage]);
68
70 const messages = chatLogNew.map((message) => message.message).join("\n") 69 const messages = chatLogNew.map((message) => message.message).join("\n")
70 let intervalId = startInterval();
71 71
72 try { 72 try {
73 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { 73 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
...@@ -83,6 +83,7 @@ function App() { ...@@ -83,6 +83,7 @@ function App() {
83 83
84 const data = await response.json(); 84 const data = await response.json();
85 const parsedData = data.message.trim(); 85 const parsedData = data.message.trim();
86 clearInterval(intervalId);
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');
...@@ -92,15 +93,47 @@ function App() { ...@@ -92,15 +93,47 @@ function App() {
92 } else { 93 } else {
93 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>'))
94 } 95 }
95 setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ])
96 96
97 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; 97 for (let i = 0; i < replaceTags.length; i++) {
98 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
99 } catch (error) { 117 } catch (error) {
100 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.";
101 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>`} ])
102 120
103 } 121 }
122
123 function startInterval() {
124 return setInterval(function() {
125 if (userMessage.message.length === 3) {
126 userMessage.message = ".";
127 } else if (userMessage.message.length === 1) {
128 userMessage.message = "..";
129 } else {
130 userMessage.message = "...";
131 }
132 var thinkingDots = document.getElementsByClassName("message");
133 var thinkingDot = thinkingDots[thinkingDots.length - 1];
134 thinkingDot.innerHTML = userMessage.message;
135 }, 500);
136 }
104 } 137 }
105 138
106 function handleTemp(temp) { 139 function handleTemp(temp) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!