Skip to content

Commit

Permalink
- Moved all the AIModel services as implementations of the New Bedroc…
Browse files Browse the repository at this point in the history
…kService

- Changed the Auto configurations to return the Interface
- Created the new Interface
  • Loading branch information
honnuanand committed Nov 27, 2023
1 parent 9baf264 commit 9402e76
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
Expand Down

0 comments on commit 9402e76

Please sign in to comment.