Skip to content

Commit db1edb7

Browse files
committed
Update next-server example
1 parent 2e8010f commit db1edb7

File tree

3 files changed

+64
-62
lines changed

3 files changed

+64
-62
lines changed

next-server/app/api/classify/route.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
import { pipeline } from "@huggingface/transformers";
44

5-
// NOTE: We attach the classifier to the global object to avoid loading it multiple times
5+
// NOTE: We attach the classifier to the global object to avoid unnecessary reloads during development
66
const classifier = (globalThis.classifier ??= await pipeline(
77
"text-classification",
88
"Xenova/distilbert-base-uncased-finetuned-sst-2-english",
99
));
1010

1111
export async function GET(request) {
12-
// https://nextjs.org/docs/app/building-your-axpplication/routing/route-handlers#url-query-parameters
13-
const searchParams = request.nextUrl.searchParams;
14-
const text = searchParams.get("text");
12+
const text = request.nextUrl.searchParams.get("text");
13+
14+
if (!text) {
15+
return Response.json({ message: "No text provided" }, { status: 400 });
16+
}
1517

1618
const result = await classifier(text);
1719
return Response.json(result[0]);

next-server/package-lock.json

Lines changed: 55 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

next-server/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
},
1111
"dependencies": {
1212
"@huggingface/transformers": "^3.0.0",
13-
"next": "15.0.0",
14-
"react": "19.0.0-rc-65a56d0e-20241020",
15-
"react-dom": "19.0.0-rc-65a56d0e-20241020"
13+
"next": "15.0.1",
14+
"react": "19.0.0-rc-69d4b800-20241021",
15+
"react-dom": "19.0.0-rc-69d4b800-20241021"
1616
},
1717
"devDependencies": {
1818
"eslint": "^9",

0 commit comments

Comments
 (0)