Download src/app/api/critical/generate/route.ts from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/app/api/critical/generate/route.ts
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/app/api/critical/generate/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/app/api/critical/generate/route.ts
2.16 kB
| import { NextRequest, NextResponse } from "next/server"; | |
| import { | |
| getRandomFlawPassage, | |
| getRandomSteelmanPosition, | |
| getRandomDevilsAdvocatePosition, | |
| type ExerciseType, | |
| type FlawDifficulty, | |
| } from "@/lib/critical/passages"; | |
| import { withApiError } from "@/lib/api-error"; | |
| /** | |
| * GET /api/critical/generate | |
| * | |
| * Query params: | |
| * type?: "flaw-finder" | "steelman" | "devils-advocate" | |
| * difficulty?: "easy" | "medium" | "hard" (only for flaw-finder) | |
| */ | |
| export const GET = withApiError(async (request: NextRequest) => { | |
| const { searchParams } = new URL(request.url); | |
| const rawType = searchParams.get("type"); | |
| const rawDiff = searchParams.get("difficulty"); | |
| const validTypes: ExerciseType[] = ["flaw-finder", "steelman", "devils-advocate"]; | |
| const validDiffs: FlawDifficulty[] = ["easy", "medium", "hard"]; | |
| const type: ExerciseType = | |
| rawType && validTypes.includes(rawType as ExerciseType) | |
| ? (rawType as ExerciseType) | |
| : validTypes[Math.floor(Math.random() * validTypes.length)]; | |
| const difficulty: FlawDifficulty | undefined = | |
| rawDiff && validDiffs.includes(rawDiff as FlawDifficulty) | |
| ? (rawDiff as FlawDifficulty) | |
| : undefined; | |
| if (type === "flaw-finder") { | |
| const passage = getRandomFlawPassage(difficulty); | |
| return NextResponse.json({ | |
| type, | |
| passage: { | |
| id: passage.id, | |
| difficulty: passage.difficulty, | |
| title: passage.title, | |
| passage: passage.passage, | |
| fallacyCount: passage.fallacies.length, | |
| // do NOT return fallacies here — those are the answer key | |
| }, | |
| }); | |
| } | |
| if (type === "steelman") { | |
| const position = getRandomSteelmanPosition(); | |
| return NextResponse.json({ | |
| type, | |
| position: { | |
| id: position.id, | |
| domain: position.domain, | |
| position: position.position, | |
| context: position.context, | |
| }, | |
| }); | |
| } | |
| // devils-advocate | |
| const position = getRandomDevilsAdvocatePosition(); | |
| return NextResponse.json({ | |
| type, | |
| position: { | |
| id: position.id, | |
| domain: position.domain, | |
| position: position.position, | |
| context: position.context, | |
| }, | |
| }); | |
| }); | |