Skip to content

Commit 7acb45d

Browse files
committed
Setup function calling
1 parent dd8fa31 commit 7acb45d

File tree

4 files changed

+248
-99
lines changed

4 files changed

+248
-99
lines changed

course-matrix/backend/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { supabase } from "../db/setupDb";
2+
import { Request } from "express";
3+
4+
export type FunctionNames = "getTimetables"; // Add all possible function names here
5+
6+
type AvailableFunctions = {
7+
[K in FunctionNames]: (args: any, req: Request) => Promise<any>;
8+
};
9+
10+
// Functions used for OpenAI function calling
11+
export const availableFunctions: AvailableFunctions = {
12+
getTimetables: async (args: any, req: Request) => {
13+
try {
14+
//Retrieve user_id
15+
const user_id = (req as any).user.id;
16+
17+
//Retrieve user timetable item based on user_id
18+
let timeTableQuery = supabase
19+
.schema("timetable")
20+
.from("timetables")
21+
.select()
22+
.eq("user_id", user_id);
23+
const { data: timetableData, error: timetableError } =
24+
await timeTableQuery;
25+
26+
if (timetableError) return { status: 400, error: timetableError.message };
27+
28+
// If no records were updated due to non-existence timetable or it doesn't belong to the user.
29+
if (!timetableData || timetableData.length === 0) {
30+
return {
31+
status: 404,
32+
error: "Timetable not found or you are not authorized to update it",
33+
};
34+
}
35+
36+
return { status: 200, data: timetableData };
37+
} catch (error) {
38+
return { status: 400, error: error };
39+
}
40+
},
41+
};

course-matrix/backend/src/constants/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ namespaceToMinResults.set("programs", 5);
4848

4949
// Consider the last X messages in history to influence vector DB query
5050
export const CHATBOT_MEMORY_THRESHOLD = 3;
51+
52+
export const CHATBOT_TIMETABLE_CMD = "/timetable";

0 commit comments

Comments
 (0)