Skip to content

Commit f06912f

Browse files
kevin-lanngithub-actions[bot]
authored andcommitted
Auto-formatted the code using Prettier
1 parent 4cb5b39 commit f06912f

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

course-matrix/backend/src/controllers/aiController.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const pinecone = new Pinecone({
3535
});
3636

3737
const index: Index<RecordMetadata> = pinecone.Index(
38-
process.env.PINECONE_INDEX_NAME!
38+
process.env.PINECONE_INDEX_NAME!,
3939
);
4040

4141
console.log("Connected to OpenAI API");
@@ -92,7 +92,7 @@ function analyzeQuery(query: string): {
9292
"prerequisites",
9393
"corequisites",
9494
"departments",
95-
"programs"
95+
"programs",
9696
);
9797
}
9898

@@ -110,7 +110,7 @@ async function searchSelectedNamespaces(
110110
query: string,
111111
k: number,
112112
namespaces: string[],
113-
filters?: Object
113+
filters?: Object,
114114
): Promise<Document[]> {
115115
let allResults: Document[] = [];
116116

@@ -132,7 +132,7 @@ async function searchSelectedNamespaces(
132132
const results = await namespaceStore.similaritySearch(
133133
query,
134134
Math.max(k, namespaceToMinResults.get(namespace)),
135-
namespace === "courses_v3" ? filters : undefined
135+
namespace === "courses_v3" ? filters : undefined,
136136
);
137137
console.log(`Found ${results.length} results in namespace: ${namespace}`);
138138
allResults = [...allResults, ...results];
@@ -153,7 +153,7 @@ async function searchSelectedNamespaces(
153153
// Reformulate user query to make more concise query to database, taking into consideration context
154154
async function reformulateQuery(
155155
latestQuery: string,
156-
conversationHistory: any[]
156+
conversationHistory: any[],
157157
): Promise<string> {
158158
try {
159159
const openai = new OpenAI({
@@ -244,7 +244,7 @@ function includeFilters(query: string) {
244244
if (keywords.some((keyword) => lowerQuery.includes(keyword))) {
245245
relaventBreadthRequirements.push(convertBreadthRequirement(namespace));
246246
}
247-
}
247+
},
248248
);
249249

250250
Object.entries(YEAR_LEVEL_KEYWORDS).forEach(([namespace, keywords]) => {
@@ -309,7 +309,7 @@ export const chat = asyncHandler(async (req: Request, res: Response) => {
309309
// Use GPT-4o to reformulate the query based on conversation history
310310
const reformulatedQuery = await reformulateQuery(
311311
latestMessage,
312-
conversationHistory.slice(-CHATBOT_MEMORY_THRESHOLD) // last K messages
312+
conversationHistory.slice(-CHATBOT_MEMORY_THRESHOLD), // last K messages
313313
);
314314
console.log(">>>> Original query:", latestMessage);
315315
console.log(">>>> Reformulated query:", reformulatedQuery);
@@ -323,8 +323,8 @@ export const chat = asyncHandler(async (req: Request, res: Response) => {
323323
if (requiresSearch) {
324324
console.log(
325325
`Query requires knowledge retrieval, searching namespaces: ${relevantNamespaces.join(
326-
", "
327-
)}`
326+
", ",
327+
)}`,
328328
);
329329

330330
const filters = includeFilters(reformulatedQuery);
@@ -335,7 +335,7 @@ export const chat = asyncHandler(async (req: Request, res: Response) => {
335335
reformulatedQuery,
336336
3,
337337
relevantNamespaces,
338-
Object.keys(filters).length === 0 ? undefined : filters
338+
Object.keys(filters).length === 0 ? undefined : filters,
339339
);
340340
// console.log("Search Results: ", searchResults);
341341

@@ -403,15 +403,15 @@ export const testSimilaritySearch = asyncHandler(
403403
if (requiresSearch) {
404404
console.log(
405405
`Query requires knowledge retrieval, searching namespaces: ${relevantNamespaces.join(
406-
", "
407-
)}`
406+
", ",
407+
)}`,
408408
);
409409

410410
// Search only the relevant namespaces
411411
const searchResults = await searchSelectedNamespaces(
412412
message,
413413
3,
414-
relevantNamespaces
414+
relevantNamespaces,
415415
);
416416
console.log("Search Results: ", searchResults);
417417

@@ -421,11 +421,11 @@ export const testSimilaritySearch = asyncHandler(
421421
}
422422
} else {
423423
console.log(
424-
"Query does not require knowledge retrieval, skipping search"
424+
"Query does not require knowledge retrieval, skipping search",
425425
);
426426
}
427427

428428
console.log("CONTEXT: ", context);
429429
res.status(200).send(context);
430-
}
430+
},
431431
);

course-matrix/backend/src/utils/embeddings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async function processCoursesCSV(filePath: string, namespace: string) {
5151
source: fileName,
5252
row: index + 1,
5353
breadth_requirement: convertBreadthRequirement(
54-
doc.pageContent.split("\n")[1].split(": ")[1]
54+
doc.pageContent.split("\n")[1].split(": ")[1],
5555
),
5656
year_level: doc.pageContent.split("\n")[10].split(": ")[1],
5757
},
@@ -101,7 +101,7 @@ async function processPDF(filePath: string, namespace: string) {
101101
// console.log("Sample split docs: ", splitDocs.slice(0, 6))
102102

103103
console.log(
104-
`Split into ${splitDocs.length} sections by "Calendar Section:" delimiter`
104+
`Split into ${splitDocs.length} sections by "Calendar Section:" delimiter`,
105105
);
106106

107107
// Store the split documents as embeddings

0 commit comments

Comments
 (0)