Make Document support single text or media content
The Document class previously allowed multiple media entries while also having a text field, leading to ambiguity in content handling. This change enforces a clear separation between text and media documents to prevent content type confusion and simplify document processing. A Document now must contain either text content or a single media entry, but never both. This aligns with the class's primary use in ETL pipelines where clear content type boundaries are essential for proper embedding generation and vector database storage. Additional architectural changes: - Document now implements a cleaner API by removing deprecated methods - Removed MediaContent interface implementation from Document class - Document.getMedia() now returns a single Media object instead of Collection - Removed EMPTY_TEXT constant in favor of proper null handling - Constructor signatures simplified and streamlined - Builder pattern improved to enforce single content type constraint The breaking changes include: - Media is now a single entry instead of a collection - Content field renamed to text for clarity - Removed support for mixed content types - Simplified builder API to prevent ambiguous construction Prefer using text-related methods over deprecated content methods to better reflect the actual content type being handled and improve API clarity.
This commit is contained in:
@@ -226,7 +226,7 @@ public class MarkdownDocumentReader implements DocumentReader {
|
||||
if (!this.currentParagraphs.isEmpty()) {
|
||||
String content = String.join("", this.currentParagraphs);
|
||||
|
||||
Document.Builder builder = this.currentDocumentBuilder.content(content);
|
||||
Document.Builder builder = this.currentDocumentBuilder.text(content);
|
||||
|
||||
this.config.additionalMetadata.forEach(builder::metadata);
|
||||
|
||||
|
||||
@@ -378,7 +378,7 @@ public class AnthropicChatModel extends AbstractToolCallSupport implements ChatM
|
||||
.filter(message -> message.getMessageType() != MessageType.SYSTEM)
|
||||
.map(message -> {
|
||||
if (message.getMessageType() == MessageType.USER) {
|
||||
List<ContentBlock> contents = new ArrayList<>(List.of(new ContentBlock(message.getContent())));
|
||||
List<ContentBlock> contents = new ArrayList<>(List.of(new ContentBlock(message.getText())));
|
||||
if (message instanceof UserMessage userMessage) {
|
||||
if (!CollectionUtils.isEmpty(userMessage.getMedia())) {
|
||||
List<ContentBlock> mediaContent = userMessage.getMedia().stream().map(media -> {
|
||||
@@ -395,8 +395,8 @@ public class AnthropicChatModel extends AbstractToolCallSupport implements ChatM
|
||||
else if (message.getMessageType() == MessageType.ASSISTANT) {
|
||||
AssistantMessage assistantMessage = (AssistantMessage) message;
|
||||
List<ContentBlock> contentBlocks = new ArrayList<>();
|
||||
if (StringUtils.hasText(message.getContent())) {
|
||||
contentBlocks.add(new ContentBlock(message.getContent()));
|
||||
if (StringUtils.hasText(message.getText())) {
|
||||
contentBlocks.add(new ContentBlock(message.getText()));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(assistantMessage.getToolCalls())) {
|
||||
for (AssistantMessage.ToolCall toolCall : assistantMessage.getToolCalls()) {
|
||||
@@ -423,7 +423,7 @@ public class AnthropicChatModel extends AbstractToolCallSupport implements ChatM
|
||||
String systemPrompt = prompt.getInstructions()
|
||||
.stream()
|
||||
.filter(m -> m.getMessageType() == MessageType.SYSTEM)
|
||||
.map(m -> m.getContent())
|
||||
.map(m -> m.getText())
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
|
||||
ChatCompletionRequest request = new ChatCompletionRequest(this.defaultOptions.getModel(), userMessages,
|
||||
|
||||
@@ -105,7 +105,7 @@ class AnthropicChatModelIT {
|
||||
.isEqualTo(response.getMetadata().getUsage().getPromptTokens()
|
||||
+ response.getMetadata().getUsage().getGenerationTokens());
|
||||
Generation generation = response.getResults().get(0);
|
||||
assertThat(generation.getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(generation.getOutput().getText()).contains("Blackbeard");
|
||||
assertThat(generation.getMetadata().getFinishReason()).isEqualTo("end_turn");
|
||||
logger.info(response.toString());
|
||||
}
|
||||
@@ -120,13 +120,13 @@ class AnthropicChatModelIT {
|
||||
AnthropicChatOptions.builder().withModel("claude-3-sonnet-20240229").build());
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
|
||||
var promptWithMessageHistory = new Prompt(List.of(new UserMessage("Dummy"), response.getResult().getOutput(),
|
||||
new UserMessage("Repeat the last assistant message.")));
|
||||
response = this.chatModel.call(promptWithMessageHistory);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,7 +162,7 @@ class AnthropicChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = listOutputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = listOutputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ class AnthropicChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = mapOutputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = mapOutputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -199,7 +199,7 @@ class AnthropicChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = beanOutputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = beanOutputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -225,7 +225,7 @@ class AnthropicChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = beanOutputConverter.convert(generationTextFromStream);
|
||||
@@ -244,8 +244,8 @@ class AnthropicChatModelIT {
|
||||
|
||||
var response = this.chatModel.call(new Prompt(List.of(userMessage)));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("banan", "apple", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("banan", "apple", "basket");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -262,7 +262,7 @@ class AnthropicChatModelIT {
|
||||
.withModel(AnthropicApi.ChatModel.CLAUDE_3_5_SONNET.getName())
|
||||
.build()));
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Spring AI", "portable API");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Spring AI", "portable API");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -288,7 +288,7 @@ class AnthropicChatModelIT {
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
Generation generation = response.getResult();
|
||||
assertThat(generation.getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(generation.getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -317,7 +317,7 @@ class AnthropicChatModelIT {
|
||||
.block()
|
||||
.stream()
|
||||
.filter(cr -> cr.getResult() != null)
|
||||
.map(cr -> cr.getResult().getOutput().getContent())
|
||||
.map(cr -> cr.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class AnthropicChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -109,7 +109,7 @@ public class AnthropicChatModelObservationIT {
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.filter(r -> r.getResult() != null)
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class AnthropicChatClientIT {
|
||||
|
||||
logger.info("" + response);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -402,7 +402,7 @@ public class AzureOpenAiChatModel extends AbstractToolCallSupport implements Cha
|
||||
case USER:
|
||||
// https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/README.md#text-completions-with-images
|
||||
List<ChatMessageContentItem> items = new ArrayList<>();
|
||||
items.add(new ChatMessageTextContentItem(message.getContent()));
|
||||
items.add(new ChatMessageTextContentItem(message.getText()));
|
||||
if (message instanceof UserMessage userMessage) {
|
||||
if (!CollectionUtils.isEmpty(userMessage.getMedia())) {
|
||||
items.addAll(userMessage.getMedia()
|
||||
@@ -413,7 +413,7 @@ public class AzureOpenAiChatModel extends AbstractToolCallSupport implements Cha
|
||||
}
|
||||
return List.of(new ChatRequestUserMessage(items));
|
||||
case SYSTEM:
|
||||
return List.of(new ChatRequestSystemMessage(message.getContent()));
|
||||
return List.of(new ChatRequestSystemMessage(message.getText()));
|
||||
case ASSISTANT:
|
||||
AssistantMessage assistantMessage = (AssistantMessage) message;
|
||||
List<ChatCompletionsToolCall> toolCalls = null;
|
||||
@@ -425,7 +425,7 @@ public class AzureOpenAiChatModel extends AbstractToolCallSupport implements Cha
|
||||
.map(tc -> ((ChatCompletionsToolCall) tc)) // !!!
|
||||
.toList();
|
||||
}
|
||||
var azureAssistantMessage = new ChatRequestAssistantMessage(message.getContent());
|
||||
var azureAssistantMessage = new ChatRequestAssistantMessage(message.getText());
|
||||
azureAssistantMessage.setToolCalls(toolCalls);
|
||||
return List.of(azureAssistantMessage);
|
||||
case TOOL:
|
||||
|
||||
@@ -68,7 +68,7 @@ public class AzureOpenAiChatClientIT {
|
||||
// @formatter:on
|
||||
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +94,7 @@ public class AzureOpenAiChatClientIT {
|
||||
|
||||
String generationTextFromStream = chatResponses
|
||||
.stream()
|
||||
.map(cr -> cr.getResult().getOutput().getContent())
|
||||
.map(cr -> cr.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
// @formatter:on
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class AzureOpenAiChatModelIT {
|
||||
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,14 +96,14 @@ class AzureOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard");
|
||||
|
||||
var promptWithMessageHistory = new Prompt(List.of(new UserMessage("Dummy"), response.getResult().getOutput(),
|
||||
new UserMessage("Repeat the last assistant message.")));
|
||||
response = this.chatModel.call(promptWithMessageHistory);
|
||||
|
||||
System.out.println(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard");
|
||||
System.out.println(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,7 +121,7 @@ class AzureOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
|
||||
}
|
||||
@@ -140,7 +140,7 @@ class AzureOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -159,7 +159,7 @@ class AzureOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.actor()).isNotNull();
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ class AzureOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -203,7 +203,7 @@ class AzureOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class AzureOpenAiChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -106,7 +106,7 @@ class AzureOpenAiChatModelObservationIT {
|
||||
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class AzureOpenAiChatModelFunctionCallIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,7 +104,7 @@ class AzureOpenAiChatModelFunctionCallIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -132,7 +132,7 @@ class AzureOpenAiChatModelFunctionCallIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -169,7 +169,7 @@ class AzureOpenAiChatModelFunctionCallIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class AzureOpenAiChatModelMetadataTests {
|
||||
|
||||
assertThat(generation).isNotNull()
|
||||
.extracting(Generation::getOutput)
|
||||
.extracting(AssistantMessage::getContent)
|
||||
.extracting(AssistantMessage::getText)
|
||||
.isEqualTo("No! You will actually land with a resounding thud. This is the way!");
|
||||
|
||||
// assertPromptMetadata(response);
|
||||
|
||||
@@ -259,7 +259,7 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
List<ContentBlock> contents = new ArrayList<>();
|
||||
if (message instanceof UserMessage) {
|
||||
var userMessage = (UserMessage) message;
|
||||
contents.add(ContentBlock.fromText(userMessage.getContent()));
|
||||
contents.add(ContentBlock.fromText(userMessage.getText()));
|
||||
|
||||
if (!CollectionUtils.isEmpty(userMessage.getMedia())) {
|
||||
List<ContentBlock> mediaContent = userMessage.getMedia()
|
||||
@@ -274,8 +274,8 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
else if (message.getMessageType() == MessageType.ASSISTANT) {
|
||||
AssistantMessage assistantMessage = (AssistantMessage) message;
|
||||
List<ContentBlock> contentBlocks = new ArrayList<>();
|
||||
if (StringUtils.hasText(message.getContent())) {
|
||||
contentBlocks.add(ContentBlock.fromText(message.getContent()));
|
||||
if (StringUtils.hasText(message.getText())) {
|
||||
contentBlocks.add(ContentBlock.fromText(message.getText()));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(assistantMessage.getToolCalls())) {
|
||||
for (AssistantMessage.ToolCall toolCall : assistantMessage.getToolCalls()) {
|
||||
@@ -315,7 +315,7 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
List<SystemContentBlock> systemMessages = prompt.getInstructions()
|
||||
.stream()
|
||||
.filter(m -> m.getMessageType() == MessageType.SYSTEM)
|
||||
.map(sysMessage -> SystemContentBlock.builder().text(sysMessage.getContent()).build())
|
||||
.map(sysMessage -> SystemContentBlock.builder().text(sysMessage.getText()).build())
|
||||
.toList();
|
||||
|
||||
FunctionCallingOptions updatedRuntimeOptions = (FunctionCallingOptions) this.defaultOptions.copy();
|
||||
|
||||
@@ -79,7 +79,7 @@ class BedrockConverseChatClientIT {
|
||||
|
||||
logger.info("" + response);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -196,7 +196,7 @@ class BedrockConverseChatClientIT {
|
||||
String generationTextFromStream = chatResponses
|
||||
.stream()
|
||||
.filter(cr -> cr.getResult() != null)
|
||||
.map(cr -> cr.getResult().getOutput().getContent())
|
||||
.map(cr -> cr.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
// @formatter:on
|
||||
|
||||
@@ -259,7 +259,7 @@ class BedrockConverseChatClientIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -340,7 +340,7 @@ class BedrockConverseChatClientIT {
|
||||
|
||||
String content = chatResponses.stream()
|
||||
.filter(cr -> cr.getResult() != null)
|
||||
.map(cr -> cr.getResult().getOutput().getContent())
|
||||
.map(cr -> cr.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ public class BedrockConverseUsageAggregationTests {
|
||||
var result = this.chatModel.call(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getContent()).isSameAs("Response Content Block");
|
||||
assertThat(result.getResult().getOutput().getText()).isSameAs("Response Content Block");
|
||||
|
||||
assertThat(result.getMetadata().getUsage().getPromptTokens()).isEqualTo(16);
|
||||
assertThat(result.getMetadata().getUsage().getGenerationTokens()).isEqualTo(14);
|
||||
@@ -148,7 +148,7 @@ public class BedrockConverseUsageAggregationTests {
|
||||
PortableFunctionCallingOptions.builder().withFunctionCallbacks(functionCallback).build()));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getContent())
|
||||
assertThat(result.getResult().getOutput().getText())
|
||||
.isSameAs(converseResponseFinal.output().message().content().get(0).text());
|
||||
|
||||
assertThat(result.getMetadata().getUsage().getPromptTokens()).isEqualTo(445 + 540);
|
||||
|
||||
@@ -101,7 +101,7 @@ class BedrockProxyChatModelIT {
|
||||
.isEqualTo(response.getMetadata().getUsage().getPromptTokens()
|
||||
+ response.getMetadata().getUsage().getGenerationTokens());
|
||||
Generation generation = response.getResults().get(0);
|
||||
assertThat(generation.getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(generation.getOutput().getText()).contains("Blackbeard");
|
||||
assertThat(generation.getMetadata().getFinishReason()).isEqualTo("end_turn");
|
||||
logger.info(response.toString());
|
||||
}
|
||||
@@ -116,14 +116,14 @@ class BedrockProxyChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
|
||||
var promptWithMessageHistory = new Prompt(List.of(new UserMessage("Dummy"), response.getResult().getOutput(),
|
||||
new UserMessage("Repeat the last assistant message.")));
|
||||
|
||||
response = this.chatModel.call(promptWithMessageHistory);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +159,7 @@ class BedrockProxyChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = listOutputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = listOutputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ class BedrockProxyChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = mapOutputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = mapOutputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -196,7 +196,7 @@ class BedrockProxyChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = beanOutputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = beanOutputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -222,7 +222,7 @@ class BedrockProxyChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = beanOutputConverter.convert(generationTextFromStream);
|
||||
@@ -241,8 +241,8 @@ class BedrockProxyChatModelIT {
|
||||
|
||||
var response = this.chatModel.call(new Prompt(List.of(userMessage)));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("banan", "apple", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("banan", "apple", "basket");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -267,7 +267,7 @@ class BedrockProxyChatModelIT {
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
Generation generation = response.getResult();
|
||||
assertThat(generation.getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(generation.getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,7 +296,7 @@ class BedrockProxyChatModelIT {
|
||||
.block()
|
||||
.stream()
|
||||
.filter(cr -> cr.getResult() != null)
|
||||
.map(cr -> cr.getResult().getOutput().getContent())
|
||||
.map(cr -> cr.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class BedrockProxyChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -109,7 +109,7 @@ public class BedrockProxyChatModelObservationIT {
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.filter(r -> r.getResult() != null)
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class MessageToPromptConverter {
|
||||
|
||||
final String systemMessages = messages.stream()
|
||||
.filter(message -> message.getMessageType() == MessageType.SYSTEM)
|
||||
.map(Message::getContent)
|
||||
.map(Message::getText)
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
|
||||
final String userMessages = messages.stream()
|
||||
@@ -83,11 +83,11 @@ public final class MessageToPromptConverter {
|
||||
protected String messageToString(Message message) {
|
||||
switch (message.getMessageType()) {
|
||||
case SYSTEM:
|
||||
return message.getContent();
|
||||
return message.getText();
|
||||
case USER:
|
||||
return this.humanPrompt + " " + message.getContent();
|
||||
return this.humanPrompt + " " + message.getText();
|
||||
case ASSISTANT:
|
||||
return this.assistantPrompt + " " + message.getContent();
|
||||
return this.assistantPrompt + " " + message.getText();
|
||||
case TOOL:
|
||||
throw new IllegalArgumentException("Tool execution results are not supported for Bedrock models");
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class BedrockAnthropic3ChatModel implements ChatModel, StreamingChatModel
|
||||
return prompt.getInstructions()
|
||||
.stream()
|
||||
.filter(m -> m.getMessageType() == MessageType.SYSTEM)
|
||||
.map(Message::getContent)
|
||||
.map(Message::getText)
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public class BedrockAnthropic3ChatModel implements ChatModel, StreamingChatModel
|
||||
.stream()
|
||||
.filter(m -> m.getMessageType() == MessageType.USER || m.getMessageType() == MessageType.ASSISTANT)
|
||||
.map(message -> {
|
||||
List<MediaContent> contents = new ArrayList<>(List.of(new MediaContent(message.getContent())));
|
||||
List<MediaContent> contents = new ArrayList<>(List.of(new MediaContent(message.getText())));
|
||||
if (message instanceof UserMessage userMessage) {
|
||||
if (!CollectionUtils.isEmpty(userMessage.getMedia())) {
|
||||
List<MediaContent> mediaContent = userMessage.getMedia()
|
||||
|
||||
@@ -79,7 +79,7 @@ class BedrockAnthropicChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
String joke2 = joke2Stream.collectList()
|
||||
.block()
|
||||
@@ -87,7 +87,7 @@ class BedrockAnthropicChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(joke1).isNotBlank();
|
||||
@@ -105,7 +105,7 @@ class BedrockAnthropicChatModelIT {
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,7 +123,7 @@ class BedrockAnthropicChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = converter.convert(generation.getOutput().getContent());
|
||||
List<String> list = converter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class BedrockAnthropicChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -164,7 +164,7 @@ class BedrockAnthropicChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConvert.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConvert.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ class BedrockAnthropicChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
|
||||
@@ -82,7 +82,7 @@ class BedrockAnthropic3ChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
String joke2 = joke2Stream.collectList()
|
||||
.block()
|
||||
@@ -90,7 +90,7 @@ class BedrockAnthropic3ChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(joke1).isNotBlank();
|
||||
@@ -108,7 +108,7 @@ class BedrockAnthropic3ChatModelIT {
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +126,7 @@ class BedrockAnthropic3ChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class BedrockAnthropic3ChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -166,7 +166,7 @@ class BedrockAnthropic3ChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
}
|
||||
@@ -192,7 +192,7 @@ class BedrockAnthropic3ChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
@@ -211,8 +211,8 @@ class BedrockAnthropic3ChatModelIT {
|
||||
|
||||
var response = this.chatModel.call(new Prompt(List.of(userMessage)));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple", "basket");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -77,7 +77,7 @@ class BedrockCohereChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
String joke2 = joke2Stream.collectList()
|
||||
.block()
|
||||
@@ -85,7 +85,7 @@ class BedrockCohereChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(joke1).isNotBlank();
|
||||
@@ -102,7 +102,7 @@ class BedrockCohereChatModelIT {
|
||||
Message systemMessage = systemPromptTemplate.createMessage(Map.of("name", name, "voice", voice));
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,7 +120,7 @@ class BedrockCohereChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ class BedrockCohereChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -159,7 +159,7 @@ class BedrockCohereChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
}
|
||||
@@ -185,7 +185,7 @@ class BedrockCohereChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
|
||||
@@ -67,7 +67,7 @@ class BedrockAi21Jurassic2ChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
String content = response.getResult().getOutput().getContent();
|
||||
String content = response.getResult().getOutput().getText();
|
||||
|
||||
// System.out.println("Response content: " + content);
|
||||
|
||||
@@ -96,9 +96,9 @@ class BedrockAi21Jurassic2ChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage), options);
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent())
|
||||
assertThat(response.getResult().getOutput().getText())
|
||||
.matches(content -> content.contains("😄") || content.contains(":)"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +118,7 @@ class BedrockAi21Jurassic2ChatModelIT {
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).doesNotContain("😄");
|
||||
assertThat(response.getResult().getOutput().getText()).doesNotContain("😄");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,7 +135,7 @@ class BedrockAi21Jurassic2ChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -151,7 +151,7 @@ class BedrockAi21Jurassic2ChatModelIT {
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("AI");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("AI");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
|
||||
@@ -75,7 +75,7 @@ class BedrockLlamaChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
String joke2 = joke2Stream.collectList()
|
||||
.block()
|
||||
@@ -83,7 +83,7 @@ class BedrockLlamaChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(joke1).isNotBlank();
|
||||
@@ -103,8 +103,7 @@ class BedrockLlamaChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).satisfies(content -> {
|
||||
assertThat(response.getResult().getOutput().getText()).satisfies(content -> {
|
||||
// Check for name
|
||||
assertThat(content).contains("Bob");
|
||||
|
||||
@@ -129,7 +128,7 @@ class BedrockLlamaChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -147,7 +146,7 @@ class BedrockLlamaChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -168,7 +167,7 @@ class BedrockLlamaChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
}
|
||||
@@ -194,7 +193,7 @@ class BedrockLlamaChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
|
||||
@@ -76,7 +76,7 @@ class BedrockTitanChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
String joke2 = joke2Stream.collectList()
|
||||
.block()
|
||||
@@ -84,7 +84,7 @@ class BedrockTitanChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(joke1).isNotBlank();
|
||||
@@ -101,7 +101,7 @@ class BedrockTitanChatModelIT {
|
||||
Message systemMessage = systemPromptTemplate.createMessage(Map.of("name", name, "voice", voice));
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,7 +119,7 @@ class BedrockTitanChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ class BedrockTitanChatModelIT {
|
||||
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class BedrockTitanChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class BedrockTitanChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
|
||||
@@ -51,14 +51,14 @@ public class ClientIT {
|
||||
""";
|
||||
Prompt prompt = new Prompt(mistral7bInstruct);
|
||||
ChatResponse chatResponse = this.huggingfaceChatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
String expectedResponse = """
|
||||
{
|
||||
"name": "John",
|
||||
"lastname": "Smith",
|
||||
"address": "#1 Samuel St."
|
||||
}""";
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isEqualTo(expectedResponse);
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isEqualTo(expectedResponse);
|
||||
assertThat(chatResponse.getResult().getOutput().getMetadata()).containsKey("generated_tokens");
|
||||
assertThat(chatResponse.getResult().getOutput().getMetadata()).containsEntry("generated_tokens", 32);
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ public class MiniMaxChatModel extends AbstractToolCallSupport implements ChatMod
|
||||
|
||||
List<ChatCompletionMessage> chatCompletionMessages = prompt.getInstructions().stream().map(message -> {
|
||||
if (message.getMessageType() == MessageType.USER || message.getMessageType() == MessageType.SYSTEM) {
|
||||
Object content = message.getContent();
|
||||
Object content = message.getText();
|
||||
return List.of(new ChatCompletionMessage(content,
|
||||
ChatCompletionMessage.Role.valueOf(message.getMessageType().name())));
|
||||
}
|
||||
@@ -452,7 +452,7 @@ public class MiniMaxChatModel extends AbstractToolCallSupport implements ChatMod
|
||||
return new ToolCall(toolCall.id(), toolCall.type(), function);
|
||||
}).toList();
|
||||
}
|
||||
return List.of(new ChatCompletionMessage(assistantMessage.getContent(),
|
||||
return List.of(new ChatCompletionMessage(assistantMessage.getText(),
|
||||
ChatCompletionMessage.Role.ASSISTANT, null, null, toolCalls));
|
||||
}
|
||||
else if (message.getMessageType() == MessageType.TOOL) {
|
||||
|
||||
@@ -98,7 +98,7 @@ public class MiniMaxRetryTests {
|
||||
var result = this.chatModel.call(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class MiniMaxRetryTests {
|
||||
var result = this.chatModel.stream(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class MiniMaxChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -111,7 +111,7 @@ public class MiniMaxChatModelObservationIT {
|
||||
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MiniMaxChatOptionsTests {
|
||||
|
||||
// markSensitiveInfo is enabled by default
|
||||
ChatResponse response = this.chatModel.call(new Prompt(messages));
|
||||
String responseContent = response.getResult().getOutput().getContent();
|
||||
String responseContent = response.getResult().getOutput().getText();
|
||||
|
||||
assertThat(responseContent).contains("133-**");
|
||||
assertThat(responseContent).doesNotContain("133-12345678");
|
||||
@@ -67,7 +67,7 @@ public class MiniMaxChatOptionsTests {
|
||||
var chatOptions = MiniMaxChatOptions.builder().withMaskSensitiveInfo(false).build();
|
||||
|
||||
ChatResponse unmaskResponse = this.chatModel.call(new Prompt(messages, chatOptions));
|
||||
String unmaskResponseContent = unmaskResponse.getResult().getOutput().getContent();
|
||||
String unmaskResponseContent = unmaskResponse.getResult().getOutput().getText();
|
||||
|
||||
assertThat(unmaskResponseContent).contains("133-12345678");
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class MiniMaxChatOptionsTests {
|
||||
.build();
|
||||
|
||||
ChatResponse response = this.chatModel.call(new Prompt(messages, options));
|
||||
String responseContent = response.getResult().getOutput().getContent();
|
||||
String responseContent = response.getResult().getOutput().getText();
|
||||
|
||||
assertThat(responseContent).contains("40");
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public class MiniMaxChatOptionsTests {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -326,11 +326,11 @@ public class MistralAiChatModel extends AbstractToolCallSupport implements ChatM
|
||||
|
||||
List<ChatCompletionMessage> chatCompletionMessages = prompt.getInstructions().stream().map(message -> {
|
||||
if (message instanceof UserMessage userMessage) {
|
||||
return List.of(new MistralAiApi.ChatCompletionMessage(userMessage.getContent(),
|
||||
return List.of(new MistralAiApi.ChatCompletionMessage(userMessage.getText(),
|
||||
MistralAiApi.ChatCompletionMessage.Role.USER));
|
||||
}
|
||||
else if (message instanceof SystemMessage systemMessage) {
|
||||
return List.of(new MistralAiApi.ChatCompletionMessage(systemMessage.getContent(),
|
||||
return List.of(new MistralAiApi.ChatCompletionMessage(systemMessage.getText(),
|
||||
MistralAiApi.ChatCompletionMessage.Role.SYSTEM));
|
||||
}
|
||||
else if (message instanceof AssistantMessage assistantMessage) {
|
||||
@@ -342,7 +342,7 @@ public class MistralAiChatModel extends AbstractToolCallSupport implements ChatM
|
||||
}).toList();
|
||||
}
|
||||
|
||||
return List.of(new MistralAiApi.ChatCompletionMessage(assistantMessage.getContent(),
|
||||
return List.of(new MistralAiApi.ChatCompletionMessage(assistantMessage.getText(),
|
||||
MistralAiApi.ChatCompletionMessage.Role.ASSISTANT, null, toolCalls, null));
|
||||
}
|
||||
else if (message instanceof ToolResponseMessage toolResponseMessage) {
|
||||
|
||||
@@ -70,7 +70,7 @@ class MistralAiChatClientIT {
|
||||
|
||||
logger.info("" + response);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +85,7 @@ class MistralAiChatClientIT {
|
||||
.call()
|
||||
.chatResponse();
|
||||
// @formatter:on
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard");
|
||||
|
||||
// @formatter:off
|
||||
response = ChatClient.create(this.chatModel).prompt()
|
||||
@@ -96,7 +96,7 @@ class MistralAiChatClientIT {
|
||||
// @formatter:on
|
||||
|
||||
logger.info("" + response);
|
||||
assertThat(response.getResult().getOutput().getContent().toLowerCase()).containsAnyOf("blackbeard",
|
||||
assertThat(response.getResult().getOutput().getText().toLowerCase()).containsAnyOf("blackbeard",
|
||||
"bartholomew roberts");
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class MistralAiChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(systemMessage, userMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,7 +111,7 @@ class MistralAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ class MistralAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -148,7 +148,7 @@ class MistralAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -174,7 +174,7 @@ class MistralAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
@@ -204,7 +204,7 @@ class MistralAiChatModelIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("30.0", "30");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("30.0", "30");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -231,7 +231,7 @@ class MistralAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class MistralAiChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -107,7 +107,7 @@ public class MistralAiChatModelObservationIT {
|
||||
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public class MistralAiRetryTests {
|
||||
var result = this.chatModel.call(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class MistralAiRetryTests {
|
||||
var result = this.chatModel.stream(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ public class MoonshotChatModel extends AbstractToolCallSupport implements ChatMo
|
||||
|
||||
List<ChatCompletionMessage> chatCompletionMessages = prompt.getInstructions().stream().map(message -> {
|
||||
if (message.getMessageType() == MessageType.USER || message.getMessageType() == MessageType.SYSTEM) {
|
||||
Object content = message.getContent();
|
||||
Object content = message.getText();
|
||||
return List.of(new ChatCompletionMessage(content,
|
||||
ChatCompletionMessage.Role.valueOf(message.getMessageType().name())));
|
||||
}
|
||||
@@ -362,7 +362,7 @@ public class MoonshotChatModel extends AbstractToolCallSupport implements ChatMo
|
||||
return new ToolCall(toolCall.id(), toolCall.type(), function);
|
||||
}).toList();
|
||||
}
|
||||
return List.of(new ChatCompletionMessage(assistantMessage.getContent(),
|
||||
return List.of(new ChatCompletionMessage(assistantMessage.getText(),
|
||||
ChatCompletionMessage.Role.ASSISTANT, null, null, toolCalls));
|
||||
}
|
||||
else if (message.getMessageType() == MessageType.TOOL) {
|
||||
|
||||
@@ -91,7 +91,7 @@ public class MoonshotRetryTests {
|
||||
var result = this.chatModel.call(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class MoonshotRetryTests {
|
||||
var result = this.chatModel.stream(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class MoonshotChatModelFunctionCallingIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,7 +100,7 @@ class MoonshotChatModelFunctionCallingIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -75,7 +75,7 @@ public class MoonshotChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,7 +93,7 @@ public class MoonshotChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class MoonshotChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class MoonshotChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class MoonshotChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -190,7 +190,7 @@ public class MoonshotChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
|
||||
@@ -82,7 +82,7 @@ public class MoonshotChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -112,7 +112,7 @@ public class MoonshotChatModelObservationIT {
|
||||
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -203,9 +203,9 @@ public class OCICohereChatModel implements ChatModel {
|
||||
for (int i = 1; i < messages.size(); i++) {
|
||||
Message message = messages.get(i);
|
||||
switch (message.getMessageType()) {
|
||||
case USER -> chatHistory.add(CohereUserMessage.builder().message(message.getContent()).build());
|
||||
case ASSISTANT -> chatHistory.add(CohereChatBotMessage.builder().message(message.getContent()).build());
|
||||
case SYSTEM -> chatHistory.add(CohereSystemMessage.builder().message(message.getContent()).build());
|
||||
case USER -> chatHistory.add(CohereUserMessage.builder().message(message.getText()).build());
|
||||
case ASSISTANT -> chatHistory.add(CohereChatBotMessage.builder().message(message.getText()).build());
|
||||
case SYSTEM -> chatHistory.add(CohereSystemMessage.builder().message(message.getText()).build());
|
||||
case TOOL -> {
|
||||
if (message instanceof ToolResponseMessage tm) {
|
||||
chatHistory.add(toToolMessage(tm));
|
||||
@@ -237,7 +237,7 @@ public class OCICohereChatModel implements ChatModel {
|
||||
.documents(options.getDocuments())
|
||||
.tools(options.getTools())
|
||||
.chatHistory(chatHistory)
|
||||
.message(message.getContent())
|
||||
.message(message.getText())
|
||||
.build();
|
||||
ServingMode servingMode = ServingModeHelper.get(options.getServingMode(), options.getModel());
|
||||
ChatDetails chatDetails = ChatDetails.builder()
|
||||
|
||||
@@ -54,7 +54,7 @@ public class OCICohereChatModelIT extends BaseOCIGenAITest {
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getMetadata().getModel()).isEqualTo(CHAT_MODEL_ID);
|
||||
assertThat(response.getResult()).isNotNull();
|
||||
assertThat(response.getResult().getOutput().getContent()).isNotBlank();
|
||||
assertThat(response.getResult().getOutput().getText()).isNotBlank();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ public class OllamaChatModel extends AbstractToolCallSupport implements ChatMode
|
||||
|
||||
List<OllamaApi.Message> ollamaMessages = prompt.getInstructions().stream().map(message -> {
|
||||
if (message instanceof UserMessage userMessage) {
|
||||
var messageBuilder = OllamaApi.Message.builder(Role.USER).content(message.getContent());
|
||||
var messageBuilder = OllamaApi.Message.builder(Role.USER).withContent(message.getText());
|
||||
if (!CollectionUtils.isEmpty(userMessage.getMedia())) {
|
||||
messageBuilder.images(
|
||||
userMessage.getMedia().stream().map(media -> this.fromMediaData(media.getData())).toList());
|
||||
@@ -325,7 +325,7 @@ public class OllamaChatModel extends AbstractToolCallSupport implements ChatMode
|
||||
return List.of(messageBuilder.build());
|
||||
}
|
||||
else if (message instanceof SystemMessage systemMessage) {
|
||||
return List.of(OllamaApi.Message.builder(Role.SYSTEM).content(systemMessage.getContent()).build());
|
||||
return List.of(OllamaApi.Message.builder(Role.SYSTEM).withContent(systemMessage.getText()).build());
|
||||
}
|
||||
else if (message instanceof AssistantMessage assistantMessage) {
|
||||
List<ToolCall> toolCalls = null;
|
||||
@@ -337,8 +337,8 @@ public class OllamaChatModel extends AbstractToolCallSupport implements ChatMode
|
||||
}).toList();
|
||||
}
|
||||
return List.of(OllamaApi.Message.builder(Role.ASSISTANT)
|
||||
.content(assistantMessage.getContent())
|
||||
.toolCalls(toolCalls)
|
||||
.withContent(assistantMessage.getText())
|
||||
.withToolCalls(toolCalls)
|
||||
.build());
|
||||
}
|
||||
else if (message instanceof ToolResponseMessage toolMessage) {
|
||||
|
||||
@@ -75,7 +75,7 @@ class OllamaChatModelFunctionCallingIT extends BaseOllamaIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,7 +103,7 @@ class OllamaChatModelFunctionCallingIT extends BaseOllamaIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
|
||||
@@ -96,13 +96,13 @@ class OllamaChatModelIT extends BaseOllamaIT {
|
||||
Prompt prompt = new Prompt(List.of(systemMessage, userMessage), portableOptions);
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("Blackbeard");
|
||||
|
||||
// ollama specific options
|
||||
var ollamaOptions = new OllamaOptions().withLowVRAM(true);
|
||||
|
||||
response = this.chatModel.call(new Prompt(List.of(systemMessage, userMessage), ollamaOptions));
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,13 +120,13 @@ class OllamaChatModelIT extends BaseOllamaIT {
|
||||
Prompt prompt = new Prompt(List.of(systemMessage, userMessage));
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard");
|
||||
|
||||
var promptWithMessageHistory = new Prompt(List.of(new UserMessage("Hello"), response.getResult().getOutput(),
|
||||
new UserMessage("Tell me just the names of those pirates.")));
|
||||
response = this.chatModel.call(promptWithMessageHistory);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,7 +156,7 @@ class OllamaChatModelIT extends BaseOllamaIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ class OllamaChatModelIT extends BaseOllamaIT {
|
||||
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result).isNotNull();
|
||||
assertThat((String) result.get("R")).containsIgnoringCase("red");
|
||||
assertThat((String) result.get("G")).containsIgnoringCase("green");
|
||||
@@ -195,7 +195,7 @@ class OllamaChatModelIT extends BaseOllamaIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
}
|
||||
@@ -219,7 +219,7 @@ class OllamaChatModelIT extends BaseOllamaIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
|
||||
@@ -67,8 +67,8 @@ class OllamaChatModelMultimodalIT extends BaseOllamaIT {
|
||||
|
||||
var response = this.chatModel.call(new Prompt(List.of(userMessage)));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bananas", "apple");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
|
||||
@@ -80,7 +80,7 @@ public class OllamaChatModelObservationIT extends BaseOllamaIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -111,7 +111,7 @@ public class OllamaChatModelObservationIT extends BaseOllamaIT {
|
||||
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -454,11 +454,10 @@ public class OpenAiChatModel extends AbstractToolCallSupport implements ChatMode
|
||||
|
||||
List<ChatCompletionMessage> chatCompletionMessages = prompt.getInstructions().stream().map(message -> {
|
||||
if (message.getMessageType() == MessageType.USER || message.getMessageType() == MessageType.SYSTEM) {
|
||||
Object content = message.getContent();
|
||||
Object content = message.getText();
|
||||
if (message instanceof UserMessage userMessage) {
|
||||
if (!CollectionUtils.isEmpty(userMessage.getMedia())) {
|
||||
List<MediaContent> contentList = new ArrayList<>(
|
||||
List.of(new MediaContent(message.getContent())));
|
||||
List<MediaContent> contentList = new ArrayList<>(List.of(new MediaContent(message.getText())));
|
||||
|
||||
contentList.addAll(userMessage.getMedia().stream().map(this::mapToMediaContent).toList());
|
||||
|
||||
@@ -485,7 +484,7 @@ public class OpenAiChatModel extends AbstractToolCallSupport implements ChatMode
|
||||
audioOutput = new AudioOutput(assistantMessage.getMedia().get(0).getId(), null, null, null);
|
||||
|
||||
}
|
||||
return List.of(new ChatCompletionMessage(assistantMessage.getContent(),
|
||||
return List.of(new ChatCompletionMessage(assistantMessage.getText(),
|
||||
ChatCompletionMessage.Role.ASSISTANT, null, null, toolCalls, null, audioOutput));
|
||||
}
|
||||
else if (message.getMessageType() == MessageType.TOOL) {
|
||||
|
||||
@@ -139,7 +139,7 @@ class OpenAiChatModelFunctionCallingIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -207,7 +207,7 @@ class OpenAiChatModelFunctionCallingIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
// needs fine tuning... evaluateQuestionAndAnswer(request, response, false);
|
||||
}
|
||||
|
||||
@@ -102,13 +102,13 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
|
||||
var promptWithMessageHistory = new Prompt(List.of(new UserMessage("Dummy"), response.getResult().getOutput(),
|
||||
new UserMessage("Repeat the last assistant message.")));
|
||||
response = this.chatModel.call(promptWithMessageHistory);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,7 +121,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
Flux<ChatResponse> chatResponseFlux = this.streamingChatModel.stream(prompt).doOnNext(chatResponse -> {
|
||||
String responseContent = chatResponse.getResults().get(0).getOutput().getContent();
|
||||
String responseContent = chatResponse.getResults().get(0).getOutput().getText();
|
||||
answer.append(responseContent);
|
||||
}).doOnComplete(() -> {
|
||||
logger.info(answer.toString());
|
||||
@@ -146,7 +146,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
.stream()
|
||||
.chatResponse()
|
||||
.doOnNext(chatResponse -> {
|
||||
String responseContent = chatResponse.getResults().get(0).getOutput().getContent();
|
||||
String responseContent = chatResponse.getResults().get(0).getOutput().getText();
|
||||
answer.append(responseContent);
|
||||
})
|
||||
.doOnComplete(() -> {
|
||||
@@ -197,7 +197,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(stitchedResponseContent).contains("Blackbeard");
|
||||
@@ -237,7 +237,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
|
||||
}
|
||||
@@ -256,7 +256,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -275,7 +275,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -292,7 +292,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -318,7 +318,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
@@ -347,9 +347,9 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("30.0", "30");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("10.0", "10");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("15.0", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("30.0", "30");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("10.0", "10");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("15.0", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -376,7 +376,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -424,9 +424,9 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
var response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket", "fruit stand");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket", "fruit stand");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
||||
@@ -442,9 +442,9 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
ChatResponse response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket", "fruit stand");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket", "fruit stand");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -465,7 +465,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
assertThat(content).contains("bananas", "apple");
|
||||
@@ -484,8 +484,8 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
.withOutputAudio(new AudioParameters(Voice.ALLOY, AudioResponseFormat.WAV))
|
||||
.build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).isNotEmpty();
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
byte[] audio = response.getResult().getOutput().getMedia().get(0).getDataAsByteArray();
|
||||
assertThat(audio).isNotEmpty();
|
||||
@@ -520,8 +520,8 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
ChatResponse response = chatModel
|
||||
.call(new Prompt(List.of(userMessage), ChatOptionsBuilder.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).containsIgnoringCase("hobbits");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).containsIgnoringCase("hobbits");
|
||||
assertThat(response.getMetadata().getModel()).containsIgnoringCase(modelName);
|
||||
}
|
||||
|
||||
@@ -541,7 +541,7 @@ public class OpenAiChatModelIT extends AbstractIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
assertThat(content).containsIgnoringCase("hobbits");
|
||||
|
||||
@@ -82,7 +82,7 @@ public class OpenAiChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -113,7 +113,7 @@ public class OpenAiChatModelObservationIT {
|
||||
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ class OpenAiChatModelProxyToolCallsIT {
|
||||
|
||||
logger.info("Response: {}", chatResponse);
|
||||
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -220,7 +220,7 @@ class OpenAiChatModelProxyToolCallsIT {
|
||||
.collectList()
|
||||
.block()
|
||||
.stream()
|
||||
.map(cr -> cr.getResult().getOutput().getContent())
|
||||
.map(cr -> cr.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
@@ -306,7 +306,7 @@ class OpenAiChatModelProxyToolCallsIT {
|
||||
|
||||
logger.info("Response: {}", chatResponse);
|
||||
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -341,7 +341,7 @@ class OpenAiChatModelProxyToolCallsIT {
|
||||
String response = responses.collectList()
|
||||
.block()
|
||||
.stream()
|
||||
.map(cr -> cr.getResult().getOutput().getContent())
|
||||
.map(cr -> cr.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class OpenAiChatModelResponseFormatIT {
|
||||
|
||||
assertThat(response).isNotNull();
|
||||
|
||||
String content = response.getResult().getOutput().getContent();
|
||||
String content = response.getResult().getOutput().getText();
|
||||
|
||||
logger.info("Response content: {}", content);
|
||||
|
||||
@@ -132,7 +132,7 @@ public class OpenAiChatModelResponseFormatIT {
|
||||
|
||||
assertThat(response).isNotNull();
|
||||
|
||||
String content = response.getResult().getOutput().getContent();
|
||||
String content = response.getResult().getOutput().getText();
|
||||
|
||||
logger.info("Response content: {}", content);
|
||||
|
||||
@@ -213,7 +213,7 @@ public class OpenAiChatModelResponseFormatIT {
|
||||
|
||||
assertThat(response).isNotNull();
|
||||
|
||||
String content = response.getResult().getOutput().getContent();
|
||||
String content = response.getResult().getOutput().getText();
|
||||
|
||||
logger.info("Response content: {}", content);
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class OpenAiChatModelTypeReferenceBeanOutputConverterIT extends AbstractIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<ActorsFilmsRecord> actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<ActorsFilmsRecord> actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms).hasSize(2);
|
||||
assertThat(actorsFilms.get(0).actor()).isEqualTo("Tom Hanks");
|
||||
@@ -94,7 +94,7 @@ class OpenAiChatModelTypeReferenceBeanOutputConverterIT extends AbstractIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
List<ActorsFilmsRecord> actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class OpenAiCompatibleChatModelIT {
|
||||
ChatResponse response = chatModel.call(prompt);
|
||||
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -94,7 +94,7 @@ public class OpenAiCompatibleChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(stitchedResponseContent).contains("Blackbeard");
|
||||
|
||||
@@ -140,7 +140,7 @@ public class OpenAiRetryTests {
|
||||
var result = this.chatModel.call(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public class OpenAiRetryTests {
|
||||
var result = this.chatModel.stream(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class OpenAiChatClientIT extends AbstractIT {
|
||||
|
||||
logger.info("" + response);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,7 +232,7 @@ class OpenAiChatClientIT extends AbstractIT {
|
||||
String generationTextFromStream = chatResponses
|
||||
.stream()
|
||||
.filter(cr -> cr.getResult() != null)
|
||||
.map(cr -> cr.getResult().getOutput().getContent())
|
||||
.map(cr -> cr.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
// @formatter:on
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ class OpenAiChatClientProxyFunctionCallsIT extends AbstractIT {
|
||||
|
||||
logger.info("Response: {}", chatResponse);
|
||||
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,7 +109,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(stitchedResponseContent).contains("Blackbeard");
|
||||
@@ -150,7 +150,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
|
||||
}
|
||||
@@ -169,7 +169,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -188,7 +188,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.getActor()).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -232,7 +232,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
@@ -260,7 +260,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -287,7 +287,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -307,9 +307,9 @@ class GroqWithOpenAiChatModelIT {
|
||||
var response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket");
|
||||
}
|
||||
|
||||
@Disabled("Groq does not support multi modality API")
|
||||
@@ -326,9 +326,9 @@ class GroqWithOpenAiChatModelIT {
|
||||
ChatResponse response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket");
|
||||
}
|
||||
|
||||
@Disabled("Groq does not support multi modality API")
|
||||
@@ -349,7 +349,7 @@ class GroqWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
assertThat(content).contains("bananas", "apple");
|
||||
|
||||
@@ -89,7 +89,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +108,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(stitchedResponseContent).contains("Blackbeard");
|
||||
@@ -149,7 +149,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.getActor()).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -231,7 +231,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
@@ -262,7 +262,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
||||
@@ -291,7 +291,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -311,9 +311,9 @@ class MistralWithOpenAiChatModelIT {
|
||||
var response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket");
|
||||
}
|
||||
|
||||
@Disabled("Mistral AI does not support multi modality API")
|
||||
@@ -330,9 +330,9 @@ class MistralWithOpenAiChatModelIT {
|
||||
ChatResponse response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket");
|
||||
}
|
||||
|
||||
@Disabled("Mistral AI does not support multi modality API")
|
||||
@@ -353,7 +353,7 @@ class MistralWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
assertThat(content).contains("bananas", "apple");
|
||||
|
||||
@@ -87,7 +87,7 @@ class NvidiaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +106,7 @@ class NvidiaWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(stitchedResponseContent).contains("Blackbeard");
|
||||
@@ -146,7 +146,7 @@ class NvidiaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
|
||||
}
|
||||
@@ -165,7 +165,7 @@ class NvidiaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -184,7 +184,7 @@ class NvidiaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.getActor()).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ class NvidiaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -228,7 +228,7 @@ class NvidiaWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.filter(c -> c != null)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
@@ -257,7 +257,7 @@ class NvidiaWithOpenAiChatModelIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -284,7 +284,7 @@ class NvidiaWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +126,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(stitchedResponseContent).contains("Blackbeard");
|
||||
@@ -167,7 +167,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
|
||||
}
|
||||
@@ -186,7 +186,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -205,7 +205,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.getActor()).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -249,7 +249,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
@@ -279,7 +279,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -306,7 +306,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -325,9 +325,9 @@ class OllamaWithOpenAiChatModelIT {
|
||||
var response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket");
|
||||
}
|
||||
|
||||
@Disabled("Not supported by the current Ollama API")
|
||||
@@ -344,9 +344,9 @@ class OllamaWithOpenAiChatModelIT {
|
||||
ChatResponse response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket");
|
||||
}
|
||||
|
||||
@Disabled("Not supported by the current Ollama API")
|
||||
@@ -369,7 +369,7 @@ class OllamaWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
assertThat(content).contains("bananas", "apple");
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
|
||||
import org.slf4j.Logger;
|
||||
@@ -102,7 +101,7 @@ class PerplexityWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(systemMessage, userMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,7 +122,7 @@ class PerplexityWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(stitchedResponseContent).contains("Blackbeard");
|
||||
@@ -162,7 +161,7 @@ class PerplexityWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -180,7 +179,7 @@ class PerplexityWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
}
|
||||
|
||||
@@ -197,7 +196,7 @@ class PerplexityWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.getActor()).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -214,7 +213,7 @@ class PerplexityWithOpenAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -239,7 +238,7 @@ class PerplexityWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.filter(c -> c != null)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
@@ -293,7 +292,7 @@ class PerplexityWithOpenAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public abstract class AbstractIT {
|
||||
|
||||
protected void evaluateQuestionAndAnswer(String question, ChatResponse response, boolean factBased) {
|
||||
assertThat(response).isNotNull();
|
||||
String answer = response.getResult().getOutput().getContent();
|
||||
String answer = response.getResult().getOutput().getText();
|
||||
logger.info("Question: " + question);
|
||||
logger.info("Answer:" + answer);
|
||||
PromptTemplate userPromptTemplate = new PromptTemplate(this.userEvaluatorResource,
|
||||
@@ -98,12 +98,12 @@ public abstract class AbstractIT {
|
||||
}
|
||||
Message userMessage = userPromptTemplate.createMessage();
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
String yesOrNo = this.chatModel.call(prompt).getResult().getOutput().getContent();
|
||||
String yesOrNo = this.chatModel.call(prompt).getResult().getOutput().getText();
|
||||
logger.info("Is Answer related to question: " + yesOrNo);
|
||||
if (yesOrNo.equalsIgnoreCase("no")) {
|
||||
SystemMessage notRelatedSystemMessage = new SystemMessage(this.qaEvaluatorNotRelatedResource);
|
||||
prompt = new Prompt(List.of(userMessage, notRelatedSystemMessage));
|
||||
String reasonForFailure = this.chatModel.call(prompt).getResult().getOutput().getContent();
|
||||
String reasonForFailure = this.chatModel.call(prompt).getResult().getOutput().getText();
|
||||
fail(reasonForFailure);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -246,7 +246,7 @@ public class QianFanChatModel implements ChatModel, StreamingChatModel {
|
||||
public ChatCompletionRequest createRequest(Prompt prompt, boolean stream) {
|
||||
var chatCompletionMessages = prompt.getInstructions()
|
||||
.stream()
|
||||
.map(m -> new ChatCompletionMessage(m.getContent(),
|
||||
.map(m -> new ChatCompletionMessage(m.getText(),
|
||||
ChatCompletionMessage.Role.valueOf(m.getMessageType().name())))
|
||||
.toList();
|
||||
var systemMessageList = chatCompletionMessages.stream().filter(msg -> msg.role() == Role.SYSTEM).toList();
|
||||
|
||||
@@ -104,7 +104,7 @@ public class QianFanRetryTests {
|
||||
var result = this.chatClient.call(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class QianFanRetryTests {
|
||||
var result = this.chatClient.stream(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(Objects.requireNonNull(result.collectList().block()).get(0).getResult().getOutput().getContent())
|
||||
assertThat(Objects.requireNonNull(result.collectList().block()).get(0).getResult().getOutput().getText())
|
||||
.isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
|
||||
@@ -68,7 +68,7 @@ class QianFanChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +87,7 @@ class QianFanChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(stitchedResponseContent).contains("Blackbeard");
|
||||
|
||||
@@ -83,7 +83,7 @@ public class QianFanChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -112,7 +112,7 @@ public class QianFanChatModelObservationIT {
|
||||
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ import org.springframework.ai.vertexai.embedding.VertexAiEmbeddingUtils.ImageBui
|
||||
import org.springframework.ai.vertexai.embedding.VertexAiEmbeddingUtils.MultimodalInstanceBuilder;
|
||||
import org.springframework.ai.vertexai.embedding.VertexAiEmbeddingUtils.VideoBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -149,44 +148,42 @@ public class VertexAiMultimodalEmbeddingModel implements DocumentEmbeddingModel
|
||||
new DocumentMetadata(document.getId(), MimeTypeUtils.TEXT_PLAIN, document.getContent()));
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(document.getMedia())) {
|
||||
|
||||
for (Media media : document.getMedia()) {
|
||||
if (media.getMimeType().isCompatibleWith(TEXT_MIME_TYPE)) {
|
||||
instanceBuilder.withText(media.getData().toString());
|
||||
documentMetadata.put(ModalityType.TEXT,
|
||||
new DocumentMetadata(document.getId(), MimeTypeUtils.TEXT_PLAIN, media.getData()));
|
||||
if (StringUtils.hasText(document.getContent())) {
|
||||
logger.warn("Media type String overrides the Document text content!");
|
||||
}
|
||||
Media media = document.getMedia();
|
||||
if (media != null) {
|
||||
if (media.getMimeType().isCompatibleWith(TEXT_MIME_TYPE)) {
|
||||
instanceBuilder.withText(media.getData().toString());
|
||||
documentMetadata.put(ModalityType.TEXT,
|
||||
new DocumentMetadata(document.getId(), MimeTypeUtils.TEXT_PLAIN, media.getData()));
|
||||
if (StringUtils.hasText(document.getContent())) {
|
||||
logger.warn("Media type String overrides the Document text content!");
|
||||
}
|
||||
else if (media.getMimeType().isCompatibleWith(IMAGE_MIME_TYPE)) {
|
||||
if (SUPPORTED_IMAGE_MIME_SUB_TYPES.contains(media.getMimeType())) {
|
||||
instanceBuilder
|
||||
.withImage(ImageBuilder.of(media.getMimeType()).withImageData(media.getData()).build());
|
||||
documentMetadata.put(ModalityType.IMAGE,
|
||||
new DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));
|
||||
}
|
||||
else {
|
||||
logger.warn("Unsupported image mime type: {}", media.getMimeType());
|
||||
throw new IllegalArgumentException("Unsupported image mime type: " + media.getMimeType());
|
||||
}
|
||||
}
|
||||
else if (media.getMimeType().isCompatibleWith(VIDEO_MIME_TYPE)) {
|
||||
instanceBuilder.withVideo(VideoBuilder.of(media.getMimeType())
|
||||
.withVideoData(media.getData())
|
||||
.withStartOffsetSec(mergedOptions.getVideoStartOffsetSec())
|
||||
.withEndOffsetSec(mergedOptions.getVideoEndOffsetSec())
|
||||
.withIntervalSec(mergedOptions.getVideoIntervalSec())
|
||||
.build());
|
||||
documentMetadata.put(ModalityType.VIDEO,
|
||||
}
|
||||
else if (media.getMimeType().isCompatibleWith(IMAGE_MIME_TYPE)) {
|
||||
if (SUPPORTED_IMAGE_MIME_SUB_TYPES.contains(media.getMimeType())) {
|
||||
instanceBuilder
|
||||
.withImage(ImageBuilder.of(media.getMimeType()).withImageData(media.getData()).build());
|
||||
documentMetadata.put(ModalityType.IMAGE,
|
||||
new DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));
|
||||
}
|
||||
else {
|
||||
logger.warn("Unsupported media type: {}", media.getMimeType());
|
||||
throw new IllegalArgumentException("Unsupported media type: " + media.getMimeType());
|
||||
logger.warn("Unsupported image mime type: {}", media.getMimeType());
|
||||
throw new IllegalArgumentException("Unsupported image mime type: " + media.getMimeType());
|
||||
}
|
||||
}
|
||||
else if (media.getMimeType().isCompatibleWith(VIDEO_MIME_TYPE)) {
|
||||
instanceBuilder.withVideo(VideoBuilder.of(media.getMimeType())
|
||||
.withVideoData(media.getData())
|
||||
.withStartOffsetSec(mergedOptions.getVideoStartOffsetSec())
|
||||
.withEndOffsetSec(mergedOptions.getVideoEndOffsetSec())
|
||||
.withIntervalSec(mergedOptions.getVideoIntervalSec())
|
||||
.build());
|
||||
documentMetadata.put(ModalityType.VIDEO,
|
||||
new DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));
|
||||
}
|
||||
else {
|
||||
logger.warn("Unsupported media type: {}", media.getMimeType());
|
||||
throw new IllegalArgumentException("Unsupported media type: " + media.getMimeType());
|
||||
}
|
||||
}
|
||||
|
||||
List<Value> instances = List.of(VertexAiEmbeddingUtils.valueOf(instanceBuilder.build()));
|
||||
|
||||
@@ -189,7 +189,7 @@ class VertexAiMultimodalEmbeddingModelIT {
|
||||
void textImageAndVideoEmbedding() {
|
||||
|
||||
var document = Document.builder()
|
||||
.content("Hello World")
|
||||
.text("Hello World")
|
||||
.media(new Media(MimeTypeUtils.IMAGE_PNG, new ClassPathResource("/test.image.png")))
|
||||
.media(new Media(new MimeType("video", "mp4"), new ClassPathResource("/test.video.mp4")))
|
||||
.build();
|
||||
|
||||
@@ -186,16 +186,16 @@ public class VertexAiGeminiChatModel extends AbstractToolCallSupport implements
|
||||
|
||||
List<Part> parts = new ArrayList<>();
|
||||
|
||||
if (systemMessage.getContent() != null) {
|
||||
parts.add(Part.newBuilder().setText(systemMessage.getContent()).build());
|
||||
if (systemMessage.getText() != null) {
|
||||
parts.add(Part.newBuilder().setText(systemMessage.getText()).build());
|
||||
}
|
||||
|
||||
return parts;
|
||||
}
|
||||
else if (message instanceof UserMessage userMessage) {
|
||||
List<Part> parts = new ArrayList<>();
|
||||
if (userMessage.getContent() != null) {
|
||||
parts.add(Part.newBuilder().setText(userMessage.getContent()).build());
|
||||
if (userMessage.getText() != null) {
|
||||
parts.add(Part.newBuilder().setText(userMessage.getText()).build());
|
||||
}
|
||||
|
||||
parts.addAll(mediaToParts(userMessage.getMedia()));
|
||||
@@ -204,8 +204,8 @@ public class VertexAiGeminiChatModel extends AbstractToolCallSupport implements
|
||||
}
|
||||
else if (message instanceof AssistantMessage assistantMessage) {
|
||||
List<Part> parts = new ArrayList<>();
|
||||
if (StringUtils.hasText(assistantMessage.getContent())) {
|
||||
parts.add(Part.newBuilder().setText(assistantMessage.getContent()).build());
|
||||
if (StringUtils.hasText(assistantMessage.getText())) {
|
||||
parts.add(Part.newBuilder().setText(assistantMessage.getText()).build());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(assistantMessage.getToolCalls())) {
|
||||
parts.addAll(assistantMessage.getToolCalls()
|
||||
|
||||
@@ -76,7 +76,7 @@ public class VertexAiChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -104,7 +104,7 @@ public class VertexAiChatModelObservationIT {
|
||||
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -69,27 +69,27 @@ class VertexAiGeminiChatModelIT {
|
||||
void roleTest() {
|
||||
Prompt prompt = createPrompt(VertexAiGeminiChatOptions.builder().build());
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMessageHistory() {
|
||||
Prompt prompt = createPrompt(VertexAiGeminiChatOptions.builder().build());
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
|
||||
var promptWithMessageHistory = new Prompt(List.of(new UserMessage("Dummy"), prompt.getInstructions().get(1),
|
||||
response.getResult().getOutput(), new UserMessage("Repeat the last assistant message.")));
|
||||
response = this.chatModel.call(promptWithMessageHistory);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
}
|
||||
|
||||
@Test
|
||||
void googleSearchTool() {
|
||||
Prompt prompt = createPrompt(VertexAiGeminiChatOptions.builder().withGoogleSearchRetrieval(true).build());
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -119,7 +119,7 @@ class VertexAiGeminiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = converter.convert(generation.getOutput().getContent());
|
||||
List<String> list = converter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ class VertexAiGeminiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -157,7 +157,7 @@ class VertexAiGeminiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConvert.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConvert.convert(generation.getOutput().getText());
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
}
|
||||
@@ -173,7 +173,7 @@ class VertexAiGeminiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
// logger.info("" + actorsFilms);
|
||||
@@ -201,7 +201,7 @@ class VertexAiGeminiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
@@ -224,7 +224,7 @@ class VertexAiGeminiChatModelIT {
|
||||
// I see a bunch of bananas in a golden basket. The bananas are ripe and yellow.
|
||||
// There are also some red apples in the basket. The basket is sitting on a table.
|
||||
// The background is a blurred light blue color.'
|
||||
assertThat(response.getResult().getOutput().getContent()).satisfies(content -> {
|
||||
assertThat(response.getResult().getOutput().getText()).satisfies(content -> {
|
||||
long count = Stream.of("bananas", "apple", "basket").filter(content::contains).count();
|
||||
assertThat(count).isGreaterThanOrEqualTo(2);
|
||||
});
|
||||
@@ -258,7 +258,7 @@ class VertexAiGeminiChatModelIT {
|
||||
|
||||
var response = this.chatModel.call(new Prompt(List.of(userMessage)));
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("Spring AI", "portable API");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Spring AI", "portable API");
|
||||
}
|
||||
|
||||
record ActorsFilmsRecord(String actor, List<String> movies) {
|
||||
|
||||
@@ -101,7 +101,7 @@ public class VertexAiGeminiRetryTests {
|
||||
|
||||
// Assertions
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getContent()).isEqualTo("Response");
|
||||
assertThat(result.getResult().getOutput().getText()).isEqualTo("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class VertexAiGeminiChatModelFunctionCallingIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,14 +127,14 @@ public class VertexAiGeminiChatModelFunctionCallingIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("15.0", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("15.0", "15");
|
||||
|
||||
ChatResponse response2 = this.chatModel
|
||||
.call(new Prompt("What is the payment status for transaction 696?", promptOptions));
|
||||
|
||||
logger.info("Response: {}", response2);
|
||||
|
||||
assertThat(response2.getResult().getOutput().getContent()).containsIgnoringCase("transaction 696 is PAYED");
|
||||
assertThat(response2.getResult().getOutput().getText()).containsIgnoringCase("transaction 696 is PAYED");
|
||||
|
||||
}
|
||||
|
||||
@@ -168,14 +168,14 @@ public class VertexAiGeminiChatModelFunctionCallingIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
|
||||
ChatResponse response2 = this.chatModel
|
||||
.call(new Prompt("What is the payment status for transaction 696?", promptOptions));
|
||||
|
||||
logger.info("Response: {}", response2);
|
||||
|
||||
assertThat(response2.getResult().getOutput().getContent()).containsIgnoringCase("transaction 696 is PAYED");
|
||||
assertThat(response2.getResult().getOutput().getText()).containsIgnoringCase("transaction 696 is PAYED");
|
||||
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public class VertexAiGeminiChatModelFunctionCallingIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
logger.info("Response: {}", responseString);
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class MessageToPromptConverter {
|
||||
|
||||
final String systemMessages = messages.stream()
|
||||
.filter(message -> message.getMessageType() == MessageType.SYSTEM)
|
||||
.map(Message::getContent)
|
||||
.map(Message::getText)
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
final String userMessages = messages.stream()
|
||||
@@ -70,11 +70,11 @@ public final class MessageToPromptConverter {
|
||||
protected String messageToString(Message message) {
|
||||
switch (message.getMessageType()) {
|
||||
case SYSTEM:
|
||||
return message.getContent();
|
||||
return message.getText();
|
||||
case USER:
|
||||
return this.humanPrompt + message.getContent();
|
||||
return this.humanPrompt + message.getText();
|
||||
case ASSISTANT:
|
||||
return this.assistantPrompt + message.getContent();
|
||||
return this.assistantPrompt + message.getText();
|
||||
case TOOL:
|
||||
throw new IllegalArgumentException(TOOL_EXECUTION_NOT_SUPPORTED_FOR_WAI_MODELS);
|
||||
}
|
||||
|
||||
@@ -359,11 +359,10 @@ public class ZhiPuAiChatModel extends AbstractToolCallSupport implements ChatMod
|
||||
|
||||
List<ChatCompletionMessage> chatCompletionMessages = prompt.getInstructions().stream().map(message -> {
|
||||
if (message.getMessageType() == MessageType.USER || message.getMessageType() == MessageType.SYSTEM) {
|
||||
Object content = message.getContent();
|
||||
Object content = message.getText();
|
||||
if (message instanceof UserMessage userMessage) {
|
||||
if (!CollectionUtils.isEmpty(userMessage.getMedia())) {
|
||||
List<MediaContent> contentList = new ArrayList<>(
|
||||
List.of(new MediaContent(message.getContent())));
|
||||
List<MediaContent> contentList = new ArrayList<>(List.of(new MediaContent(message.getText())));
|
||||
|
||||
contentList.addAll(userMessage.getMedia()
|
||||
.stream()
|
||||
@@ -387,7 +386,7 @@ public class ZhiPuAiChatModel extends AbstractToolCallSupport implements ChatMod
|
||||
return new ToolCall(toolCall.id(), toolCall.type(), function);
|
||||
}).toList();
|
||||
}
|
||||
return List.of(new ChatCompletionMessage(assistantMessage.getContent(),
|
||||
return List.of(new ChatCompletionMessage(assistantMessage.getText(),
|
||||
ChatCompletionMessage.Role.ASSISTANT, null, null, toolCalls));
|
||||
}
|
||||
else if (message.getMessageType() == MessageType.TOOL) {
|
||||
|
||||
@@ -112,7 +112,7 @@ public class ZhiPuAiRetryTests {
|
||||
var result = this.chatModel.call(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class ZhiPuAiRetryTests {
|
||||
var result = this.chatModel.stream(new Prompt("text"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getContent()).isSameAs("Response");
|
||||
assertThat(result.collectList().block().get(0).getResult().getOutput().getText()).isSameAs("Response");
|
||||
assertThat(this.retryListener.onSuccessRetryCount).isEqualTo(2);
|
||||
assertThat(this.retryListener.onErrorRetryCount).isEqualTo(2);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class ZhiPuAiChatModelIT {
|
||||
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
|
||||
ChatResponse response = this.chatModel.call(prompt);
|
||||
assertThat(response.getResults()).hasSize(1);
|
||||
assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard");
|
||||
assertThat(response.getResults().get(0).getOutput().getText()).contains("Blackbeard");
|
||||
// needs fine tuning... evaluateQuestionAndAnswer(request, response, false);
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ class ZhiPuAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
assertThat(stitchedResponseContent).contains("Blackbeard");
|
||||
@@ -131,7 +131,7 @@ class ZhiPuAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getContent());
|
||||
List<String> list = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(list).hasSize(5);
|
||||
|
||||
}
|
||||
@@ -150,7 +150,7 @@ class ZhiPuAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getContent());
|
||||
Map<String, Object> result = outputConverter.convert(generation.getOutput().getText());
|
||||
assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
}
|
||||
@@ -169,7 +169,7 @@ class ZhiPuAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,7 +186,7 @@ class ZhiPuAiChatModelIT {
|
||||
Prompt prompt = new Prompt(promptTemplate.createMessage());
|
||||
Generation generation = this.chatModel.call(prompt).getResult();
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent());
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getText());
|
||||
logger.info("" + actorsFilms);
|
||||
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
|
||||
assertThat(actorsFilms.movies()).hasSize(5);
|
||||
@@ -211,7 +211,7 @@ class ZhiPuAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
|
||||
@@ -241,9 +241,9 @@ class ZhiPuAiChatModelIT {
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("30.0", "30");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("10.0", "10");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("15.0", "15");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("30.0", "30");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("10.0", "10");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("15.0", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -270,7 +270,7 @@ class ZhiPuAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
|
||||
@@ -291,9 +291,9 @@ class ZhiPuAiChatModelIT {
|
||||
var response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
||||
@@ -309,9 +309,9 @@ class ZhiPuAiChatModelIT {
|
||||
ChatResponse response = this.chatModel
|
||||
.call(new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().withModel(modelName).build()));
|
||||
|
||||
logger.info(response.getResult().getOutput().getContent());
|
||||
assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("bowl", "basket");
|
||||
logger.info(response.getResult().getOutput().getText());
|
||||
assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple");
|
||||
assertThat(response.getResult().getOutput().getText()).containsAnyOf("bowl", "basket");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -331,7 +331,7 @@ class ZhiPuAiChatModelIT {
|
||||
.map(ChatResponse::getResults)
|
||||
.flatMap(List::stream)
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getContent)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
assertThat(content).contains("bananas", "apple");
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ZhiPuAiChatModelObservationIT {
|
||||
Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
|
||||
|
||||
ChatResponse chatResponse = this.chatModel.call(prompt);
|
||||
assertThat(chatResponse.getResult().getOutput().getContent()).isNotEmpty();
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).isNotEmpty();
|
||||
|
||||
ChatResponseMetadata responseMetadata = chatResponse.getMetadata();
|
||||
assertThat(responseMetadata).isNotNull();
|
||||
@@ -108,7 +108,7 @@ public class ZhiPuAiChatModelObservationIT {
|
||||
|
||||
String aggregatedResponse = responses.subList(0, responses.size() - 1)
|
||||
.stream()
|
||||
.map(r -> r.getResult().getOutput().getContent())
|
||||
.map(r -> r.getResult().getOutput().getText())
|
||||
.collect(Collectors.joining());
|
||||
assertThat(aggregatedResponse).isNotEmpty();
|
||||
|
||||
|
||||
@@ -115,8 +115,8 @@ public class DefaultChatClient implements ChatClient {
|
||||
Message lastMessage = messages.get(messages.size() - 1);
|
||||
if (lastMessage.getMessageType() == MessageType.USER) {
|
||||
UserMessage userMessage = (UserMessage) lastMessage;
|
||||
if (StringUtils.hasText(userMessage.getContent())) {
|
||||
userText = lastMessage.getContent();
|
||||
if (StringUtils.hasText(userMessage.getText())) {
|
||||
userText = lastMessage.getText();
|
||||
}
|
||||
Collection<Media> messageMedia = userMessage.getMedia();
|
||||
if (!CollectionUtils.isEmpty(messageMedia)) {
|
||||
@@ -493,10 +493,10 @@ public class DefaultChatClient implements ChatClient {
|
||||
@Nullable
|
||||
private static String getContentFromChatResponse(@Nullable ChatResponse chatResponse) {
|
||||
if (chatResponse == null || chatResponse.getResult() == null || chatResponse.getResult().getOutput() == null
|
||||
|| chatResponse.getResult().getOutput().getContent() == null) {
|
||||
|| chatResponse.getResult().getOutput().getText() == null) {
|
||||
return null;
|
||||
}
|
||||
return chatResponse.getResult().getOutput().getContent();
|
||||
return chatResponse.getResult().getOutput().getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -562,10 +562,10 @@ public class DefaultChatClient implements ChatClient {
|
||||
public Flux<String> content() {
|
||||
return doGetObservableFluxChatResponse(this.request).map(r -> {
|
||||
if (r.getResult() == null || r.getResult().getOutput() == null
|
||||
|| r.getResult().getOutput().getContent() == null) {
|
||||
|| r.getResult().getOutput().getText() == null) {
|
||||
return "";
|
||||
}
|
||||
return r.getResult().getOutput().getContent();
|
||||
return r.getResult().getOutput().getText();
|
||||
}).filter(StringUtils::hasLength);
|
||||
}
|
||||
|
||||
@@ -1005,11 +1005,11 @@ public class DefaultChatClient implements ChatClient {
|
||||
}
|
||||
|
||||
public String content() {
|
||||
return doGetChatResponse(this.prompt).getResult().getOutput().getContent();
|
||||
return doGetChatResponse(this.prompt).getResult().getOutput().getText();
|
||||
}
|
||||
|
||||
public List<String> contents() {
|
||||
return doGetChatResponse(this.prompt).getResults().stream().map(r -> r.getOutput().getContent()).toList();
|
||||
return doGetChatResponse(this.prompt).getResults().stream().map(r -> r.getOutput().getText()).toList();
|
||||
}
|
||||
|
||||
public ChatResponse chatResponse() {
|
||||
@@ -1046,10 +1046,10 @@ public class DefaultChatClient implements ChatClient {
|
||||
public Flux<String> content() {
|
||||
return doGetFluxChatResponse(this.prompt).map(r -> {
|
||||
if (r.getResult() == null || r.getResult().getOutput() == null
|
||||
|| r.getResult().getOutput().getContent() == null) {
|
||||
|| r.getResult().getOutput().getText() == null) {
|
||||
return "";
|
||||
}
|
||||
return r.getResult().getOutput().getContent();
|
||||
return r.getResult().getOutput().getText();
|
||||
}).filter(StringUtils::hasLength);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ public class PromptChatMemoryAdvisor extends AbstractChatMemoryAdvisor<ChatMemor
|
||||
|
||||
String memory = (memoryMessages != null) ? memoryMessages.stream()
|
||||
.filter(m -> m.getMessageType() == MessageType.USER || m.getMessageType() == MessageType.ASSISTANT)
|
||||
.map(m -> m.getMessageType() + ":" + ((Content) m).getContent())
|
||||
.map(m -> m.getMessageType() + ":" + ((Content) m).getText())
|
||||
.collect(Collectors.joining(System.lineSeparator())) : "";
|
||||
|
||||
Map<String, Object> advisedSystemParams = new HashMap<>(request.systemParams());
|
||||
|
||||
@@ -227,7 +227,7 @@ public class QuestionAnswerAdvisor implements CallAroundAdvisor, StreamAroundAdv
|
||||
context.put(RETRIEVED_DOCUMENTS, documents);
|
||||
|
||||
String documentContext = documents.stream()
|
||||
.map(Content::getContent)
|
||||
.map(Document::getText)
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
|
||||
// 4. Advise the user parameters.
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.ai.chat.client.advisor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -35,7 +34,6 @@ import org.springframework.ai.chat.messages.MessageType;
|
||||
import org.springframework.ai.chat.messages.UserMessage;
|
||||
import org.springframework.ai.chat.model.MessageAggregator;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.model.Content;
|
||||
import org.springframework.ai.vectorstore.SearchRequest;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -43,6 +41,8 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* Memory is retrieved from a VectorStore added into the prompt's system text.
|
||||
*
|
||||
* This only works for text based exchanges with the models, not multi-modal exchanges.
|
||||
*
|
||||
* @author Christian Tzolov
|
||||
* @author Thomas Vitale
|
||||
* @since 1.0.0
|
||||
@@ -146,7 +146,7 @@ public class VectorStoreChatMemoryAdvisor extends AbstractChatMemoryAdvisor<Vect
|
||||
List<Document> documents = this.getChatMemoryStore().similaritySearch(searchRequest);
|
||||
|
||||
String longTermMemory = documents.stream()
|
||||
.map(Content::getContent)
|
||||
.map(Document::getText)
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
|
||||
Map<String, Object> advisedSystemParams = new HashMap<>(request.systemParams());
|
||||
@@ -186,13 +186,16 @@ public class VectorStoreChatMemoryAdvisor extends AbstractChatMemoryAdvisor<Vect
|
||||
metadata.put(DOCUMENT_METADATA_MESSAGE_TYPE, message.getMessageType().name());
|
||||
if (message instanceof UserMessage userMessage) {
|
||||
return Document.builder()
|
||||
.content(userMessage.getContent())
|
||||
.media(new ArrayList<>(userMessage.getMedia()))
|
||||
.text(userMessage.getText())
|
||||
// userMessage.getMedia().get(0).getId()
|
||||
// TODO vector store for memory would not store this into the
|
||||
// vector store, could store an 'id' instead
|
||||
// .media(userMessage.getMedia())
|
||||
.metadata(metadata)
|
||||
.build();
|
||||
}
|
||||
else if (message instanceof AssistantMessage assistantMessage) {
|
||||
return Document.builder().content(assistantMessage.getContent()).metadata(metadata).build();
|
||||
return Document.builder().text(assistantMessage.getText()).metadata(metadata).build();
|
||||
}
|
||||
throw new RuntimeException("Unknown message type: " + message.getMessageType());
|
||||
})
|
||||
|
||||
@@ -97,6 +97,11 @@ public abstract class AbstractMessage implements Message {
|
||||
* Get the content of the message.
|
||||
* @return the content of the message
|
||||
*/
|
||||
@Override
|
||||
public String getText() {
|
||||
return this.textContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent() {
|
||||
return this.textContent;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SystemMessage extends AbstractMessage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent() {
|
||||
public String getText() {
|
||||
return this.textContent;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,17 +66,17 @@ public class UserMessage extends AbstractMessage implements MediaContent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserMessage{" + "content='" + getContent() + '\'' + ", properties=" + this.metadata + ", messageType="
|
||||
return "UserMessage{" + "content='" + getText() + '\'' + ", properties=" + this.metadata + ", messageType="
|
||||
+ this.messageType + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Media> getMedia() {
|
||||
public List<Media> getMedia() {
|
||||
return this.media;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent() {
|
||||
public String getText() {
|
||||
return this.textContent;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public abstract class AbstractToolCallSupport {
|
||||
toolContextMap = new HashMap<>(functionCallOptions.getToolContext());
|
||||
|
||||
List<Message> toolCallHistory = new ArrayList<>(prompt.copy().getInstructions());
|
||||
toolCallHistory.add(new AssistantMessage(assistantMessage.getContent(), assistantMessage.getMetadata(),
|
||||
toolCallHistory.add(new AssistantMessage(assistantMessage.getText(), assistantMessage.getMetadata(),
|
||||
assistantMessage.getToolCalls()));
|
||||
|
||||
toolContextMap.put(ToolContext.TOOL_CALL_HISTORY, toolCallHistory);
|
||||
|
||||
@@ -31,13 +31,13 @@ public interface ChatModel extends Model<Prompt, ChatResponse>, StreamingChatMod
|
||||
default String call(String message) {
|
||||
Prompt prompt = new Prompt(new UserMessage(message));
|
||||
Generation generation = call(prompt).getResult();
|
||||
return (generation != null) ? generation.getOutput().getContent() : "";
|
||||
return (generation != null) ? generation.getOutput().getText() : "";
|
||||
}
|
||||
|
||||
default String call(Message... messages) {
|
||||
Prompt prompt = new Prompt(Arrays.asList(messages));
|
||||
Generation generation = call(prompt).getResult();
|
||||
return (generation != null) ? generation.getOutput().getContent() : "";
|
||||
return (generation != null) ? generation.getOutput().getText() : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -108,8 +108,8 @@ public class MessageAggregator {
|
||||
&& chatResponse.getResult().getMetadata() != ChatGenerationMetadata.NULL) {
|
||||
generationMetadataRef.set(chatResponse.getResult().getMetadata());
|
||||
}
|
||||
if (chatResponse.getResult().getOutput().getContent() != null) {
|
||||
messageTextContentRef.get().append(chatResponse.getResult().getOutput().getContent());
|
||||
if (chatResponse.getResult().getOutput().getText() != null) {
|
||||
messageTextContentRef.get().append(chatResponse.getResult().getOutput().getText());
|
||||
}
|
||||
if (chatResponse.getResult().getOutput().getMetadata() != null) {
|
||||
messageMetadataMapRef.get().putAll(chatResponse.getResult().getOutput().getMetadata());
|
||||
|
||||
@@ -30,15 +30,15 @@ public interface StreamingChatModel extends StreamingModel<Prompt, ChatResponse>
|
||||
default Flux<String> stream(String message) {
|
||||
Prompt prompt = new Prompt(message);
|
||||
return stream(prompt).map(response -> (response.getResult() == null || response.getResult().getOutput() == null
|
||||
|| response.getResult().getOutput().getContent() == null) ? ""
|
||||
: response.getResult().getOutput().getContent());
|
||||
|| response.getResult().getOutput().getText() == null) ? ""
|
||||
: response.getResult().getOutput().getText());
|
||||
}
|
||||
|
||||
default Flux<String> stream(Message... messages) {
|
||||
Prompt prompt = new Prompt(Arrays.asList(messages));
|
||||
return stream(prompt).map(response -> (response.getResult() == null || response.getResult().getOutput() == null
|
||||
|| response.getResult().getOutput().getContent() == null) ? ""
|
||||
: response.getResult().getOutput().getContent());
|
||||
|| response.getResult().getOutput().getText() == null) ? ""
|
||||
: response.getResult().getOutput().getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class ChatModelObservationContentProcessor {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
return context.getRequest().getInstructions().stream().map(Content::getContent).toList();
|
||||
return context.getRequest().getInstructions().stream().map(Content::getText).toList();
|
||||
}
|
||||
|
||||
public static List<String> completion(ChatModelObservationContext context) {
|
||||
@@ -46,7 +46,7 @@ public final class ChatModelObservationContentProcessor {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(context.getResponse().getResult().getOutput().getContent())) {
|
||||
if (!StringUtils.hasText(context.getResponse().getResult().getOutput().getText())) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ public final class ChatModelObservationContentProcessor {
|
||||
.getResults()
|
||||
.stream()
|
||||
.filter(generation -> generation.getOutput() != null
|
||||
&& StringUtils.hasText(generation.getOutput().getContent()))
|
||||
.map(generation -> generation.getOutput().getContent())
|
||||
&& StringUtils.hasText(generation.getOutput().getText()))
|
||||
.map(generation -> generation.getOutput().getText())
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class Prompt implements ModelRequest<List<Message>> {
|
||||
public String getContents() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Message message : getInstructions()) {
|
||||
sb.append(message.getContent());
|
||||
sb.append(message.getText());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -119,14 +119,13 @@ public class Prompt implements ModelRequest<List<Message>> {
|
||||
List<Message> messagesCopy = new ArrayList<>();
|
||||
this.messages.forEach(message -> {
|
||||
if (message instanceof UserMessage userMessage) {
|
||||
messagesCopy
|
||||
.add(new UserMessage(userMessage.getContent(), userMessage.getMedia(), message.getMetadata()));
|
||||
messagesCopy.add(new UserMessage(userMessage.getText(), userMessage.getMedia(), message.getMetadata()));
|
||||
}
|
||||
else if (message instanceof SystemMessage systemMessage) {
|
||||
messagesCopy.add(new SystemMessage(systemMessage.getContent()));
|
||||
messagesCopy.add(new SystemMessage(systemMessage.getText()));
|
||||
}
|
||||
else if (message instanceof AssistantMessage assistantMessage) {
|
||||
messagesCopy.add(new AssistantMessage(assistantMessage.getContent(), assistantMessage.getMetadata(),
|
||||
messagesCopy.add(new AssistantMessage(assistantMessage.getText(), assistantMessage.getMetadata(),
|
||||
assistantMessage.getToolCalls()));
|
||||
}
|
||||
else if (message instanceof ToolResponseMessage toolResponseMessage) {
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.ai.document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -31,7 +28,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.ai.document.id.IdGenerator;
|
||||
import org.springframework.ai.document.id.RandomIdGenerator;
|
||||
import org.springframework.ai.model.Media;
|
||||
import org.springframework.ai.model.MediaContent;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -39,25 +35,69 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* A document is a container for the content and metadata of a document. It also contains
|
||||
* the document's unique ID and an optional embedding.
|
||||
*
|
||||
* A Document can hold either text content or media content, but not both. This ensures
|
||||
* clear content type handling and processing.
|
||||
*
|
||||
* It is intended to be used to take data from external sources as part of spring-ai's ETL
|
||||
* pipeline and create an embedding for the text or media and store that embedding in a
|
||||
* vector database.
|
||||
*
|
||||
* <p>
|
||||
* Example of creating a text document: <pre>{@code
|
||||
* // Using constructor
|
||||
* Document textDoc = new Document("Sample text content", Map.of("source", "user-input"));
|
||||
*
|
||||
* // Using builder
|
||||
* Document textDoc = Document.builder()
|
||||
* .text("Sample text content")
|
||||
* .metadata("source", "user-input")
|
||||
* .build();
|
||||
* }</pre>
|
||||
*
|
||||
* <p>
|
||||
* Example of creating a media document: <pre>{@code
|
||||
* // Using constructor
|
||||
* Media imageContent = new Media(MediaType.IMAGE_PNG, new byte[] {...});
|
||||
* Document mediaDoc = new Document(imageContent, Map.of("filename", "sample.png"));
|
||||
*
|
||||
* // Using builder
|
||||
* Document mediaDoc = Document.builder()
|
||||
* .media(new Media(MediaType.IMAGE_PNG, new byte[] {...}))
|
||||
* .metadata("filename", "sample.png")
|
||||
* .build();
|
||||
* }</pre>
|
||||
*
|
||||
* <p>
|
||||
* Example of checking content type and accessing content: <pre>{@code
|
||||
* if (document.isText()) {
|
||||
* String textContent = document.getText();
|
||||
* // Process text content
|
||||
* } else {
|
||||
* Media mediaContent = document.getMedia();
|
||||
* // Process media content
|
||||
* }
|
||||
* }</pre>
|
||||
*/
|
||||
@JsonIgnoreProperties({ "contentFormatter" })
|
||||
public class Document implements MediaContent {
|
||||
public class Document {
|
||||
|
||||
public static final ContentFormatter DEFAULT_CONTENT_FORMATTER = DefaultContentFormatter.defaultConfig();
|
||||
|
||||
public static final String EMPTY_TEXT = "";
|
||||
|
||||
/**
|
||||
* Unique ID
|
||||
*/
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Document content.
|
||||
* Document string content.
|
||||
*/
|
||||
private final String content;
|
||||
private final String text;
|
||||
|
||||
private final Collection<Media> media;
|
||||
/**
|
||||
* Document media content
|
||||
*/
|
||||
private final Media media;
|
||||
|
||||
/**
|
||||
* Metadata for the document. It should not be nested and values should be restricted
|
||||
@@ -66,9 +106,18 @@ public class Document implements MediaContent {
|
||||
private final Map<String, Object> metadata;
|
||||
|
||||
/**
|
||||
* Measure of similarity between the document embedding and the query vector. The
|
||||
* higher the score, the more they are similar. It's the opposite of the distance
|
||||
* measure.
|
||||
* A numeric score associated with this document that can represent various types of
|
||||
* relevance measures.
|
||||
* <p>
|
||||
* Common uses include:
|
||||
* <ul>
|
||||
* <li>Measure of similarity between the document embedding and a query vector, where
|
||||
* higher scores indicate greater similarity (opposite of distance measure)
|
||||
* <li>Text relevancy rankings from retrieval systems
|
||||
* <li>Custom relevancy metrics from RAG patterns
|
||||
* </ul>
|
||||
* <p>
|
||||
* Higher values typically indicate greater relevance or similarity.
|
||||
*/
|
||||
@Nullable
|
||||
private final Double score;
|
||||
@@ -90,56 +139,33 @@ public class Document implements MediaContent {
|
||||
this(content, new HashMap<>());
|
||||
}
|
||||
|
||||
public Document(String content, Map<String, Object> metadata) {
|
||||
this(content, metadata, new RandomIdGenerator());
|
||||
public Document(String text, Map<String, Object> metadata) {
|
||||
this(new RandomIdGenerator().generateId(), text, null, metadata, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use builder instead: {@link Document#builder()}.
|
||||
*/
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Document(String content, Collection<Media> media, Map<String, Object> metadata) {
|
||||
this(new RandomIdGenerator().generateId(content, metadata), content, media, metadata);
|
||||
public Document(String id, String text, Map<String, Object> metadata) {
|
||||
this(id, text, null, metadata, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use builder instead: {@link Document#builder()}.
|
||||
*/
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Document(String content, Map<String, Object> metadata, IdGenerator idGenerator) {
|
||||
this(idGenerator.generateId(content, metadata), content, metadata);
|
||||
public Document(Media media, Map<String, Object> metadata) {
|
||||
this(new RandomIdGenerator().generateId(), null, media, metadata, null);
|
||||
}
|
||||
|
||||
public Document(String id, String content, Map<String, Object> metadata) {
|
||||
this(id, content, List.of(), metadata);
|
||||
public Document(String id, Media media, Map<String, Object> metadata) {
|
||||
this(id, null, media, metadata, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use builder instead: {@link Document#builder()}.
|
||||
*/
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Document(String id, String content, Collection<Media> media, Map<String, Object> metadata) {
|
||||
this(id, content, media, metadata, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use builder instead: {@link Document#builder()}.
|
||||
*/
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Document(String id, String content, @Nullable Collection<Media> media,
|
||||
@Nullable Map<String, Object> metadata, @Nullable Double score) {
|
||||
private Document(String id, String text, Media media, Map<String, Object> metadata, @Nullable Double score) {
|
||||
Assert.hasText(id, "id cannot be null or empty");
|
||||
Assert.notNull(content, "content cannot be null");
|
||||
Assert.notNull(media, "media cannot be null");
|
||||
Assert.noNullElements(media, "media cannot have null elements");
|
||||
Assert.notNull(metadata, "metadata cannot be null");
|
||||
Assert.noNullElements(metadata.keySet(), "metadata cannot have null keys");
|
||||
Assert.noNullElements(metadata.values(), "metadata cannot have null values");
|
||||
Assert.isTrue(text != null ^ media != null, "exactly one of text or media must be specified");
|
||||
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
this.media = media != null ? media : List.of();
|
||||
this.metadata = metadata != null ? metadata : new HashMap<>();
|
||||
this.text = text;
|
||||
this.media = media;
|
||||
this.metadata = new HashMap<>(metadata);
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
@@ -147,17 +173,55 @@ public class Document implements MediaContent {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique identifier for this document.
|
||||
* <p>
|
||||
* This ID is either explicitly provided during document creation or generated using
|
||||
* the configured {@link IdGenerator} (defaults to {@link RandomIdGenerator}).
|
||||
* @return the unique identifier of this document
|
||||
* @see RandomIdGenerator
|
||||
*/
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* @deprecated Use getText() instead as it more accurately reflects the content type
|
||||
*/
|
||||
@Deprecated
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
return this.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Media> getMedia() {
|
||||
/**
|
||||
* Returns the document's text content, if any.
|
||||
* @return the text content if {@link #isText()} is true, null otherwise
|
||||
* @see #isText()
|
||||
* @see #getMedia()
|
||||
*/
|
||||
@Nullable
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this document contains text or media content.
|
||||
* @return true if this document contains text content (accessible via
|
||||
* {@link #getText()}), false if it contains media content (accessible via
|
||||
* {@link #getMedia()})
|
||||
*/
|
||||
public boolean isText() {
|
||||
return this.text != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the document's media content, if any.
|
||||
* @return the media content if {@link #isText()} is false, null otherwise
|
||||
* @see #isText()
|
||||
* @see #getText()
|
||||
*/
|
||||
@Nullable
|
||||
public Media getMedia() {
|
||||
return this.media;
|
||||
}
|
||||
|
||||
@@ -180,7 +244,13 @@ public class Document implements MediaContent {
|
||||
return formatter.format(this, metadataMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Returns the metadata associated with this document.
|
||||
* <p>
|
||||
* The metadata values are restricted to simple types (string, int, float, boolean)
|
||||
* for compatibility with Vector Databases.
|
||||
* @return the metadata map
|
||||
*/
|
||||
public Map<String, Object> getMetadata() {
|
||||
return this.metadata;
|
||||
}
|
||||
@@ -227,11 +297,7 @@ public class Document implements MediaContent {
|
||||
}
|
||||
|
||||
public Builder mutate() {
|
||||
return new Builder().id(this.id)
|
||||
.content(this.content)
|
||||
.media(new ArrayList<>(this.media))
|
||||
.metadata(this.metadata)
|
||||
.score(this.score);
|
||||
return new Builder().id(this.id).text(this.text).media(this.media).metadata(this.metadata).score(this.score);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -240,19 +306,19 @@ public class Document implements MediaContent {
|
||||
return false;
|
||||
}
|
||||
Document document = (Document) o;
|
||||
return Objects.equals(this.id, document.id) && Objects.equals(this.content, document.content)
|
||||
return Objects.equals(this.id, document.id) && Objects.equals(this.text, document.text)
|
||||
&& Objects.equals(this.media, document.media) && Objects.equals(this.metadata, document.metadata)
|
||||
&& Objects.equals(this.score, document.score);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.id, this.content, this.media, this.metadata, this.score);
|
||||
return Objects.hash(this.id, this.text, this.media, this.metadata, this.score);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Document{" + "id='" + this.id + '\'' + ", content='" + this.content + '\'' + ", media=" + this.media
|
||||
return "Document{" + "id='" + this.id + '\'' + ", text='" + this.text + '\'' + ", media='" + this.media + '\''
|
||||
+ ", metadata=" + this.metadata + ", score=" + this.score + '}';
|
||||
}
|
||||
|
||||
@@ -260,9 +326,9 @@ public class Document implements MediaContent {
|
||||
|
||||
private String id;
|
||||
|
||||
private String content = Document.EMPTY_TEXT;
|
||||
private String text;
|
||||
|
||||
private List<Media> media = new ArrayList<>();
|
||||
private Media media;
|
||||
|
||||
private Map<String, Object> metadata = new HashMap<>();
|
||||
|
||||
@@ -285,83 +351,92 @@ public class Document implements MediaContent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder content(String content) {
|
||||
this.content = content;
|
||||
/**
|
||||
* Sets the text content of the document.
|
||||
* <p>
|
||||
* Either text or media content must be set before building the document, but not
|
||||
* both.
|
||||
* @param text the text content
|
||||
* @return the builder instance
|
||||
* @see #media(Media)
|
||||
*/
|
||||
public Builder text(@Nullable String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder media(List<Media> media) {
|
||||
Assert.notNull(media, "media cannot be null");
|
||||
this.media.addAll(media);
|
||||
/**
|
||||
* Sets the text content of the document.
|
||||
* @param text the text content to set
|
||||
* @return the builder instance
|
||||
* @deprecated since 1.0.0-M5, use {@link #text(String)} instead as it more
|
||||
* accurately reflects that this Document instance will contain text rather than
|
||||
* generic content. This method will be removed in a future release.
|
||||
*/
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Builder content(@Nullable String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder media(Media... media) {
|
||||
Assert.noNullElements(media, "media cannot contain null elements");
|
||||
this.media.addAll(List.of(media));
|
||||
/**
|
||||
* Sets the media content of the document.
|
||||
* <p>
|
||||
* Either text or media content must be set before building the document, but not
|
||||
* both.
|
||||
* @param media the media content
|
||||
* @return the builder instance
|
||||
* @see #text(String)
|
||||
*/
|
||||
public Builder media(@Nullable Media media) {
|
||||
this.media = media;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder metadata(Map<String, Object> metadata) {
|
||||
Assert.notNull(metadata, "metadata cannot be null");
|
||||
this.metadata = metadata;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder metadata(String key, Object value) {
|
||||
Assert.notNull(key, "metadata key cannot be null");
|
||||
Assert.notNull(value, "metadata value cannot be null");
|
||||
this.metadata.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder embedding(float[] embedding) {
|
||||
Assert.notNull(embedding, "embedding cannot be null");
|
||||
this.embedding = embedding;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a score value for this document.
|
||||
* <p>
|
||||
* Common uses include:
|
||||
* <ul>
|
||||
* <li>Measure of similarity between the document embedding and a query vector,
|
||||
* where higher scores indicate greater similarity (opposite of distance measure)
|
||||
* <li>Text relevancy rankings from retrieval systems
|
||||
* <li>Custom relevancy metrics from RAG patterns
|
||||
* </ul>
|
||||
* <p>
|
||||
* Higher values typically indicate greater relevance or similarity.
|
||||
* @param score the document score, may be null
|
||||
* @return the builder instance
|
||||
*/
|
||||
public Builder score(@Nullable Double score) {
|
||||
this.score = score;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Builder withIdGenerator(IdGenerator idGenerator) {
|
||||
return idGenerator(idGenerator);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Builder withId(String id) {
|
||||
return id(id);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Builder withContent(String content) {
|
||||
return content(content);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Builder withMedia(List<Media> media) {
|
||||
return media(media);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Builder withMedia(Media media) {
|
||||
return media(media);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Builder withMetadata(Map<String, Object> metadata) {
|
||||
return metadata(metadata);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.0.0-M5", forRemoval = true)
|
||||
public Builder withMetadata(String key, Object value) {
|
||||
return metadata(key, value);
|
||||
}
|
||||
|
||||
public Document build() {
|
||||
if (!StringUtils.hasText(this.id)) {
|
||||
this.id = this.idGenerator.generateId(this.content, this.metadata);
|
||||
this.id = this.idGenerator.generateId(this.text, this.metadata);
|
||||
}
|
||||
var document = new Document(this.id, this.content, this.media, this.metadata, this.score);
|
||||
var document = new Document(this.id, this.text, this.media, this.metadata, this.score);
|
||||
document.setEmbedding(this.embedding);
|
||||
return document;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface Evaluator {
|
||||
default String doGetSupportingData(EvaluationRequest evaluationRequest) {
|
||||
List<Content> data = evaluationRequest.getDataList();
|
||||
return data.stream()
|
||||
.map(Content::getContent)
|
||||
.map(Content::getText)
|
||||
.filter(StringUtils::hasText)
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
}
|
||||
|
||||
@@ -33,7 +33,15 @@ public interface Content {
|
||||
* Get the content of the message.
|
||||
* @return the content of the message
|
||||
*/
|
||||
String getContent(); // TODO consider getText
|
||||
String getText();
|
||||
|
||||
/**
|
||||
* Get the content of the message.
|
||||
* @return the content of the message
|
||||
* @deprecated Use getText
|
||||
*/
|
||||
@Deprecated(since = "1.0.0.M5")
|
||||
String getContent();
|
||||
|
||||
/**
|
||||
* Get the metadata associated with the content.
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package org.springframework.ai.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface MediaContent extends Content {
|
||||
|
||||
/**
|
||||
* Get the media associated with the content.
|
||||
*/
|
||||
Collection<Media> getMedia();
|
||||
List<Media> getMedia();
|
||||
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public final class ContextualQueryAugmenter implements QueryAugmenter {
|
||||
|
||||
// 1. Collect content from documents.
|
||||
String documentContext = documents.stream()
|
||||
.map(Content::getContent)
|
||||
.map(Document::getText)
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
|
||||
// 2. Define prompt parameters.
|
||||
|
||||
@@ -56,8 +56,8 @@ public class JTokkitTokenCountEstimator implements TokenCountEstimator {
|
||||
public int estimate(MediaContent content) {
|
||||
int tokenCount = 0;
|
||||
|
||||
if (content.getContent() != null) {
|
||||
tokenCount += this.estimate(content.getContent());
|
||||
if (content.getText() != null) {
|
||||
tokenCount += this.estimate(content.getText());
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(content.getMedia())) {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class KeywordMetadataEnricher implements DocumentTransformer {
|
||||
|
||||
var template = new PromptTemplate(String.format(KEYWORDS_TEMPLATE, this.keywordCount));
|
||||
Prompt prompt = template.create(Map.of(CONTEXT_STR_PLACEHOLDER, document.getContent()));
|
||||
String keywords = this.chatModel.call(prompt).getResult().getOutput().getContent();
|
||||
String keywords = this.chatModel.call(prompt).getResult().getOutput().getText();
|
||||
document.getMetadata().putAll(Map.of(EXCERPT_KEYWORDS_METADATA_KEY, keywords));
|
||||
}
|
||||
return documents;
|
||||
|
||||
@@ -97,7 +97,7 @@ public class SummaryMetadataEnricher implements DocumentTransformer {
|
||||
|
||||
Prompt prompt = new PromptTemplate(this.summaryTemplate)
|
||||
.create(Map.of(CONTEXT_STR_PLACEHOLDER, documentContext));
|
||||
documentSummaries.add(this.chatModel.call(prompt).getResult().getOutput().getContent());
|
||||
documentSummaries.add(this.chatModel.call(prompt).getResult().getOutput().getText());
|
||||
}
|
||||
|
||||
for (int i = 0; i < documentSummaries.size(); i++) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user