From 9402e7607277205afc33d9e3838dbf62fafa7fb6 Mon Sep 17 00:00:00 2001 From: honnuanand Date: Sun, 26 Nov 2023 18:58:59 -0800 Subject: [PATCH] - Moved all the AIModel services as implementations of the New BedrockService - Changed the Auto configurations to return the Interface - Created the new Interface --- .../starter/autoconfigure/aimodels/ClaudeConfig.java | 5 +++-- .../starter/autoconfigure/aimodels/JurassicConfig.java | 5 +++-- .../starter/autoconfigure/aimodels/LlamaConfig.java | 5 +++-- .../springboot/starter/service/BedrockService.java | 9 +++++++++ .../starter/service/{ => impl}/ClaudeService.java | 8 +++++--- .../starter/service/{ => impl}/JurassicService.java | 8 +++++--- .../starter/service/{ => impl}/LlamaService.java | 8 +++++--- 7 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/BedrockService.java rename src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/{ => impl}/ClaudeService.java (88%) rename src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/{ => impl}/JurassicService.java (86%) rename src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/{ => impl}/LlamaService.java (86%) diff --git a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/ClaudeConfig.java b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/ClaudeConfig.java index 7e4ac19..3f255f4 100644 --- a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/ClaudeConfig.java +++ b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/ClaudeConfig.java @@ -1,7 +1,8 @@ package io.clue2solve.aws.bedrock.springboot.starter.autoconfigure.aimodels; import io.clue2solve.aws.bedrock.springboot.starter.config.ClaudeProperties; -import io.clue2solve.aws.bedrock.springboot.starter.service.ClaudeService; +import io.clue2solve.aws.bedrock.springboot.starter.service.BedrockService; +import io.clue2solve.aws.bedrock.springboot.starter.service.impl.ClaudeService; import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; @@ -12,7 +13,7 @@ public class ClaudeConfig { @Bean - public ClaudeService claudeService(BedrockRuntimeClient client, ClaudeProperties properties) { + public BedrockService claudeService(BedrockRuntimeClient client, ClaudeProperties properties) { return new ClaudeService(client, properties); } diff --git a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/JurassicConfig.java b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/JurassicConfig.java index 6c4eded..38b4a0a 100644 --- a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/JurassicConfig.java +++ b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/JurassicConfig.java @@ -1,7 +1,8 @@ package io.clue2solve.aws.bedrock.springboot.starter.autoconfigure.aimodels; import io.clue2solve.aws.bedrock.springboot.starter.config.JurassicProperties; -import io.clue2solve.aws.bedrock.springboot.starter.service.JurassicService; +import io.clue2solve.aws.bedrock.springboot.starter.service.BedrockService; +import io.clue2solve.aws.bedrock.springboot.starter.service.impl.JurassicService; import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; @@ -12,7 +13,7 @@ public class JurassicConfig { @Bean - public JurassicService jurassicService(BedrockRuntimeClient client, JurassicProperties properties) { + public BedrockService jurassicService(BedrockRuntimeClient client, JurassicProperties properties) { return new JurassicService(client, properties); } diff --git a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/LlamaConfig.java b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/LlamaConfig.java index 9e747a9..5215088 100644 --- a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/LlamaConfig.java +++ b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/autoconfigure/aimodels/LlamaConfig.java @@ -1,7 +1,8 @@ package io.clue2solve.aws.bedrock.springboot.starter.autoconfigure.aimodels; import io.clue2solve.aws.bedrock.springboot.starter.config.LlamaProperties; -import io.clue2solve.aws.bedrock.springboot.starter.service.LlamaService; +import io.clue2solve.aws.bedrock.springboot.starter.service.BedrockService; +import io.clue2solve.aws.bedrock.springboot.starter.service.impl.LlamaService; import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; @@ -12,7 +13,7 @@ public class LlamaConfig { @Bean - public LlamaService llamaService(BedrockRuntimeClient client, LlamaProperties properties) { + public BedrockService llamaService(BedrockRuntimeClient client, LlamaProperties properties) { return new LlamaService(client, properties); } diff --git a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/BedrockService.java b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/BedrockService.java new file mode 100644 index 0000000..3b1347f --- /dev/null +++ b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/BedrockService.java @@ -0,0 +1,9 @@ +package io.clue2solve.aws.bedrock.springboot.starter.service; + +import com.fasterxml.jackson.core.JsonProcessingException; + +public interface BedrockService { + + String invoke(String prompt) throws JsonProcessingException; + +} \ No newline at end of file diff --git a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/ClaudeService.java b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/impl/ClaudeService.java similarity index 88% rename from src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/ClaudeService.java rename to src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/impl/ClaudeService.java index b66698b..c2a7652 100644 --- a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/ClaudeService.java +++ b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/impl/ClaudeService.java @@ -1,5 +1,6 @@ -package io.clue2solve.aws.bedrock.springboot.starter.service; +package io.clue2solve.aws.bedrock.springboot.starter.service.impl; +import io.clue2solve.aws.bedrock.springboot.starter.service.BedrockService; import org.slf4j.LoggerFactory; import org.slf4j.Logger; import com.fasterxml.jackson.core.JsonProcessingException; @@ -13,7 +14,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -public class ClaudeService { +public class ClaudeService implements BedrockService { private static final Logger logger = LoggerFactory.getLogger(ClaudeService.class); @@ -27,7 +28,8 @@ public ClaudeService(BedrockRuntimeClient client, ClaudeProperties properties) { logger.info("Instantiating ClaudeService"); } - public String invokeClaude(String prompt) throws JsonProcessingException { + @Override + public String invoke(String prompt) throws JsonProcessingException { try { String enclosedPrompt = "Human: " + prompt + "\n\nAssistant:"; ObjectMapper mapper = new ObjectMapper(); diff --git a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/JurassicService.java b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/impl/JurassicService.java similarity index 86% rename from src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/JurassicService.java rename to src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/impl/JurassicService.java index 6b92119..b9986d0 100644 --- a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/JurassicService.java +++ b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/impl/JurassicService.java @@ -1,7 +1,8 @@ -package io.clue2solve.aws.bedrock.springboot.starter.service; +package io.clue2solve.aws.bedrock.springboot.starter.service.impl; import com.fasterxml.jackson.core.JsonProcessingException; import io.clue2solve.aws.bedrock.springboot.starter.config.JurassicProperties; +import io.clue2solve.aws.bedrock.springboot.starter.service.BedrockService; import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; import software.amazon.awssdk.awscore.exception.AwsServiceException; import software.amazon.awssdk.core.SdkBytes; @@ -10,7 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -public class JurassicService { +public class JurassicService implements BedrockService { private final BedrockRuntimeClient client; @@ -21,7 +22,8 @@ public JurassicService(BedrockRuntimeClient client, JurassicProperties propertie this.properties = properties; } - public String invokeJurassic2(String prompt) throws JsonProcessingException { + @Override + public String invoke(String prompt) throws JsonProcessingException { try { ObjectMapper mapper = new ObjectMapper(); ObjectNode payload = mapper.createObjectNode(); diff --git a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/LlamaService.java b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/impl/LlamaService.java similarity index 86% rename from src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/LlamaService.java rename to src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/impl/LlamaService.java index 6e0a8c5..ffb38b3 100644 --- a/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/LlamaService.java +++ b/src/main/java/io/clue2solve/aws/bedrock/springboot/starter/service/impl/LlamaService.java @@ -1,16 +1,17 @@ -package io.clue2solve.aws.bedrock.springboot.starter.service; +package io.clue2solve.aws.bedrock.springboot.starter.service.impl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import io.clue2solve.aws.bedrock.springboot.starter.config.LlamaProperties; +import io.clue2solve.aws.bedrock.springboot.starter.service.BedrockService; import software.amazon.awssdk.awscore.exception.AwsServiceException; import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelRequest; import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelResponse; -public class LlamaService { +public class LlamaService implements BedrockService { private final BedrockRuntimeClient client; @@ -21,7 +22,8 @@ public LlamaService(BedrockRuntimeClient client, LlamaProperties properties) { this.properties = properties; } - public String invokeLlama(String prompt) throws JsonProcessingException { + @Override + public String invoke(String prompt) throws JsonProcessingException { try { ObjectMapper mapper = new ObjectMapper(); ObjectNode payload = mapper.createObjectNode();