Manus AI commited on
Commit
e351908
·
1 Parent(s): b660f2d

Fix: Explicitly use Featherless AI provider for abliterated models via HF Router and add fallback

Browse files
Files changed (1) hide show
  1. server/_core/llm.ts +38 -7
server/_core/llm.ts CHANGED
@@ -287,6 +287,8 @@ export async function invokeLLM(params: InvokeParams): Promise<InvokeResult> {
287
  response_format,
288
  } = params;
289
 
 
 
290
  const model = params.model || "huihui-ai/Qwen2.5-72B-Instruct-abliterated";
291
 
292
  const payload: Record<string, unknown> = {
@@ -322,21 +324,50 @@ export async function invokeLLM(params: InvokeParams): Promise<InvokeResult> {
322
  const apiUrl = resolveApiUrl(model);
323
  console.log(`[LLM] Invoking ${model} at ${apiUrl}`);
324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  const response = await fetch(apiUrl, {
326
  method: "POST",
327
- headers: {
328
- "content-type": "application/json",
329
- authorization: `Bearer ${apiKey}`,
330
- "x-use-cache": "false",
331
- "x-wait-for-model": "true",
332
- "x-inference-provider": "featherless",
333
- },
334
  body: JSON.stringify(payload),
335
  });
336
 
337
  if (!response.ok) {
338
  const errorText = await response.text();
339
  console.error(`[LLM Error] Status: ${response.status}, Body: ${errorText}`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  throw new Error(
341
  `LLM invoke failed: ${response.status} ${response.statusText} – ${errorText}`
342
  );
 
287
  response_format,
288
  } = params;
289
 
290
+ // Use a more widely supported model if the abliterated one fails,
291
+ // or ensure the provider is correctly specified.
292
  const model = params.model || "huihui-ai/Qwen2.5-72B-Instruct-abliterated";
293
 
294
  const payload: Record<string, unknown> = {
 
324
  const apiUrl = resolveApiUrl(model);
325
  console.log(`[LLM] Invoking ${model} at ${apiUrl}`);
326
 
327
+ // For abliterated models, we MUST specify the provider in the payload or headers correctly
328
+ // Some providers on HF Router require specific headers
329
+ const headers: Record<string, string> = {
330
+ "content-type": "application/json",
331
+ authorization: `Bearer ${apiKey}`,
332
+ "x-use-cache": "false",
333
+ "x-wait-for-model": "true",
334
+ };
335
+
336
+ // If using HF Router, we can try to force a provider that supports this model
337
+ if (apiUrl.includes("router.huggingface.co")) {
338
+ headers["x-inference-provider"] = "featherless";
339
+ }
340
+
341
  const response = await fetch(apiUrl, {
342
  method: "POST",
343
+ headers: headers,
 
 
 
 
 
 
344
  body: JSON.stringify(payload),
345
  });
346
 
347
  if (!response.ok) {
348
  const errorText = await response.text();
349
  console.error(`[LLM Error] Status: ${response.status}, Body: ${errorText}`);
350
+
351
+ // Fallback mechanism: If the abliterated model fails, try the standard Qwen model
352
+ if (model.includes("abliterated") && (response.status === 400 || response.status === 404)) {
353
+ console.log("[LLM] Falling back to standard Qwen2.5-72B-Instruct");
354
+ const fallbackModel = "Qwen/Qwen2.5-72B-Instruct";
355
+ payload.model = fallbackModel;
356
+
357
+ const fallbackResponse = await fetch(apiUrl, {
358
+ method: "POST",
359
+ headers: {
360
+ "content-type": "application/json",
361
+ authorization: `Bearer ${apiKey}`,
362
+ },
363
+ body: JSON.stringify(payload),
364
+ });
365
+
366
+ if (fallbackResponse.ok) {
367
+ return (await fallbackResponse.json()) as InvokeResult;
368
+ }
369
+ }
370
+
371
  throw new Error(
372
  `LLM invoke failed: ${response.status} ${response.statusText} – ${errorText}`
373
  );