hi
- User
hi
- Assistant
Hello! How can I assist you today?
- User
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
hi
Hello! How can I assist you today?
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
what am i doing wrong in this code, if (err) return console.log(false) if (res.statusCode !== 200 || err) { doesn't even want to read because requestPromise returns 404 with an uncaughtexceptioin
const RP = await requestPromise.post({
url: this.key, // huggingface.co space API
headers: {
"accept": "text/event-stream",
"authorization": Bearer ${process.env['HF_KEY']},
"content-type": "application/json",
},
body: JSON.stringify(payload),
method: 'POST'
}, async (err, res, bod) => {
if (err) return console.log(false)
if (res.statusCode !== 200 || err) {
results = {
message: {
error: "Scan Failed: Server error, we'll try again.",
code: 600010
}
}
await RP
}
try {
let pol = JSON.parse(bod)
let data = [
pol.data[0]
]
let combinedTotals = {
toxicity: 0 / 2,
severe_toxicity: 0,
obscene: 0,
threat: 0,
insult: 0,
identity_attack: 0,
sexual_explicit: 0,
};
let threshold = {
keep: 1,
low: 1.5,
delete: 1.6,
serious: 2.8,
mostlikely: 10.5,
};
const categoryLevels = {};
const parseJson = data[0].replace(/'/g, '"');
const parsedData = JSON.parse(parseJson);
Object.keys(combinedTotals).forEach((category) => {
if (parsedData.original && parsedData.original[category]) {
combinedTotals[category] += parsedData.original[category];
}
if (parsedData.unbiased && parsedData.unbiased[category]) {
combinedTotals[category] += parsedData.unbiased[category];
}
if (parsedData.multilingual && parsedData.multilingual[category]) {
combinedTotals[category] += parsedData.multilingual[category];
}
});
for (const category in combinedTotals) {
if (combinedTotals[category] <= threshold.keep) {
categoryLevels[category] = "Unlikely";
} else if (combinedTotals[category] > threshold.keep && combinedTotals[category] <= threshold.low) {
categoryLevels[category] = "Low";
} else if (combinedTotals[category] > threshold.low && combinedTotals[category] <= threshold.delete) {
categoryLevels[category] = "Partially";
} else if (combinedTotals[category] > threshold.delete && combinedTotals[category] <= threshold.serious) {
categoryLevels[category] = "Likely";
} else if (combinedTotals[category] > threshold.serious && combinedTotals[category] <= threshold.mostlikely) {
categoryLevels[category] = "Most Likely";
} else {
categoryLevels[category] = "Unknown";
}
}
let startingPoints = this.nvp;
// Loop through each category in combinedTotals and add its value to the combinedTotal
for (const category in combinedTotals) {
startingPoints += combinedTotals[category];
}
process.stdout.write(`Starting points: ${startingPoints}`);
const sortedCategoryLevels = Object.keys(categoryLevels).sort().reduce((acc, key) => {
acc[key] = categoryLevels[key];
return acc;
}, {});
let bestCategory = "",
bestValue = -Infinity,
secondBestCategory = "",
secondBestValue = -Infinity;
for (const category in combinedTotals) {
const value = combinedTotals[category];
if (value > bestValue) {
secondBestCategory = bestCategory;
secondBestValue = bestValue;
bestCategory = category;
bestValue = value;
} else if (value > secondBestValue) {
secondBestCategory = category;
secondBestValue = value;
}
}
results = {
toxicity: combinedTotals,
levelsCategory: sortedCategoryLevels,
totals: {
total: startingPoints,
category: bestCategory, secondBestCategory
},
status: 200100
}
} catch (error) {
console.log(error)
results = {
message: {
error: "Scan Failed: Something went wrong with automod algorithm",
code: 600011
}
}
}
})
To help you find out what’s wrong with your code, let's address the issues step-by-step:
request-promise-native is installed and used correctly.async/await with request-promise-native.Here’s a revised version of your code:
const requestPromise = require('request-promise-native'); // Ensure you have this installed
const payload = {}; // Define your payload here
async function makeRequest() {
try {
const options = {
url: this.key, // huggingface.co space API
headers: {
"accept": "text/event-stream",
"authorization": `Bearer ${process.env.HF_KEY}`,
"content-type": "application/json",
},
body: JSON.stringify(payload),
method: 'POST'
};
const response = await requestPromise(options);
const res = JSON.parse(response);
if (res.statusCode !== 200) {
throw new Error(`Request failed with status ${res.statusCode}`);
}
// Assuming bod is a JSON string that gets parsed
let pol = res;
let data = [
pol.data[0]
];
let combinedTotals = {
toxicity: 0 / 2,
severe_toxicity: 0,
obscene: 0,
threat: 0,
insult: 0,
identity_attack: 0,
sexual_explicit: 0,
};
let threshold = {
keep: 1,
low: 1.5,
delete: 1.6,
serious: 2.8,
mostlikely: 10.5,
};
const categoryLevels = {};
const parseJson = data[0].replace(/'/g, '"');
const parsedData = JSON.parse(parseJson);
Object.keys(combinedTotals).forEach((category) => {
if (parsedData.original && parsedData.original[category]) {
combinedTotals[category] += parsedData.original[category];
}
if (parsedData.unbiased && parsedData.unbiased[category]) {
combinedTotals[category] += parsedData.unbiased[category];
}
if (parsedData.multilingual && parsedData.multilingual[category]) {
combinedTotals[category] += parsedData.multilingual[category];
}
});
for (const category in combinedTotals) {
if (combinedTotals[category] <= threshold.keep) {
categoryLevels[category] = "Unlikely";
} else if (combinedTotals[category] > threshold.keep && combinedTotals[category] <= threshold.low) {
categoryLevels[category] = "Low";
} else if (combinedTotals[category] > threshold.low && combinedTotals[category] <= threshold.delete) {
categoryLevels[category] = "Partially";
} else if (combinedTotals[category] > threshold.delete && combinedTotals[category] <= threshold.serious) {
categoryLevels[category] = "Likely";
} else if (combinedTotals[category] > threshold.serious && combinedTotals[category] <= threshold.mostlikely) {
categoryLevels[category] = "Most Likely";
} else {
categoryLevels[category] = "Unknown";
}
}
let startingPoints = this.nvp;
for (const category in combinedTotals) {
startingPoints += combinedTotals[category];
}
process.stdout.write(`Starting points: ${startingPoints}`);
const sortedCategoryLevels = Object.keys(categoryLevels).sort().reduce((acc, key) => {
acc[key] = categoryLevels[key];
return acc;
}, {});
let bestCategory = "",
bestValue = -Infinity,
secondBestCategory = "",
secondBestValue = -Infinity;
for (const category in combinedTotals) {
const value = combinedTotals[category];
if (value > bestValue) {
secondBestCategory = bestCategory;
secondBestValue = bestValue;
bestCategory = category;
bestValue = value;
} else if (value > secondBestValue) {
secondBestCategory = category;
secondBestValue = value;
}
}
const results = {
toxicity: combinedTotals,
levelsCategory: sortedCategoryLevels,
totals: {
total: startingPoints,
category: bestCategory, secondBestCategory
},
status: 200100
};
console.log(results);
} catch (error) {
console.error(`Scan Failed: ${error.message}`);
const results = {
message: {
error: "Scan Failed: Something went wrong with automod algorithm",
code: 600011
}
};
console.log(results);
}
}
makeRequest();
request-promise-native: Directly used it with await.try-catch block to capture errors while making the request.Make sure you adjust the this.key and this.nvp references as per your context.
Not yet included in a published release.