-
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.
refactor(ai): Improve modularization of AI logic
- Loading branch information
1 parent
3981a66
commit 6393ae6
Showing
51 changed files
with
408 additions
and
259 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
plugins { | ||
id 'code-quality-conventions' | ||
id 'java-conventions' | ||
id 'sbom-conventions' | ||
id 'release-conventions' | ||
} | ||
|
||
repositories { | ||
maven { url 'https://repo.spring.io/milestone' } | ||
} | ||
|
||
dependencies { | ||
implementation project(":arconia-ai:arconia-ai-tools") | ||
|
||
implementation "org.slf4j:slf4j-api" | ||
implementation "org.springframework:spring-context" | ||
|
||
compileOnly "org.springframework.ai:spring-ai-core:${springAiVersion}" | ||
|
||
testImplementation "org.springframework.boot:spring-boot-starter-test" | ||
testImplementation "org.springframework.ai:spring-ai-core:${springAiVersion}" | ||
} | ||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
pom { | ||
name = "Arconia AI Client" | ||
description = "Arconia AI Client." | ||
} | ||
} | ||
} | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
...a/ai/core/client/advisor/CallAdvisor.java → ...rconia/ai/client/advisor/CallAdvisor.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.arconia.ai.core.client.advisor; | ||
package io.arconia.ai.client.advisor; | ||
|
||
import java.util.Map; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...ai/core/client/advisor/StreamAdvisor.java → ...onia/ai/client/advisor/StreamAdvisor.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.arconia.ai.core.client.advisor; | ||
package io.arconia.ai.client.advisor; | ||
|
||
import java.util.Map; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...conia/ai/core/tools/aot/package-info.java → ...conia/ai/client/advisor/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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
@NonNullApi | ||
@NonNullFields | ||
package io.arconia.ai.core.tools.aot; | ||
package io.arconia.ai.client.advisor; | ||
|
||
import org.springframework.lang.NonNullApi; | ||
import org.springframework.lang.NonNullFields; |
2 changes: 1 addition & 1 deletion
2
.../arconia/ai/core/client/package-info.java → ...va/io/arconia/ai/client/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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
@NonNullApi | ||
@NonNullFields | ||
package io.arconia.ai.core.client; | ||
package io.arconia.ai.client; | ||
|
||
import org.springframework.lang.NonNullApi; | ||
import org.springframework.lang.NonNullFields; |
6 changes: 0 additions & 6 deletions
6
arconia-ai/arconia-ai-core/src/main/java/io/arconia/ai/core/client/advisor/package-info.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
arconia-ai/arconia-ai-core/src/main/java/io/arconia/ai/core/tools/ToolCallback.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
...ia-ai/arconia-ai-core/src/main/java/io/arconia/ai/core/tools/annotation/package-info.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
...nia-ai-core/src/main/java/io/arconia/ai/core/tools/aot/JacksonJsonSchemaRuntimeHints.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
arconia-ai/arconia-ai-core/src/main/java/io/arconia/ai/core/tools/metadata/package-info.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
arconia-ai/arconia-ai-core/src/main/java/io/arconia/ai/core/tools/method/package-info.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
arconia-ai/arconia-ai-core/src/main/java/io/arconia/ai/core/tools/util/package-info.java
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
arconia-ai/arconia-ai-core/src/main/resources/META-INF/spring/aot.factories
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
...i-core/src/test/java/io/arconia/ai/core/tools/aot/JacksonJsonSchemaRuntimeHintsTests.java
This file was deleted.
Oops, something went wrong.
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
59 changes: 49 additions & 10 deletions
59
arconia-ai/arconia-ai-mcp/src/main/java/io/arconia/ai/mcp/tools/McpToolCallback.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 |
---|---|---|
@@ -1,45 +1,84 @@ | ||
package io.arconia.ai.mcp.tools; | ||
|
||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
|
||
import org.springframework.ai.mcp.client.McpSyncClient; | ||
import org.springframework.ai.mcp.spec.McpSchema; | ||
import org.springframework.ai.model.ModelOptionsUtils; | ||
import org.springframework.lang.Nullable; | ||
|
||
import io.arconia.ai.core.tools.ToolCallback; | ||
import io.arconia.ai.core.tools.json.JsonParser; | ||
import io.arconia.ai.core.tools.metadata.DefaultToolMetadata; | ||
import io.arconia.ai.core.tools.metadata.ToolMetadata; | ||
import io.arconia.ai.tools.ToolCallback; | ||
import io.arconia.ai.tools.definition.ToolDefinition; | ||
import io.arconia.ai.tools.json.JsonParser; | ||
|
||
/** | ||
* A {@link ToolCallback} for handling calls to MCP tools. | ||
*/ | ||
public class McpToolCallback implements ToolCallback { | ||
|
||
private final ToolMetadata toolMetadata; | ||
private static final Function<String,Map<String,Object>> DEFAULT_TOOL_INPUT_PARSER = | ||
toolInput -> JsonParser.fromJson(toolInput, new TypeReference<>() {}); | ||
|
||
private final ToolDefinition toolDefinition; | ||
private final McpSyncClient mcpClient; | ||
private final Function<String,Map<String,Object>> toolInputParser; | ||
|
||
public McpToolCallback(McpSchema.Tool tool, McpSyncClient mcpClient) { | ||
this.toolMetadata = DefaultToolMetadata.builder() | ||
public McpToolCallback(McpSchema.Tool tool, McpSyncClient mcpClient, @Nullable Function<String,Map<String,Object>> toolInputParser) { | ||
this.toolDefinition = ToolDefinition.builder() | ||
.name(tool.name()) | ||
.description(tool.description()) | ||
.inputTypeSchema(JsonParser.toJson(tool.inputSchema())) | ||
.build(); | ||
this.mcpClient = mcpClient; | ||
this.toolInputParser = toolInputParser != null ? toolInputParser : DEFAULT_TOOL_INPUT_PARSER; | ||
} | ||
|
||
@Override | ||
public ToolMetadata getToolMetadata() { | ||
return this.toolMetadata; | ||
public ToolDefinition getToolDefinition() { | ||
return toolDefinition; | ||
} | ||
|
||
@Override | ||
public String call(String toolInput) { | ||
Map<String, Object> arguments = JsonParser.fromJson(toolInput, new TypeReference<>() {}); | ||
Map<String, Object> arguments = toolInputParser.apply(toolInput); | ||
McpSchema.CallToolResult response = this.mcpClient.callTool(new McpSchema.CallToolRequest(this.getName(), arguments)); | ||
return ModelOptionsUtils.toJsonString(response.content()); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private McpSchema.Tool tool; | ||
private McpSyncClient mcpClient; | ||
private Function<String,Map<String,Object>> toolInputParser; | ||
|
||
private Builder() {} | ||
|
||
public Builder tool(McpSchema.Tool tool) { | ||
this.tool = tool; | ||
return this; | ||
} | ||
|
||
public Builder mcpClient(McpSyncClient mcpClient) { | ||
this.mcpClient = mcpClient; | ||
return this; | ||
} | ||
|
||
public Builder toolInputParser(Function<String,Map<String,Object>> toolInputParser) { | ||
this.toolInputParser = toolInputParser; | ||
return this; | ||
} | ||
|
||
public McpToolCallback build() { | ||
return new McpToolCallback(tool, mcpClient, toolInputParser); | ||
} | ||
|
||
} | ||
|
||
} |
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
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
Oops, something went wrong.