Enables in chat tool calling

This commit is contained in:
Markus Klenke
2024-12-07 01:04:13 +01:00
parent b6a293add7
commit 69f6fd81cf
3 changed files with 23 additions and 5 deletions

View File

@@ -777,6 +777,22 @@ public class OllamaAPI {
result = requestCaller.call(request, streamHandler);
} else {
result = requestCaller.callSync(request);
// check if toolCallIsWanted
List<OllamaChatToolCalls> toolCalls = result.getResponseModel().getMessage().getToolCalls();
int toolCallTries = 0;
while(toolCalls != null && !toolCalls.isEmpty() && toolCallTries <3){
for (OllamaChatToolCalls toolCall : toolCalls){
String toolName = toolCall.getFunction().getName();
ToolFunction toolFunction = toolRegistry.getToolFunction(toolName);
Map<String, Object> arguments = toolCall.getFunction().getArguments();
Object res = toolFunction.apply(arguments);
request.getMessages().add(new OllamaChatMessage(OllamaChatMessageRole.TOOL,"[ToolCall-Result]" + toolName + "(" + arguments.keySet() +") : " + res + "[/ToolCall-Result]"));
}
result = requestCaller.callSync(request);
toolCalls = result.getResponseModel().getMessage().getToolCalls();
toolCallTries++;
}
}
return result;

View File

@@ -12,5 +12,5 @@ import java.util.Map;
public class OllamaToolCallsFunction
{
private String name;
private Map<String,String> arguments;
private Map<String,Object> arguments;
}