@@ -75,6 +75,19 @@ function parseExamDetail(analysis: string): ExamDetail {
75
75
const jsonMatch = analysis . match ( / \{ [ \s \S ] * \} / ) ;
76
76
if ( jsonMatch ) {
77
77
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
+ }
78
91
return examDetail
79
92
}
80
93
@@ -86,6 +99,8 @@ function parseExamDetail(analysis: string): ExamDetail {
86
99
slot : "Unknown" ,
87
100
"course-code" : "Unknown" ,
88
101
"exam-type" : "Unknown" ,
102
+ semester : "Fall" ,
103
+ year : new Date ( ) . getFullYear ( ) . toString ( )
89
104
} ;
90
105
}
91
106
}
@@ -104,18 +119,22 @@ async function analyzeImage(dataUrl: string): Promise<AnalysisResult[]> {
104
119
// const dataUrl = `data:image/png;base64,${imageBase64}`;
105
120
106
121
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
+ }` ;
119
138
120
139
const chatResponse = ( await client . chat . complete ( {
121
140
model : "pixtral-12b" ,
@@ -155,6 +174,8 @@ async function analyzeImage(dataUrl: string): Promise<AnalysisResult[]> {
155
174
slot : "Error" ,
156
175
"course-code" : "Error" ,
157
176
"exam-type" : "Error" ,
177
+ semester : "Fall" ,
178
+ year : new Date ( ) . getFullYear ( ) . toString ( )
158
179
} ,
159
180
rawAnalysis : `Error analyzing image: ${ errorMessage } ` ,
160
181
} ,
0 commit comments