fixes
Showing
3 changed files
with
69 additions
and
80 deletions
| ... | @@ -29,7 +29,7 @@ function App() { | ... | @@ -29,7 +29,7 @@ function App() { |
| 29 | fetch(process.env.REACT_APP_SERVER_URL + "/models") | 29 | fetch(process.env.REACT_APP_SERVER_URL + "/models") |
| 30 | .then(res => res.json()) | 30 | .then(res => res.json()) |
| 31 | .then(data => { | 31 | .then(data => { |
| 32 | console.log(data.models.data) | 32 | // console.log(data.models.data) |
| 33 | // set models in order alpahbetically | 33 | // set models in order alpahbetically |
| 34 | data.models.data.sort((a, b) => { | 34 | data.models.data.sort((a, b) => { |
| 35 | if(a.id < b.id) { return -1; } | 35 | if(a.id < b.id) { return -1; } |
| ... | @@ -51,8 +51,7 @@ function App() { | ... | @@ -51,8 +51,7 @@ function App() { |
| 51 | const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { | 51 | const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { |
| 52 | method: "POST", | 52 | method: "POST", |
| 53 | headers: { | 53 | headers: { |
| 54 | "Content-Type": "application/json", | 54 | "Content-Type": "application/json" |
| 55 | "Accept":"application/json" | ||
| 56 | }, | 55 | }, |
| 57 | body: JSON.stringify({ | 56 | body: JSON.stringify({ |
| 58 | message: messages, | 57 | message: messages, |
| ... | @@ -60,73 +59,29 @@ function App() { | ... | @@ -60,73 +59,29 @@ function App() { |
| 60 | }) | 59 | }) |
| 61 | }); | 60 | }); |
| 62 | const data = await response.json(); | 61 | const data = await response.json(); |
| 63 | |||
| 64 | const parsedData = data.message.trim(); | 62 | const parsedData = data.message.trim(); |
| 63 | console.log(parsedData) | ||
| 64 | const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table']; | ||
| 65 | |||
| 66 | const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); | ||
| 67 | console.log(regex) | ||
| 68 | const matches = parsedData.match(regex); | ||
| 69 | console.log(matches); | ||
| 70 | if (!matches) { | ||
| 71 | var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. ')) | ||
| 72 | console.log("not programming!") | ||
| 73 | // return replaceTags | ||
| 74 | } else { | ||
| 75 | replaceTags = (parsedData.replace(':',':<code>').replace('<?','<?').replace('?>','?>').replace(/\n/g, '<br>')) | ||
| 76 | console.log("programming!") | ||
| 77 | // return replaceTags | ||
| 78 | //.replace('<?','<' + '?').replace('?>','?'+'>') | ||
| 79 | } | ||
| 80 | setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ]) | ||
| 65 | 81 | ||
| 66 | setChatLog([...chatLogNew, { user: "gpt", message: `${data.message}`} ]) | 82 | // setChatLog([...chatLogNew, { user: "gpt", message: `<div>${parsedData}</div>`} ]) |
| 67 | var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; | 83 | var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; |
| 68 | scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; | 84 | scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; |
| 69 | |||
| 70 | |||
| 71 | // var oHttp = new XMLHttpRequest(); | ||
| 72 | // oHttp.open("POST", "https://api.openai.com/v1/completions"); | ||
| 73 | // oHttp.setRequestHeader("Accept", "application/json"); | ||
| 74 | // oHttp.setRequestHeader("Content-Type", "application/json"); | ||
| 75 | // oHttp.setRequestHeader("Authorization", "Bearer " + "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") | ||
| 76 | |||
| 77 | // oHttp.onreadystatechange = function () { | ||
| 78 | // if (oHttp.readyState === 4) { | ||
| 79 | // var s = '' | ||
| 80 | // var oJson = {} | ||
| 81 | // if (s != "") s += "\n"; | ||
| 82 | // try { | ||
| 83 | // oJson = JSON.parse(oHttp.responseText); | ||
| 84 | // } catch (ex) { | ||
| 85 | // s += "Error: " + ex.message | ||
| 86 | // } | ||
| 87 | // if (oJson.error && oJson.error.message) { | ||
| 88 | // s += "Error: " + oJson.error.message; | ||
| 89 | // } else if (oJson.choices && oJson.choices[0].text) { | ||
| 90 | // s = oJson.choices[0].text; | ||
| 91 | // var a = s.split("?\n"); | ||
| 92 | // if (a.length == 2) { | ||
| 93 | // s = a[1]; | ||
| 94 | // } | ||
| 95 | // // if (selLang.value != "en-US") { | ||
| 96 | // // var a = s.split("?\n"); | ||
| 97 | // // if (a.length == 2) { | ||
| 98 | // // s = a[1]; | ||
| 99 | // // } | ||
| 100 | // // } | ||
| 101 | // if (s == "") s = "No response"; | ||
| 102 | // console.log('ssssssssssssssssssssss',s); | ||
| 103 | // var replaceBR= (s.replace(/(?:\r\n|\r|\n)/g, "<br>")).replace(/\r?\n|\r/, ""); | ||
| 104 | |||
| 105 | // setChatLog([...chatLogNew, { user: "gpt", message: `${replaceBR}`} ]); | ||
| 106 | // } | ||
| 107 | // } | ||
| 108 | // }; | ||
| 109 | |||
| 110 | // var sModel = currentModel;// "text-davinci-003"; | ||
| 111 | // var iMaxTokens = 100; | ||
| 112 | // var sUserId = "1"; | ||
| 113 | // var dTemperature =temperature; | ||
| 114 | |||
| 115 | // var data = { | ||
| 116 | // model: sModel, | ||
| 117 | // prompt: messages, | ||
| 118 | // max_tokens: iMaxTokens, | ||
| 119 | // //user: sUserId, | ||
| 120 | // temperature: dTemperature, | ||
| 121 | // // frequency_penalty: 0.0, //Number between -2.0 and 2.0 Positive value decrease the model's likelihood to repeat the same line verbatim. | ||
| 122 | // //presence_penalty: 0.0, //Number between -2.0 and 2.0. Positive values increase the model's likelihood to talk about new topics. | ||
| 123 | // //stop: ["#", ";"] //Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. | ||
| 124 | // } | ||
| 125 | var oHttp = new XMLHttpRequest(); | ||
| 126 | oHttp.open("POST", "/your-endpoint", true); | ||
| 127 | oHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); | ||
| 128 | oHttp.send(JSON.stringify(data)); | ||
| 129 | |||
| 130 | } | 85 | } |
| 131 | 86 | ||
| 132 | function handleTemp(temp) { | 87 | function handleTemp(temp) { | ... | ... |
| ... | @@ -45,7 +45,8 @@ span.info { | ... | @@ -45,7 +45,8 @@ span.info { |
| 45 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#feffff', endColorstr='#eff7f5',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */ | 45 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#feffff', endColorstr='#eff7f5',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */ |
| 46 | } | 46 | } |
| 47 | .chat-message-center { | 47 | .chat-message-center { |
| 48 | padding: 20px 10px !important; | 48 | padding: 20px 10vw !important; |
| 49 | max-width: none; | ||
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | .avatar { | 52 | .avatar { |
| ... | @@ -131,3 +132,49 @@ span.info { | ... | @@ -131,3 +132,49 @@ span.info { |
| 131 | text-align: center; | 132 | text-align: center; |
| 132 | padding: 10px 0; | 133 | padding: 10px 0; |
| 133 | } | 134 | } |
| 135 | |||
| 136 | .message code { | ||
| 137 | background: #303030; | ||
| 138 | width: 100%; | ||
| 139 | color: #fff; | ||
| 140 | padding: 15px 20px; | ||
| 141 | border-radius: 10px; | ||
| 142 | font-family: monospace, sans-serif; | ||
| 143 | font-size: 12px; | ||
| 144 | display: block; | ||
| 145 | margin: 15px 5px; | ||
| 146 | } | ||
| 147 | |||
| 148 | code br:nth-child(-n+2) { | ||
| 149 | display: none; | ||
| 150 | } | ||
| 151 | |||
| 152 | @media (min-width: 1280px) { | ||
| 153 | .message { | ||
| 154 | font-size: 18px; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | @media (max-width: 1279px) { | ||
| 159 | .message { | ||
| 160 | font-size: 16px; | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | @media (max-width: 991px) { | ||
| 165 | .message { | ||
| 166 | font-size: 14px; | ||
| 167 | } | ||
| 168 | .chat-message-center { | ||
| 169 | padding: 20px 5vw !important; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | @media (max-width: 414px) { | ||
| 174 | .message { | ||
| 175 | font-size: 14px; | ||
| 176 | } | ||
| 177 | .chat-message-center { | ||
| 178 | padding: 20px 5vw !important; | ||
| 179 | } | ||
| 180 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -33,19 +33,6 @@ app.post('/api', async (req, res) => { | ... | @@ -33,19 +33,6 @@ app.post('/api', async (req, res) => { |
| 33 | temperature, | 33 | temperature, |
| 34 | }); | 34 | }); |
| 35 | 35 | ||
| 36 | // let messagess = response.data.choices[0].text | ||
| 37 | |||
| 38 | // let arr_msg1 = messagess.split('<code>') | ||
| 39 | // for (let i = 0; i < arr_msg1.length; i++) { | ||
| 40 | // messagess = messagess.replace('<code>','<pre class="cdeblk"><code>').replace(': ```',': <pre class="cdeblk"><code>').replace('```','</code></pre>') | ||
| 41 | // } | ||
| 42 | |||
| 43 | // let arr_msg2 = messagess.split('</code>') | ||
| 44 | // for (let i = 0; i < arr_msg2.length; i++) { | ||
| 45 | // messagess = messagess.replace('</code>','</code></pre>') | ||
| 46 | // } | ||
| 47 | |||
| 48 | |||
| 49 | res.json({ | 36 | res.json({ |
| 50 | message: response.data.choices[0].text, | 37 | message: response.data.choices[0].text, |
| 51 | }) | 38 | }) | ... | ... |
-
Please register or sign in to post a comment