From 5401e8560b717bf750d4322af230da4f88361aa6 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 19 May 2026 19:27:19 +0200 Subject: [PATCH] refactor: remove dead generateFollowUps frontend wrapper (#24794) generateFollowUps in src/lib/apis/index.ts is dead: it appears only at its own definition, nothing imports or calls it, and it targets a non-existent path (/api/v1/tasks/follow_ups/completions, plural) while the real route is /tasks/follow_up/completions (singular). Follow-up suggestions are generated server-side in the chat-completion middleware and delivered over the chat:message:follow_ups websocket event, so this wrapper was never on the live path. Removes only the dead wrapper. The backend POST /tasks/follow_up/completions endpoint is intentionally kept: it is a member of the actively-used /tasks/*/completions family (title, tags, emoji, queries, moa) and its handler delegates to the core generate_follow_ups function. Co-authored-by: Claude Opus 4.7 (1M context) --- src/lib/apis/index.ts | 72 ------------------------------------------- 1 file changed, 72 deletions(-) diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index 544434ab5d..24b096cd75 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -821,78 +821,6 @@ export const generateTitle = async ( } }; -export const generateFollowUps = async ( - token: string = '', - model: string, - messages: string, - chat_id?: string -) => { - let error = null; - - const res = await fetch(`${WEBUI_BASE_URL}/api/v1/tasks/follow_ups/completions`, { - method: 'POST', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - }, - body: JSON.stringify({ - model: model, - messages: messages, - ...(chat_id && { chat_id: chat_id }) - }) - }) - .then(async (res) => { - if (!res.ok) throw await res.json(); - return res.json(); - }) - .catch((err) => { - console.error(err); - if ('detail' in err) { - error = err.detail; - } - return null; - }); - - if (error) { - throw error; - } - - try { - // Step 1: Safely extract the response string - const response = res?.choices[0]?.message?.content ?? ''; - - // Step 2: Attempt to fix common JSON format issues like single quotes - const sanitizedResponse = response.replace(/['‘’`]/g, '"'); // Convert single quotes to double quotes for valid JSON - - // Step 3: Find the relevant JSON block within the response - const jsonStartIndex = sanitizedResponse.indexOf('{'); - const jsonEndIndex = sanitizedResponse.lastIndexOf('}'); - - // Step 4: Check if we found a valid JSON block (with both `{` and `}`) - if (jsonStartIndex !== -1 && jsonEndIndex !== -1) { - const jsonResponse = sanitizedResponse.substring(jsonStartIndex, jsonEndIndex + 1); - - // Step 5: Parse the JSON block - const parsed = JSON.parse(jsonResponse); - - // Step 6: If there's a "follow_ups" key, return the follow_ups array; otherwise, return an empty array - if (parsed && parsed.follow_ups) { - return Array.isArray(parsed.follow_ups) ? parsed.follow_ups : []; - } else { - return []; - } - } - - // If no valid JSON block found, return an empty array - return []; - } catch (e) { - // Catch and safely return empty array on any parsing errors - console.error('Failed to parse response: ', e); - return []; - } -}; - export const generateTags = async ( token: string = '', model: string,