Delete src/routes/api/aiEvaluateImageToStar.js
parent
d2db8ead08
commit
6b1cad684d
|
@ -1,87 +0,0 @@
|
||||||
const AWS = require('aws-sdk');
|
|
||||||
const axios = require('axios');
|
|
||||||
const FormData = require('form-data');
|
|
||||||
const mongoose = require('mongoose');
|
|
||||||
const Game = require('../../models/gameModel');
|
|
||||||
|
|
||||||
const aiEvaluateImageToStar = async (req, res) => {
|
|
||||||
try {
|
|
||||||
const { userId, gameName, gameID, gameTime, gameStar, screenShot } = req.body;
|
|
||||||
if (!screenShot) {
|
|
||||||
return res.status(400).json({ error: 'Screenshot is required' });
|
|
||||||
}
|
|
||||||
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('image', screenShot);
|
|
||||||
const screenshotUrl = await axios.post('https://teachertrainingchennai.in/api/uploadBase64/', formData, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
// .then(response => {
|
|
||||||
// console.log('Response:', response.data);
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// console.error('Error:', error);
|
|
||||||
// });
|
|
||||||
console.log(screenshotUrl.data.filePath)
|
|
||||||
const openAiPayload = {
|
|
||||||
model: 'gpt-4o-mini',
|
|
||||||
messages: [
|
|
||||||
{
|
|
||||||
role: 'user',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
text: 'The coloring was done by a 5-year-old kid. Give a score between 3 to 10 in JSON format.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'image_url',
|
|
||||||
image_url: {
|
|
||||||
url: screenshotUrl.data.filePath,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
max_tokens: 300,
|
|
||||||
};
|
|
||||||
|
|
||||||
// console.log('AAAAAA')
|
|
||||||
const openAiResponse = await axios.post(
|
|
||||||
'https://api.openai.com/v1/chat/completions',
|
|
||||||
openAiPayload,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const rResp=openAiResponse.data.choices[0].message;
|
|
||||||
const cleanContent = rResp.content.replace(/```json|```/g, '').trim();
|
|
||||||
const parsedScore = JSON.parse(cleanContent);
|
|
||||||
// console.log(parsedScore); // { score: 8 }
|
|
||||||
const gameData = new Game({
|
|
||||||
gameName,
|
|
||||||
userId,
|
|
||||||
gameID,
|
|
||||||
gameTime,
|
|
||||||
score: parsedScore.score || 'N/A',
|
|
||||||
gameStar,
|
|
||||||
screenshotUrl:screenshotUrl.data.filePath,
|
|
||||||
});
|
|
||||||
|
|
||||||
await gameData.save();
|
|
||||||
|
|
||||||
return res.status(200).json({
|
|
||||||
message: 'Game data saved successfully',
|
|
||||||
data: gameData,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error:', error.message);
|
|
||||||
return res.status(500).json({ error: 'Something went wrong' });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = aiEvaluateImageToStar;
|
|
Loading…
Reference in New Issue