mode selection, settings added to ui
This commit is contained in:
@@ -46,21 +46,29 @@ async function postJSON(url, data) {
|
||||
// -----------------------------------------------------
|
||||
// The unified chat handler
|
||||
// -----------------------------------------------------
|
||||
async function handleChatRequest(session_id, user_msg, mode = "cortex") {
|
||||
async function handleChatRequest(session_id, user_msg, mode = "cortex", backend = null) {
|
||||
let reason;
|
||||
|
||||
// Determine which endpoint to use based on mode
|
||||
const endpoint = mode === "standard" ? CORTEX_SIMPLE : CORTEX_REASON;
|
||||
const modeName = mode === "standard" ? "simple" : "reason";
|
||||
|
||||
console.log(`Relay → routing to Cortex.${modeName} (mode: ${mode})`);
|
||||
console.log(`Relay → routing to Cortex.${modeName} (mode: ${mode}${backend ? `, backend: ${backend}` : ''})`);
|
||||
|
||||
// Build request payload
|
||||
const payload = {
|
||||
session_id,
|
||||
user_prompt: user_msg
|
||||
};
|
||||
|
||||
// Add backend parameter if provided (only for standard mode)
|
||||
if (backend && mode === "standard") {
|
||||
payload.backend = backend;
|
||||
}
|
||||
|
||||
// Call appropriate Cortex endpoint
|
||||
try {
|
||||
reason = await postJSON(endpoint, {
|
||||
session_id,
|
||||
user_prompt: user_msg
|
||||
});
|
||||
reason = await postJSON(endpoint, payload);
|
||||
} catch (e) {
|
||||
console.error(`Relay → Cortex.${modeName} error:`, e.message);
|
||||
throw new Error(`cortex_${modeName}_failed: ${e.message}`);
|
||||
@@ -96,14 +104,15 @@ app.post("/v1/chat/completions", async (req, res) => {
|
||||
const lastMessage = messages[messages.length - 1];
|
||||
const user_msg = lastMessage?.content || "";
|
||||
const mode = req.body.mode || "cortex"; // Get mode from request, default to cortex
|
||||
const backend = req.body.backend || null; // Get backend preference
|
||||
|
||||
if (!user_msg) {
|
||||
return res.status(400).json({ error: "No message content provided" });
|
||||
}
|
||||
|
||||
console.log(`Relay (v1) → received: "${user_msg}" [mode: ${mode}]`);
|
||||
console.log(`Relay (v1) → received: "${user_msg}" [mode: ${mode}${backend ? `, backend: ${backend}` : ''}]`);
|
||||
|
||||
const result = await handleChatRequest(session_id, user_msg, mode);
|
||||
const result = await handleChatRequest(session_id, user_msg, mode, backend);
|
||||
|
||||
res.json({
|
||||
id: `chatcmpl-${Date.now()}`,
|
||||
@@ -145,10 +154,11 @@ app.post("/chat", async (req, res) => {
|
||||
const session_id = req.body.session_id || "default";
|
||||
const user_msg = req.body.message || "";
|
||||
const mode = req.body.mode || "cortex"; // Get mode from request, default to cortex
|
||||
const backend = req.body.backend || null; // Get backend preference
|
||||
|
||||
console.log(`Relay → received: "${user_msg}" [mode: ${mode}]`);
|
||||
console.log(`Relay → received: "${user_msg}" [mode: ${mode}${backend ? `, backend: ${backend}` : ''}]`);
|
||||
|
||||
const result = await handleChatRequest(session_id, user_msg, mode);
|
||||
const result = await handleChatRequest(session_id, user_msg, mode, backend);
|
||||
res.json(result);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user