Skip to content

GH-1599 Remove deprecations prior to M2 #1736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi;
import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi.AnthropicChatRequest;
import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi.AnthropicChatResponse;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
Expand Down Expand Up @@ -68,7 +69,7 @@ public ChatResponse call(Prompt prompt) {

AnthropicChatResponse response = this.anthropicChatApi.chatCompletion(request);

return new ChatResponse(List.of(new Generation(response.completion())));
return new ChatResponse(List.of(new Generation(new AssistantMessage(response.completion()))));
}

@Override
Expand All @@ -80,12 +81,13 @@ public Flux<ChatResponse> stream(Prompt prompt) {

return fluxResponse.map(response -> {
String stopReason = response.stopReason() != null ? response.stopReason() : null;
var generation = new Generation(response.completion());
ChatGenerationMetadata chatGenerationMetadata = null;
if (response.amazonBedrockInvocationMetrics() != null) {
generation = generation.withGenerationMetadata(
ChatGenerationMetadata.from(stopReason, response.amazonBedrockInvocationMetrics()));
chatGenerationMetadata = ChatGenerationMetadata.from(stopReason,
response.amazonBedrockInvocationMetrics());
}
return new ChatResponse(List.of(generation));
return new ChatResponse(
List.of(new Generation(new AssistantMessage(response.completion()), chatGenerationMetadata)));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,13 @@ public Flux<ChatResponse> stream(Prompt prompt) {
inputTokens.set(response.message().usage().inputTokens());
}
String content = response.type() == StreamingType.CONTENT_BLOCK_DELTA ? response.delta().text() : "";

var generation = new Generation(content);

ChatGenerationMetadata chatGenerationMetadata = null;
if (response.type() == StreamingType.MESSAGE_DELTA) {
generation = generation.withGenerationMetadata(ChatGenerationMetadata
.from(response.delta().stopReason(), new Anthropic3ChatBedrockApi.AnthropicUsage(inputTokens.get(),
response.usage().outputTokens())));
chatGenerationMetadata = ChatGenerationMetadata.from(response.delta().stopReason(),
new Anthropic3ChatBedrockApi.AnthropicUsage(inputTokens.get(),
response.usage().outputTokens()));
}

return new ChatResponse(List.of(generation));
return new ChatResponse(List.of(new Generation(new AssistantMessage(content), chatGenerationMetadata)));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi;
import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatRequest;
import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatResponse;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
import org.springframework.ai.chat.metadata.Usage;
import org.springframework.ai.chat.model.ChatModel;
Expand Down Expand Up @@ -61,7 +62,10 @@ public BedrockCohereChatModel(CohereChatBedrockApi chatApi, BedrockCohereChatOpt
@Override
public ChatResponse call(Prompt prompt) {
CohereChatResponse response = this.chatApi.chatCompletion(this.createRequest(prompt, false));
List<Generation> generations = response.generations().stream().map(g -> new Generation(g.text())).toList();
List<Generation> generations = response.generations()
.stream()
.map(g -> new Generation(new AssistantMessage(g.text())))
.toList();

return new ChatResponse(generations);
}
Expand All @@ -73,9 +77,9 @@ public Flux<ChatResponse> stream(Prompt prompt) {
String finishReason = g.finishReason().name();
Usage usage = BedrockUsage.from(g.amazonBedrockInvocationMetrics());
return new ChatResponse(List
.of(new Generation("").withGenerationMetadata(ChatGenerationMetadata.from(finishReason, usage))));
.of(new Generation(new AssistantMessage(""), ChatGenerationMetadata.from(finishReason, usage))));
}
return new ChatResponse(List.of(new Generation(g.text())));
return new ChatResponse(List.of(new Generation(new AssistantMessage(g.text()))));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.ai.bedrock.MessageToPromptConverter;
import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi;
import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatRequest;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
Expand Down Expand Up @@ -68,8 +69,8 @@ public ChatResponse call(Prompt prompt) {

return new ChatResponse(response.completions()
.stream()
.map(completion -> new Generation(completion.data().text())
.withGenerationMetadata(ChatGenerationMetadata.from(completion.finishReason().reason(), null)))
.map(completion -> new Generation(new AssistantMessage(completion.data().text()),
ChatGenerationMetadata.from(completion.finishReason().reason(), null)))
.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi;
import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi.LlamaChatRequest;
import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi.LlamaChatResponse;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
import org.springframework.ai.chat.metadata.Usage;
import org.springframework.ai.chat.model.ChatModel;
Expand Down Expand Up @@ -68,7 +69,7 @@ public ChatResponse call(Prompt prompt) {

LlamaChatResponse response = this.chatApi.chatCompletion(request);

return new ChatResponse(List.of(new Generation(response.generation()).withGenerationMetadata(
return new ChatResponse(List.of(new Generation(new AssistantMessage(response.generation()),
ChatGenerationMetadata.from(response.stopReason().name(), extractUsage(response)))));
}

Expand All @@ -81,8 +82,8 @@ public Flux<ChatResponse> stream(Prompt prompt) {

return fluxResponse.map(response -> {
String stopReason = response.stopReason() != null ? response.stopReason().name() : null;
return new ChatResponse(List.of(new Generation(response.generation())
.withGenerationMetadata(ChatGenerationMetadata.from(stopReason, extractUsage(response)))));
return new ChatResponse(List.of(new Generation(new AssistantMessage(response.generation()),
ChatGenerationMetadata.from(stopReason, extractUsage(response)))));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatRequest;
import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatResponse;
import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatResponseChunk;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
import org.springframework.ai.chat.metadata.Usage;
import org.springframework.ai.chat.model.ChatModel;
Expand Down Expand Up @@ -62,7 +63,7 @@ public ChatResponse call(Prompt prompt) {
TitanChatResponse response = this.chatApi.chatCompletion(this.createRequest(prompt));
List<Generation> generations = response.results()
.stream()
.map(result -> new Generation(result.outputText()))
.map(result -> new Generation(new AssistantMessage(result.outputText())))
.toList();

return new ChatResponse(generations);
Expand All @@ -71,21 +72,18 @@ public ChatResponse call(Prompt prompt) {
@Override
public Flux<ChatResponse> stream(Prompt prompt) {
return this.chatApi.chatCompletionStream(this.createRequest(prompt)).map(chunk -> {

Generation generation = new Generation(chunk.outputText());

ChatGenerationMetadata chatGenerationMetadata = null;
if (chunk.amazonBedrockInvocationMetrics() != null) {
String completionReason = chunk.completionReason().name();
generation = generation.withGenerationMetadata(
ChatGenerationMetadata.from(completionReason, chunk.amazonBedrockInvocationMetrics()));
chatGenerationMetadata = ChatGenerationMetadata.from(completionReason,
chunk.amazonBedrockInvocationMetrics());
}
else if (chunk.inputTextTokenCount() != null && chunk.totalOutputTextTokenCount() != null) {
String completionReason = chunk.completionReason().name();
generation = generation
.withGenerationMetadata(ChatGenerationMetadata.from(completionReason, extractUsage(chunk)));

chatGenerationMetadata = ChatGenerationMetadata.from(completionReason, extractUsage(chunk));
}
return new ChatResponse(List.of(generation));
return new ChatResponse(
List.of(new Generation(new AssistantMessage(chunk.outputText()), chatGenerationMetadata)));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.model.Generation;
Expand Down Expand Up @@ -103,7 +105,7 @@ public ChatResponse call(Prompt prompt) {
new TypeReference<Map<String, Object>>() {

});
Generation generation = new Generation(generatedText, detailsMap);
Generation generation = new Generation(new AssistantMessage(generatedText, detailsMap));
generations.add(generation);
return new ChatResponse(generations);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ public enum ChatModel implements ChatModelDescription {
ABAB_6_5_T_Chat("abab6.5t-chat"),
ABAB_6_5_G_Chat("abab6.5g-chat"),
ABAB_5_5_Chat("abab5.5-chat"),
ABAB_5_5_S_Chat("abab5.5s-chat"),

@Deprecated(since = "1.0.0-M2", forRemoval = true) // Replaced by ABAB_6_5_S_Chat
ABAB_6_Chat("abab6-chat");
ABAB_5_5_S_Chat("abab5.5s-chat");

public final String value;

Expand Down Expand Up @@ -269,11 +266,6 @@ public enum ChatCompletionFinishReason {
*/
@JsonProperty("tool_calls")
TOOL_CALLS,
/**
* (deprecated) The model called a function.
*/
@JsonProperty("function_call")
FUNCTION_CALL,
/**
* Only for compatibility with Mistral AI API.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@ public enum ChatCompletionFinishReason {
*/
@JsonProperty("tool_calls")
TOOL_CALLS,
/**
* (deprecated) The model called a function.
*/
@JsonProperty("function_call")
FUNCTION_CALL,
/**
* Only for compatibility with Mistral AI API.
*/
Expand Down
Loading