8982493b by Janis

Merge branch '28786_moderation' into 'master'

28786_moderation

See merge request !73
2 parents ee73076e def2b837
......@@ -47,10 +47,10 @@ function App() {
let model_list = [];
for( var i = 1; i < data.models.data.length; i++ ) {
let model = data.models.data[i];
if( !(model.id == "whisper-1"
|| model.id == "gpt-4"
|| model.id == "gpt-4-0314"
|| model.id == "gpt-4-0613") ) model_list.push(model);
if( !(model.id === "whisper-1"
|| model.id === "gpt-4"
|| model.id === "gpt-4-0314"
|| model.id === "gpt-4-0613") ) model_list.push(model);
}
setModels(model_list)
})
......@@ -86,14 +86,14 @@ function App() {
}
}
let chatLogNew = [...chatLog, { user: "me", message: `${userModifiedInput}`} ]
let chatLogNew = [...chatLog, { user: "user", message: `${userModifiedInput}`} ]
setChatInput("");
setChatLog(chatLogNew)
const userMessage = { user: "gpt", message: "..." };
setChatLog(prevChatLog => [...prevChatLog, userMessage]);
var messages = chatLogNew.map((message) => message.message).join("\n")
var messages = chatLogNew.map((message) => { if(message.user !== 'me') return message.message }).join("\n")
if(currentModel == GPTTurbo || currentModel == GPTTurbo0301) {
// "gpt-3.5-turbo"
let chatLogTurboNew = [...chatLogTurbo, { role: "user", content: chatInput }];
......@@ -116,7 +116,16 @@ function App() {
const data = await response.json();
const parsedData = data.message.trim();
// "gpt-3.5-turbo"
let chatLogTurboNew = [...chatLogTurbo, { role: "assistant", content: parsedData }];
let chatLogTurboNew = chatLogTurbo;
if(data.success === false) {
setChatLog(prevChatLog => {
const lastMsg = prevChatLog[prevChatLog.length - 2];
return [...prevChatLog.slice(0, prevChatLog.length - 2), { user: "me", message: lastMsg.message }];
});
userModifiedInput = "";
}
chatLogTurboNew.push({ role: "user", content: userModifiedInput });
chatLogTurboNew.push({ role: "assistant", content: parsedData });
setChatLogTurbo(chatLogTurboNew);
//
clearInterval(intervalId);
......
......@@ -57,6 +57,19 @@ app.post('/api', async (req, res) => {
query_prompt = arr_body.join("\n")
}
}
const moderation = await axios.post("https://api.openai.com/v1/moderations", {
input: query_prompt
}, { headers: { 'content-type': 'application/json', 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` } });
if(moderation.data.results[0].flagged) {
res.json({
success: false,
message: "I'm sorry, but I can't assist with that. We want everyone to use our tool safely and responsibly.\nIf you have any other questions or need advice on a different topic, feel free to ask."
});
res.end();
return;
}
try {
const response = await openai.createCompletion({
model: `${currentModel}`,// "text-davinci-003",
......@@ -93,6 +106,20 @@ async function runGPTTurbo(req, res) {
// "gpt-3.5-turbo"
const { message, currentModel, temperature } = req.body;
var input = '';
const message_history = JSON.parse(message);
const query_prompt = message_history.length ? message_history[message_history.length - 1].content : "";
const moderation = await axios.post("https://api.openai.com/v1/moderations", {
input: query_prompt
}, { headers: { 'content-type': 'application/json', 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` } });
if(moderation.data.results[0].flagged) {
res.json({
success: false,
message: "I'm sorry, but I can't assist with that. We want everyone to use our tool safely and responsibly.\nIf you have any other questions or need advice on a different topic, feel free to ask."
});
res.end();
return;
}
try {
const response = await openai.createChatCompletion({
model: `${currentModel}`,
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!