Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 961 Bytes
3d4392e ce559ed 3d4392e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import { NextResponse, NextRequest } from "next/server"
import queryString from "query-string"
import { predict } from "../../providers/huggingface/predictWithHuggingFace"
import { systemPrompt } from "./systemPrompt"
export async function GET(req: NextRequest) {
const qs = queryString.parseUrl(req.url || "")
const query = (qs || {}).query
let prompt = ""
try {
prompt = decodeURIComponent(query?.p?.toString() || "").trim()
} catch (err) {}
if (!prompt) {
return NextResponse.json({ error: 'no prompt provided' }, { status: 400 });
}
const userPrompt = `HTML snippet to generate: ${prompt}`
const html = await predict({
systemPrompt,
userPrompt,
nbMaxNewTokens: 400,
prefix: "<div class=\"",
})
console.log("generated div: ", html)
// const html = `<html><head></head><body></body></html>`
return new NextResponse(html, {
status: 200,
headers: new Headers({ "content-type": "text/html" }),
})
}
|