Skip to content

Commit

Permalink
Moderation
Browse files Browse the repository at this point in the history
  • Loading branch information
redji committed Mar 21, 2024
1 parent 6b5d90a commit 509e52c
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions prompt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fetch from 'node-fetch';

const APIKey = '';
const OpenAIKey = '';
let moderationAnswer = [];

// Function to make a request with a delay
async function makeRequestWithDelay(url, options, delay) {
Expand All @@ -27,11 +29,8 @@ fetch('https://tasks.aidevs.pl/token/helloapi', {
})
.then(async (response) => {
const data = await response.json();
console.log(data);
const token = data.token;
const url = `https://tasks.aidevs.pl/task/${token}`;
console.log(token);
console.log(url);

// Second curl command with a delay of 2000 milliseconds (2 seconds)
const response2 = await makeRequestWithDelay(url, {
Expand All @@ -51,4 +50,50 @@ fetch('https://tasks.aidevs.pl/token/helloapi', {
}, 10);
console.log(response3);
})
.catch(error => console.error('Error:', error));

// Second curl command
fetch('https://tasks.aidevs.pl/token/moderation', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({apikey: APIKey})
})
.then(async (response) => {
const data = await response.json();
const token = data.token;
const url = `https://tasks.aidevs.pl/task/${token}`;

// Second curl command with a delay of 2000 milliseconds (2 seconds)
const response2 = await makeRequestWithDelay(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}, 10);

moderationAnswer = []; // Clear previous values

for (const element of response2.input) {
const response3 = await makeRequestWithDelay(`https://api.openai.com/v1/moderations`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${OpenAIKey}`
},
body: JSON.stringify({ input: element })
});
moderationAnswer.push(response3.results[0].flagged ? 1 : 0);
}
// Third curl command with a delay of 2000 milliseconds (2 seconds)
const response4 = await makeRequestWithDelay(`https://tasks.aidevs.pl/answer/${token}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({answer: moderationAnswer})
}, 10);
console.log(response4);
})
.catch(error => console.error('Error:', error));

0 comments on commit 509e52c

Please sign in to comment.