Add support for Anthropic Claude 3.5 Sonnet

- add support for the Anthropic API
 - add support for the Bedrok Anthropic API

 Related to #914
This commit is contained in:
Christian Tzolov
2024-06-21 19:14:13 +02:00
parent dfa3ceb1ab
commit ae76407f13
4 changed files with 19 additions and 6 deletions

View File

@@ -120,6 +120,8 @@ public class AnthropicApi {
public enum ChatModel implements ModelDescription {
// @formatter:off
CLAUDE_3_5_SONNET("claude-3-5-sonnet-20240620"),
CLAUDE_3_OPUS("claude-3-opus-20240229"),
CLAUDE_3_SONNET("claude-3-sonnet-20240229"),
CLAUDE_3_HAIKU("claude-3-haiku-20240307"),

View File

@@ -24,6 +24,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,13 +71,16 @@ class AnthropicChatModelIT {
@Value("classpath:/prompts/system-message.st")
private Resource systemResource;
@Test
void roleTest() {
@ParameterizedTest(name = "{0} : {displayName} ")
@ValueSource(strings = { "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307",
"claude-3-5-sonnet-20240620" })
void roleTest(String modelName) {
UserMessage userMessage = new UserMessage(
"Tell me about 3 famous pirates from the Golden Age of Piracy and why they did.");
SystemPromptTemplate systemPromptTemplate = new SystemPromptTemplate(systemResource);
Message systemMessage = systemPromptTemplate.createMessage(Map.of("name", "Bob", "voice", "pirate"));
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
Prompt prompt = new Prompt(List.of(userMessage, systemMessage),
AnthropicChatOptions.builder().withModel(modelName).build());
ChatResponse response = chatModel.call(prompt);
assertThat(response.getResults()).hasSize(1);
assertThat(response.getMetadata().getUsage().getGenerationTokens()).isGreaterThan(0);

View File

@@ -258,7 +258,8 @@ class AnthropicChatClientIT {
}
@ParameterizedTest(name = "{0} : {displayName} ")
@ValueSource(strings = { "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307" })
@ValueSource(strings = { "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307",
"claude-3-5-sonnet-20240620" })
void multiModalityEmbeddedImage(String modelName) throws IOException {
// @formatter:off
@@ -277,7 +278,8 @@ class AnthropicChatClientIT {
@Disabled("Currently Anthropic API does not support external image URLs")
@ParameterizedTest(name = "{0} : {displayName} ")
@ValueSource(strings = { "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307" })
@ValueSource(strings = { "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307",
"claude-3-5-sonnet-20240620" })
void multiModalityImageUrl(String modelName) throws IOException {
// TODO: add url method that wrapps the checked exception.

View File

@@ -462,7 +462,11 @@ public class Anthropic3ChatBedrockApi extends
/**
* anthropic.claude-3-opus-20240229-v1:0
*/
CLAUDE_V3_OPUS("anthropic.claude-3-opus-20240229-v1:0");
CLAUDE_V3_OPUS("anthropic.claude-3-opus-20240229-v1:0"),
/**
* anthropic.claude-3-5-sonnet-20240620-v1:0
*/
CLAUDE_V3_5_SONNET("anthropic.claude-3-5-sonnet-20240620-v1:0");
private final String id;