Spaces:
Sleeping
Sleeping
ausername-12345 commited on
Commit ·
81a01b5
1
Parent(s): 67dcad9
Add API test endpoint for debugging
Browse files
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
server.js
CHANGED
|
@@ -103,6 +103,33 @@ app.get("/api/check", (_, res) => {
|
|
| 103 |
res.json({ ok: true, token: !!process.env.HF_TOKEN });
|
| 104 |
});
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
app.use((err, _req, res, _next) => {
|
| 107 |
console.error("Unhandled:", err);
|
| 108 |
res.status(500).json({ error: err.message || "Internal error" });
|
|
|
|
| 103 |
res.json({ ok: true, token: !!process.env.HF_TOKEN });
|
| 104 |
});
|
| 105 |
|
| 106 |
+
app.post("/api/test-hf", async (req, res) => {
|
| 107 |
+
try {
|
| 108 |
+
const token = process.env.HF_TOKEN;
|
| 109 |
+
const model = req.body.model || "HuggingFaceH4/zephyr-7b-beta";
|
| 110 |
+
const body = {
|
| 111 |
+
model,
|
| 112 |
+
max_tokens: 100,
|
| 113 |
+
messages: [
|
| 114 |
+
{ role: "user", content: "Say hello in one word" },
|
| 115 |
+
],
|
| 116 |
+
};
|
| 117 |
+
const hfRes = await fetchWithTimeout(
|
| 118 |
+
`https://api-inference.huggingface.co/models/${model}/v1/chat/completions`,
|
| 119 |
+
{
|
| 120 |
+
method: "POST",
|
| 121 |
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
|
| 122 |
+
body: JSON.stringify(body),
|
| 123 |
+
},
|
| 124 |
+
30000,
|
| 125 |
+
);
|
| 126 |
+
const text = await hfRes.text();
|
| 127 |
+
res.status(hfRes.status).json({ status: hfRes.status, body: text.slice(0, 1000) });
|
| 128 |
+
} catch (err) {
|
| 129 |
+
res.status(500).json({ error: err.message });
|
| 130 |
+
}
|
| 131 |
+
});
|
| 132 |
+
|
| 133 |
app.use((err, _req, res, _next) => {
|
| 134 |
console.error("Unhandled:", err);
|
| 135 |
res.status(500).json({ error: err.message || "Internal error" });
|