diff options
| author | Michael Peter Christen <mc@yacy.net> | 2026-03-28 21:32:37 +0100 |
|---|---|---|
| committer | Michael Peter Christen <mc@yacy.net> | 2026-03-28 21:32:37 +0100 |
| commit | e0bf6b8c68f0d141f1ee4c35a3e65108caf27615 (patch) | |
| tree | 554d1ba33a170c6beda9a6cdeaee874be68da3b8 /source | |
| parent | 3c3388201f26ad50aed1c0879966d5926d22401c (diff) | |
Respect persisted tooling capability for chat models
Diffstat (limited to 'source')
| -rw-r--r-- | source/net/yacy/ai/LLM.java | 7 | ||||
| -rw-r--r-- | source/net/yacy/ai/ToolCallProtocol.java | 14 |
2 files changed, 13 insertions, 8 deletions
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; |
