Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- server/_core/llm.ts +39 -0
server/_core/llm.ts
CHANGED
|
@@ -171,6 +171,45 @@ const normalizeMessage = (message: Message) => {
|
|
| 171 |
};
|
| 172 |
};
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
const resolveApiUrl = (model: string) => {
|
| 175 |
const hfToken = process.env.HF_TOKEN || process.env.HF_ACCESS_TOKEN;
|
| 176 |
|
|
|
|
| 171 |
};
|
| 172 |
};
|
| 173 |
|
| 174 |
+
const normalizeToolChoice = (
|
| 175 |
+
toolChoice: ToolChoice | undefined,
|
| 176 |
+
tools: Tool[] | undefined
|
| 177 |
+
): "none" | "auto" | ToolChoiceExplicit | undefined => {
|
| 178 |
+
if (!toolChoice) return undefined;
|
| 179 |
+
|
| 180 |
+
if (toolChoice === "none" || toolChoice === "auto") {
|
| 181 |
+
return toolChoice;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
if (toolChoice === "required") {
|
| 185 |
+
if (!tools || tools.length === 0) {
|
| 186 |
+
throw new Error(
|
| 187 |
+
"tool_choice 'required' was provided but no tools were configured"
|
| 188 |
+
);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
if (tools.length > 1) {
|
| 192 |
+
throw new Error(
|
| 193 |
+
"tool_choice 'required' needs a single tool or specify the tool name explicitly"
|
| 194 |
+
);
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
return {
|
| 198 |
+
type: "function",
|
| 199 |
+
function: { name: tools[0].function.name },
|
| 200 |
+
};
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
if ("name" in toolChoice) {
|
| 204 |
+
return {
|
| 205 |
+
type: "function",
|
| 206 |
+
function: { name: toolChoice.name },
|
| 207 |
+
};
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
return toolChoice;
|
| 211 |
+
};
|
| 212 |
+
|
| 213 |
const resolveApiUrl = (model: string) => {
|
| 214 |
const hfToken = process.env.HF_TOKEN || process.env.HF_ACCESS_TOKEN;
|
| 215 |
|