b0078561 by RSA

fixes

1 parent 8533480c
......@@ -29,7 +29,7 @@ function App() {
fetch(process.env.REACT_APP_SERVER_URL + "/models")
.then(res => res.json())
.then(data => {
console.log(data.models.data)
// console.log(data.models.data)
// set models in order alpahbetically
data.models.data.sort((a, b) => {
if(a.id < b.id) { return -1; }
......@@ -51,8 +51,7 @@ function App() {
const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept":"application/json"
"Content-Type": "application/json"
},
body: JSON.stringify({
message: messages,
......@@ -60,73 +59,29 @@ function App() {
})
});
const data = await response.json();
const parsedData = data.message.trim();
console.log(parsedData)
const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table'];
const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi');
console.log(regex)
const matches = parsedData.match(regex);
console.log(matches);
if (!matches) {
var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. '))
console.log("not programming!")
// return replaceTags
} else {
replaceTags = (parsedData.replace(':',':<code>').replace('<?','&#60;?').replace('?>','?&#62;').replace(/\n/g, '<br>'))
console.log("programming!")
// return replaceTags
//.replace('<?','&#60;' + '?').replace('?>','?'+'&#62;')
}
setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ])
setChatLog([...chatLogNew, { user: "gpt", message: `${data.message}`} ])
// setChatLog([...chatLogNew, { user: "gpt", message: `<div>${parsedData}</div>`} ])
var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0];
scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight;
// var oHttp = new XMLHttpRequest();
// oHttp.open("POST", "https://api.openai.com/v1/completions");
// oHttp.setRequestHeader("Accept", "application/json");
// oHttp.setRequestHeader("Content-Type", "application/json");
// oHttp.setRequestHeader("Authorization", "Bearer " + "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")
// oHttp.onreadystatechange = function () {
// if (oHttp.readyState === 4) {
// var s = ''
// var oJson = {}
// if (s != "") s += "\n";
// try {
// oJson = JSON.parse(oHttp.responseText);
// } catch (ex) {
// s += "Error: " + ex.message
// }
// if (oJson.error && oJson.error.message) {
// s += "Error: " + oJson.error.message;
// } else if (oJson.choices && oJson.choices[0].text) {
// s = oJson.choices[0].text;
// var a = s.split("?\n");
// if (a.length == 2) {
// s = a[1];
// }
// // if (selLang.value != "en-US") {
// // var a = s.split("?\n");
// // if (a.length == 2) {
// // s = a[1];
// // }
// // }
// if (s == "") s = "No response";
// console.log('ssssssssssssssssssssss',s);
// var replaceBR= (s.replace(/(?:\r\n|\r|\n)/g, "<br>")).replace(/\r?\n|\r/, "");
// setChatLog([...chatLogNew, { user: "gpt", message: `${replaceBR}`} ]);
// }
// }
// };
// var sModel = currentModel;// "text-davinci-003";
// var iMaxTokens = 100;
// var sUserId = "1";
// var dTemperature =temperature;
// var data = {
// model: sModel,
// prompt: messages,
// max_tokens: iMaxTokens,
// //user: sUserId,
// temperature: dTemperature,
// // frequency_penalty: 0.0, //Number between -2.0 and 2.0 Positive value decrease the model's likelihood to repeat the same line verbatim.
// //presence_penalty: 0.0, //Number between -2.0 and 2.0. Positive values increase the model's likelihood to talk about new topics.
// //stop: ["#", ";"] //Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
// }
var oHttp = new XMLHttpRequest();
oHttp.open("POST", "/your-endpoint", true);
oHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
oHttp.send(JSON.stringify(data));
}
function handleTemp(temp) {
......
......@@ -45,7 +45,8 @@ span.info {
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#feffff', endColorstr='#eff7f5',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
}
.chat-message-center {
padding: 20px 10px !important;
padding: 20px 10vw !important;
max-width: none;
}
.avatar {
......@@ -131,3 +132,49 @@ span.info {
text-align: center;
padding: 10px 0;
}
.message code {
background: #303030;
width: 100%;
color: #fff;
padding: 15px 20px;
border-radius: 10px;
font-family: monospace, sans-serif;
font-size: 12px;
display: block;
margin: 15px 5px;
}
code br:nth-child(-n+2) {
display: none;
}
@media (min-width: 1280px) {
.message {
font-size: 18px;
}
}
@media (max-width: 1279px) {
.message {
font-size: 16px;
}
}
@media (max-width: 991px) {
.message {
font-size: 14px;
}
.chat-message-center {
padding: 20px 5vw !important;
}
}
@media (max-width: 414px) {
.message {
font-size: 14px;
}
.chat-message-center {
padding: 20px 5vw !important;
}
}
\ No newline at end of file
......
......@@ -33,19 +33,6 @@ app.post('/api', async (req, res) => {
temperature,
});
// let messagess = response.data.choices[0].text
// let arr_msg1 = messagess.split('<code>')
// for (let i = 0; i < arr_msg1.length; i++) {
// messagess = messagess.replace('<code>','<pre class="cdeblk"><code>').replace(': ```',': <pre class="cdeblk"><code>').replace('```','</code></pre>')
// }
// let arr_msg2 = messagess.split('</code>')
// for (let i = 0; i < arr_msg2.length; i++) {
// messagess = messagess.replace('</code>','</code></pre>')
// }
res.json({
message: response.data.choices[0].text,
})
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!