Change default build setting to disable Checkstyle enforcement
- Disable project-wide Checkstyle checks to unblock development - Add documentation for enabling Checkstyle locally - Fix remaining checkstyle violations in current codebase Fixes #1669
This commit is contained in:
committed by
Mark Pollack
parent
cbef2d1600
commit
66f58d2d70
@@ -94,6 +94,12 @@ To check javadocs using the [javadoc:javadoc](https://maven.apache.org/plugins/m
|
||||
./mvnw javadoc:javadoc -Pjavadoc
|
||||
```
|
||||
|
||||
To build with checkstyles enabled.
|
||||
Checkstyles are currently disabled, but you can enable them by doing the following:
|
||||
```shell
|
||||
./mvnw clean package -DskipTests -Ddisable.checks=false
|
||||
```
|
||||
|
||||
## Project Links
|
||||
|
||||
* [Documentation](https://docs.spring.io/spring-ai/reference/)
|
||||
|
||||
@@ -111,7 +111,7 @@ public class MarkdownDocumentReader implements DocumentReader {
|
||||
|
||||
private Document.Builder currentDocumentBuilder;
|
||||
|
||||
public DocumentVisitor(MarkdownDocumentReaderConfig config) {
|
||||
DocumentVisitor(MarkdownDocumentReaderConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class MarkdownDocumentReaderConfig {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public static final class Builder {
|
||||
|
||||
private boolean horizontalRuleCreateDocument = false;
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2023-2024 the original author or authors.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ https://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
@@ -81,4 +97,4 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2024 - 2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.bedrock.converse;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -26,44 +27,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.bedrock.converse.api.ConverseApiUtils;
|
||||
import org.springframework.ai.bedrock.converse.api.URLValidator;
|
||||
import org.springframework.ai.chat.messages.AssistantMessage;
|
||||
import org.springframework.ai.chat.messages.MessageType;
|
||||
import org.springframework.ai.chat.messages.ToolResponseMessage;
|
||||
import org.springframework.ai.chat.messages.UserMessage;
|
||||
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
|
||||
import org.springframework.ai.chat.metadata.ChatResponseMetadata;
|
||||
import org.springframework.ai.chat.metadata.DefaultUsage;
|
||||
import org.springframework.ai.chat.model.AbstractToolCallSupport;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.ai.chat.model.Generation;
|
||||
import org.springframework.ai.chat.model.MessageAggregator;
|
||||
import org.springframework.ai.chat.observation.ChatModelObservationContext;
|
||||
import org.springframework.ai.chat.observation.ChatModelObservationConvention;
|
||||
import org.springframework.ai.chat.observation.ChatModelObservationDocumentation;
|
||||
import org.springframework.ai.chat.observation.DefaultChatModelObservationConvention;
|
||||
import org.springframework.ai.chat.prompt.ChatOptions;
|
||||
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.ai.model.ModelOptionsUtils;
|
||||
import org.springframework.ai.model.function.FunctionCallback;
|
||||
import org.springframework.ai.model.function.FunctionCallbackContext;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptions;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder.PortableFunctionCallingOptions;
|
||||
import org.springframework.ai.observation.conventions.AiProvider;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import io.micrometer.observation.Observation;
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.Sinks;
|
||||
@@ -97,6 +65,39 @@ import software.amazon.awssdk.services.bedrockruntime.model.ToolResultContentBlo
|
||||
import software.amazon.awssdk.services.bedrockruntime.model.ToolSpecification;
|
||||
import software.amazon.awssdk.services.bedrockruntime.model.ToolUseBlock;
|
||||
|
||||
import org.springframework.ai.bedrock.converse.api.ConverseApiUtils;
|
||||
import org.springframework.ai.bedrock.converse.api.URLValidator;
|
||||
import org.springframework.ai.chat.messages.AssistantMessage;
|
||||
import org.springframework.ai.chat.messages.MessageType;
|
||||
import org.springframework.ai.chat.messages.ToolResponseMessage;
|
||||
import org.springframework.ai.chat.messages.UserMessage;
|
||||
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
|
||||
import org.springframework.ai.chat.metadata.ChatResponseMetadata;
|
||||
import org.springframework.ai.chat.metadata.DefaultUsage;
|
||||
import org.springframework.ai.chat.model.AbstractToolCallSupport;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.ai.chat.model.Generation;
|
||||
import org.springframework.ai.chat.model.MessageAggregator;
|
||||
import org.springframework.ai.chat.observation.ChatModelObservationContext;
|
||||
import org.springframework.ai.chat.observation.ChatModelObservationConvention;
|
||||
import org.springframework.ai.chat.observation.ChatModelObservationDocumentation;
|
||||
import org.springframework.ai.chat.observation.DefaultChatModelObservationConvention;
|
||||
import org.springframework.ai.chat.prompt.ChatOptions;
|
||||
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.ai.model.ModelOptionsUtils;
|
||||
import org.springframework.ai.model.function.FunctionCallback;
|
||||
import org.springframework.ai.model.function.FunctionCallbackContext;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptions;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder.PortableFunctionCallingOptions;
|
||||
import org.springframework.ai.observation.conventions.AiProvider;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A {@link ChatModel} implementation that uses the Amazon Bedrock Converse API to
|
||||
* interact with the <a href=
|
||||
@@ -335,7 +336,7 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
.topP(updatedRuntimeOptions.getTopP() != null ? updatedRuntimeOptions.getTopP().floatValue() : null)
|
||||
.build();
|
||||
Document additionalModelRequestFields = ConverseApiUtils
|
||||
.getChatOptionsAdditionalModelRequestFields(defaultOptions, prompt.getOptions());
|
||||
.getChatOptionsAdditionalModelRequestFields(this.defaultOptions, prompt.getOptions());
|
||||
|
||||
return ConverseRequest.builder()
|
||||
.modelId(updatedRuntimeOptions.getModel())
|
||||
@@ -411,10 +412,8 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
List<Generation> generations = message.content()
|
||||
.stream()
|
||||
.filter(content -> content.type() != ContentBlock.Type.TOOL_USE)
|
||||
.map(content -> {
|
||||
return new Generation(new AssistantMessage(content.text(), Map.of()),
|
||||
ChatGenerationMetadata.from(response.stopReasonAsString(), null));
|
||||
})
|
||||
.map(content -> new Generation(new AssistantMessage(content.text(), Map.of()),
|
||||
ChatGenerationMetadata.from(response.stopReasonAsString(), null)))
|
||||
.toList();
|
||||
|
||||
List<Generation> allGenerations = new ArrayList<>(generations);
|
||||
@@ -508,7 +507,7 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
// @formatter:off
|
||||
Flux<ChatResponse> chatResponses = ConverseApiUtils.toChatResponse(response);
|
||||
|
||||
Flux<ChatResponse> chatResponseFlux = chatResponses.switchMap(chatResponse -> {
|
||||
Flux<ChatResponse> chatResponseFlux = chatResponses.switchMap(chatResponse -> {
|
||||
if (!this.isProxyToolCalls(prompt, this.defaultOptions) && chatResponse != null
|
||||
&& this.isToolCall(chatResponse, Set.of("tool_use"))) {
|
||||
var toolCallConversation = this.handleToolCalls(prompt, chatResponse);
|
||||
@@ -540,14 +539,14 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
Sinks.Many<ConverseStreamOutput> eventSink = Sinks.many().multicast().onBackpressureBuffer();
|
||||
|
||||
ConverseStreamResponseHandler.Visitor visitor = ConverseStreamResponseHandler.Visitor.builder()
|
||||
.onDefault((output) -> {
|
||||
.onDefault(output -> {
|
||||
logger.debug("Received converse stream output:{}", output);
|
||||
eventSink.tryEmitNext(output);
|
||||
})
|
||||
.build();
|
||||
|
||||
ConverseStreamResponseHandler responseHandler = ConverseStreamResponseHandler.builder()
|
||||
.onEventStream(stream -> stream.subscribe((e) -> e.accept(visitor)))
|
||||
.onEventStream(stream -> stream.subscribe(e -> e.accept(visitor)))
|
||||
.onComplete(() -> {
|
||||
EmitResult emitResult = eventSink.tryEmitComplete();
|
||||
|
||||
@@ -559,7 +558,7 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
eventSink.emitComplete(EmitFailureHandler.busyLooping(Duration.ofSeconds(3)));
|
||||
logger.info("Completed streaming response.");
|
||||
})
|
||||
.onError((error) -> {
|
||||
.onError(error -> {
|
||||
logger.error("Error handling Bedrock converse stream response", error);
|
||||
eventSink.tryEmitError(error);
|
||||
})
|
||||
@@ -571,11 +570,20 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the provided convention for reporting observation data
|
||||
* @param observationConvention The provided convention
|
||||
*/
|
||||
public void setObservationConvention(ChatModelObservationConvention observationConvention) {
|
||||
Assert.notNull(observationConvention, "observationConvention cannot be null");
|
||||
this.observationConvention = observationConvention;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public static final class Builder {
|
||||
|
||||
private AwsCredentialsProvider credentialsProvider;
|
||||
|
||||
@@ -696,13 +704,4 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the provided convention for reporting observation data
|
||||
* @param observationConvention The provided convention
|
||||
*/
|
||||
public void setObservationConvention(ChatModelObservationConvention observationConvention) {
|
||||
Assert.notNull(observationConvention, "observationConvention cannot be null");
|
||||
this.observationConvention = observationConvention;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2024 - 2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -13,13 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.bedrock.converse.api;
|
||||
|
||||
import software.amazon.awssdk.services.bedrockruntime.model.TokenUsage;
|
||||
|
||||
import org.springframework.ai.chat.metadata.Usage;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import software.amazon.awssdk.services.bedrockruntime.model.TokenUsage;
|
||||
|
||||
/**
|
||||
* {@link Usage} implementation for Bedrock Converse API.
|
||||
*
|
||||
@@ -46,17 +47,17 @@ public class BedrockUsage implements Usage {
|
||||
|
||||
@Override
|
||||
public Long getPromptTokens() {
|
||||
return inputTokens;
|
||||
return this.inputTokens;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getGenerationTokens() {
|
||||
return outputTokens;
|
||||
return this.outputTokens;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BedrockUsage [inputTokens=" + inputTokens + ", outputTokens=" + outputTokens + "]";
|
||||
return "BedrockUsage [inputTokens=" + this.inputTokens + ", outputTokens=" + this.outputTokens + "]";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2024 - 2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.bedrock.converse.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -24,18 +25,6 @@ import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.ai.chat.messages.AssistantMessage;
|
||||
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
|
||||
import org.springframework.ai.chat.metadata.ChatResponseMetadata;
|
||||
import org.springframework.ai.chat.metadata.DefaultUsage;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.ai.chat.model.Generation;
|
||||
import org.springframework.ai.chat.prompt.ChatOptions;
|
||||
import org.springframework.ai.model.ModelOptions;
|
||||
import org.springframework.ai.model.ModelOptionsUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import software.amazon.awssdk.core.SdkField;
|
||||
@@ -56,6 +45,18 @@ import software.amazon.awssdk.services.bedrockruntime.model.MessageStopEvent;
|
||||
import software.amazon.awssdk.services.bedrockruntime.model.TokenUsage;
|
||||
import software.amazon.awssdk.services.bedrockruntime.model.ToolUseBlockStart;
|
||||
|
||||
import org.springframework.ai.chat.messages.AssistantMessage;
|
||||
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
|
||||
import org.springframework.ai.chat.metadata.ChatResponseMetadata;
|
||||
import org.springframework.ai.chat.metadata.DefaultUsage;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.ai.chat.model.Generation;
|
||||
import org.springframework.ai.chat.prompt.ChatOptions;
|
||||
import org.springframework.ai.model.ModelOptions;
|
||||
import org.springframework.ai.model.ModelOptionsUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Amazon Bedrock Converse API utils.
|
||||
*
|
||||
@@ -63,7 +64,16 @@ import software.amazon.awssdk.services.bedrockruntime.model.ToolUseBlockStart;
|
||||
* @author Christian Tzolov
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ConverseApiUtils {
|
||||
public final class ConverseApiUtils {
|
||||
|
||||
public static final ChatResponse EMPTY_CHAT_RESPONSE = ChatResponse.builder()
|
||||
.withGenerations(List.of())
|
||||
.withMetadata("empty", true)
|
||||
.build();
|
||||
|
||||
private ConverseApiUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isToolUseStart(ConverseStreamOutput event) {
|
||||
if (event == null || event.sdkEventType() == null || event.sdkEventType() != EventType.CONTENT_BLOCK_START) {
|
||||
@@ -80,139 +90,6 @@ public class ConverseApiUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
public record Aggregation(MetadataAggregation metadataAggregation, ChatResponse chatResponse) {
|
||||
public Aggregation() {
|
||||
this(MetadataAggregation.builder().build(), EMPTY_CHAT_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Special event used to aggregate multiple tool use events into a single event with
|
||||
* list of aggregated ContentBlockToolUse.
|
||||
*/
|
||||
public static class ToolUseAggregationEvent implements ConverseStreamOutput {
|
||||
|
||||
public record ToolUseEntry(Integer index, String id, String name, String input) {
|
||||
}
|
||||
|
||||
private Integer index;
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String partialJson = "";
|
||||
|
||||
private List<ToolUseEntry> toolUseEntries = new ArrayList<>();
|
||||
|
||||
private DefaultUsage usage;
|
||||
|
||||
public List<ToolUseEntry> toolUseEntries() {
|
||||
return this.toolUseEntries;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return (this.index == null || this.id == null || this.name == null
|
||||
|| !StringUtils.hasText(this.partialJson));
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent withIndex(Integer index) {
|
||||
this.index = index;
|
||||
return this;
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent withId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent withName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent withUsage(DefaultUsage usage) {
|
||||
this.usage = usage;
|
||||
return this;
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent appendPartialJson(String partialJson) {
|
||||
this.partialJson = this.partialJson + partialJson;
|
||||
return this;
|
||||
}
|
||||
|
||||
void squashIntoContentBlock() {
|
||||
this.toolUseEntries.add(new ToolUseEntry(this.index, this.id, this.name, this.partialJson));
|
||||
this.index = null;
|
||||
this.id = null;
|
||||
this.name = null;
|
||||
this.partialJson = "";
|
||||
this.usage = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EventToolUseBuilder [index=" + this.index + ", id=" + this.id + ", name=" + this.name
|
||||
+ ", partialJson=" + this.partialJson + ", toolUseMap=" + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SdkField<?>> sdkFields() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Visitor visitor) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static ConverseStreamOutput mergeToolUseEvents(ConverseStreamOutput previousEvent,
|
||||
ConverseStreamOutput event) {
|
||||
|
||||
ToolUseAggregationEvent toolUseEventAggregator = (ToolUseAggregationEvent) previousEvent;
|
||||
|
||||
if (event.sdkEventType() == EventType.CONTENT_BLOCK_START) {
|
||||
|
||||
ContentBlockStartEvent contentBlockStart = (ContentBlockStartEvent) event;
|
||||
|
||||
if (ContentBlockStart.Type.TOOL_USE.equals(contentBlockStart.start().type())) {
|
||||
ToolUseBlockStart cbToolUse = contentBlockStart.start().toolUse();
|
||||
|
||||
return toolUseEventAggregator.withIndex(contentBlockStart.contentBlockIndex())
|
||||
.withId(cbToolUse.toolUseId())
|
||||
.withName(cbToolUse.name())
|
||||
.appendPartialJson(""); // CB START always has empty JSON.
|
||||
}
|
||||
}
|
||||
else if (event.sdkEventType() == EventType.CONTENT_BLOCK_DELTA) {
|
||||
ContentBlockDeltaEvent contentBlockDelta = (ContentBlockDeltaEvent) event;
|
||||
if (ContentBlockDelta.Type.TOOL_USE == contentBlockDelta.delta().type()) {
|
||||
return toolUseEventAggregator.appendPartialJson(contentBlockDelta.delta().toolUse().input());
|
||||
}
|
||||
}
|
||||
else if (event.sdkEventType() == EventType.CONTENT_BLOCK_STOP) {
|
||||
return toolUseEventAggregator;
|
||||
}
|
||||
else if (event.sdkEventType() == EventType.MESSAGE_STOP) {
|
||||
return toolUseEventAggregator;
|
||||
}
|
||||
else if (event.sdkEventType() == EventType.METADATA) {
|
||||
ConverseStreamMetadataEvent metadataEvent = (ConverseStreamMetadataEvent) event;
|
||||
DefaultUsage usage = new DefaultUsage(metadataEvent.usage().inputTokens().longValue(),
|
||||
metadataEvent.usage().outputTokens().longValue(), metadataEvent.usage().totalTokens().longValue());
|
||||
toolUseEventAggregator.withUsage(usage);
|
||||
// TODO
|
||||
if (!toolUseEventAggregator.isEmpty()) {
|
||||
toolUseEventAggregator.squashIntoContentBlock();
|
||||
return toolUseEventAggregator;
|
||||
}
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
public static Flux<ChatResponse> toChatResponse(Flux<ConverseStreamOutput> responses) {
|
||||
|
||||
AtomicBoolean isInsideTool = new AtomicBoolean(false);
|
||||
@@ -228,7 +105,7 @@ public class ConverseApiUtils {
|
||||
return true;
|
||||
}
|
||||
return !isInsideTool.get();
|
||||
}).concatMapIterable(window -> {// Merging the window chunks into a single chunk.
|
||||
}).concatMapIterable(window -> { // Merging the window chunks into a single chunk.
|
||||
Mono<ConverseStreamOutput> monoChunk = window.reduce(new ToolUseAggregationEvent(),
|
||||
ConverseApiUtils::mergeToolUseEvents);
|
||||
return List.of(monoChunk);
|
||||
@@ -333,81 +210,49 @@ public class ConverseApiUtils {
|
||||
.filter(chatResponse -> chatResponse != ConverseApiUtils.EMPTY_CHAT_RESPONSE);
|
||||
}
|
||||
|
||||
public static final ChatResponse EMPTY_CHAT_RESPONSE = ChatResponse.builder()
|
||||
.withGenerations(List.of())
|
||||
.withMetadata("empty", true)
|
||||
.build();
|
||||
public static ConverseStreamOutput mergeToolUseEvents(ConverseStreamOutput previousEvent,
|
||||
ConverseStreamOutput event) {
|
||||
|
||||
public record MetadataAggregation(String role, String stopReason, Document additionalModelResponseFields,
|
||||
TokenUsage tokenUsage, ConverseStreamMetrics metrics, ConverseStreamTrace trace) {
|
||||
ToolUseAggregationEvent toolUseEventAggregator = (ToolUseAggregationEvent) previousEvent;
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
if (event.sdkEventType() == EventType.CONTENT_BLOCK_START) {
|
||||
|
||||
ContentBlockStartEvent contentBlockStart = (ContentBlockStartEvent) event;
|
||||
|
||||
if (ContentBlockStart.Type.TOOL_USE.equals(contentBlockStart.start().type())) {
|
||||
ToolUseBlockStart cbToolUse = contentBlockStart.start().toolUse();
|
||||
|
||||
return toolUseEventAggregator.withIndex(contentBlockStart.contentBlockIndex())
|
||||
.withId(cbToolUse.toolUseId())
|
||||
.withName(cbToolUse.name())
|
||||
.appendPartialJson(""); // CB START always has empty JSON.
|
||||
}
|
||||
}
|
||||
else if (event.sdkEventType() == EventType.CONTENT_BLOCK_DELTA) {
|
||||
ContentBlockDeltaEvent contentBlockDelta = (ContentBlockDeltaEvent) event;
|
||||
if (ContentBlockDelta.Type.TOOL_USE == contentBlockDelta.delta().type()) {
|
||||
return toolUseEventAggregator.appendPartialJson(contentBlockDelta.delta().toolUse().input());
|
||||
}
|
||||
}
|
||||
else if (event.sdkEventType() == EventType.CONTENT_BLOCK_STOP) {
|
||||
return toolUseEventAggregator;
|
||||
}
|
||||
else if (event.sdkEventType() == EventType.MESSAGE_STOP) {
|
||||
return toolUseEventAggregator;
|
||||
}
|
||||
else if (event.sdkEventType() == EventType.METADATA) {
|
||||
ConverseStreamMetadataEvent metadataEvent = (ConverseStreamMetadataEvent) event;
|
||||
DefaultUsage usage = new DefaultUsage(metadataEvent.usage().inputTokens().longValue(),
|
||||
metadataEvent.usage().outputTokens().longValue(), metadataEvent.usage().totalTokens().longValue());
|
||||
toolUseEventAggregator.withUsage(usage);
|
||||
// TODO
|
||||
if (!toolUseEventAggregator.isEmpty()) {
|
||||
toolUseEventAggregator.squashIntoContentBlock();
|
||||
return toolUseEventAggregator;
|
||||
}
|
||||
}
|
||||
|
||||
public final static class Builder {
|
||||
|
||||
private String role;
|
||||
|
||||
private String stopReason;
|
||||
|
||||
private Document additionalModelResponseFields;
|
||||
|
||||
private TokenUsage tokenUsage;
|
||||
|
||||
private ConverseStreamMetrics metrics;
|
||||
|
||||
private ConverseStreamTrace trace;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder copy(MetadataAggregation metadataAggregation) {
|
||||
this.role = metadataAggregation.role;
|
||||
this.stopReason = metadataAggregation.stopReason;
|
||||
this.additionalModelResponseFields = metadataAggregation.additionalModelResponseFields;
|
||||
this.tokenUsage = metadataAggregation.tokenUsage;
|
||||
this.metrics = metadataAggregation.metrics;
|
||||
this.trace = metadataAggregation.trace;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withRole(String role) {
|
||||
this.role = role;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withStopReason(String stopReason) {
|
||||
this.stopReason = stopReason;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withAdditionalModelResponseFields(Document additionalModelResponseFields) {
|
||||
this.additionalModelResponseFields = additionalModelResponseFields;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTokenUsage(TokenUsage tokenUsage) {
|
||||
this.tokenUsage = tokenUsage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withMetrics(ConverseStreamMetrics metrics) {
|
||||
this.metrics = metrics;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTrace(ConverseStreamTrace trace) {
|
||||
this.trace = trace;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MetadataAggregation build() {
|
||||
return new MetadataAggregation(role, stopReason, additionalModelResponseFields, tokenUsage, metrics,
|
||||
trace);
|
||||
}
|
||||
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -496,4 +341,164 @@ public class ConverseApiUtils {
|
||||
return Document.fromMap(attr);
|
||||
}
|
||||
|
||||
public record Aggregation(MetadataAggregation metadataAggregation, ChatResponse chatResponse) {
|
||||
public Aggregation() {
|
||||
this(MetadataAggregation.builder().build(), EMPTY_CHAT_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Special event used to aggregate multiple tool use events into a single event with
|
||||
* list of aggregated ContentBlockToolUse.
|
||||
*/
|
||||
public static class ToolUseAggregationEvent implements ConverseStreamOutput {
|
||||
|
||||
private Integer index;
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String partialJson = "";
|
||||
|
||||
private List<ToolUseEntry> toolUseEntries = new ArrayList<>();
|
||||
|
||||
private DefaultUsage usage;
|
||||
|
||||
public List<ToolUseEntry> toolUseEntries() {
|
||||
return this.toolUseEntries;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return (this.index == null || this.id == null || this.name == null
|
||||
|| !StringUtils.hasText(this.partialJson));
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent withIndex(Integer index) {
|
||||
this.index = index;
|
||||
return this;
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent withId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent withName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent withUsage(DefaultUsage usage) {
|
||||
this.usage = usage;
|
||||
return this;
|
||||
}
|
||||
|
||||
ToolUseAggregationEvent appendPartialJson(String partialJson) {
|
||||
this.partialJson = this.partialJson + partialJson;
|
||||
return this;
|
||||
}
|
||||
|
||||
void squashIntoContentBlock() {
|
||||
this.toolUseEntries.add(new ToolUseEntry(this.index, this.id, this.name, this.partialJson));
|
||||
this.index = null;
|
||||
this.id = null;
|
||||
this.name = null;
|
||||
this.partialJson = "";
|
||||
this.usage = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EventToolUseBuilder [index=" + this.index + ", id=" + this.id + ", name=" + this.name
|
||||
+ ", partialJson=" + this.partialJson + ", toolUseMap=" + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SdkField<?>> sdkFields() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Visitor visitor) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public record ToolUseEntry(Integer index, String id, String name, String input) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public record MetadataAggregation(String role, String stopReason, Document additionalModelResponseFields,
|
||||
TokenUsage tokenUsage, ConverseStreamMetrics metrics, ConverseStreamTrace trace) {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public final static class Builder {
|
||||
|
||||
private String role;
|
||||
|
||||
private String stopReason;
|
||||
|
||||
private Document additionalModelResponseFields;
|
||||
|
||||
private TokenUsage tokenUsage;
|
||||
|
||||
private ConverseStreamMetrics metrics;
|
||||
|
||||
private ConverseStreamTrace trace;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder copy(MetadataAggregation metadataAggregation) {
|
||||
this.role = metadataAggregation.role;
|
||||
this.stopReason = metadataAggregation.stopReason;
|
||||
this.additionalModelResponseFields = metadataAggregation.additionalModelResponseFields;
|
||||
this.tokenUsage = metadataAggregation.tokenUsage;
|
||||
this.metrics = metadataAggregation.metrics;
|
||||
this.trace = metadataAggregation.trace;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withRole(String role) {
|
||||
this.role = role;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withStopReason(String stopReason) {
|
||||
this.stopReason = stopReason;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withAdditionalModelResponseFields(Document additionalModelResponseFields) {
|
||||
this.additionalModelResponseFields = additionalModelResponseFields;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTokenUsage(TokenUsage tokenUsage) {
|
||||
this.tokenUsage = tokenUsage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withMetrics(ConverseStreamMetrics metrics) {
|
||||
this.metrics = metrics;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTrace(ConverseStreamTrace trace) {
|
||||
this.trace = trace;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MetadataAggregation build() {
|
||||
return new MetadataAggregation(this.role, this.stopReason, this.additionalModelResponseFields,
|
||||
this.tokenUsage, this.metrics, this.trace);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Copyright 2024 - 2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.bedrock.converse.api;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
@@ -27,7 +28,7 @@ import java.util.regex.Pattern;
|
||||
* @author Christian Tzolov
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class URLValidator {
|
||||
public final class URLValidator {
|
||||
|
||||
// Basic URL regex pattern
|
||||
// Protocol (http:// or https://)
|
||||
@@ -41,6 +42,10 @@ public class URLValidator {
|
||||
"(#[\\w-]*)?" + // Optional fragment
|
||||
"$");
|
||||
|
||||
private URLValidator() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick validation using regex pattern Good for basic checks but may not catch all
|
||||
* edge cases
|
||||
@@ -121,4 +126,4 @@ public class URLValidator {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2024-2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.ai.bedrock.converse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
@@ -31,6 +29,8 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
@@ -47,7 +47,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(classes = BedrockConverseTestConfiguration.class)
|
||||
@EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*")
|
||||
@@ -88,7 +88,7 @@ class BedrockConverseChatClientIT {
|
||||
.user(u -> u.text("List five {subject}")
|
||||
.param("subject", "ice cream flavors"))
|
||||
.call()
|
||||
.entity(new ParameterizedTypeReference<List<String>>() {});
|
||||
.entity(new ParameterizedTypeReference<List<String>>() { });
|
||||
// @formatter:on
|
||||
|
||||
logger.info(collection.toString());
|
||||
@@ -211,7 +211,7 @@ class BedrockConverseChatClientIT {
|
||||
|
||||
// @formatter:off
|
||||
String response = ChatClient.create(this.chatModel)
|
||||
.prompt("What's the weather like in San Francisco, Tokyo, and Paris? Return the temperature in Celsius.")
|
||||
.prompt("What's the weather like in San Francisco, Tokyo, and Paris? Return the temperature in Celsius.")
|
||||
.function("getCurrentWeather", "Get the weather in location", new MockWeatherService())
|
||||
.call()
|
||||
.content();
|
||||
|
||||
@@ -18,13 +18,13 @@ package org.springframework.ai.bedrock.converse;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
|
||||
import org.springframework.ai.model.function.FunctionCallingOptions;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
|
||||
@SpringBootConfiguration
|
||||
public class BedrockConverseTestConfiguration {
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.ai.bedrock.converse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -32,6 +30,8 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.chat.messages.AssistantMessage;
|
||||
import org.springframework.ai.chat.messages.Message;
|
||||
@@ -57,7 +57,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(classes = BedrockConverseTestConfiguration.class, properties = "spring.ai.retry.on-http-codes=429")
|
||||
@EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*")
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.ai.bedrock.converse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -45,6 +43,8 @@ import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for observation instrumentation in {@link BedrockProxyChatModel}.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2024-2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -65,7 +65,7 @@ public class MockWeatherService implements Function<MockWeatherService.Request,
|
||||
*/
|
||||
public final String unitName;
|
||||
|
||||
private Unit(String text) {
|
||||
Unit(String text) {
|
||||
this.unitName = text;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2024 - 2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -13,15 +13,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ai.bedrock.converse;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
|
||||
package org.springframework.ai.bedrock.converse;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
|
||||
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*")
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
/*
|
||||
* Copyright 2024 - 2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.bedrock.converse.experiements;
|
||||
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
|
||||
import org.springframework.ai.bedrock.converse.BedrockProxyChatModel;
|
||||
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
|
||||
/**
|
||||
* Used for reverse engineering the protocol.
|
||||
*
|
||||
@@ -29,7 +30,11 @@ import software.amazon.awssdk.regions.Region;
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
public class BedrockConverseChatModelMain {
|
||||
public final class BedrockConverseChatModelMain {
|
||||
|
||||
private BedrockConverseChatModelMain() {
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
@@ -1,37 +1,42 @@
|
||||
/*
|
||||
* Copyright 2024 - 2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.bedrock.converse.experiements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.bedrockruntime.model.ConverseStreamOutput;
|
||||
|
||||
import org.springframework.ai.bedrock.converse.BedrockProxyChatModel;
|
||||
import org.springframework.ai.bedrock.converse.MockWeatherService;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.ai.model.function.FunctionCallbackWrapper;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder.PortableFunctionCallingOptions;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.bedrockruntime.model.ConverseStreamOutput;
|
||||
|
||||
/**
|
||||
* Used for reverse engineering the protocol
|
||||
*/
|
||||
public class BedrockConverseChatModelMain2 {
|
||||
public final class BedrockConverseChatModelMain2 {
|
||||
|
||||
private BedrockConverseChatModelMain2() {
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
<developerConnection>git@github.com:spring-projects/spring-ai.git</developerConnection>
|
||||
</scm>
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
|
||||
<properties>
|
||||
<antlr.version>4.13.1</antlr.version>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck" />
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.imports.AvoidStaticImportCheck">
|
||||
<property name="excludes"
|
||||
value="org.springframework.ai.autoconfigure.vectorstore.observation.ObservationTestUtil.*, org.awaitility.Awaitility.*, org.springframework.ai.aot.AiRuntimeHints.*, org.springframework.ai.openai.metadata.support.OpenAiApiResponseHeaders.*, org.springframework.ai.image.observation.ImageModelObservationDocumentation.*, org.springframework.ai.embedding.observation.EmbeddingModelObservationDocumentation.*, org.springframework.aot.hint.predicate.RuntimeHintsPredicates.*, org.springframework.ai.vectorstore.filter.Filter.ExpressionType.*, org.springframework.ai.chat.observation.ChatModelObservationDocumentation.*, org.assertj.core.api.AssertionsForClassTypes.*, org.junit.jupiter.api.Assertions.*, org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.mockito.ArgumentMatchers.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo, org.springframework.test.web.client.match.MockRestRequestMatchers.*, org.springframework.test.web.client.response.MockRestResponseCreators.*, org.springframework.web.reactive.function.server.RequestPredicates.*, org.springframework.web.reactive.function.server.RouterFunctions.*, org.springframework.test.web.servlet.setup.MockMvcBuilders.*"/>
|
||||
value="org.springframework.ai.autoconfigure.vectorstore.observation.ObservationTestUtil.*, org.awaitility.Awaitility.*, org.springframework.ai.aot.AiRuntimeHints.*, org.springframework.ai.openai.metadata.support.OpenAiApiResponseHeaders.*, org.springframework.ai.image.observation.ImageModelObservationDocumentation.*, org.springframework.ai.embedding.observation.EmbeddingModelObservationDocumentation.*, org.springframework.aot.hint.predicate.RuntimeHintsPredicates.*, org.springframework.ai.vectorstore.filter.Filter.ExpressionType.*, org.springframework.ai.chat.observation.ChatModelObservationDocumentation.*, org.assertj.core.groups.Tuple.*, org.assertj.core.api.AssertionsForClassTypes.*, org.junit.jupiter.api.Assertions.*, org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.mockito.ArgumentMatchers.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo, org.springframework.test.web.client.match.MockRestRequestMatchers.*, org.springframework.test.web.client.response.MockRestResponseCreators.*, org.springframework.web.reactive.function.server.RequestPredicates.*, org.springframework.web.reactive.function.server.RouterFunctions.*, org.springframework.test.web.servlet.setup.MockMvcBuilders.*"/>
|
||||
</module>
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck" />
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck" />
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
<!-- testing -->
|
||||
<hikari-cp.version>4.0.3</hikari-cp.version>
|
||||
</properties>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<!-- testing -->
|
||||
<hikari-cp.version>4.0.3</hikari-cp.version>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
<jedis.version>5.1.0</jedis.version>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<disable.checks>false</disable.checks>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
Reference in New Issue
Block a user