Spaces:
Running
Running
Download js/classifier.js from Siddarthrao/FederaQ: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/spaces/Siddarthrao/FederaQ/resolve/main/js/classifier.js
- Command line
-
hf download hf://spaces/Siddarthrao/FederaQ/js/classifier.js
-
curl -L -o classifier.js https://huggingface.co/spaces/Siddarthrao/FederaQ/resolve/main/js/classifier.js
1.47 kB
| import { PROXY_URL, MODEL } from "./config.js"; | |
| const SYSTEM_PROMPT = ` | |
| You are a query intent classifier for FederaQ. | |
| Return ONLY valid JSON β no preamble, no markdown, no backticks. | |
| { | |
| "intent": "cross-system" | "live-status" | "inventory" | "pipeline" | "single-connector", | |
| "connectors": array of "CRM" | "ERP" | "Ticketing", | |
| "confidence": float 0-1, | |
| "format": "TABLE" | "CHART" | "CARD" | "PROSE", | |
| "format_confidence": float 0-1, | |
| "sensitivity": "high" | "low" | |
| } | |
| Rules: | |
| - confidence < 0.60 β connectors: ["CRM","ERP","Ticketing"] | |
| - format_confidence < 0.70 β omit format field | |
| - cross-system queries involve β₯2 connectors | |
| - inventory β ERP, pipeline β CRM, live-status β Ticketing | |
| `; | |
| export async function classifyIntent(query) { | |
| try { | |
| const res = await fetch(PROXY_URL, { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ | |
| model: MODEL, | |
| temperature: 0.0, | |
| max_tokens: 300, | |
| messages: [ | |
| { role: "system", content: SYSTEM_PROMPT }, | |
| { role: "user", content: query } | |
| ] | |
| }) | |
| }); | |
| const data = await res.json(); | |
| const text = data.choices?.[0]?.message?.content || "{}"; | |
| return JSON.parse(text.replace(/```json|```/g, "").trim()); | |
| } catch { | |
| return { intent: "cross-system", connectors: ["CRM","ERP","Ticketing"], confidence: 0.5, format: "TABLE", format_confidence: 0.8, sensitivity: "low" }; | |
| } | |
| } | |