b14db9b8 by RSA

fix

1 parent 0a4a261d
...@@ -71,38 +71,44 @@ function App() { ...@@ -71,38 +71,44 @@ 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 // console.log(parsedData) 87 // console.log(parsedData)
87 const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table']; 88 const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table'];
88 89
89 const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); 90 const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi');
90 // console.log(regex) 91 // console.log(regex)
91 const matches = parsedData.match(regex); 92 const matches = parsedData.match(regex);
92 // console.log(matches); 93 // console.log(matches);
93 if (!matches) { 94 if (!matches) {
94 var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. ')) 95 var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. '))
95 // console.log("not programming!") 96 // console.log("not programming!")
96 } else { 97 } else {
97 replaceTags = (parsedData.replace(':',':<code>').replace('<?','&#60;?').replace('?>','?&#62;').replace(/\n/g, '<br>')) 98 replaceTags = (parsedData.replace(':',':<code>').replace('<?','&#60;?').replace('?>','?&#62;').replace(/\n/g, '<br>'))
98 // console.log("programming!") 99 // console.log("programming!")
99 //.replace('<?','&#60;' + '?').replace('?>','?'+'&#62;') 100 //.replace('<?','&#60;' + '?').replace('?>','?'+'&#62;')
101 }
102 setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ])
103
104 // setChatLog([...chatLogNew, { user: "gpt", message: `<div>${parsedData}</div>`} ])
105 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0];
106 scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight;
107 } catch (error) {
108 const errorMsg = "We are currently experiencing heavy flow as of the moment, please try again.";
109 setChatLog([...chatLogNew, { user: "gpt", message: `<div class="errormsg">${errorMsg}</div>`} ])
110 // res.status(500).send(error || 'Something went wrong');
100 } 111 }
101 setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ])
102
103 // setChatLog([...chatLogNew, { user: "gpt", message: `<div>${parsedData}</div>`} ])
104 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0];
105 scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight;
106 } 112 }
107 113
108 function handleTemp(temp) { 114 function handleTemp(temp) {
......
...@@ -2,6 +2,13 @@ ...@@ -2,6 +2,13 @@
2 background-color: #101827 !important; 2 background-color: #101827 !important;
3 } 3 }
4 4
5 .errormsg {
6 border: 1px solid red;
7 padding: 15px 25px;
8 border-radius: 10px;
9 background: rgb(255 0 0 / 15%);
10 }
11
5 .side-menu-button { 12 .side-menu-button {
6 border:0 solid white; 13 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 */ 14 /* 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 */
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!