Skip to content

Commit 029612c

Browse files
committed
Setup generateTimetable function call
1 parent 037da20 commit 029612c

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { Request } from "express";
55
export type FunctionNames =
66
| "getTimetables"
77
| "updateTimetable"
8-
| "deleteTimetable";
8+
| "deleteTimetable"
9+
| "generateTimetable";
910

1011
type AvailableFunctions = {
1112
[K in FunctionNames]: (args: any, req: Request) => Promise<any>;
@@ -168,4 +169,7 @@ export const availableFunctions: AvailableFunctions = {
168169
return { status: 500, error: error };
169170
}
170171
},
172+
generateTimetable: async (args: any, req: Request) => {
173+
174+
}
171175
};

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
import { z } from "zod";
4040
import { analyzeQuery } from "../utils/analyzeQuery";
4141
import { includeFilters } from "../utils/includeFilters";
42+
import { TimetableFormSchema } from "../models/timetable-form";
4243

4344
const openai = createOpenAI({
4445
baseURL: process.env.OPENAI_BASE_URL,
@@ -281,6 +282,13 @@ export const chat = asyncHandler(async (req: Request, res: Response) => {
281282
return await availableFunctions.deleteTimetable(args, req);
282283
},
283284
}),
285+
generateTimetable: tool({
286+
description: "Generate a timetable based on selected courses and restrictions",
287+
parameters: TimetableFormSchema,
288+
execute: async (args) => {
289+
return await availableFunctions.generateTimetable(args, req)
290+
}
291+
})
284292
},
285293
maxSteps: CHATBOT_TOOL_CALL_MAX_STEPS, // Controls how many back and forths the model can take with user or calling multiple tools
286294
experimental_repairToolCall: async ({
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { z, ZodType } from "zod";
2+
3+
export type TimetableForm = {
4+
name: string;
5+
date: Date;
6+
semester: string;
7+
search: string;
8+
courses: {
9+
id: number;
10+
code: string;
11+
name: string;
12+
}[];
13+
restrictions: RestrictionForm[];
14+
};
15+
16+
export type RestrictionForm = {
17+
type: string;
18+
days?: string[];
19+
numDays?: number;
20+
startTime?: Date;
21+
endTime?: Date;
22+
disabled?: boolean;
23+
};
24+
25+
export const daysOfWeek = [
26+
{
27+
id: "MO",
28+
label: "Monday",
29+
},
30+
{
31+
id: "TU",
32+
label: "Tuesday",
33+
},
34+
{
35+
id: "WE",
36+
label: "Wednesday",
37+
},
38+
{
39+
id: "TH",
40+
label: "Thursday",
41+
},
42+
{
43+
id: "FR",
44+
label: "Friday",
45+
},
46+
] as const;
47+
48+
export const SemesterEnum = z.enum(["Summer 2025", "Fall 2025", "Winter 2026"]);
49+
50+
export const CourseSchema = z.object({
51+
id: z.number(),
52+
code: z
53+
.string()
54+
.max(8, "Invalid course code")
55+
.min(1, "Course code is required"),
56+
name: z.string(),
57+
});
58+
59+
export const RestrictionSchema = z
60+
.object({
61+
type: z.string().min(1, "Restriction type is required"),
62+
days: z.array(z.string()).optional(),
63+
numDays: z
64+
.number()
65+
.positive()
66+
.max(4, "Cannot block all days of the week")
67+
.optional(),
68+
startTime: z.date().optional(),
69+
endTime: z.date().optional(),
70+
disabled: z.boolean().optional(),
71+
})
72+
73+
export const TimetableFormSchema = z
74+
.object({
75+
name: z
76+
.string()
77+
.max(100, "Name cannot exceed 100 characters")
78+
.min(1, "Name cannot be empty"),
79+
date: z.date(),
80+
semester: SemesterEnum,
81+
search: z.string(),
82+
courses: z.array(CourseSchema),
83+
restrictions: z.array(RestrictionSchema),
84+
});
85+

0 commit comments

Comments
 (0)