Skip to content

Commit

Permalink
All Files except tests now have Javadocs Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
honnuanand committed Nov 28, 2023
1 parent 7fd4c2b commit 1b7a1b7
Show file tree
Hide file tree
Showing 19 changed files with 291 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration class for Claude
*/
@Configuration
@Conditional(OnClaude.class)
public class ClaudeConfig {

/**
* Bean for ClaudeService
* @param client BedrockRuntimeClient
* @param properties ClaudeProperties
* @return BedrockService
*/
@Bean(name = "claudeService")
public BedrockService claudeService(BedrockRuntimeClient client, ClaudeProperties properties) {
return new ClaudeService(client, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration class for Jurassic
*/
@Configuration
@Conditional(OnJurassic.class)
public class JurassicConfig {

/**
* Bean for JurassicService
* @param client BedrockRuntimeClient
* @param properties JurassicProperties
* @return BedrockService
*/
@Bean(name = "jurassicService")
public BedrockService jurassicService(BedrockRuntimeClient client, JurassicProperties properties) {
return new JurassicService(client, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration class for Llama
*/
@Configuration
@ConditionalOnProperty(name = "aws.bedrock.model.llama.id", havingValue = "meta.llama2-13b-chat-v1")
public class LlamaConfig {

/**
* Bean for LlamaService
* @param client BedrockRuntimeClient
* @param properties LlamaProperties
* @return BedrockService
*/
@Bean(name = "llamaService")
public BedrockService llamaService(BedrockRuntimeClient client, LlamaProperties properties) {
return new LlamaService(client, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
* Configuration class for ModelProperties
*/
@Configuration
@EnableConfigurationProperties({ ClaudeProperties.class, JurassicProperties.class, LlamaProperties.class,
TitanProperties.class })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,37 @@
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

/**
* Condition class for Claude
*/
class OnClaude extends AnyNestedCondition {

/**
* Constructor
*/
OnClaude() {
super(ConfigurationPhase.PARSE_CONFIGURATION);
}

/**
* Condition for Claude v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.claude.id", havingValue = "anthropic.claude-v2")
static class OnClaudeV2 {

}

/**
* Condition for Claude v1
*/
@ConditionalOnProperty(name = "aws.bedrock.model.claude.id", havingValue = "anthropic.claude-v1")
static class OnClaudeV1 {

}

/**
* Condition for Claude Instant v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.claude.id", havingValue = "anthropic.claude-instant-v1")
static class OnClaudeInstantV1 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,61 @@
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

/**
* Condition class for Jurassic
*/
class OnJurassic extends AnyNestedCondition {

/**
* Constructor
*/
OnJurassic() {
super(ConfigurationPhase.PARSE_CONFIGURATION);
}

/**
* Condition for Jurassic v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.jurassic.id", havingValue = "ai21.j2-grande-instruct")
static class OnJurassic2GrandeInstruct {

}

/**
* Condition for Jurassic v1
*/
@ConditionalOnProperty(name = "aws.bedrock.model.jurassic.id", havingValue = "ai21.j2-jumbo-instruct")
static class OnJurassic2JumboInstruct {

}

/**
* Condition for Jurassic Instant v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.jurassic.id", havingValue = "ai21.j2-mid")
static class OnJurassic2Mid {

}

/**
* Condition for Jurassic Instant v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.jurassic.id", havingValue = "ai21.j2-mid-v1")
static class OnJurassic2MidV1 {

}

/**
* Condition for Jurassic Instant v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.jurassic.id", havingValue = "ai21.j2-ultra")
static class OnCJurassic2Ultra {

}

/**
* Condition for Jurassic Instant v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.jurassic.idd", havingValue = "ai21.j2-ultra-v1")
static class OnCJurassic2UltraV1 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,61 @@
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

/**
* Condition class for Titan
*/
class OnTitan extends AnyNestedCondition {

/**
* Constructor
*/
OnTitan() {
super(ConfigurationPhase.PARSE_CONFIGURATION);
}

/**
* Condition for Titan v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.titan.id", havingValue = "amazon.titan-tg1-large")
static class OnTitanLarge {

}

/**
* Condition for Titan v1
*/
@ConditionalOnProperty(name = "aws.bedrock.model.titan.id", havingValue = "amazon.titan-tg1-medium")
static class OnTitanMedium {

}

/**
* Condition for Titan Instant v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.titan.id", havingValue = "amazon.titan-embed-g1-text-02")
static class OnTitanTextEmbeddingsV2 {

}

/**
* Condition for Titan Instant v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.titan.id", havingValue = "amazon.titan-text-lite-v1")
static class OnTitanTextLiteV1 {

}

/**
* Condition for Titan Instant v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.titan.id", havingValue = "amazon.titan-text-express-v1")
static class OnTitanTextExpressV1 {

}

/**
* Condition for Titan Instant v2
*/
@ConditionalOnProperty(name = "aws.bedrock.model.titan.id", havingValue = "amazon.titan-embed-text-v1")
static class OnTitanTextEmbeddingsV1 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;

/**
* Configuration class for Titan
*/
@Configuration
@Conditional(OnTitan.class)
public class TitanConfig {

/**
* Bean for TitanService
* @param client BedrockRuntimeClient
* @param properties TitanProperties
* @return BedrockService
*/
@Bean(name = "titanService")
public BedrockService titanService(BedrockRuntimeClient client, TitanProperties properties) {
return new TitanService(client, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,46 @@
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;

/**
* Configuration class for BedrockClient
*/
@Configuration
public class BedrockClientConfig {

/**
* AwsCredentialsProvider
*/
private AwsCredentialsProvider awsCredentialsProvider;

/**
* Region
*/
@Value("${aws.region}")
private String region;

/**
* Constructor
* @param awsCredentialsProvider AwsCredentialsProvider
*/
@Autowired
public BedrockClientConfig(AwsCredentialsProvider awsCredentialsProvider) {
this.awsCredentialsProvider = awsCredentialsProvider;
}

/**
* Bean for BedrockClient
* @return BedrockClient
*/
@Bean
@ConditionalOnProperty(name = "bedrock.client.type", havingValue = "sync")
public BedrockClient bedrockClient() {
return BedrockClient.builder().region(Region.of(region)).credentialsProvider(awsCredentialsProvider).build();
}

/**
* Bean for BedrockRuntimeClient
* @return BedrockRuntimeClient
*/
@Bean
public BedrockRuntimeClient bedrockRuntimeClient() {
return BedrockRuntimeClient.builder()
Expand All @@ -39,6 +60,10 @@ public BedrockRuntimeClient bedrockRuntimeClient() {
.build();
}

/**
* Bean for BedrockRuntimeAsyncClient
* @return BedrockRuntimeAsyncClient
*/
@Bean
@ConditionalOnProperty(name = "bedrock.client.type", havingValue = "async")
public BedrockRuntimeAsyncClient bedrockRuntimeAsyncClient() {
Expand All @@ -48,6 +73,10 @@ public BedrockRuntimeAsyncClient bedrockRuntimeAsyncClient() {
.build();
}

/**
* Bean for BedrockAsyncClient
* @return BedrockAsyncClient
*/
@Bean
@ConditionalOnProperty(name = "bedrock.client.type", havingValue = "async")
public BedrockAsyncClient bedrockAsyncClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
import java.util.List;
import java.util.Optional;

/**
* Sample properties aws.bedrock.model.claude.id=anthropic.claude-v2
* aws.bedrock.model.claude.prePrompt=Human:
* aws.bedrock.model.claude.postPrompt=Assistant: aws.bedrock.model.claude.maxTokens=100
* aws.bedrock.model.claude.temperature=0.5 aws.bedrock.model.claude.stopSequences=Human:,
* Assistant:
*
* @see <a href="https://docs.ai21.com/reference/claude-complete-api-ref">...</a>
*/
@Validated
@ConfigurationProperties(prefix = "aws.bedrock.model.claude")
public record ClaudeProperties(
Expand All @@ -17,6 +26,15 @@ public record ClaudeProperties(
@DecimalMin("0.0") @DecimalMax("1.0") Double temperature, @Min(1) @Max(100000) Integer maxTokens,
@Nullable List<String> stopSequences) {

/**
* Constructor
* @param id String
* @param prePrompt String
* @param postPrompt String
* @param temperature Double
* @param maxTokens Integer
* @param stopSequences List<String>
*/
public ClaudeProperties(String id, String prePrompt, String postPrompt, Double temperature, Integer maxTokens,
List<String> stopSequences) {
this.id = Optional.ofNullable(id).orElse("anthropic.claude-v2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@
@Validated
@ConfigurationProperties(prefix = "aws.bedrock.model.jurassic")
public record JurassicProperties(@Pattern(
/**
* Model ID
*/
regexp = "ai21.j2-grande-instruct|ai21.j2-jumbo-instruct|ai21.j2-mid|ai21.j2-mid-v1|ai21.j2-ultra|ai21.j2-ultra-v1") String id,
@Nullable String prePrompt, @Min(1) @Max(8192) Integer maxTokens,
@DecimalMin("0.0") @DecimalMax("1.0") Double temperature) {

/**
* Constructor
* @param id String
* @param prePrompt String
* @param maxTokens Integer
* @param temperature Double
*/
public JurassicProperties(String id, String prePrompt, Integer maxTokens, Double temperature) {
this.id = Optional.ofNullable(id).orElse("ai21.j2-mid-v1");
this.prePrompt = Optional.ofNullable(prePrompt).orElse("Human: ");
Expand Down
Loading

0 comments on commit 1b7a1b7

Please sign in to comment.