Skip to content

Commit 395cbfd

Browse files
fix prettier
1 parent d040204 commit 395cbfd

File tree

6 files changed

+24
-29
lines changed

6 files changed

+24
-29
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
This platform is an AI-powered solution designed to enhance UPSC preparation for aspirants. It is now open to open-source contributions, inviting the community to collaborate and improve its features.
44

55
It provides various AI backed tools
6+
67
### Tools
8+
79
1. [AI Answer writing](https://aspirants-six.vercel.app/ai/answer-evaluator)
810

911
### Our Tech Stack
12+
1013
1. [Next](https://nextjs.org/)
1114
2. [Postgres](https://www.postgresql.org/)
1215
3. [Prisma](https://www.prisma.io/)

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "3.8"
22

33
services:
44
db:
5-
image: postgres:latest
5+
image: postgres:14
66
container_name: aspirants-local-db
77
environment:
88
POSTGRES_DB: aspirants-local

src/app/api/asp-ai/evaluate-answer/route.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import { ErrorCodes } from "@/app/lib/constants";
1212
import RatelimitService from "@/app/server/services/integrations/rateLimitig.service";
1313

1414
const s3 = S3Service.getInstance(process.env.AWS_S3_BUCKET_NAME!);
15-
const textExtract =TextractService.getInstance(process.env.AWS_S3_BUCKET_NAME!);
16-
const rl = RatelimitService.getInstance().getRatelimit()
15+
const textExtract = TextractService.getInstance(
16+
process.env.AWS_S3_BUCKET_NAME!,
17+
);
18+
const rl = RatelimitService.getInstance().getRatelimit();
1719

1820
export const maxDuration = 60;
1921

@@ -52,7 +54,15 @@ export async function POST(req: Request) {
5254
const question = form.get("question")?.toString();
5355

5456
// Validate the form data
55-
await validateEvaluateAnswerAPIFormData(answerPDF, question);
57+
if (!validateEvaluateAnswerAPIFormData(answerPDF, question)) {
58+
return NextResponse.json(
59+
{
60+
error: "Invalid form data, requires both question and answerPDF",
61+
errorCode: ErrorCodes.BAD_REQUEST,
62+
},
63+
{ status: 400 },
64+
);
65+
}
5666

5767
const answerId = cuid();
5868
const s3Key = questionId
@@ -82,7 +92,7 @@ export async function POST(req: Request) {
8292
});
8393

8494
return NextResponse.json({
85-
modelAnswer: evaluation.modelAnswer.replace,
95+
modelAnswer: evaluation.modelAnswer,
8696
score: evaluation.score,
8797
mistakesAndCorrections: evaluation.mistakesAndCorrections,
8898
goodParts: evaluation.goodParts,

src/app/components/ai/answer-evaluation/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ export const EvaluateAnswer = ({
4141
const [uploadedAnswer, setUploadedAnswer] = useState<File | null>(null);
4242
const [question, setQuestion] = useState<string | undefined>(initialQuestion);
4343

44+
console.log("uploaded answer====", uploadedAnswer);
45+
4446
const [{ loading, error, value: results }, handleSubmit] = useAsyncFn(
4547
async () => {
4648
const formData = new FormData();
4749
if (question) {
4850
formData.append("question", question);
4951
}
5052
if (uploadedAnswer) {
53+
console.log("uploadedAnswer while calling the api", uploadedAnswer);
5154
formData.append("answer", uploadedAnswer);
5255
}
5356
if (questionId) {

src/app/server/services/ai/evaluateAnswer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const parser = StructuredOutputParser.fromZodSchema(
3535
}),
3636
)
3737
.describe(
38-
"An array of objects, each highlighting a good aspect of the answer",
38+
"An array of objects, each highlighting a good aspect of the answer if there are any",
3939
)
4040
.nullable()
4141
.optional(),
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
import { ErrorCodes } from "@/app/lib/constants";
2-
import { NextResponse } from "next/server";
3-
41
// TODO: Replace this with zod schema.
5-
export async function validateEvaluateAnswerAPIFormData(
2+
export function validateEvaluateAnswerAPIFormData(
63
answerPDF: FormDataEntryValue | null,
74
question?: string,
85
) {
9-
if (!answerPDF) {
10-
return NextResponse.json(
11-
{
12-
error: "No answer provided to evaluate",
13-
errorCode: ErrorCodes.BAD_REQUEST,
14-
},
15-
{ status: 400 },
16-
);
17-
}
18-
19-
if (!question) {
20-
return NextResponse.json(
21-
{
22-
error: "No question provided to evaluate",
23-
errorCode: ErrorCodes.BAD_REQUEST,
24-
},
25-
{ status: 400 },
26-
);
27-
}
6+
return answerPDF && question;
287
}

0 commit comments

Comments
 (0)