diff options
| -rw-r--r-- | htroot/LLMSelection_p.html | 4 | ||||
| -rw-r--r-- | source/net/yacy/ai/LLM.java | 7 | ||||
| -rw-r--r-- | source/net/yacy/ai/ToolCallProtocol.java | 14 |
3 files changed, 16 insertions, 9 deletions
diff --git a/htroot/LLMSelection_p.html b/htroot/LLMSelection_p.html index 74f38d48a..983a52822 100644 --- a/htroot/LLMSelection_p.html +++ b/htroot/LLMSelection_p.html @@ -674,15 +674,17 @@ const cell = row.cells[col]; if (!cell) continue; let checkbox = cell.querySelector('input[type="checkbox"]'); + let isNewCheckbox = false; if (!checkbox) { checkbox = document.createElement("input"); checkbox.type = "checkbox"; cell.textContent = ""; cell.appendChild(checkbox); checkbox.checked = !!defaultChecked && isSelectableUsageColumn(col); + isNewCheckbox = true; } checkbox.disabled = col >= PRODUCTION_MODEL_FEATURE_COLUMN_START || !isSelectableUsageColumn(col); - if (!isSelectableUsageColumn(col)) checkbox.checked = false; + if (isNewCheckbox && !isSelectableUsageColumn(col)) checkbox.checked = false; initializeUsageCheckbox(checkbox, col); } if (defaultChecked) { diff --git a/source/net/yacy/ai/LLM.java b/source/net/yacy/ai/LLM.java index 8e9530e79..6314d5cbd 100644 --- a/source/net/yacy/ai/LLM.java +++ b/source/net/yacy/ai/LLM.java @@ -70,9 +70,11 @@ public class LLM { public static class LLMModel { public LLM llm; public String model; - public LLMModel(LLM llm, String model) { + public boolean tooling; + public LLMModel(LLM llm, String model, boolean tooling) { this.llm = llm; this.model = model; + this.tooling = tooling; } } @@ -108,9 +110,10 @@ public class LLM { final String api_key = row.optString("api_key", ""); final int max_tokens = Integer.parseInt(row.optString("max_tokens", "4096")); final String model = row.optString("model", ""); + final boolean tooling = row.optBoolean("tooling", false); final LLMType type = LLMType.valueOf(row.optString("service", "OLLAMA")); LLM llm = new LLM(hoststub, api_key, max_tokens, type); - LLMModel llmmodel = new LLMModel(llm, model); + LLMModel llmmodel = new LLMModel(llm, model, tooling); return llmmodel; } } diff --git a/source/net/yacy/ai/ToolCallProtocol.java b/source/net/yacy/ai/ToolCallProtocol.java index 68c575723..97ed6d950 100644 --- a/source/net/yacy/ai/ToolCallProtocol.java +++ b/source/net/yacy/ai/ToolCallProtocol.java @@ -84,15 +84,15 @@ public final class ToolCallProtocol { * @param forceStream when true, sets {@code stream=true} in the cloned body * @return prepared request body clone */ - public static JSONObject prepareToolRequestBody(JSONObject body, boolean forceStream) { + public static JSONObject prepareToolRequestBody(JSONObject body, boolean forceStream, boolean toolingEnabled) { try { final JSONObject prepared = body == null ? new JSONObject(true) : new JSONObject(body.toString()); if (forceStream) prepared.put("stream", true); - net.yacy.ai.ToolProvider.ensureTools(prepared); + if (toolingEnabled) net.yacy.ai.ToolProvider.ensureTools(prepared); return prepared; } catch (JSONException e) { final JSONObject fallback = new JSONObject(true); - net.yacy.ai.ToolProvider.ensureTools(fallback); + if (toolingEnabled) net.yacy.ai.ToolProvider.ensureTools(fallback); return fallback; } } @@ -117,9 +117,10 @@ public final class ToolCallProtocol { * @throws IOException on network/stream/protocol errors */ public static int proxyToolLifecycle(ServletOutputStream out, LLM.LLMModel llm4Chat, JSONObject originalBody, JSONArray messages, JSONObject initialMetadata) throws IOException { - final JSONObject preparedBody = prepareToolRequestBody(originalBody, false); + final JSONObject preparedBody = prepareToolRequestBody(originalBody, false, llm4Chat != null && llm4Chat.tooling); final HttpURLConnection conn = openChatCompletionConnection(llm4Chat, preparedBody); final int status = conn.getResponseCode(); + //final String message = conn.getResponseMessage(); if (status == 200) { handleInitialStreamAndContinue(out, conn, llm4Chat, preparedBody, messages, initialMetadata); } else { @@ -277,7 +278,7 @@ public final class ToolCallProtocol { } // Build follow-up completion request from original body template. - final JSONObject followup = prepareToolRequestBody(originalBody, true); + final JSONObject followup = prepareToolRequestBody(originalBody, true, llm4Chat != null && llm4Chat.tooling); followup.put("messages", newMessages); final HttpURLConnection followConn = openChatCompletionConnection(llm4Chat, followup); if (followConn.getResponseCode() != 200) { @@ -367,7 +368,8 @@ public final class ToolCallProtocol { } conn.setDoOutput(true); try (OutputStream os = conn.getOutputStream()) { - os.write(requestBody.toString().getBytes(StandardCharsets.UTF_8)); + String rbody = requestBody.toString(); + os.write(rbody.getBytes(StandardCharsets.UTF_8)); os.flush(); } return conn; |
