Skip to content

Commit 545965e

Browse files
authored
Merge pull request #88 from guth01/staging
semester&year incorporation
2 parents 5813427 + 1c080f2 commit 545965e

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ export type ExamDetail = {
150150
slot: string;
151151
"course-code": string;
152152
"exam-type": string;
153+
semester: "Fall" | "Winter" | "Summer" | "Weekend";
154+
year: string;
153155
};
154156
export interface Filters {
155157
papers: IPaper[];

src/util/mistral.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ function parseExamDetail(analysis: string): ExamDetail {
7575
const jsonMatch = analysis.match(/\{[\s\S]*\}/);
7676
if (jsonMatch) {
7777
const examDetail: ExamDetail = JSON.parse(jsonMatch[0]) as ExamDetail;
78+
if (examDetail.semester) {
79+
const validSemesters = ["Fall", "Winter", "Summer", "Weekend"];
80+
if (!validSemesters.includes(examDetail.semester)) {
81+
examDetail.semester = "Fall"; // Default to Fall if invalid
82+
}
83+
}
84+
85+
if (examDetail.year) {
86+
const yearPattern = /^\d{4}$/;
87+
if (!yearPattern.test(examDetail.year)) {
88+
examDetail.year = new Date().getFullYear().toString(); // Default to current year if invalid
89+
}
90+
}
7891
return examDetail
7992
}
8093

@@ -86,6 +99,8 @@ function parseExamDetail(analysis: string): ExamDetail {
8699
slot: "Unknown",
87100
"course-code": "Unknown",
88101
"exam-type": "Unknown",
102+
semester: "Fall",
103+
year: new Date().getFullYear().toString()
89104
};
90105
}
91106
}
@@ -104,18 +119,22 @@ async function analyzeImage(dataUrl: string): Promise<AnalysisResult[]> {
104119
// const dataUrl = `data:image/png;base64,${imageBase64}`;
105120

106121
const prompt = `Please analyze this exam paper image and extract the following details in JSON format:
107-
- course-name: The full name of the course (3-4 words, no numbers or special characters)
108-
- slot: One of A1|A2|B1|B2|C1|C2|D1|D2|E1|E2|F1|F2|G1|G2
109-
- course-code: The course code (format: department letters + numbers)
110-
- exam-type: One of "Final Assessment Test|Continuous Assessment Test - 1|Continuous Assessment Test - 2"
111-
112-
Provide the response in this exact format:
113-
{
114-
"course-name": "...",
115-
"slot": "...",
116-
"course-code": "...",
117-
"exam-type": "..."
118-
}`;
122+
- course-name: The full name of the course (3-4 words, no numbers or special characters)
123+
- slot: One of A1|A2|B1|B2|C1|C2|D1|D2|E1|E2|F1|F2|G1|G2
124+
- course-code: The course code (format: department letters + numbers)
125+
- exam-type: One of "Final Assessment Test|Continuous Assessment Test - 1|Continuous Assessment Test - 2"
126+
- semester: Must be exactly one of "Fall", "Winter", "Summer", or "Weekend"
127+
- year: The year in YYYY format (e.g., "2023")
128+
129+
Provide the response in this exact format:
130+
{
131+
"course-name": "...",
132+
"slot": "...",
133+
"course-code": "...",
134+
"exam-type": "...",
135+
"semester": "...",
136+
"year": "..."
137+
}`;
119138

120139
const chatResponse = (await client.chat.complete({
121140
model: "pixtral-12b",
@@ -155,6 +174,8 @@ async function analyzeImage(dataUrl: string): Promise<AnalysisResult[]> {
155174
slot: "Error",
156175
"course-code": "Error",
157176
"exam-type": "Error",
177+
semester: "Fall",
178+
year: new Date().getFullYear().toString()
158179
},
159180
rawAnalysis: `Error analyzing image: ${errorMessage}`,
160181
},

0 commit comments

Comments
 (0)