@@ -2,6 +2,11 @@ const OpenAI = require('openai');
22const functions = require ( 'firebase-functions' ) ;
33const admin = require ( 'firebase-admin' ) ;
44
5+ /**
6+ * Formats all document data using a single OpenAI API call to ensure consistent structure
7+ * @param {string } userId - The user ID
8+ * @returns {Promise<Object> } Formatted data for calculations and predictions
9+ */
510/**
611 * Formats all document data using a single OpenAI API call to ensure consistent structure
712 * @param {string } userId - The user ID
@@ -50,7 +55,7 @@ exports.formatDocumentsData = async (userId) => {
5055 apiKey : apiKey
5156 } ) ;
5257
53- // Create a prompt with all document texts
58+ // Create a unified prompt with all document texts
5459 const prompt = createFormattingPrompt ( documentsByType ) ;
5560
5661 // Call OpenAI API
@@ -87,6 +92,11 @@ exports.formatDocumentsData = async (userId) => {
8792 }
8893} ;
8994
95+ /**
96+ * Creates the prompt for OpenAI formatting
97+ * @param {Object } documentsByType - Documents organized by type
98+ * @returns {string } Formatted prompt
99+ */
90100/**
91101 * Creates the prompt for OpenAI formatting
92102 * @param {Object } documentsByType - Documents organized by type
@@ -169,6 +179,12 @@ For the academicHistory.relevantCourses, analyze the transcript to find courses
169179` ;
170180}
171181
182+ /**
183+ * Stores the formatted data in Firestore
184+ * @param {string } userId - The user ID
185+ * @param {Object } formattedData - The formatted data
186+ * @returns {Promise<void> }
187+ */
172188/**
173189 * Stores the formatted data in Firestore
174190 * @param {string } userId - The user ID
@@ -192,6 +208,12 @@ async function storeFormattedData(userId, formattedData) {
192208 }
193209}
194210
211+ /**
212+ * Updates the status of processed documents
213+ * @param {string } userId - The user ID
214+ * @param {Array } documents - The document snapshots
215+ * @returns {Promise<void> }
216+ */
195217/**
196218 * Updates the status of processed documents
197219 * @param {string } userId - The user ID
@@ -215,6 +237,11 @@ async function updateDocumentStatus(userId, documents) {
215237 console . log ( 'Successfully updated document statuses' ) ;
216238}
217239
240+ /**
241+ * Creates a fallback formatted data structure if OpenAI fails
242+ * @param {Object } documentsByType - Documents organized by type
243+ * @returns {Object } Fallback formatted data
244+ */
218245/**
219246 * Creates a fallback formatted data structure if OpenAI fails
220247 * @param {Object } documentsByType - Documents organized by type
@@ -266,6 +293,11 @@ function createFallbackFormattedData(documentsByType) {
266293 } ;
267294}
268295
296+ /**
297+ * Extract grade weights using regex patterns
298+ * @param {string } text - Text to extract grade weights from
299+ * @returns {Array } Array of {name, weight} objects
300+ */
269301/**
270302 * Extract grade weights using regex patterns
271303 * @param {string } text - Text to extract grade weights from
@@ -312,6 +344,9 @@ function extractGradeWeights(text) {
312344 }
313345}
314346
347+ /**
348+ * Helper function to get OpenAI API key
349+ */
315350/**
316351 * Helper function to get OpenAI API key
317352 */
0 commit comments