From 4d9a78581255d0b52ee81e5441795351c1a058b0 Mon Sep 17 00:00:00 2001 From: Kar l5 Date: Mon, 6 Jan 2025 19:22:28 +0530 Subject: [PATCH] correction --- src/routes/api/aiFeedbackOnReport.js | 7 +++---- src/routes/api/aiFeedbackOnReportWithFollowup.js | 10 ++++++---- src/routes/api/aiFollowupQuestion.js | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/routes/api/aiFeedbackOnReport.js b/src/routes/api/aiFeedbackOnReport.js index b5511af..880741e 100644 --- a/src/routes/api/aiFeedbackOnReport.js +++ b/src/routes/api/aiFeedbackOnReport.js @@ -1,11 +1,10 @@ const aiFeedbackOnReport = async (req, res) => { - // const fetch = require('node-fetch'); + const fetch = require('node-fetch'); const url = process.env.AI_API_ENDOINT; - const api_key = process.env.AI_API_KEY; + const api_key = process.env.OPENAI_KEY; const payload = { "model": "gpt-4o-mini", - "messages": [{ "role": "user", - "content": JSON.stringify(req.body.score) + " - is the students report card. " + req.body.instruction }] + "messages": [{ "role": "user", "content": JSON.stringify(req.body.score) + " - is the students report card. " + req.body.instruction }] } try { const apiResponse = await fetch(url, { diff --git a/src/routes/api/aiFeedbackOnReportWithFollowup.js b/src/routes/api/aiFeedbackOnReportWithFollowup.js index 9faba0d..cbe3eee 100644 --- a/src/routes/api/aiFeedbackOnReportWithFollowup.js +++ b/src/routes/api/aiFeedbackOnReportWithFollowup.js @@ -11,7 +11,7 @@ const aiFollowupQuestion = async (req, res) => { const database = client.db(dbName); // Replace with your database 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', { method: 'POST', headers: { @@ -26,12 +26,13 @@ const aiFollowupQuestion = async (req, res) => { }); const data = await response.json(); - return data.choices[0].message.content; + return data; + // return data.choices[0].message.content; } 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) { return res.status(500).json({ success: false, @@ -48,9 +49,10 @@ const aiFollowupQuestion = async (req, res) => { conversationHistory: [ { role: 'system', content: 'You are a helpful assistant.' }, // { 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); } else { conversation = await conversationsCollection.findOne({ sessionId: sessionId }); diff --git a/src/routes/api/aiFollowupQuestion.js b/src/routes/api/aiFollowupQuestion.js index df653c3..5ce63f7 100644 --- a/src/routes/api/aiFollowupQuestion.js +++ b/src/routes/api/aiFollowupQuestion.js @@ -1,7 +1,7 @@ const aiFollowupQuestion = async (req, res) => { const { MongoClient } = require('mongodb'); - // const fetch = require('node-fetch'); + const fetch = require('node-fetch'); const { v4: uuidv4 } = require('uuid'); const url = process.env.MONGODB_URL; const dbName = process.env.MONGO_DB_NAME;