Skip to content

Commit ff648b1

Browse files
committed
minor update of tool spec
add exception and use tool id
1 parent e2ae0de commit ff648b1

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.javaaidev.easyllmtools.integration.springai;
2+
3+
public class ToolCallException extends RuntimeException {
4+
5+
public ToolCallException(String toolId, String message, Throwable cause) {
6+
super(String.format("Error when calling the tool: %s, message: %s", toolId, message), cause);
7+
}
8+
}

integration/spring-ai/src/main/kotlin/com/javaaidev/easyllmtools/integration/springai/ToolFunctionCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public String call(String functionInput) {
3737
var result = tool.call(input);
3838
return objectMapper.writeValueAsString(result);
3939
} catch (Exception e) {
40-
throw new RuntimeException("Failed to call tool", e);
40+
throw new ToolCallException(tool.getId(), e.getMessage(), e);
4141
}
4242
}
4343
}

integration/spring-ai/src/main/kotlin/com/javaaidev/easyllmtools/integration/springai/ToolsFunctionCallbackResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public FunctionCallback resolve(String name) {
5656
@Override
5757
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
5858
var tools = applicationContext.getBeansOfType(Tool.class);
59-
LOGGER.info("Found tools: {}", tools.values().stream().map(Tool::getName).toList());
59+
LOGGER.info("Found tools: {}", tools.values().stream().map(Tool::getId).toList());
6060
for (Tool tool : tools.values()) {
61-
toolsMap.put(tool.getName(), tool);
61+
toolsMap.put(tool.getId(), tool);
6262
}
6363
}
6464
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
package com.javaaidev.easyllmtools.llmtoolspec;
22

3+
/**
4+
* Factory to create a tool
5+
*/
36
public interface ToolFactory {
47

8+
/**
9+
* ID of tool created by this factory
10+
*
11+
* @return tool id
12+
*/
513
String toolId();
614
}

0 commit comments

Comments
 (0)