ausername-12345 commited on
Commit
66a8b59
·
1 Parent(s): 10c67f5

Test direct model inference on huggingface.co

Browse files
Files changed (1) hide show
  1. server.js +30 -17
server.js CHANGED
@@ -50,26 +50,39 @@ app.post("/api/hf", async (req, res) => {
50
 
51
  app.get("/api/test-lib", async (_, res) => {
52
  const results = {};
 
53
 
54
- try {
55
- const r = await fetch("https://huggingface.co/api/tasks");
56
- const data = await r.json();
57
- const keys = Object.keys(data);
58
- results["available_tasks"] = keys;
59
-
60
- // Find conversational/text-generation models
61
- for (const task of ["conversational", "text-generation", "text2text-generation"]) {
62
- const taskData = data[task];
63
- if (taskData) {
64
- results[task] = {
65
- models: (taskData.models || []).slice(0, 15).map(m => ({ id: m.id, provider: m.provider })),
66
- };
67
- } else {
68
- results[task] = null;
69
- }
 
 
 
70
  }
 
 
 
 
 
 
 
 
 
71
  } catch (e) {
72
- results["error"] = e.message;
73
  }
74
 
75
  res.json(results);
 
50
 
51
  app.get("/api/test-lib", async (_, res) => {
52
  const results = {};
53
+ const token = process.env.HF_TOKEN;
54
 
55
+ // Try direct model inference on huggingface.co
56
+ const models = ["google/gemma-2-2b-it", "gpt2", "Qwen/Qwen2.5-7B-Instruct-1M"];
57
+ for (const model of models) {
58
+ try {
59
+ const r = await fetch(`https://huggingface.co/${model}`, {
60
+ method: "POST",
61
+ headers: {
62
+ "Content-Type": "application/json",
63
+ Authorization: `Bearer ${token}`,
64
+ },
65
+ body: JSON.stringify({
66
+ inputs: "What is a jar opener? Answer in one sentence.",
67
+ parameters: { max_new_tokens: 50 },
68
+ }),
69
+ });
70
+ const text = await r.text();
71
+ results[`model_${model}`] = { status: r.status, body: text.slice(0, 300) };
72
+ } catch (e) {
73
+ results[`model_${model}`] = { error: e.message };
74
  }
75
+ }
76
+
77
+ // Also try the /api/models/{model} endpoint
78
+ try {
79
+ const r = await fetch("https://huggingface.co/api/models/google/gemma-2-2b-it", {
80
+ headers: { Authorization: `Bearer ${token}` },
81
+ });
82
+ const d = await r.json();
83
+ results["model_info"] = { pipeline_tag: d.pipeline_tag, inference: d.inference, cardData: d.cardData ? "present" : "none" };
84
  } catch (e) {
85
+ results["model_info_error"] = e.message;
86
  }
87
 
88
  res.json(results);