-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ai): More robust and extensive tool calling support based on met…
…hods
- Loading branch information
1 parent
6393ae6
commit 643fb10
Showing
32 changed files
with
2,070 additions
and
485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 3 additions & 16 deletions
19
.../arconia-ai-tools/src/main/java/io/arconia/ai/tools/definition/DefaultToolDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...-ai-tools/src/main/java/io/arconia/ai/tools/execution/DefaultToolCallResultConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.arconia.ai.tools.execution; | ||
|
||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.Assert; | ||
|
||
import io.arconia.ai.tools.json.JsonParser; | ||
|
||
/** | ||
* A default implementation of {@link ToolCallResultConverter}. | ||
*/ | ||
public class DefaultToolCallResultConverter implements ToolCallResultConverter { | ||
|
||
@Override | ||
public String apply(@Nullable Object result, Class<?> returnType) { | ||
Assert.notNull(returnType, "returnType cannot be null"); | ||
if (returnType == Void.TYPE) { | ||
return "Done"; | ||
} else { | ||
return JsonParser.toJson(result); | ||
} | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...arconia-ai-tools/src/main/java/io/arconia/ai/tools/execution/ToolCallResultConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.arconia.ai.tools.execution; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
import org.springframework.lang.Nullable; | ||
|
||
/** | ||
* A functional interface to convert tool call results to a String | ||
* that can be sent back to the AI model. | ||
*/ | ||
@FunctionalInterface | ||
public interface ToolCallResultConverter extends BiFunction<Object, Class<?>, String> { | ||
|
||
/** | ||
* Given an Object returned by a tool, convert it | ||
* to a String compatible with the given class type. | ||
*/ | ||
String apply(@Nullable Object result, Class<?> returnType); | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
.../arconia-ai-tools/src/main/java/io/arconia/ai/tools/execution/ToolExecutionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.arconia.ai.tools.execution; | ||
|
||
import io.arconia.ai.tools.definition.ToolDefinition; | ||
|
||
/** | ||
* An exception thrown when a tool execution fails. | ||
*/ | ||
public class ToolExecutionException extends RuntimeException { | ||
|
||
private final ToolDefinition toolDefinition; | ||
|
||
public ToolExecutionException(ToolDefinition toolDefinition, Throwable cause) { | ||
super(cause.getMessage(), cause); | ||
this.toolDefinition = toolDefinition; | ||
} | ||
|
||
public ToolDefinition getToolDefinition() { | ||
return toolDefinition; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
arconia-ai/arconia-ai-tools/src/main/java/io/arconia/ai/tools/execution/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@NonNullApi | ||
@NonNullFields | ||
package io.arconia.ai.tools.execution; | ||
|
||
import org.springframework.lang.NonNullApi; | ||
import org.springframework.lang.NonNullFields; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.