correction
parent
f68b1e78e0
commit
4d9a785812
|
@ -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, {
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue