correction
parent
f68b1e78e0
commit
4d9a785812
|
@ -1,11 +1,10 @@
|
||||||
const aiFeedbackOnReport = async (req, res) => {
|
const aiFeedbackOnReport = async (req, res) => {
|
||||||
// const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const url = process.env.AI_API_ENDOINT;
|
const url = process.env.AI_API_ENDOINT;
|
||||||
const api_key = process.env.AI_API_KEY;
|
const api_key = process.env.OPENAI_KEY;
|
||||||
const payload = {
|
const payload = {
|
||||||
"model": "gpt-4o-mini",
|
"model": "gpt-4o-mini",
|
||||||
"messages": [{ "role": "user",
|
"messages": [{ "role": "user", "content": JSON.stringify(req.body.score) + " - is the students report card. " + req.body.instruction }]
|
||||||
"content": JSON.stringify(req.body.score) + " - is the students report card. " + req.body.instruction }]
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const apiResponse = await fetch(url, {
|
const apiResponse = await fetch(url, {
|
||||||
|
|
|
@ -11,7 +11,7 @@ const aiFollowupQuestion = async (req, res) => {
|
||||||
const database = client.db(dbName); // Replace with your database name
|
const database = client.db(dbName); // Replace with your database name
|
||||||
const conversationsCollection = database.collection('conversations'); // Replace with your collection name
|
const conversationsCollection = database.collection('conversations'); // Replace with your collection name
|
||||||
|
|
||||||
async function fetchOpenAICompletion(prompt, messages, model = "gpt-3.5-turbo-16k", max_tokens = 200) {
|
async function fetchOpenAICompletion(prompt, messages, model = "gpt-3.5-turbo-16k", max_tokens = 600) {
|
||||||
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -26,12 +26,13 @@ const aiFollowupQuestion = async (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data.choices[0].message.content;
|
return data;
|
||||||
|
// return data.choices[0].message.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { prompt, sessionId, model = "gpt-4o-mini", max_tokens = 200 } = req.body;
|
const { prompt, sessionId, model = "gpt-4o-mini", max_tokens = 600 } = req.body;
|
||||||
if (!conversationsCollection) {
|
if (!conversationsCollection) {
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -48,9 +49,10 @@ const aiFollowupQuestion = async (req, res) => {
|
||||||
conversationHistory: [
|
conversationHistory: [
|
||||||
{ role: 'system', content: 'You are a helpful assistant.' },
|
{ role: 'system', content: 'You are a helpful assistant.' },
|
||||||
// { role: 'user', content: prompt },
|
// { role: 'user', content: prompt },
|
||||||
{ role: 'user', content: req.body.score + " - is the students report card. " + req.body.instruction },
|
{ role: 'user', content: JSON.stringify(req.body.score) + " - is the students report card. " + req.body.instruction },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
// console.log(req.body.score[0])
|
||||||
await conversationsCollection.insertOne(conversation);
|
await conversationsCollection.insertOne(conversation);
|
||||||
} else {
|
} else {
|
||||||
conversation = await conversationsCollection.findOne({ sessionId: sessionId });
|
conversation = await conversationsCollection.findOne({ sessionId: sessionId });
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const aiFollowupQuestion = async (req, res) => {
|
const aiFollowupQuestion = async (req, res) => {
|
||||||
|
|
||||||
const { MongoClient } = require('mongodb');
|
const { MongoClient } = require('mongodb');
|
||||||
// const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
const url = process.env.MONGODB_URL;
|
const url = process.env.MONGODB_URL;
|
||||||
const dbName = process.env.MONGO_DB_NAME;
|
const dbName = process.env.MONGO_DB_NAME;
|
||||||
|
|
Loading…
Reference in New Issue