Spaces:
Sleeping
Sleeping
ausername-12345 commited on
Commit ·
e22b79f
1
Parent(s): 7510230
Direct router test + better error details
Browse files
server.js
CHANGED
|
@@ -49,18 +49,55 @@ app.post("/api/hf", async (req, res) => {
|
|
| 49 |
});
|
| 50 |
|
| 51 |
app.get("/api/test-lib", async (_, res) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
try {
|
| 53 |
-
const token = process.env.HF_TOKEN;
|
| 54 |
const hf = new HfInference(token);
|
| 55 |
const result = await hf.chatCompletion({
|
| 56 |
model: "HuggingFaceH4/zephyr-7b-beta",
|
| 57 |
messages: [{ role: "user", content: "Say OK in one word" }],
|
| 58 |
max_tokens: 10,
|
| 59 |
});
|
| 60 |
-
|
| 61 |
} catch (err) {
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
}
|
|
|
|
|
|
|
| 64 |
});
|
| 65 |
|
| 66 |
app.use((err, _req, res, _next) => {
|
|
|
|
| 49 |
});
|
| 50 |
|
| 51 |
app.get("/api/test-lib", async (_, res) => {
|
| 52 |
+
const results = {};
|
| 53 |
+
const token = process.env.HF_TOKEN;
|
| 54 |
+
|
| 55 |
+
try {
|
| 56 |
+
// Direct test: call router.huggingface.co directly
|
| 57 |
+
const routes = [
|
| 58 |
+
"https://router.huggingface.co/auto/v1/chat/completions",
|
| 59 |
+
"https://router.huggingface.co/hf-inference/v1/chat/completions",
|
| 60 |
+
"https://router.huggingface.co/replicate/v1/chat/completions",
|
| 61 |
+
];
|
| 62 |
+
for (const url of routes) {
|
| 63 |
+
try {
|
| 64 |
+
const r = await fetch(url, {
|
| 65 |
+
method: "POST",
|
| 66 |
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
|
| 67 |
+
body: JSON.stringify({
|
| 68 |
+
model: "HuggingFaceH4/zephyr-7b-beta",
|
| 69 |
+
messages: [{ role: "user", content: "Say hi" }],
|
| 70 |
+
max_tokens: 10,
|
| 71 |
+
}),
|
| 72 |
+
});
|
| 73 |
+
results[url] = { status: r.status, body: (await r.text()).slice(0, 300) };
|
| 74 |
+
} catch (e) {
|
| 75 |
+
results[url] = { error: e.message };
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
} catch (err) {
|
| 79 |
+
results._error = err.message;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// Also test the HF lib
|
| 83 |
try {
|
|
|
|
| 84 |
const hf = new HfInference(token);
|
| 85 |
const result = await hf.chatCompletion({
|
| 86 |
model: "HuggingFaceH4/zephyr-7b-beta",
|
| 87 |
messages: [{ role: "user", content: "Say OK in one word" }],
|
| 88 |
max_tokens: 10,
|
| 89 |
});
|
| 90 |
+
results.lib = { ok: true, result };
|
| 91 |
} catch (err) {
|
| 92 |
+
results.lib = {
|
| 93 |
+
ok: false,
|
| 94 |
+
error: err.message,
|
| 95 |
+
status: err.httpResponse?.status,
|
| 96 |
+
body: typeof err.httpResponse?.body === "object" ? JSON.stringify(err.httpResponse.body).slice(0, 500) : String(err.httpResponse?.body).slice(0, 500),
|
| 97 |
+
};
|
| 98 |
}
|
| 99 |
+
|
| 100 |
+
res.json(results);
|
| 101 |
});
|
| 102 |
|
| 103 |
app.use((err, _req, res, _next) => {
|