Switch back to use slf4j logging

- Revert the changes to update to use Apache Commons Logging and re-add the previously used slf4j logging
This commit is contained in:
Ilayaperumal Gopinathan
2025-02-01 08:13:28 +00:00
committed by Mark Pollack
parent b86772d44c
commit 2932769883
199 changed files with 1064 additions and 815 deletions

View File

@@ -22,10 +22,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentReader;
@@ -33,7 +34,6 @@ import org.springframework.ai.reader.pdf.config.PdfDocumentReaderConfig;
import org.springframework.ai.reader.pdf.layout.PDFLayoutTextStripperByArea;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -55,10 +55,10 @@ public class PagePdfDocumentReader implements DocumentReader {
private static final String PDF_PAGE_REGION = "pdfPageRegion";
private static final LogAccessor logger = new LogAccessor(LogFactory.getLog(PagePdfDocumentReader.class));
protected final PDDocument document;
private final Logger logger = LoggerFactory.getLogger(getClass());
protected String resourceFileName;
private PdfDocumentReaderConfig config;
@@ -112,7 +112,7 @@ public class PagePdfDocumentReader implements DocumentReader {
for (PDPage page : this.document.getDocumentCatalog().getPages()) {
lastPage = page;
if (counter % logFrequency == 0 && counter / logFrequency < 10) {
logger.info("Processing PDF page: " + (counter + 1));
logger.info("Processing PDF page: {}", (counter + 1));
}
counter++;
@@ -154,7 +154,7 @@ public class PagePdfDocumentReader implements DocumentReader {
readDocuments.add(toDocument(lastPage, pageTextGroupList.stream().collect(Collectors.joining()),
startPageNumber, pageNumber));
}
logger.info("Processing " + totalPages + " pages");
logger.info("Processing {} pages", totalPages);
return readDocuments;
}

View File

@@ -23,6 +23,8 @@ import java.util.List;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentReader;
@@ -32,7 +34,6 @@ import org.springframework.ai.reader.pdf.config.PdfDocumentReaderConfig;
import org.springframework.ai.reader.pdf.layout.PDFLayoutTextStripperByArea;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -61,7 +62,7 @@ public class ParagraphPdfDocumentReader implements DocumentReader {
protected final PDDocument document;
private static final LogAccessor logger = new LogAccessor(ParagraphPdfDocumentReader.class);
private final Logger logger = LoggerFactory.getLogger(getClass());
private final ParagraphManager paragraphTextExtractor;

View File

@@ -77,6 +77,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -27,6 +27,8 @@ import java.util.stream.Collectors;
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;
@@ -65,7 +67,6 @@ import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -91,7 +92,7 @@ public class AnthropicChatModel extends AbstractToolCallSupport implements ChatM
public static final Double DEFAULT_TEMPERATURE = 0.8;
private static final LogAccessor logger = new LogAccessor(AnthropicChatModel.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicChatModel.class);
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();

View File

@@ -27,6 +27,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.anthropic.api.AnthropicApi;
@@ -57,7 +59,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.StringUtils;
@@ -68,7 +69,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "ANTHROPIC_API_KEY", matches = ".+")
class AnthropicChatModelIT {
private static final LogAccessor logger = new LogAccessor(AnthropicChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicChatModelIT.class);
@Autowired
protected ChatModel chatModel;
@@ -282,7 +283,7 @@ class AnthropicChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
Generation generation = response.getResult();
assertThat(generation).isNotNull();
@@ -321,7 +322,7 @@ class AnthropicChatModelIT {
.map(cr -> cr.getResult().getOutput().getText())
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}
@@ -346,7 +347,7 @@ class AnthropicChatModelIT {
ChatResponse chatResponse = responseFlux.last().block();
logger.info("Response: " + chatResponse);
logger.info("Response: {}", chatResponse);
Usage usage = chatResponse.getMetadata().getUsage();
assertThat(usage).isNotNull();

View File

@@ -23,10 +23,11 @@ import java.util.List;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.anthropic.api.AnthropicApi.StreamEvent;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class EventParsingTests {
private static final LogAccessor logger = new LogAccessor(EventParsingTests.class);
private static final Logger logger = LoggerFactory.getLogger(EventParsingTests.class);
@Test
public void readEvents() throws IOException {

View File

@@ -22,6 +22,8 @@ import java.util.function.Function;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.anthropic.api.AnthropicApi;
import org.springframework.ai.anthropic.api.AnthropicApi.AnthropicMessage;
@@ -34,7 +36,6 @@ import org.springframework.ai.anthropic.api.tool.XmlHelper.Tools;
import org.springframework.ai.anthropic.api.tool.XmlHelper.Tools.ToolDescription;
import org.springframework.ai.anthropic.api.tool.XmlHelper.Tools.ToolDescription.Parameter;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@@ -80,7 +81,7 @@ public class AnthropicApiLegacyToolIT {
public static final ConcurrentHashMap<String, Function> FUNCTIONS = new ConcurrentHashMap<>();
private static final LogAccessor logger = new LogAccessor(AnthropicApiLegacyToolIT.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicApiLegacyToolIT.class);
AnthropicApi anthropicApi = new AnthropicApi(System.getenv("ANTHROPIC_API_KEY"));

View File

@@ -23,6 +23,8 @@ import java.util.function.Function;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.anthropic.api.AnthropicApi;
import org.springframework.ai.anthropic.api.AnthropicApi.AnthropicMessage;
@@ -33,7 +35,6 @@ import org.springframework.ai.anthropic.api.AnthropicApi.ContentBlock.Type;
import org.springframework.ai.anthropic.api.AnthropicApi.Role;
import org.springframework.ai.anthropic.api.AnthropicApi.Tool;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
@@ -55,7 +56,7 @@ public class AnthropicApiToolIT {
public static final ConcurrentHashMap<String, Function> FUNCTIONS = new ConcurrentHashMap<>();
private static final LogAccessor logger = new LogAccessor(AnthropicApiToolIT.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicApiToolIT.class);
AnthropicApi anthropicApi = new AnthropicApi(System.getenv("ANTHROPIC_API_KEY"));

View File

@@ -28,6 +28,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.anthropic.AnthropicChatOptions;
@@ -48,7 +50,6 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.MimeTypeUtils;
@@ -59,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@ActiveProfiles("logging-test")
class AnthropicChatClientIT {
private static final LogAccessor logger = new LogAccessor(AnthropicChatClientIT.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicChatClientIT.class);
@Autowired
ChatModel chatModel;
@@ -218,7 +219,7 @@ class AnthropicChatClientIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -236,7 +237,7 @@ class AnthropicChatClientIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -257,7 +258,7 @@ class AnthropicChatClientIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -277,7 +278,7 @@ class AnthropicChatClientIT {
// @formatter:on
String content = response.collectList().block().stream().collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}
@@ -339,7 +340,7 @@ class AnthropicChatClientIT {
String content = response.collectList().block().stream().collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("bananas", "apple");
assertThat(content).containsAnyOf("bowl", "basket");
}

View File

@@ -23,6 +23,8 @@ import java.util.concurrent.ConcurrentHashMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.anthropic.AnthropicTestConfiguration;
import org.springframework.ai.chat.client.ChatClient;
@@ -34,7 +36,6 @@ import org.springframework.ai.tool.definition.ToolDefinition;
import org.springframework.ai.tool.method.MethodToolCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.log.LogAccessor;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.ReflectionUtils;
@@ -47,8 +48,8 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
@SuppressWarnings("null")
class AnthropicChatClientMethodInvokingFunctionCallbackIT {
private static final LogAccessor logger = new LogAccessor(
AnthropicChatClientMethodInvokingFunctionCallbackIT.class);
private static final Logger logger = LoggerFactory
.getLogger(AnthropicChatClientMethodInvokingFunctionCallbackIT.class);
public static Map<String, Object> arguments = new ConcurrentHashMap<>();
@@ -74,7 +75,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -98,7 +99,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -126,7 +127,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(arguments).containsEntry("roomName", "living room");
assertThat(arguments).containsEntry("on", true);
@@ -154,7 +155,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -181,7 +182,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
.call()
.content();
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
assertThat(arguments).containsEntry("tool", "value");
@@ -238,7 +239,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(arguments).containsEntry("turnLivingRoomLightOn", true);
}
@@ -256,7 +257,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response:" + response);
logger.info("Response: {}", response);
assertThat(arguments).containsEntry("roomName", "living room")
.containsEntry("color", TestFunctionClass.LightColor.RED);
@@ -318,7 +319,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
public void turnLight(String roomName, boolean on) {
arguments.put("roomName", roomName);
arguments.put("on", on);
logger.info("Turn light in room: " + roomName + " to: " + on);
logger.info("Turn light in room: {} to: {}", roomName, on);
}
public void turnLivingRoomLightOn() {
@@ -335,7 +336,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
public void changeRoomLightColor(String roomName, LightColor color) {
arguments.put("roomName", roomName);
arguments.put("color", color);
logger.info("Change light colur in room: " + roomName + " to color: " + color);
logger.info("Change light colur in room: {} to color: {}", roomName, color);
}
}

View File

@@ -59,6 +59,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -25,6 +25,8 @@ import com.azure.ai.openai.models.Embeddings;
import com.azure.ai.openai.models.EmbeddingsOptions;
import com.azure.ai.openai.models.EmbeddingsUsage;
import io.micrometer.observation.ObservationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.metadata.DefaultUsage;
import org.springframework.ai.document.Document;
@@ -40,7 +42,6 @@ import org.springframework.ai.embedding.observation.EmbeddingModelObservationCon
import org.springframework.ai.embedding.observation.EmbeddingModelObservationDocumentation;
import org.springframework.ai.model.EmbeddingUtils;
import org.springframework.ai.observation.conventions.AiProvider;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -54,7 +55,7 @@ import org.springframework.util.CollectionUtils;
*/
public class AzureOpenAiEmbeddingModel extends AbstractEmbeddingModel {
private static final LogAccessor logger = new LogAccessor(AzureOpenAiEmbeddingModel.class);
private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiEmbeddingModel.class);
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();

View File

@@ -29,6 +29,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.azure.openai.metadata.AzureOpenAiImageGenerationMetadata;
import org.springframework.ai.azure.openai.metadata.AzureOpenAiImageResponseMetadata;
@@ -40,7 +42,6 @@ import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.image.ImageResponseMetadata;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.util.JacksonUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.Assert;
/**
@@ -57,7 +58,7 @@ public class AzureOpenAiImageModel implements ImageModel {
private static final String DEFAULT_DEPLOYMENT_NAME = AzureOpenAiImageOptions.DEFAULT_IMAGE_MODEL;
private final LogAccessor logger = new LogAccessor(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
private final OpenAIClient openAIClient;
@@ -90,14 +91,14 @@ public class AzureOpenAiImageModel implements ImageModel {
ImageGenerationOptions imageGenerationOptions = toOpenAiImageOptions(imagePrompt);
String deploymentOrModelName = getDeploymentName(imagePrompt);
if (logger.isTraceEnabled()) {
logger.trace("Azure ImageGenerationOptions call " + deploymentOrModelName + " with the following options : "
+ toPrettyJson(imageGenerationOptions));
logger.trace("Azure ImageGenerationOptions call {} with the following options : {} ", deploymentOrModelName,
toPrettyJson(imageGenerationOptions));
}
var images = this.openAIClient.getImageGenerations(deploymentOrModelName, imageGenerationOptions);
if (logger.isTraceEnabled()) {
logger.trace("Azure ImageGenerations: " + toPrettyJson(images));
logger.trace("Azure ImageGenerations: {}", toPrettyJson(images));
}
List<ImageGeneration> imageGenerations = images.getData().stream().map(entry -> {

View File

@@ -29,6 +29,8 @@ import com.azure.ai.openai.OpenAIServiceVersion;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.http.policy.HttpLogOptions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -49,7 +51,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -58,7 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RequiresAzureCredentials
class AzureOpenAiChatModelIT {
private static final LogAccessor logger = new LogAccessor(AzureOpenAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiChatModelIT.class);
@Autowired
private AzureOpenAiChatModel chatModel;

View File

@@ -30,6 +30,8 @@ import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import okio.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
@@ -37,7 +39,6 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.log.LogAccessor;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
@@ -205,7 +206,7 @@ public class MockAiTestConfiguration {
*/
static class MockWebServerFactoryBean implements FactoryBean<MockWebServer>, InitializingBean, DisposableBean {
private final LogAccessor logger = new LogAccessor(getClass().getName());
private final Logger logger = LoggerFactory.getLogger(getClass().getName());
private final Queue<MockResponse> queuedResponses = new ConcurrentLinkedDeque<>();
@@ -221,7 +222,7 @@ public class MockAiTestConfiguration {
this.dispatcher = dispatcher;
}
protected LogAccessor getLogger() {
protected Logger getLogger() {
return logger;
}
@@ -255,8 +256,8 @@ public class MockAiTestConfiguration {
this.mockWebServer.shutdown();
}
catch (IOException e) {
getLogger().warn("MockWebServer was not shutdown correctly: " + e.getMessage());
getLogger().trace(e, "MockWebServer shutdown failure");
getLogger().warn("MockWebServer was not shutdown correctly: {}", e.getMessage());
getLogger().trace("MockWebServer shutdown failure", e);
}
}

View File

@@ -27,6 +27,8 @@ import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.ai.openai.models.ChatCompletionStreamOptions;
import com.azure.core.credential.AzureKeyCredential;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.azure.openai.AzureOpenAiChatModel;
@@ -43,7 +45,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RequiresAzureCredentials
class AzureOpenAiChatModelFunctionCallIT {
private static final LogAccessor logger = new LogAccessor(AzureOpenAiChatModelFunctionCallIT.class);
private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiChatModelFunctionCallIT.class);
@Autowired
private String selectedModel;
@@ -77,7 +78,7 @@ class AzureOpenAiChatModelFunctionCallIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult()).isNotNull();
assertThat(response.getResult().getOutput()).isNotNull();
@@ -105,7 +106,7 @@ class AzureOpenAiChatModelFunctionCallIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -136,7 +137,7 @@ class AzureOpenAiChatModelFunctionCallIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(counter.get()).isGreaterThan(30).as("The response should be chunked in more than 30 messages");
@@ -165,7 +166,7 @@ class AzureOpenAiChatModelFunctionCallIT {
Flux<ChatResponse> response = this.chatModel.stream(new Prompt(messages, promptOptions));
ChatResponse chatResponse = response.last().block();
logger.info("Response: " + chatResponse);
logger.info("Response: {}", chatResponse);
assertThat(chatResponse.getMetadata().getUsage().getTotalTokens()).isGreaterThan(600).isLessThan(800);
@@ -201,7 +202,7 @@ class AzureOpenAiChatModelFunctionCallIT {
.filter(Objects::nonNull)
.collect(Collectors.joining());
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(content).contains("30", "10", "15");
}

View File

@@ -32,6 +32,8 @@ import java.util.Set;
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;
@@ -99,7 +101,6 @@ import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.ai.observation.conventions.AiProvider;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StreamUtils;
@@ -133,7 +134,7 @@ import org.springframework.util.StringUtils;
*/
public class BedrockProxyChatModel extends AbstractToolCallSupport implements ChatModel {
private static final LogAccessor logger = new LogAccessor(BedrockProxyChatModel.class);
private static final Logger logger = LoggerFactory.getLogger(BedrockProxyChatModel.class);
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
@@ -199,7 +200,7 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
ConverseResponse converseResponse = this.bedrockRuntimeClient.converse(converseRequest);
logger.debug("ConverseResponse: " + converseResponse);
logger.debug("ConverseResponse: {}", converseResponse);
var response = this.toChatResponse(converseResponse, perviousChatResponse);
@@ -654,7 +655,7 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
ConverseStreamResponseHandler.Visitor visitor = ConverseStreamResponseHandler.Visitor.builder()
.onDefault(output -> {
logger.debug("Received converse stream output: " + output);
logger.debug("Received converse stream output:{}", output);
eventSink.emitNext(output, DEFAULT_EMIT_FAILURE_HANDLER);
})
.build();
@@ -666,7 +667,7 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
logger.info("Completed streaming response.");
})
.onError(error -> {
logger.error(error, "Error handling Bedrock converse stream response");
logger.error("Error handling Bedrock converse stream response", error);
eventSink.emitError(error, DEFAULT_EMIT_FAILURE_HANDLER);
})
.build();

View File

@@ -26,6 +26,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
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;
@@ -43,7 +45,6 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RequiresAwsCredentials
class BedrockConverseChatClientIT {
private static final LogAccessor logger = new LogAccessor(BedrockConverseChatClientIT.class);
private static final Logger logger = LoggerFactory.getLogger(BedrockConverseChatClientIT.class);
@Value("classpath:/prompts/system-message.st")
private Resource systemTextResource;
@@ -218,7 +219,7 @@ class BedrockConverseChatClientIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -252,7 +253,7 @@ class BedrockConverseChatClientIT {
assertThat(metadata.getUsage().getTotalTokens())
.isEqualTo(metadata.getUsage().getPromptTokens() + metadata.getUsage().getCompletionTokens());
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -272,7 +273,7 @@ class BedrockConverseChatClientIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -293,7 +294,7 @@ class BedrockConverseChatClientIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -334,7 +335,7 @@ class BedrockConverseChatClientIT {
.filter(cr -> cr.getResult() != null)
.map(cr -> cr.getResult().getOutput().getText())
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}
@@ -354,7 +355,7 @@ class BedrockConverseChatClientIT {
// @formatter:on
String content = response.collectList().block().stream().collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("15");
}
@@ -414,7 +415,7 @@ class BedrockConverseChatClientIT {
String content = response.collectList().block().stream().collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("bananas", "apple");
assertThat(content).containsAnyOf("bowl", "basket");
}

View File

@@ -27,6 +27,8 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
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;
@@ -52,7 +54,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -61,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RequiresAwsCredentials
class BedrockProxyChatModelIT {
private static final LogAccessor logger = new LogAccessor(BedrockProxyChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(BedrockProxyChatModelIT.class);
@Autowired
protected ChatModel chatModel;
@@ -261,7 +262,7 @@ class BedrockProxyChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
Generation generation = response.getResult();
assertThat(generation.getOutput().getText()).contains("30", "10", "15");
@@ -296,7 +297,7 @@ class BedrockProxyChatModelIT {
.map(cr -> cr.getResult().getOutput().getText())
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}

View File

@@ -21,6 +21,8 @@ import java.time.Duration;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
import software.amazon.awssdk.regions.Region;
@@ -36,7 +38,6 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
@@ -49,7 +50,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@RequiresAwsCredentials
public class BedrockNovaChatClientIT {
private static final LogAccessor logger = new LogAccessor(BedrockNovaChatClientIT.class);
private static final Logger logger = LoggerFactory.getLogger(BedrockNovaChatClientIT.class);
@Autowired
ChatModel chatModel;
@@ -165,7 +166,7 @@ public class BedrockNovaChatClientIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}

View File

@@ -27,6 +27,8 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import reactor.core.publisher.Sinks.EmitFailureHandler;
@@ -43,7 +45,6 @@ import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelWithRespo
import software.amazon.awssdk.services.bedrockruntime.model.ResponseStream;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.Assert;
/**
@@ -66,7 +67,7 @@ import org.springframework.util.Assert;
*/
public abstract class AbstractBedrockApi<I, O, SO> {
private static final LogAccessor logger = new LogAccessor(AbstractBedrockApi.class);
private static final Logger logger = LoggerFactory.getLogger(AbstractBedrockApi.class);
/**
* Default emit failure handler.
@@ -289,7 +290,7 @@ public abstract class AbstractBedrockApi<I, O, SO> {
eventSink.emitNext(response, DEFAULT_EMIT_FAILURE_HANDLER);
}
catch (Exception e) {
logger.error(e, "Failed to unmarshall");
logger.error("Failed to unmarshall", e);
eventSink.emitError(e, DEFAULT_EMIT_FAILURE_HANDLER);
}
})

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023-2025 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.
@@ -20,7 +20,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.bedrock.titan.api.TitanEmbeddingBedrockApi;
import org.springframework.ai.bedrock.titan.api.TitanEmbeddingBedrockApi.TitanEmbeddingRequest;
@@ -31,7 +32,6 @@ import org.springframework.ai.embedding.Embedding;
import org.springframework.ai.embedding.EmbeddingOptions;
import org.springframework.ai.embedding.EmbeddingRequest;
import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.Assert;
/**
@@ -47,7 +47,7 @@ import org.springframework.util.Assert;
*/
public class BedrockTitanEmbeddingModel extends AbstractEmbeddingModel {
private static final LogAccessor logger = new LogAccessor(LogFactory.getLog(BedrockTitanEmbeddingModel.class));
private final Logger logger = LoggerFactory.getLogger(getClass());
private final TitanEmbeddingBedrockApi embeddingApi;

View File

@@ -72,6 +72,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -60,6 +60,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -26,6 +26,8 @@ import java.util.concurrent.ConcurrentHashMap;
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;
@@ -64,7 +66,6 @@ import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -83,7 +84,7 @@ import org.springframework.util.CollectionUtils;
*/
public class MiniMaxChatModel extends AbstractToolCallSupport implements ChatModel, StreamingChatModel {
private static final LogAccessor logger = new LogAccessor(MiniMaxChatModel.class);
private static final Logger logger = LoggerFactory.getLogger(MiniMaxChatModel.class);
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
@@ -228,14 +229,14 @@ public class MiniMaxChatModel extends AbstractToolCallSupport implements ChatMod
var chatCompletion = completionEntity.getBody();
if (chatCompletion == null) {
logger.warn("No chat completion returned for prompt: " + prompt);
logger.warn("No chat completion returned for prompt: {}", prompt);
return new ChatResponse(List.of());
}
List<Choice> choices = chatCompletion.choices();
if (choices == null) {
logger.warn("No choices returned for prompt: " + prompt + ", because: "
+ chatCompletion.baseResponse().message());
logger.warn("No choices returned for prompt: {}, because: {}}", prompt,
chatCompletion.baseResponse().message());
return new ChatResponse(List.of());
}
@@ -328,7 +329,7 @@ public class MiniMaxChatModel extends AbstractToolCallSupport implements ChatMod
return new ChatResponse(generations, from(chatCompletion2));
}
catch (Exception e) {
logger.error(e, "Error processing chat completion");
logger.error("Error processing chat completion", e);
return new ChatResponse(List.of());
}
}));

View File

@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.List;
import io.micrometer.observation.ObservationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.metadata.DefaultUsage;
import org.springframework.ai.document.Document;
@@ -38,7 +40,6 @@ import org.springframework.ai.minimax.api.MiniMaxApi;
import org.springframework.ai.minimax.api.MiniMaxApiConstants;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.lang.Nullable;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -52,7 +53,7 @@ import org.springframework.util.Assert;
*/
public class MiniMaxEmbeddingModel extends AbstractEmbeddingModel {
private static final LogAccessor logger = new LogAccessor(MiniMaxEmbeddingModel.class);
private static final Logger logger = LoggerFactory.getLogger(MiniMaxEmbeddingModel.class);
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
@@ -166,7 +167,7 @@ public class MiniMaxEmbeddingModel extends AbstractEmbeddingModel {
.execute(ctx -> this.miniMaxApi.embeddings(apiRequest).getBody());
if (apiEmbeddingResponse == null) {
logger.warn("No embeddings returned for request: " + request);
logger.warn("No embeddings returned for request: {}", request);
return new EmbeddingResponse(List.of());
}

View File

@@ -24,6 +24,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletion;
import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionMessage;
@@ -31,7 +33,6 @@ import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionMessage.Role;
import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionMessage.ToolCall;
import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionRequest;
import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionRequest.ToolChoiceBuilder;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".+")
public class MiniMaxApiToolFunctionCallIT {
private static final LogAccessor logger = new LogAccessor(MiniMaxApiToolFunctionCallIT.class);
private final Logger logger = LoggerFactory.getLogger(MiniMaxApiToolFunctionCallIT.class);
MockWeatherService weatherService = new MockWeatherService();

View File

@@ -23,6 +23,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -34,7 +36,6 @@ import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.minimax.MiniMaxChatModel;
import org.springframework.ai.minimax.MiniMaxChatOptions;
import org.springframework.ai.minimax.api.MiniMaxApi;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -44,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".+")
public class MiniMaxChatOptionsTests {
private static final LogAccessor logger = new LogAccessor(MiniMaxChatOptionsTests.class);
private static final Logger logger = LoggerFactory.getLogger(MiniMaxChatOptionsTests.class);
private final MiniMaxChatModel chatModel = new MiniMaxChatModel(new MiniMaxApi(System.getenv("MINIMAX_API_KEY")));
@@ -134,7 +135,7 @@ public class MiniMaxChatOptionsTests {
.map(AssistantMessage::getText)
.filter(Objects::nonNull)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("40");
}

View File

@@ -61,6 +61,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -27,6 +27,8 @@ import java.util.concurrent.ConcurrentHashMap;
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;
@@ -64,7 +66,6 @@ import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -87,7 +88,7 @@ public class MistralAiChatModel extends AbstractToolCallSupport implements ChatM
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
private final LogAccessor logger = new LogAccessor(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
/**
* The default options used for the chat completion requests.
@@ -202,7 +203,7 @@ public class MistralAiChatModel extends AbstractToolCallSupport implements ChatM
ChatCompletion chatCompletion = completionEntity.getBody();
if (chatCompletion == null) {
logger.warn("No chat completion returned for prompt: " + prompt);
logger.warn("No chat completion returned for prompt: {}", prompt);
return new ChatResponse(List.of());
}
@@ -299,7 +300,7 @@ public class MistralAiChatModel extends AbstractToolCallSupport implements ChatM
}
}
catch (Exception e) {
logger.error(e, "Error processing chat completion");
logger.error("Error processing chat completion", e);
return new ChatResponse(List.of());
}
}));

View File

@@ -19,6 +19,8 @@ package org.springframework.ai.mistralai;
import java.util.List;
import io.micrometer.observation.ObservationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.metadata.DefaultUsage;
import org.springframework.ai.document.Document;
@@ -37,7 +39,6 @@ import org.springframework.ai.embedding.observation.EmbeddingModelObservationDoc
import org.springframework.ai.mistralai.api.MistralAiApi;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -51,7 +52,7 @@ import org.springframework.util.Assert;
*/
public class MistralAiEmbeddingModel extends AbstractEmbeddingModel {
private static final LogAccessor logger = new LogAccessor(MistralAiEmbeddingModel.class);
private static final Logger logger = LoggerFactory.getLogger(MistralAiEmbeddingModel.class);
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
@@ -125,7 +126,7 @@ public class MistralAiEmbeddingModel extends AbstractEmbeddingModel {
.execute(ctx -> this.mistralAiApi.embeddings(apiRequest).getBody());
if (apiEmbeddingResponse == null) {
logger.warn("No embeddings returned for request: " + request);
logger.warn("No embeddings returned for request: {}", request);
return new EmbeddingResponse(List.of());
}

View File

@@ -23,6 +23,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -39,7 +41,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "MISTRAL_AI_API_KEY", matches = ".+")
class MistralAiChatClientIT {
private static final LogAccessor logger = new LogAccessor(MistralAiChatClientIT.class);
private static final Logger logger = LoggerFactory.getLogger(MistralAiChatClientIT.class);
@Autowired
MistralAiChatModel chatModel;
@@ -232,7 +233,7 @@ class MistralAiChatClientIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).containsAnyOf("30.0", "30");
assertThat(response).containsAnyOf("10.0", "10");
@@ -254,7 +255,7 @@ class MistralAiChatClientIT {
.prompt().call().content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).containsAnyOf("30.0", "30");
assertThat(response).containsAnyOf("10.0", "10");
@@ -277,7 +278,7 @@ class MistralAiChatClientIT {
// @formatter:on
String content = response.collectList().block().stream().collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).containsAnyOf("30.0", "30");
assertThat(content).containsAnyOf("10.0", "10");

View File

@@ -28,6 +28,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -54,7 +56,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -69,7 +70,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "MISTRAL_AI_API_KEY", matches = ".+")
class MistralAiChatModelIT {
private static final LogAccessor logger = new LogAccessor(MistralAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(MistralAiChatModelIT.class);
@Autowired
protected ChatModel chatModel;
@@ -212,7 +213,7 @@ class MistralAiChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).containsAnyOf("30.0", "30");
assertThat(response.getMetadata()).isNotNull();
@@ -245,7 +246,7 @@ class MistralAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).containsAnyOf("10.0", "10");
}
@@ -302,7 +303,7 @@ class MistralAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("bananas", "apple");
assertThat(content).containsAnyOf("bowl", "basket", "fruit stand");
}
@@ -325,7 +326,7 @@ class MistralAiChatModelIT {
Flux<ChatResponse> response = this.streamingChatModel.stream(new Prompt(messages, promptOptions));
ChatResponse chatResponse = response.last().block();
logger.info("Response: " + chatResponse);
logger.info("Response: {}", chatResponse);
assertThat(chatResponse.getMetadata()).isNotNull();
assertThat(chatResponse.getMetadata().getUsage()).isNotNull();
assertThat(chatResponse.getMetadata().getUsage().getTotalTokens()).isLessThan(1050).isGreaterThan(750);

View File

@@ -23,6 +23,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.mistralai.api.MistralAiApi;
import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletion;
@@ -33,7 +35,6 @@ import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletionRequest;
import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletionRequest.ToolChoice;
import org.springframework.ai.mistralai.api.MistralAiApi.FunctionTool.Type;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ObjectUtils;
@@ -48,7 +49,7 @@ public class MistralAiApiToolFunctionCallIT {
static final String MISTRAL_AI_CHAT_MODEL = MistralAiApi.ChatModel.LARGE.getValue();
private final LogAccessor logger = new LogAccessor(MistralAiApiToolFunctionCallIT.class);
private final Logger logger = LoggerFactory.getLogger(MistralAiApiToolFunctionCallIT.class);
MockWeatherService weatherService = new MockWeatherService();

View File

@@ -26,6 +26,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.mistralai.api.MistralAiApi;
import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletion;
@@ -36,7 +38,6 @@ import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletionRequest;
import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletionRequest.ToolChoice;
import org.springframework.ai.mistralai.api.MistralAiApi.FunctionTool;
import org.springframework.ai.mistralai.api.MistralAiApi.FunctionTool.Type;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@@ -63,7 +64,7 @@ public class PaymentStatusFunctionCallingIT {
static Map<String, Function<Transaction, ?>> functions = Map.of("retrieve_payment_status",
new RetrievePaymentStatus(), "retrieve_payment_date", new RetrievePaymentDate());
private final LogAccessor logger = new LogAccessor(PaymentStatusFunctionCallingIT.class);
private final Logger logger = LoggerFactory.getLogger(PaymentStatusFunctionCallingIT.class);
private static <T> T jsonToObject(String json, Class<T> targetClass) {
try {

View File

@@ -61,6 +61,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -25,6 +25,8 @@ import java.util.concurrent.ConcurrentHashMap;
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;
@@ -65,7 +67,6 @@ import org.springframework.ai.moonshot.api.MoonshotApi.ChatCompletionRequest;
import org.springframework.ai.moonshot.api.MoonshotApi.FunctionTool;
import org.springframework.ai.moonshot.api.MoonshotConstants;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -80,7 +81,7 @@ import org.springframework.util.CollectionUtils;
*/
public class MoonshotChatModel extends AbstractToolCallSupport implements ChatModel, StreamingChatModel {
private static final LogAccessor logger = new LogAccessor(MoonshotChatModel.class);
private static final Logger logger = LoggerFactory.getLogger(MoonshotChatModel.class);
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
@@ -204,13 +205,13 @@ public class MoonshotChatModel extends AbstractToolCallSupport implements ChatMo
var chatCompletion = completionEntity.getBody();
if (chatCompletion == null) {
logger.warn("No chat completion returned for prompt: " + prompt);
logger.warn("No chat completion returned for prompt: {}", prompt);
return new ChatResponse(List.of());
}
List<Choice> choices = chatCompletion.choices();
if (choices == null) {
logger.warn("No choices returned for prompt: " + prompt);
logger.warn("No choices returned for prompt: {}", prompt);
return new ChatResponse(List.of());
}
@@ -311,7 +312,7 @@ public class MoonshotChatModel extends AbstractToolCallSupport implements ChatMo
return new ChatResponse(generations, from(chatCompletion2, cumulativeUsage));
}
catch (Exception e) {
logger.error(e, "Error processing chat completion");
logger.error("Error processing chat completion", e);
return new ChatResponse(List.of());
}

View File

@@ -24,6 +24,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.moonshot.api.MoonshotApi.ChatCompletion;
import org.springframework.ai.moonshot.api.MoonshotApi.ChatCompletionMessage;
@@ -33,7 +35,6 @@ import org.springframework.ai.moonshot.api.MoonshotApi.ChatCompletionRequest;
import org.springframework.ai.moonshot.api.MoonshotApi.ChatCompletionRequest.ToolChoiceBuilder;
import org.springframework.ai.moonshot.api.MoonshotApi.FunctionTool;
import org.springframework.ai.moonshot.api.MoonshotApi.FunctionTool.Type;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@@ -70,7 +71,7 @@ public class MoonshotApiToolFunctionCallIT {
}
"""));
private static final LogAccessor logger = new LogAccessor(MoonshotApiToolFunctionCallIT.class);
private final Logger logger = LoggerFactory.getLogger(MoonshotApiToolFunctionCallIT.class);
private final MockWeatherService weatherService = new MockWeatherService();

View File

@@ -24,6 +24,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -40,7 +42,6 @@ import org.springframework.ai.moonshot.api.MockWeatherService;
import org.springframework.ai.moonshot.api.MoonshotApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -48,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "MOONSHOT_API_KEY", matches = ".+")
class MoonshotChatModelFunctionCallingIT {
private static final LogAccessor logger = new LogAccessor(MoonshotChatModelFunctionCallingIT.class);
private static final Logger logger = LoggerFactory.getLogger(MoonshotChatModelFunctionCallingIT.class);
@Autowired
ChatModel chatModel;
@@ -99,7 +100,7 @@ class MoonshotChatModelFunctionCallingIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -131,7 +132,7 @@ class MoonshotChatModelFunctionCallingIT {
.map(AssistantMessage::getText)
.filter(Objects::nonNull)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}

View File

@@ -23,6 +23,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.messages.Message;
@@ -43,7 +45,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -54,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "MOONSHOT_API_KEY", matches = ".+")
public class MoonshotChatModelIT {
private static final LogAccessor logger = new LogAccessor(MoonshotChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(MoonshotChatModelIT.class);
@Autowired
protected ChatModel chatModel;

View File

@@ -65,6 +65,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -69,6 +69,11 @@
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -18,13 +18,14 @@ package org.springframework.ai.ollama.management;
import java.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.util.retry.Retry;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.ollama.api.OllamaApi.DeleteModelRequest;
import org.springframework.ai.ollama.api.OllamaApi.ListModelResponse;
import org.springframework.ai.ollama.api.OllamaApi.PullModelRequest;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -37,7 +38,7 @@ import org.springframework.util.CollectionUtils;
*/
public class OllamaModelManager {
private static final LogAccessor logger = new LogAccessor(OllamaModelManager.class);
private final Logger logger = LoggerFactory.getLogger(OllamaModelManager.class);
private final OllamaApi ollamaApi;
@@ -80,13 +81,13 @@ public class OllamaModelManager {
}
public void deleteModel(String modelName) {
logger.info("Start deletion of model: " + modelName);
logger.info("Start deletion of model: {}", modelName);
if (!isModelAvailable(modelName)) {
logger.info("Model " + modelName + " not found");
logger.info("Model {} not found", modelName);
return;
}
this.ollamaApi.deleteModel(new DeleteModelRequest(modelName));
logger.info("Completed deletion of model: " + modelName);
logger.info("Completed deletion of model: {}", modelName);
}
public void pullModel(String modelName) {
@@ -100,20 +101,20 @@ public class OllamaModelManager {
if (PullModelStrategy.WHEN_MISSING.equals(pullModelStrategy)) {
if (isModelAvailable(modelName)) {
logger.debug("Model '" + modelName + "' already available. Skipping pull operation.");
logger.debug("Model '{}' already available. Skipping pull operation.", modelName);
return;
}
}
// @formatter:off
logger.info("Start pulling model: "+ modelName);
logger.info("Start pulling model: {}", modelName);
this.ollamaApi.pullModel(new PullModelRequest(modelName))
.bufferUntilChanged(OllamaApi.ProgressResponse::status)
.doOnEach(signal -> {
var progressResponses = signal.get();
if (!CollectionUtils.isEmpty(progressResponses) && progressResponses.get(progressResponses.size() - 1) != null) {
logger.info("Pulling the '"+ modelName +"' model - Status: "+ progressResponses.get(progressResponses.size() - 1).status());
logger.info("Pulling the '{}' model - Status: {}", modelName, progressResponses.get(progressResponses.size() - 1).status());
}
})
.takeUntil(progressResponses ->
@@ -121,7 +122,7 @@ public class OllamaModelManager {
.timeout(this.options.timeout())
.retryWhen(Retry.backoff(this.options.maxRetries(), Duration.ofSeconds(5)))
.blockLast();
logger.info("Completed pulling the '"+ modelName +"' model");
logger.info("Completed pulling the '{}' model", modelName);
// @formatter:on
}

View File

@@ -21,6 +21,8 @@ import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -38,14 +40,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = OllamaChatModelFunctionCallingIT.Config.class)
class OllamaChatModelFunctionCallingIT extends BaseOllamaIT {
private static final LogAccessor logger = new LogAccessor(OllamaChatModelFunctionCallingIT.class);
private static final Logger logger = LoggerFactory.getLogger(OllamaChatModelFunctionCallingIT.class);
private static final String MODEL = "qwen2.5:3b";
@@ -70,7 +71,7 @@ class OllamaChatModelFunctionCallingIT extends BaseOllamaIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -101,7 +102,7 @@ class OllamaChatModelFunctionCallingIT extends BaseOllamaIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}

View File

@@ -19,6 +19,8 @@ package org.springframework.ai.ollama;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
@@ -30,7 +32,6 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,7 +40,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
@SpringBootTest
class OllamaChatModelMultimodalIT extends BaseOllamaIT {
private static final LogAccessor logger = new LogAccessor(OllamaChatModelMultimodalIT.class);
private static final Logger logger = LoggerFactory.getLogger(OllamaChatModelMultimodalIT.class);
private static final String MODEL = "llava-phi3";

View File

@@ -23,6 +23,8 @@ import java.util.Map;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.ollama.BaseOllamaIT;
@@ -31,7 +33,6 @@ import org.springframework.ai.ollama.api.OllamaApi.ChatResponse;
import org.springframework.ai.ollama.api.OllamaApi.Message;
import org.springframework.ai.ollama.api.OllamaApi.Message.Role;
import org.springframework.ai.ollama.api.OllamaApi.Message.ToolCall;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -43,7 +44,7 @@ public class OllamaApiToolFunctionCallIT extends BaseOllamaIT {
private static final String MODEL = "qwen2.5:3b";
private static final LogAccessor logger = new LogAccessor(OllamaApiToolFunctionCallIT.class);
private static final Logger logger = LoggerFactory.getLogger(OllamaApiToolFunctionCallIT.class);
static OllamaApi ollamaApi;

View File

@@ -76,6 +76,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -17,6 +17,8 @@
package org.springframework.ai.openai;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.metadata.RateLimit;
@@ -30,7 +32,6 @@ import org.springframework.ai.openai.audio.speech.StreamingSpeechModel;
import org.springframework.ai.openai.metadata.audio.OpenAiAudioSpeechResponseMetadata;
import org.springframework.ai.openai.metadata.support.OpenAiResponseHeaderExtractor;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -52,7 +53,7 @@ public class OpenAiAudioSpeechModel implements SpeechModel, StreamingSpeechModel
*/
private static final Float SPEED = 1.0f;
private final LogAccessor logger = new LogAccessor(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
/**
* The default options used for the audio completion requests.
@@ -131,7 +132,7 @@ public class OpenAiAudioSpeechModel implements SpeechModel, StreamingSpeechModel
var speech = speechEntity.getBody();
if (speech == null) {
logger.warn("No speech response returned for speechRequest: " + speechRequest);
logger.warn("No speech response returned for speechRequest: {}", speechRequest);
return new SpeechResponse(new Speech(new byte[0]));
}

View File

@@ -16,6 +16,9 @@
package org.springframework.ai.openai;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.audio.transcription.AudioTranscription;
import org.springframework.ai.audio.transcription.AudioTranscriptionPrompt;
import org.springframework.ai.audio.transcription.AudioTranscriptionResponse;
@@ -27,7 +30,6 @@ import org.springframework.ai.openai.metadata.audio.OpenAiAudioTranscriptionResp
import org.springframework.ai.openai.metadata.support.OpenAiResponseHeaderExtractor;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -45,7 +47,7 @@ import org.springframework.util.Assert;
*/
public class OpenAiAudioTranscriptionModel implements Model<AudioTranscriptionPrompt, AudioTranscriptionResponse> {
private static final LogAccessor logger = new LogAccessor(OpenAiAudioTranscriptionModel.class);
private final Logger logger = LoggerFactory.getLogger(getClass());
private final OpenAiAudioTranscriptionOptions defaultOptions;
@@ -116,7 +118,7 @@ public class OpenAiAudioTranscriptionModel implements Model<AudioTranscriptionPr
var transcription = transcriptionEntity.getBody();
if (transcription == null) {
logger.warn("No transcription returned for request: " + audioResource);
logger.warn("No transcription returned for request: {}", audioResource);
return new AudioTranscriptionResponse(null);
}
@@ -137,7 +139,7 @@ public class OpenAiAudioTranscriptionModel implements Model<AudioTranscriptionPr
var transcription = transcriptionEntity.getBody();
if (transcription == null) {
logger.warn("No transcription returned for request: " + audioResource);
logger.warn("No transcription returned for request: {}", audioResource);
return new AudioTranscriptionResponse(null);
}

View File

@@ -29,6 +29,8 @@ import java.util.stream.Collectors;
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;
@@ -74,7 +76,6 @@ import org.springframework.ai.openai.metadata.support.OpenAiResponseHeaderExtrac
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -107,7 +108,7 @@ import org.springframework.util.StringUtils;
*/
public class OpenAiChatModel extends AbstractToolCallSupport implements ChatModel {
private static final LogAccessor logger = new LogAccessor(OpenAiChatModel.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatModel.class);
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
@@ -240,13 +241,13 @@ public class OpenAiChatModel extends AbstractToolCallSupport implements ChatMode
var chatCompletion = completionEntity.getBody();
if (chatCompletion == null) {
logger.warn("No chat completion returned for prompt: " + prompt);
logger.warn("No chat completion returned for prompt: {}", prompt);
return new ChatResponse(List.of());
}
List<Choice> choices = chatCompletion.choices();
if (choices == null) {
logger.warn("No choices returned for prompt: " + prompt);
logger.warn("No choices returned for prompt: {}", prompt);
return new ChatResponse(List.of());
}
@@ -357,7 +358,7 @@ public class OpenAiChatModel extends AbstractToolCallSupport implements ChatMode
return new ChatResponse(generations, from(chatCompletion2, null, accumulatedUsage));
}
catch (Exception e) {
logger.error(e, "Error processing chat completion");
logger.error("Error processing chat completion", e);
return new ChatResponse(List.of());
}
// When in stream mode and enabled to include the usage, the OpenAI

View File

@@ -19,6 +19,8 @@ package org.springframework.ai.openai;
import java.util.List;
import io.micrometer.observation.ObservationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.metadata.DefaultUsage;
import org.springframework.ai.document.Document;
@@ -38,7 +40,6 @@ import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.ai.openai.api.OpenAiApi.EmbeddingList;
import org.springframework.ai.openai.api.common.OpenAiApiConstants;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.lang.Nullable;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -51,7 +52,7 @@ import org.springframework.util.Assert;
*/
public class OpenAiEmbeddingModel extends AbstractEmbeddingModel {
private static final LogAccessor logger = new LogAccessor(OpenAiEmbeddingModel.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiEmbeddingModel.class);
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
@@ -162,7 +163,7 @@ public class OpenAiEmbeddingModel extends AbstractEmbeddingModel {
.execute(ctx -> this.openAiApi.embeddings(apiRequest).getBody());
if (apiEmbeddingResponse == null) {
logger.warn("No embeddings returned for request: " + request);
logger.warn("No embeddings returned for request: {}", request);
return new EmbeddingResponse(List.of());
}

View File

@@ -19,6 +19,8 @@ package org.springframework.ai.openai;
import java.util.List;
import io.micrometer.observation.ObservationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.image.Image;
import org.springframework.ai.image.ImageGeneration;
@@ -36,7 +38,6 @@ import org.springframework.ai.openai.api.OpenAiImageApi;
import org.springframework.ai.openai.api.common.OpenAiApiConstants;
import org.springframework.ai.openai.metadata.OpenAiImageGenerationMetadata;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.retry.support.RetryTemplate;
@@ -54,7 +55,7 @@ import org.springframework.util.Assert;
*/
public class OpenAiImageModel implements ImageModel {
private static final LogAccessor logger = new LogAccessor(OpenAiImageModel.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiImageModel.class);
private static final ImageModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultImageModelObservationConvention();
@@ -164,7 +165,7 @@ public class OpenAiImageModel implements ImageModel {
OpenAiImageApi.OpenAiImageRequest openAiImageRequest) {
OpenAiImageApi.OpenAiImageResponse imageApiResponse = imageResponseEntity.getBody();
if (imageApiResponse == null) {
logger.warn("No image response returned for request: " + openAiImageRequest);
logger.warn("No image response returned for request: {}", openAiImageRequest);
return new ImageResponse(List.of());
}

View File

@@ -19,6 +19,9 @@ package org.springframework.ai.openai;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.moderation.Categories;
import org.springframework.ai.moderation.CategoryScores;
@@ -31,7 +34,6 @@ import org.springframework.ai.moderation.ModerationResponse;
import org.springframework.ai.moderation.ModerationResult;
import org.springframework.ai.openai.api.OpenAiModerationApi;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -45,7 +47,7 @@ import org.springframework.util.Assert;
*/
public class OpenAiModerationModel implements ModerationModel {
private final LogAccessor logger = new LogAccessor(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
private final OpenAiModerationApi openAiModerationApi;
@@ -104,7 +106,7 @@ public class OpenAiModerationModel implements ModerationModel {
OpenAiModerationApi.OpenAiModerationRequest openAiModerationRequest) {
OpenAiModerationApi.OpenAiModerationResponse moderationApiResponse = moderationResponseEntity.getBody();
if (moderationApiResponse == null) {
logger.warn("No moderation response returned for request: " + openAiModerationRequest);
logger.warn("No moderation response returned for request: {}", openAiModerationRequest);
return new ModerationResponse(new Generation());
}

View File

@@ -23,9 +23,11 @@ import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.metadata.RateLimit;
import org.springframework.ai.openai.metadata.OpenAiRateLimit;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -47,7 +49,7 @@ import static org.springframework.ai.openai.metadata.support.OpenAiApiResponseHe
*/
public final class OpenAiResponseHeaderExtractor {
private static final LogAccessor logger = new LogAccessor(OpenAiResponseHeaderExtractor.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiResponseHeaderExtractor.class);
private OpenAiResponseHeaderExtractor() {
@@ -96,8 +98,8 @@ public final class OpenAiResponseHeaderExtractor {
return Long.parseLong(headerValue.trim());
}
catch (NumberFormatException e) {
logger.warn("Value [" + headerName + "] for HTTP header [" + headerValue + "] is not valid: "
+ e.getMessage());
logger.warn("Value [{}] for HTTP header [{}] is not valid: {}", headerName, headerValue,
e.getMessage());
}
}

View File

@@ -22,6 +22,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.UserMessage;
@@ -41,7 +43,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -49,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
public class AcmeIT extends AbstractIT {
private static final LogAccessor logger = new LogAccessor(AcmeIT.class);
private static final Logger logger = LoggerFactory.getLogger(AcmeIT.class);
@Value("classpath:/data/acme/bikes.json")
private Resource bikesResource;

View File

@@ -23,6 +23,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.openai.api.OpenAiApi;
@@ -32,7 +34,6 @@ import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionMessage.Role;
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionMessage.ToolCall;
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest;
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest.ToolChoiceBuilder;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
public class OpenAiApiToolFunctionCallIT {
private static final LogAccessor logger = new LogAccessor(OpenAiApiToolFunctionCallIT.class);
private final Logger logger = LoggerFactory.getLogger(OpenAiApiToolFunctionCallIT.class);
MockWeatherService weatherService = new MockWeatherService();

View File

@@ -25,6 +25,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -47,7 +49,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -55,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
class OpenAiChatModelFunctionCallingIT {
private static final LogAccessor logger = new LogAccessor(OpenAiChatModelFunctionCallingIT.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatModelFunctionCallingIT.class);
@Autowired
ChatModel chatModel;
@@ -75,7 +76,7 @@ class OpenAiChatModelFunctionCallingIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(state).containsEntry("Light", "ON");
}
@@ -136,7 +137,7 @@ class OpenAiChatModelFunctionCallingIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -208,7 +209,7 @@ class OpenAiChatModelFunctionCallingIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}

View File

@@ -32,6 +32,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -65,7 +67,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -75,7 +76,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
public class OpenAiChatModelIT extends AbstractIT {
private static final LogAccessor logger = new LogAccessor(OpenAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatModelIT.class);
@Value("classpath:/prompts/system-message.st")
private Resource systemResource;
@@ -348,7 +349,7 @@ public class OpenAiChatModelIT extends AbstractIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).containsAnyOf("30.0", "30");
assertThat(response.getResult().getOutput().getText()).containsAnyOf("10.0", "10");
@@ -381,7 +382,7 @@ public class OpenAiChatModelIT extends AbstractIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).containsAnyOf("30.0", "30");
assertThat(content).containsAnyOf("10.0", "10");
@@ -405,10 +406,10 @@ public class OpenAiChatModelIT extends AbstractIT {
.build();
ChatResponse chatResponse = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + chatResponse);
logger.info("Response: {}", chatResponse);
Usage usage = chatResponse.getMetadata().getUsage();
logger.info("Usage: " + usage);
logger.info("Usage: {}", usage);
assertThat(usage).isNotNull();
assertThat(usage).isNotInstanceOf(EmptyUsage.class);
assertThat(usage).isInstanceOf(DefaultUsage.class);
@@ -437,7 +438,7 @@ public class OpenAiChatModelIT extends AbstractIT {
Flux<ChatResponse> response = this.streamingChatModel.stream(new Prompt(messages, promptOptions));
Usage usage = response.last().block().getMetadata().getUsage();
logger.info("Usage: " + usage);
logger.info("Usage: {}", usage);
assertThat(usage).isNotNull();
assertThat(usage).isNotInstanceOf(EmptyUsage.class);
assertThat(usage).isInstanceOf(DefaultUsage.class);
@@ -501,7 +502,7 @@ public class OpenAiChatModelIT extends AbstractIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).containsAnyOf("bananas", "apple", "bowl", "basket", "fruit stand");
}
@@ -576,7 +577,7 @@ public class OpenAiChatModelIT extends AbstractIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).containsIgnoringCase("hobbits");
}

View File

@@ -30,6 +30,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -50,7 +52,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.CollectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -59,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
class OpenAiChatModelProxyToolCallsIT {
private static final LogAccessor logger = new LogAccessor(OpenAiChatModelProxyToolCallsIT.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatModelProxyToolCallsIT.class);
private static final String DEFAULT_MODEL = "gpt-4o-mini";
@@ -185,7 +186,7 @@ class OpenAiChatModelProxyToolCallsIT {
}
while (isToolCall);
logger.info("Response: " + chatResponse);
logger.info("Response: {}", chatResponse);
assertThat(chatResponse.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -222,7 +223,7 @@ class OpenAiChatModelProxyToolCallsIT {
.map(cr -> cr.getResult().getOutput().getText())
.collect(Collectors.joining());
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
@@ -303,7 +304,7 @@ class OpenAiChatModelProxyToolCallsIT {
return functionResponse;
});
logger.info("Response: " + chatResponse);
logger.info("Response: {}", chatResponse);
assertThat(chatResponse.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -343,7 +344,7 @@ class OpenAiChatModelProxyToolCallsIT {
.map(cr -> cr.getResult().getOutput().getText())
.collect(Collectors.joining());
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");

View File

@@ -25,6 +25,8 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
@@ -38,7 +40,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,7 +53,7 @@ public class OpenAiChatModelResponseFormatIT {
private static ObjectMapper MAPPER = new ObjectMapper().enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
private final LogAccessor logger = new LogAccessor(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private OpenAiChatModel openAiChatModel;
@@ -90,7 +91,7 @@ public class OpenAiChatModelResponseFormatIT {
String content = response.getResult().getOutput().getText();
logger.info("Response content: " + content);
logger.info("Response content: {}", content);
assertThat(isValidJson(content)).isTrue();
}
@@ -133,7 +134,7 @@ public class OpenAiChatModelResponseFormatIT {
String content = response.getResult().getOutput().getText();
logger.info("Response content: " + content);
logger.info("Response content: {}", content);
assertThat(isValidJson(content)).isTrue();
}
@@ -214,7 +215,7 @@ public class OpenAiChatModelResponseFormatIT {
String content = response.getResult().getOutput().getText();
logger.info("Response content: " + content);
logger.info("Response content: {}", content);
assertThat(isValidJson(content)).isTrue();

View File

@@ -22,6 +22,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.model.ChatResponse;
@@ -33,7 +35,6 @@ import org.springframework.ai.openai.OpenAiTestConfiguration;
import org.springframework.ai.openai.testutils.AbstractIT;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -41,7 +42,8 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
class OpenAiChatModelTypeReferenceBeanOutputConverterIT extends AbstractIT {
private static final LogAccessor logger = new LogAccessor(OpenAiChatModelTypeReferenceBeanOutputConverterIT.class);
private static final Logger logger = LoggerFactory
.getLogger(OpenAiChatModelTypeReferenceBeanOutputConverterIT.class);
@Test
void typeRefOutputConverterRecords() {

View File

@@ -24,6 +24,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -46,7 +48,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Description;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -57,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".*")
public class OpenAiPaymentTransactionIT {
private static final LogAccessor logger = new LogAccessor(OpenAiPaymentTransactionIT.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiPaymentTransactionIT.class);
private static final Map<Transaction, Status> DATASET = Map.of(new Transaction("001"), new Status("pending"),
new Transaction("002"), new Status("approved"), new Transaction("003"), new Status("rejected"));
@@ -131,7 +132,7 @@ public class OpenAiPaymentTransactionIT {
private static class LoggingAdvisor implements CallAroundAdvisor {
private static final LogAccessor logger = new LogAccessor(LoggingAdvisor.class);
private final Logger logger = LoggerFactory.getLogger(LoggingAdvisor.class);
public String getName() {
return this.getClass().getSimpleName();

View File

@@ -25,6 +25,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.audio.transcription.AudioTranscriptionPrompt;
@@ -62,7 +64,6 @@ import org.springframework.ai.openai.api.OpenAiImageApi.OpenAiImageResponse;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.ai.retry.TransientAiException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
@@ -83,7 +84,7 @@ import static org.mockito.BDDMockito.given;
@ExtendWith(MockitoExtension.class)
public class OpenAiRetryTests {
private static final LogAccessor logger = new LogAccessor(OpenAiRetryTests.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiRetryTests.class);
private TestRetryListener retryListener;

View File

@@ -28,6 +28,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -48,7 +50,6 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.MimeTypeUtils;
@@ -59,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@ActiveProfiles("logging-test")
class OpenAiChatClientIT extends AbstractIT {
private static final LogAccessor logger = new LogAccessor(OpenAiChatClientIT.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientIT.class);
@Value("classpath:/prompts/system-message.st")
private Resource systemTextResource;
@@ -256,7 +257,7 @@ class OpenAiChatClientIT extends AbstractIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -275,7 +276,7 @@ class OpenAiChatClientIT extends AbstractIT {
.prompt().call().content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -295,7 +296,7 @@ class OpenAiChatClientIT extends AbstractIT {
// @formatter:on
String content = response.collectList().block().stream().collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}
@@ -357,7 +358,7 @@ class OpenAiChatClientIT extends AbstractIT {
String content = response.collectList().block().stream().collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("bananas", "apple");
assertThat(content).containsAnyOf("bowl", "basket");
}

View File

@@ -22,6 +22,8 @@ import java.util.concurrent.ConcurrentHashMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
@@ -31,7 +33,6 @@ import org.springframework.ai.tool.definition.ToolDefinition;
import org.springframework.ai.tool.method.MethodToolCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.log.LogAccessor;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.ReflectionUtils;
@@ -43,7 +44,8 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
@ActiveProfiles("logging-test")
class OpenAiChatClientMethodInvokingFunctionCallbackIT {
private static final LogAccessor logger = new LogAccessor(OpenAiChatClientMethodInvokingFunctionCallbackIT.class);
private static final Logger logger = LoggerFactory
.getLogger(OpenAiChatClientMethodInvokingFunctionCallbackIT.class);
public static Map<String, Object> arguments = new ConcurrentHashMap<>();
@@ -74,7 +76,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -100,7 +102,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(arguments).containsEntry("roomName", "living room");
assertThat(arguments).containsEntry("on", true);
@@ -128,7 +130,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -156,7 +158,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
assertThat(arguments).containsEntry("tool", "value");
@@ -209,7 +211,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(arguments).containsEntry("turnLivingRoomLightOn", true);
}
@@ -262,7 +264,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
public void turnLight(String roomName, boolean on) {
arguments.put("roomName", roomName);
arguments.put("on", on);
logger.info("Turn light in room: " + roomName + " to: " + on);
logger.info("Turn light in room: {} to: {}", roomName, on);
}
public void turnLivingRoomLightOn() {

View File

@@ -25,6 +25,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -38,7 +40,6 @@ import org.springframework.ai.tool.function.FunctionToolCallback;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.test.context.ActiveProfiles;
import static org.assertj.core.api.Assertions.assertThat;
@@ -48,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@ActiveProfiles("logging-test")
class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
private static final LogAccessor logger = new LogAccessor(OpenAiChatClientMultipleFunctionCallsIT.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientMultipleFunctionCallsIT.class);
@Value("classpath:/prompts/system-message.st")
private Resource systemTextResource;
@@ -76,7 +77,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).doesNotContain("30", "10", "15");
@@ -91,7 +92,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
@@ -102,7 +103,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
.content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).doesNotContain("30", "10", "15");
@@ -122,7 +123,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
.prompt().call().content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -165,7 +166,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
.prompt().call().content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -209,7 +210,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
.call().content();
// @formatter:on
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response).contains("30", "10", "15");
}
@@ -229,7 +230,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
// @formatter:on
String content = response.collectList().block().stream().collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");

View File

@@ -27,6 +27,8 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -47,7 +49,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.CollectionUtils;
@@ -58,7 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@ActiveProfiles("logging-test")
class OpenAiChatClientProxyFunctionCallsIT extends AbstractIT {
private static final LogAccessor logger = new LogAccessor(OpenAiChatClientMultipleFunctionCallsIT.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientMultipleFunctionCallsIT.class);
@Value("classpath:/prompts/system-message.st")
private Resource systemTextResource;
@@ -176,7 +177,7 @@ class OpenAiChatClientProxyFunctionCallsIT extends AbstractIT {
}
while (isToolCall);
logger.info("Response: " + chatResponse);
logger.info("Response: {}", chatResponse);
assertThat(chatResponse.getResult().getOutput().getText()).contains("30", "10", "15");
}

View File

@@ -27,6 +27,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -54,7 +56,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -72,7 +73,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@Disabled("Requires DeepSeek credits")
class DeepSeekWithOpenAiChatModelIT {
private static final LogAccessor logger = new LogAccessor(DeepSeekWithOpenAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(DeepSeekWithOpenAiChatModelIT.class);
private static final String DEEPSEEK_BASE_URL = "https://api.deepseek.com";
@@ -211,7 +212,7 @@ class DeepSeekWithOpenAiChatModelIT {
DeepSeekWithOpenAiChatModelIT.ActorsFilmsRecord actorsFilms = outputConverter
.convert(generation.getOutput().getText());
logger.info("" + actorsFilms);
logger.info("{}", actorsFilms);
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
assertThat(actorsFilms.movies()).hasSize(5);
}
@@ -241,7 +242,7 @@ class DeepSeekWithOpenAiChatModelIT {
.collect(Collectors.joining());
DeepSeekWithOpenAiChatModelIT.ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
logger.info("" + actorsFilms);
logger.info("{}", actorsFilms);
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
assertThat(actorsFilms.movies()).hasSize(5);
}
@@ -264,7 +265,7 @@ class DeepSeekWithOpenAiChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -296,7 +297,7 @@ class DeepSeekWithOpenAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}

View File

@@ -29,6 +29,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -58,7 +60,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -68,7 +69,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@Disabled("Due to rate limiting it is hard to run it in one go")
class GroqWithOpenAiChatModelIT {
private static final LogAccessor logger = new LogAccessor(GroqWithOpenAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(GroqWithOpenAiChatModelIT.class);
private static final String GROQ_BASE_URL = "https://api.groq.com/openai";
@@ -257,7 +258,7 @@ class GroqWithOpenAiChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -288,7 +289,7 @@ class GroqWithOpenAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}
@@ -350,7 +351,7 @@ class GroqWithOpenAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("bananas", "apple");
assertThat(content).containsAnyOf("bowl", "basket");
}

View File

@@ -29,6 +29,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -58,7 +60,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -67,7 +68,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "MISTRAL_AI_API_KEY", matches = ".+")
class MistralWithOpenAiChatModelIT {
private static final LogAccessor logger = new LogAccessor(MistralWithOpenAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(MistralWithOpenAiChatModelIT.class);
private static final String MISTRAL_BASE_URL = "https://api.mistral.ai";
@@ -259,7 +260,7 @@ class MistralWithOpenAiChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -292,7 +293,7 @@ class MistralWithOpenAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}
@@ -354,7 +355,7 @@ class MistralWithOpenAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("bananas", "apple");
assertThat(content).containsAnyOf("bowl", "basket");
}

View File

@@ -25,6 +25,8 @@ 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;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -52,7 +54,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -65,7 +66,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@Disabled("Requires NVIDIA credits")
class NvidiaWithOpenAiChatModelIT {
private static final LogAccessor logger = new LogAccessor(NvidiaWithOpenAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(NvidiaWithOpenAiChatModelIT.class);
private static final String NVIDIA_BASE_URL = "https://integrate.api.nvidia.com";
@@ -254,7 +255,7 @@ class NvidiaWithOpenAiChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -285,7 +286,7 @@ class NvidiaWithOpenAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023-2025 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.
@@ -29,6 +29,8 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.ollama.OllamaContainer;
@@ -61,7 +63,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -71,7 +72,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = OllamaWithOpenAiChatModelIT.Config.class)
class OllamaWithOpenAiChatModelIT {
private static final LogAccessor logger = new LogAccessor(OllamaWithOpenAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(OllamaWithOpenAiChatModelIT.class);
private static final String DEFAULT_OLLAMA_MODEL = "mistral";
@@ -280,7 +281,7 @@ class OllamaWithOpenAiChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -316,7 +317,7 @@ class OllamaWithOpenAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}
@@ -379,7 +380,7 @@ class OllamaWithOpenAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("bananas", "apple");
assertThat(content).containsAnyOf("bowl", "basket");
}

View File

@@ -25,6 +25,8 @@ 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;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -53,7 +55,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.web.client.RestClient;
import org.springframework.web.reactive.function.client.WebClient;
@@ -76,7 +77,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@Disabled("Requires Perplexity credits")
class PerplexityWithOpenAiChatModelIT {
private static final LogAccessor logger = new LogAccessor(PerplexityWithOpenAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(PerplexityWithOpenAiChatModelIT.class);
private static final String PERPLEXITY_BASE_URL = "https://api.perplexity.ai";
@@ -266,7 +267,7 @@ class PerplexityWithOpenAiChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResults().stream().mapToLong(r -> r.getOutput().getToolCalls().size()).sum()).isZero();
}
@@ -296,7 +297,7 @@ class PerplexityWithOpenAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).doesNotContain("toolCalls");
}

View File

@@ -19,6 +19,9 @@ package org.springframework.ai.openai.testutils;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.model.ChatModel;
@@ -35,14 +38,13 @@ import org.springframework.ai.openai.OpenAiModerationModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
public abstract class AbstractIT {
private static final LogAccessor logger = new LogAccessor(AbstractIT.class);
private static final Logger logger = LoggerFactory.getLogger(AbstractIT.class);
@Autowired
protected ChatModel chatModel;

View File

@@ -60,6 +60,12 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -23,6 +23,8 @@ import java.util.Map;
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;
@@ -50,7 +52,6 @@ import org.springframework.ai.qianfan.api.QianFanApi.ChatCompletionMessage.Role;
import org.springframework.ai.qianfan.api.QianFanApi.ChatCompletionRequest;
import org.springframework.ai.qianfan.api.QianFanConstants;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -68,7 +69,7 @@ import org.springframework.util.Assert;
*/
public class QianFanChatModel implements ChatModel, StreamingChatModel {
private static final LogAccessor logger = new LogAccessor(QianFanChatModel.class);
private static final Logger logger = LoggerFactory.getLogger(QianFanChatModel.class);
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
@@ -168,7 +169,7 @@ public class QianFanChatModel implements ChatModel, StreamingChatModel {
var chatCompletion = completionEntity.getBody();
if (chatCompletion == null) {
logger.warn("No chat completion returned for prompt: " + prompt);
logger.warn("No chat completion returned for prompt: {}", prompt);
return new ChatResponse(List.of());
}

View File

@@ -19,6 +19,8 @@ package org.springframework.ai.qianfan;
import java.util.List;
import io.micrometer.observation.ObservationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.metadata.DefaultUsage;
import org.springframework.ai.document.Document;
@@ -38,7 +40,6 @@ import org.springframework.ai.qianfan.api.QianFanApi;
import org.springframework.ai.qianfan.api.QianFanApi.EmbeddingList;
import org.springframework.ai.qianfan.api.QianFanConstants;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.lang.Nullable;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -52,7 +53,7 @@ import org.springframework.util.Assert;
*/
public class QianFanEmbeddingModel extends AbstractEmbeddingModel {
private static final LogAccessor logger = new LogAccessor(QianFanEmbeddingModel.class);
private static final Logger logger = LoggerFactory.getLogger(QianFanEmbeddingModel.class);
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
@@ -164,12 +165,12 @@ public class QianFanEmbeddingModel extends AbstractEmbeddingModel {
.execute(ctx -> this.qianFanApi.embeddings(apiRequest).getBody());
if (apiEmbeddingResponse == null) {
logger.warn("No embeddings returned for request: " + request);
logger.warn("No embeddings returned for request: {}", request);
return new EmbeddingResponse(List.of());
}
if (apiEmbeddingResponse.errorNsg() != null) {
logger.error("Error message returned for request: " + apiEmbeddingResponse.errorNsg());
logger.error("Error message returned for request: {}", apiEmbeddingResponse.errorNsg());
throw new RuntimeException("Embedding failed: error code:" + apiEmbeddingResponse.errorCode()
+ ", message:" + apiEmbeddingResponse.errorNsg());
}

View File

@@ -19,6 +19,8 @@ package org.springframework.ai.qianfan;
import java.util.List;
import io.micrometer.observation.ObservationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.image.Image;
import org.springframework.ai.image.ImageGeneration;
@@ -34,7 +36,6 @@ import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.qianfan.api.QianFanConstants;
import org.springframework.ai.qianfan.api.QianFanImageApi;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.retry.support.RetryTemplate;
@@ -49,7 +50,7 @@ import org.springframework.util.Assert;
*/
public class QianFanImageModel implements ImageModel {
private static final LogAccessor logger = new LogAccessor(QianFanImageModel.class);
private static final Logger logger = LoggerFactory.getLogger(QianFanImageModel.class);
private static final ImageModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultImageModelObservationConvention();
@@ -174,7 +175,7 @@ public class QianFanImageModel implements ImageModel {
QianFanImageApi.QianFanImageRequest qianFanImageRequest) {
QianFanImageApi.QianFanImageResponse imageApiResponse = imageResponseEntity.getBody();
if (imageApiResponse == null) {
logger.warn("No image response returned for request: " + qianFanImageRequest);
logger.warn("No image response returned for request: {}", qianFanImageRequest);
return new ImageResponse(List.of());
}

View File

@@ -60,6 +60,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -37,6 +37,8 @@ import ai.onnxruntime.OrtEnvironment;
import ai.onnxruntime.OrtException;
import ai.onnxruntime.OrtSession;
import io.micrometer.observation.ObservationRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.MetadataMode;
@@ -53,7 +55,6 @@ import org.springframework.ai.observation.conventions.AiProvider;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -88,7 +89,7 @@ public class TransformersEmbeddingModel extends AbstractEmbeddingModel implement
public static final String DEFAULT_MODEL_OUTPUT_NAME = "last_hidden_state";
private static final LogAccessor logger = new LogAccessor(TransformersEmbeddingModel.class);
private static final Log logger = LogFactory.getLog(TransformersEmbeddingModel.class);
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();

View File

@@ -83,6 +83,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation-test</artifactId>

View File

@@ -29,6 +29,8 @@ import com.google.cloud.aiplatform.v1.PredictResponse;
import com.google.cloud.aiplatform.v1.PredictionServiceClient;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.metadata.DefaultUsage;
import org.springframework.ai.chat.metadata.Usage;
@@ -47,7 +49,6 @@ import org.springframework.ai.vertexai.embedding.VertexAiEmbeddingUtils;
import org.springframework.ai.vertexai.embedding.VertexAiEmbeddingUtils.ImageBuilder;
import org.springframework.ai.vertexai.embedding.VertexAiEmbeddingUtils.MultimodalInstanceBuilder;
import org.springframework.ai.vertexai.embedding.VertexAiEmbeddingUtils.VideoBuilder;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -63,7 +64,7 @@ import org.springframework.util.StringUtils;
*/
public class VertexAiMultimodalEmbeddingModel implements DocumentEmbeddingModel {
private static final LogAccessor logger = new LogAccessor(VertexAiMultimodalEmbeddingModel.class);
private static final Logger logger = LoggerFactory.getLogger(VertexAiMultimodalEmbeddingModel.class);
private static final MimeType TEXT_MIME_TYPE = MimeTypeUtils.parseMimeType("text/*");
@@ -163,7 +164,7 @@ public class VertexAiMultimodalEmbeddingModel implements DocumentEmbeddingModel
new DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));
}
else {
logger.warn("Unsupported image mime type: " + media.getMimeType());
logger.warn("Unsupported image mime type: {}", media.getMimeType());
throw new IllegalArgumentException("Unsupported image mime type: " + media.getMimeType());
}
}
@@ -178,7 +179,7 @@ public class VertexAiMultimodalEmbeddingModel implements DocumentEmbeddingModel
new DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));
}
else {
logger.warn("Unsupported media type: " + media.getMimeType());
logger.warn("Unsupported media type: {}", media.getMimeType());
throw new IllegalArgumentException("Unsupported media type: " + media.getMimeType());
}
}

View File

@@ -84,6 +84,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -189,7 +189,7 @@ class VertexAiGeminiChatModelIT {
.map(AssistantMessage::getText)
.collect(Collectors.joining());
// logger.info("" + actorsFilms);
// logger.info("{}", actorsFilms);
assertThat(generationTextFromStream).isNotEmpty();
}
@@ -218,7 +218,7 @@ class VertexAiGeminiChatModelIT {
.collect(Collectors.joining());
ActorsFilmsRecord actorsFilms = outputConverter.convert(generationTextFromStream);
// logger.info("" + actorsFilms);
// logger.info("{}", actorsFilms);
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
assertThat(actorsFilms.movies()).hasSize(5);
}

View File

@@ -23,15 +23,15 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import org.springframework.core.log.LogAccessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Christian Tzolov
*/
public class MockWeatherService implements Function<MockWeatherService.Request, MockWeatherService.Response> {
private final LogAccessor logger = new LogAccessor(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
public Response apply(Request request) {
@@ -47,7 +47,7 @@ public class MockWeatherService implements Function<MockWeatherService.Request,
temperature = 30;
}
logger.info("Request is " + request + ", response temperature is " + temperature);
logger.info("Request is {}, response temperature is {}", request, temperature);
return new Response(temperature, Unit.C);
}

View File

@@ -25,6 +25,8 @@ import com.google.cloud.vertexai.Transport;
import com.google.cloud.vertexai.VertexAI;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -41,7 +43,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -50,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "VERTEX_AI_GEMINI_LOCATION", matches = ".*")
public class VertexAiGeminiChatModelFunctionCallingIT {
private final LogAccessor logger = new LogAccessor(getClass());
private static final Logger logger = LoggerFactory.getLogger(VertexAiGeminiChatModelFunctionCallingIT.class);
@Autowired
private VertexAiGeminiChatModel chatModel;
@@ -91,7 +92,7 @@ public class VertexAiGeminiChatModelFunctionCallingIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");
}
@@ -124,14 +125,14 @@ public class VertexAiGeminiChatModelFunctionCallingIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
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);
logger.info("Response: {}", response2);
assertThat(response2.getResult().getOutput().getText()).containsIgnoringCase("transaction 696 is PAYED");
@@ -166,7 +167,7 @@ public class VertexAiGeminiChatModelFunctionCallingIT {
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + responseString);
logger.info("Response: {}", responseString);
assertThat(responseString).contains("30", "10", "15");

View File

@@ -26,6 +26,8 @@ import com.google.cloud.vertexai.VertexAI;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.ChatClient;
@@ -44,7 +46,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Description;
import org.springframework.core.log.LogAccessor;
import static org.assertj.core.api.Assertions.assertThat;
@@ -56,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "VERTEX_AI_GEMINI_LOCATION", matches = ".*")
public class VertexAiGeminiPaymentTransactionIT {
private static final LogAccessor logger = new LogAccessor(VertexAiGeminiPaymentTransactionIT.class);
private static final Logger logger = LoggerFactory.getLogger(VertexAiGeminiPaymentTransactionIT.class);
private static final Map<Transaction, Status> DATASET = Map.of(new Transaction("001"), new Status("pending"),
new Transaction("002"), new Status("approved"), new Transaction("003"), new Status("rejected"));
@@ -115,7 +116,7 @@ public class VertexAiGeminiPaymentTransactionIT {
private static class LoggingAdvisor implements CallAroundAdvisor {
private static final LogAccessor logger = new LogAccessor(LoggingAdvisor.class);
private final Logger logger = LoggerFactory.getLogger(LoggingAdvisor.class);
@Override
public String getName() {

View File

@@ -57,6 +57,11 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.cloud</groupId>
<artifactId>sdk-core</artifactId>

View File

@@ -19,6 +19,9 @@ package org.springframework.ai.watsonx;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.AbstractEmbeddingModel;
import org.springframework.ai.embedding.Embedding;
@@ -29,7 +32,6 @@ import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.ai.watsonx.api.WatsonxAiApi;
import org.springframework.ai.watsonx.api.WatsonxAiEmbeddingRequest;
import org.springframework.ai.watsonx.api.WatsonxAiEmbeddingResponse;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -49,7 +51,7 @@ import org.springframework.util.StringUtils;
*/
public class WatsonxAiEmbeddingModel extends AbstractEmbeddingModel {
private static final LogAccessor logger = new LogAccessor(WatsonxAiEmbeddingModel.class);
private final Logger logger = LoggerFactory.getLogger(getClass());
private final WatsonxAiApi watsonxAiApi;

View File

@@ -58,6 +58,11 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>

View File

@@ -27,6 +27,8 @@ import java.util.concurrent.ConcurrentHashMap;
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;
@@ -67,7 +69,6 @@ import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionMessage.Role;
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionMessage.ToolCall;
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionRequest;
import org.springframework.ai.zhipuai.api.ZhiPuApiConstants;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -87,7 +88,7 @@ import org.springframework.util.MimeType;
*/
public class ZhiPuAiChatModel extends AbstractToolCallSupport implements ChatModel, StreamingChatModel {
private static final LogAccessor logger = new LogAccessor(ZhiPuAiChatModel.class);
private static final Logger logger = LoggerFactory.getLogger(ZhiPuAiChatModel.class);
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
@@ -211,7 +212,7 @@ public class ZhiPuAiChatModel extends AbstractToolCallSupport implements ChatMod
var chatCompletion = completionEntity.getBody();
if (chatCompletion == null) {
logger.warn("No chat completion returned for prompt: " + prompt);
logger.warn("No chat completion returned for prompt: {}", prompt);
return new ChatResponse(List.of());
}
@@ -296,7 +297,7 @@ public class ZhiPuAiChatModel extends AbstractToolCallSupport implements ChatMod
return new ChatResponse(generations, from(chatCompletion2));
}
catch (Exception e) {
logger.error(e, "Error processing chat completion");
logger.error("Error processing chat completion", e);
return new ChatResponse(List.of());
}

View File

@@ -21,6 +21,8 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import io.micrometer.observation.ObservationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.metadata.DefaultUsage;
import org.springframework.ai.document.Document;
@@ -39,7 +41,6 @@ import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.ai.zhipuai.api.ZhiPuAiApi;
import org.springframework.ai.zhipuai.api.ZhiPuApiConstants;
import org.springframework.core.log.LogAccessor;
import org.springframework.lang.Nullable;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -52,7 +53,7 @@ import org.springframework.util.Assert;
*/
public class ZhiPuAiEmbeddingModel extends AbstractEmbeddingModel {
private static final LogAccessor logger = new LogAccessor(ZhiPuAiEmbeddingModel.class);
private static final Logger logger = LoggerFactory.getLogger(ZhiPuAiEmbeddingModel.class);
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
@@ -174,7 +175,7 @@ public class ZhiPuAiEmbeddingModel extends AbstractEmbeddingModel {
ZhiPuAiApi.EmbeddingList<ZhiPuAiApi.Embedding> response = this.retryTemplate
.execute(ctx -> this.zhiPuAiApi.embeddings(apiRequest).getBody());
if (response == null || response.data() == null || response.data().isEmpty()) {
logger.warn("No embeddings returned for input: " + inputContent);
logger.warn("No embeddings returned for input: {}", inputContent);
embeddingList.add(new float[0]);
}
else {

View File

@@ -18,6 +18,9 @@ package org.springframework.ai.zhipuai;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.image.Image;
import org.springframework.ai.image.ImageGeneration;
import org.springframework.ai.image.ImageModel;
@@ -27,7 +30,6 @@ import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.ai.zhipuai.api.ZhiPuAiImageApi;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
@@ -41,7 +43,7 @@ import org.springframework.util.Assert;
*/
public class ZhiPuAiImageModel implements ImageModel {
private static final LogAccessor logger = new LogAccessor(ZhiPuAiImageModel.class);
private static final Logger logger = LoggerFactory.getLogger(ZhiPuAiImageModel.class);
public final RetryTemplate retryTemplate;
@@ -99,7 +101,7 @@ public class ZhiPuAiImageModel implements ImageModel {
ZhiPuAiImageApi.ZhiPuAiImageRequest zhiPuAiImageRequest) {
ZhiPuAiImageApi.ZhiPuAiImageResponse imageApiResponse = imageResponseEntity.getBody();
if (imageApiResponse == null) {
logger.warn("No image response returned for request: " + zhiPuAiImageRequest);
logger.warn("No image response returned for request: {}", zhiPuAiImageRequest);
return new ImageResponse(List.of());
}

View File

@@ -24,6 +24,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletion;
@@ -32,7 +34,6 @@ import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionMessage.Role;
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionMessage.ToolCall;
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionRequest;
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionRequest.ToolChoiceBuilder;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@@ -43,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "ZHIPU_AI_API_KEY", matches = ".+")
public class ZhiPuAiApiToolFunctionCallIT {
private static final LogAccessor logger = new LogAccessor(ZhiPuAiApiToolFunctionCallIT.class);
private final Logger logger = LoggerFactory.getLogger(ZhiPuAiApiToolFunctionCallIT.class);
MockWeatherService weatherService = new MockWeatherService();

View File

@@ -29,6 +29,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -56,7 +58,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -68,7 +69,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@EnabledIfEnvironmentVariable(named = "ZHIPU_AI_API_KEY", matches = ".+")
class ZhiPuAiChatModelIT {
private static final LogAccessor logger = new LogAccessor(ZhiPuAiChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(ZhiPuAiChatModelIT.class);
@Autowired
protected ChatModel chatModel;
@@ -238,7 +239,7 @@ class ZhiPuAiChatModelIT {
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
logger.info("Response: " + response);
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getText()).containsAnyOf("30.0", "30");
assertThat(response.getResult().getOutput().getText()).containsAnyOf("10.0", "10");
@@ -271,7 +272,7 @@ class ZhiPuAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).containsAnyOf("30.0", "30");
assertThat(content).containsAnyOf("10.0", "10");
@@ -332,7 +333,7 @@ class ZhiPuAiChatModelIT {
.map(Generation::getOutput)
.map(AssistantMessage::getText)
.collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("bananas", "apple");
assertThat(content).containsAnyOf("bowl", "basket");
}

View File

@@ -25,10 +25,11 @@ import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aot.hint.TypeReference;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.log.LogAccessor;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
@@ -42,7 +43,7 @@ import org.springframework.core.type.filter.TypeFilter;
*/
public abstract class AiRuntimeHints {
private static final LogAccessor logger = new LogAccessor(AiRuntimeHints.class);
private static final Logger log = LoggerFactory.getLogger(AiRuntimeHints.class);
/**
* Finds classes in a package that are annotated with JsonInclude or have Jackson
@@ -90,8 +91,8 @@ public abstract class AiRuntimeHints {
.stream()//
.map(bd -> TypeReference.of(Objects.requireNonNull(bd.getBeanClassName())))//
.peek(tr -> {
if (logger.isDebugEnabled()) {
logger.debug("registering [" + tr.getName() + ']');
if (log.isDebugEnabled()) {
log.debug("registering [" + tr.getName() + ']');
}
})
.collect(Collectors.toUnmodifiableSet());

View File

@@ -18,6 +18,8 @@ package org.springframework.ai.chat.client.advisor;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.advisor.api.AdvisedRequest;
@@ -29,7 +31,6 @@ import org.springframework.ai.chat.client.advisor.api.StreamAroundAdvisorChain;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.model.MessageAggregator;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.core.log.LogAccessor;
/**
* A simple logger advisor that logs the request and response messages.
@@ -43,7 +44,7 @@ public class SimpleLoggerAdvisor implements CallAroundAdvisor, StreamAroundAdvis
public static final Function<ChatResponse, String> DEFAULT_RESPONSE_TO_STRING = response -> ModelOptionsUtils
.toJsonStringPrettyPrinter(response);
private static final LogAccessor logger = new LogAccessor(SimpleLoggerAdvisor.class);
private static final Logger logger = LoggerFactory.getLogger(SimpleLoggerAdvisor.class);
private final Function<AdvisedRequest, String> requestToString;
@@ -77,12 +78,12 @@ public class SimpleLoggerAdvisor implements CallAroundAdvisor, StreamAroundAdvis
}
private AdvisedRequest before(AdvisedRequest request) {
logger.debug("request: " + this.requestToString.apply(request));
logger.debug("request: {}", this.requestToString.apply(request));
return request;
}
private void observeAfter(AdvisedResponse advisedResponse) {
logger.debug("response: " + this.responseToString.apply(advisedResponse.response()));
logger.debug("response: {}", this.responseToString.apply(advisedResponse.response()));
}
@Override

View File

@@ -19,9 +19,11 @@ package org.springframework.ai.chat.metadata;
import java.util.Map;
import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.model.AbstractResponseMetadata;
import org.springframework.ai.model.ResponseMetadata;
import org.springframework.core.log.LogAccessor;
/**
* Models common AI provider metadata returned in an AI response.
@@ -34,7 +36,7 @@ import org.springframework.core.log.LogAccessor;
*/
public class ChatResponseMetadata extends AbstractResponseMetadata implements ResponseMetadata {
private static final LogAccessor logger = new LogAccessor(ChatResponseMetadata.class);
private static final Logger logger = LoggerFactory.getLogger(ChatResponseMetadata.class);
private String id = ""; // Set to blank to preserve backward compat with previous
@@ -138,7 +140,7 @@ public class ChatResponseMetadata extends AbstractResponseMetadata implements Re
this.chatResponseMetadata.map.put(key, value);
}
else {
logger.debug("Ignore null value for key [" + key + "]");
logger.debug("Ignore null value for key [{}]", key);
}
return this;
}

View File

@@ -22,6 +22,8 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.client.advisor.api.AdvisedResponse;
@@ -32,7 +34,6 @@ import org.springframework.ai.chat.metadata.EmptyRateLimit;
import org.springframework.ai.chat.metadata.PromptMetadata;
import org.springframework.ai.chat.metadata.RateLimit;
import org.springframework.ai.chat.metadata.Usage;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.StringUtils;
/**
@@ -45,7 +46,7 @@ import org.springframework.util.StringUtils;
*/
public class MessageAggregator {
private static final LogAccessor logger = new LogAccessor(MessageAggregator.class);
private static final Logger logger = LoggerFactory.getLogger(MessageAggregator.class);
public Flux<AdvisedResponse> aggregateAdvisedResponse(Flux<AdvisedResponse> advisedResponses,
Consumer<AdvisedResponse> aggregationHandler) {
@@ -167,7 +168,7 @@ public class MessageAggregator {
metadataPromptMetadataRef.set(PromptMetadata.empty());
metadataRateLimitRef.set(new EmptyRateLimit());
}).doOnError(e -> logger.error(e, "Aggregation Error"));
}).doOnError(e -> logger.error("Aggregation Error", e));
}
public record DefaultUsage(Integer promptTokens, Integer completionTokens, Integer totalTokens) implements Usage {

View File

@@ -34,10 +34,11 @@ import com.github.victools.jsonschema.generator.SchemaGeneratorConfig;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.victools.jsonschema.module.jackson.JacksonModule;
import com.github.victools.jsonschema.module.jackson.JacksonOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.util.JacksonUtils;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.log.LogAccessor;
import org.springframework.lang.NonNull;
/**
@@ -58,7 +59,7 @@ import org.springframework.lang.NonNull;
*/
public class BeanOutputConverter<T> implements StructuredOutputConverter<T> {
private static final LogAccessor logger = new LogAccessor(BeanOutputConverter.class);
private final Logger logger = LoggerFactory.getLogger(BeanOutputConverter.class);
/**
* The target class type reference to which the output will be converted.
@@ -226,7 +227,7 @@ public class BeanOutputConverter<T> implements StructuredOutputConverter<T> {
return this.objectMapper.readValue(this.jsonSchema, Map.class);
}
catch (JsonProcessingException ex) {
logger.error(ex, "Could not parse the JSON Schema to a Map object");
logger.error("Could not parse the JSON Schema to a Map object", ex);
throw new IllegalStateException(ex);
}
}

Some files were not shown because too many files have changed in this diff Show More