Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- server/_core/env.ts +1 -1
- server/_core/llm.ts +12 -6
server/_core/env.ts
CHANGED
|
@@ -6,5 +6,5 @@ export const ENV = {
|
|
| 6 |
ownerOpenId: process.env.OWNER_OPEN_ID ?? "",
|
| 7 |
isProduction: process.env.NODE_ENV === "production",
|
| 8 |
forgeApiUrl: process.env.BUILT_IN_FORGE_API_URL ?? "",
|
| 9 |
-
forgeApiKey: process.env.BUILT_IN_FORGE_API_KEY ?? "",
|
| 10 |
};
|
|
|
|
| 6 |
ownerOpenId: process.env.OWNER_OPEN_ID ?? "",
|
| 7 |
isProduction: process.env.NODE_ENV === "production",
|
| 8 |
forgeApiUrl: process.env.BUILT_IN_FORGE_API_URL ?? "",
|
| 9 |
+
forgeApiKey: process.env.BUILT_IN_FORGE_API_KEY ?? process.env.HF_TOKEN ?? "",
|
| 10 |
};
|
server/_core/llm.ts
CHANGED
|
@@ -209,14 +209,20 @@ const normalizeToolChoice = (
|
|
| 209 |
return toolChoice;
|
| 210 |
};
|
| 211 |
|
| 212 |
-
const resolveApiUrl = () =>
|
| 213 |
-
ENV.forgeApiUrl && ENV.forgeApiUrl.trim().length > 0
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
const assertApiKey = () => {
|
| 218 |
if (!ENV.forgeApiKey) {
|
| 219 |
-
throw new Error("
|
| 220 |
}
|
| 221 |
};
|
| 222 |
|
|
@@ -280,7 +286,7 @@ export async function invokeLLM(params: InvokeParams): Promise<InvokeResult> {
|
|
| 280 |
} = params;
|
| 281 |
|
| 282 |
const payload: Record<string, unknown> = {
|
| 283 |
-
model: "gemini-2.5-flash",
|
| 284 |
messages: messages.map(normalizeMessage),
|
| 285 |
};
|
| 286 |
|
|
|
|
| 209 |
return toolChoice;
|
| 210 |
};
|
| 211 |
|
| 212 |
+
const resolveApiUrl = () => {
|
| 213 |
+
if (ENV.forgeApiUrl && ENV.forgeApiUrl.trim().length > 0) {
|
| 214 |
+
return `${ENV.forgeApiUrl.replace(/\/$/, "")}/v1/chat/completions`;
|
| 215 |
+
}
|
| 216 |
+
// If we are using HF_TOKEN, we might want to use HF Inference API
|
| 217 |
+
if (process.env.HF_TOKEN && !process.env.BUILT_IN_FORGE_API_KEY) {
|
| 218 |
+
return "https://api-inference.huggingface.co/v1/chat/completions";
|
| 219 |
+
}
|
| 220 |
+
return "https://forge.manus.im/v1/chat/completions";
|
| 221 |
+
};
|
| 222 |
|
| 223 |
const assertApiKey = () => {
|
| 224 |
if (!ENV.forgeApiKey) {
|
| 225 |
+
throw new Error("No API Key found. Please configure HF_TOKEN or BUILT_IN_FORGE_API_KEY in Space Secrets.");
|
| 226 |
}
|
| 227 |
};
|
| 228 |
|
|
|
|
| 286 |
} = params;
|
| 287 |
|
| 288 |
const payload: Record<string, unknown> = {
|
| 289 |
+
model: process.env.HF_TOKEN && !process.env.BUILT_IN_FORGE_API_KEY ? "Qwen/Qwen2.5-72B-Instruct" : "gemini-2.5-flash",
|
| 290 |
messages: messages.map(normalizeMessage),
|
| 291 |
};
|
| 292 |
|