Skip to content

Commit 25ba38c

Browse files
catching any throwable while probing if a model supports tools in JeddictBrain (#278)
1 parent f6f6dc7 commit 25ba38c

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

src/main/java/io/github/jeddict/ai/lang/JeddictBrain.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import io.github.jeddict.ai.util.PropertyChangeEmitter;
5353
import java.lang.reflect.InvocationTargetException;
5454
import java.util.ArrayList;
55+
import java.util.Arrays;
5556
import java.util.Collections;
5657
import java.util.HashMap;
5758
import java.util.List;
@@ -228,7 +229,7 @@ public <T> T pairProgrammer(PairProgrammer.Specialist specialist) {
228229

229230
builder.hallucinatedToolNameStrategy((exec) -> {
230231
final ToolExecutionRequest ter = (ToolExecutionRequest)exec;
231-
232+
232233
LOG.finest(() -> "tool hallucination: " + ter.name());
233234
return ToolExecutionResultMessage.from(
234235
ter, "Error: there is no tool called " + ter.name() + " try with a different name"
@@ -290,20 +291,32 @@ protected boolean probeToolSupport() {
290291
// Otherwise probe the model by trying to trigger the execution of the
291292
// ToolsProbingTool tool
292293
//
293-
final ToolsProbingTool probeTool = new ToolsProbingTool();
294-
final ToolsProber prober = AgenticServices.agentBuilder(ToolsProber.class)
295-
.chatModel(model(false))
296-
.tools(probeTool)
297-
.build();
298-
final boolean toolsSupport = prober.probe(probeTool.probeText);
294+
try {
295+
final ToolsProbingTool probeTool = new ToolsProbingTool();
296+
final ToolsProber prober = AgenticServices.agentBuilder(ToolsProber.class)
297+
.chatModel(model(false))
298+
.tools(probeTool)
299+
.build();
299300

300-
probedModels.put(modelName, toolsSupport);
301+
final boolean toolsSupport = prober.probe(probeTool.probeText);
301302

302-
LOG.info(
303-
LOG_MSG.formatted(modelName, (toolsSupport) ? "supports" : "does not support")
304-
);
303+
probedModels.put(modelName, toolsSupport);
304+
305+
LOG.info(
306+
LOG_MSG.formatted(modelName, (toolsSupport) ? "supports" : "does not support")
307+
);
308+
309+
return toolsSupport;
310+
} catch (final Throwable t) {
311+
LOG.severe(() ->
312+
"error probing tool support, returning false %s\n%s".formatted(
313+
t.toString(),
314+
Arrays.toString(t.getStackTrace())
315+
)
316+
);
317+
}
305318

306-
return toolsSupport;
319+
return false;
307320
}
308321

309322

0 commit comments

Comments
 (0)