Use Apache Commons Logging
- Remove existing spring-boot-starter-logging - Update to use Springframework's LogAccessor to use commons logging Resolves #2095
This commit is contained in:
@@ -22,11 +22,10 @@ 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;
|
||||
@@ -34,6 +33,7 @@ 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,9 +55,9 @@ public class PagePdfDocumentReader implements DocumentReader {
|
||||
|
||||
private static final String PDF_PAGE_REGION = "pdfPageRegion";
|
||||
|
||||
protected final PDDocument document;
|
||||
private static final LogAccessor logger = new LogAccessor(LogFactory.getLog(PagePdfDocumentReader.class));
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected final PDDocument document;
|
||||
|
||||
protected String resourceFileName;
|
||||
|
||||
@@ -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 {} pages", totalPages);
|
||||
logger.info("Processing " + totalPages + " pages");
|
||||
return readDocuments;
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ 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;
|
||||
@@ -34,6 +32,7 @@ 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;
|
||||
|
||||
@@ -62,7 +61,7 @@ public class ParagraphPdfDocumentReader implements DocumentReader {
|
||||
|
||||
protected final PDDocument document;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private static final LogAccessor logger = new LogAccessor(ParagraphPdfDocumentReader.class);
|
||||
|
||||
private final ParagraphManager paragraphTextExtractor;
|
||||
|
||||
|
||||
@@ -76,10 +76,6 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
|
||||
@@ -27,8 +27,6 @@ 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;
|
||||
|
||||
@@ -67,6 +65,7 @@ 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;
|
||||
@@ -92,7 +91,7 @@ public class AnthropicChatModel extends AbstractToolCallSupport implements ChatM
|
||||
|
||||
public static final Double DEFAULT_TEMPERATURE = 0.8;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AnthropicChatModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AnthropicChatModel.class);
|
||||
|
||||
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ 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;
|
||||
@@ -59,6 +57,7 @@ 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;
|
||||
@@ -69,7 +68,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "ANTHROPIC_API_KEY", matches = ".+")
|
||||
class AnthropicChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AnthropicChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AnthropicChatModelIT.class);
|
||||
|
||||
@Autowired
|
||||
protected ChatModel chatModel;
|
||||
@@ -284,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();
|
||||
@@ -324,7 +323,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");
|
||||
}
|
||||
|
||||
@@ -350,7 +349,7 @@ class AnthropicChatModelIT {
|
||||
|
||||
ChatResponse chatResponse = responseFlux.last().block();
|
||||
|
||||
logger.info("Response: {}", chatResponse);
|
||||
logger.info("Response: " + chatResponse);
|
||||
Usage usage = chatResponse.getMetadata().getUsage();
|
||||
|
||||
assertThat(usage).isNotNull();
|
||||
|
||||
@@ -23,11 +23,10 @@ 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;
|
||||
|
||||
@@ -37,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class EventParsingTests {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EventParsingTests.class);
|
||||
private static final LogAccessor logger = new LogAccessor(EventParsingTests.class);
|
||||
|
||||
@Test
|
||||
public void readEvents() throws IOException {
|
||||
|
||||
@@ -22,8 +22,6 @@ 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;
|
||||
@@ -36,6 +34,7 @@ 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;
|
||||
@@ -81,7 +80,7 @@ public class AnthropicApiLegacyToolIT {
|
||||
|
||||
public static final ConcurrentHashMap<String, Function> FUNCTIONS = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AnthropicApiLegacyToolIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AnthropicApiLegacyToolIT.class);
|
||||
|
||||
AnthropicApi anthropicApi = new AnthropicApi(System.getenv("ANTHROPIC_API_KEY"));
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ 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;
|
||||
@@ -35,6 +33,7 @@ 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;
|
||||
|
||||
@@ -56,7 +55,7 @@ public class AnthropicApiToolIT {
|
||||
|
||||
public static final ConcurrentHashMap<String, Function> FUNCTIONS = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AnthropicApiToolIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AnthropicApiToolIT.class);
|
||||
|
||||
AnthropicApi anthropicApi = new AnthropicApi(System.getenv("ANTHROPIC_API_KEY"));
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ 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;
|
||||
@@ -50,6 +48,7 @@ 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;
|
||||
|
||||
@@ -60,7 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ActiveProfiles("logging-test")
|
||||
class AnthropicChatClientIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AnthropicChatClientIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AnthropicChatClientIT.class);
|
||||
|
||||
@Autowired
|
||||
ChatModel chatModel;
|
||||
@@ -220,7 +219,7 @@ class AnthropicChatClientIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -239,7 +238,7 @@ class AnthropicChatClientIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -261,7 +260,7 @@ class AnthropicChatClientIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -282,7 +281,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");
|
||||
}
|
||||
@@ -344,7 +343,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");
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ 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,6 +32,7 @@ import org.springframework.ai.chat.model.ToolContext;
|
||||
import org.springframework.ai.model.function.FunctionCallback;
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -44,8 +43,8 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
@ActiveProfiles("logging-test")
|
||||
class AnthropicChatClientMethodInvokingFunctionCallbackIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(AnthropicChatClientMethodInvokingFunctionCallbackIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(
|
||||
AnthropicChatClientMethodInvokingFunctionCallbackIT.class);
|
||||
|
||||
public static Map<String, Object> arguments = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -68,7 +67,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -88,7 +87,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -110,7 +109,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);
|
||||
@@ -133,7 +132,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -156,7 +155,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
assertThat(arguments).containsEntry("tool", "value");
|
||||
@@ -203,7 +202,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(arguments).containsEntry("turnLivingRoomLightOn", true);
|
||||
}
|
||||
@@ -264,7 +263,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
|
||||
public void turnLight(String roomName, boolean on) {
|
||||
arguments.put("roomName", roomName);
|
||||
arguments.put("on", on);
|
||||
logger.info("Turn light in room: {} to: {}", roomName, on);
|
||||
logger.info("Turn light in room: " + roomName + " to: " + on);
|
||||
}
|
||||
|
||||
public void turnLivingRoomLightOn() {
|
||||
|
||||
@@ -59,11 +59,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
||||
@@ -25,8 +25,6 @@ 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;
|
||||
@@ -42,6 +40,7 @@ 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;
|
||||
|
||||
@@ -55,7 +54,7 @@ import org.springframework.util.CollectionUtils;
|
||||
*/
|
||||
public class AzureOpenAiEmbeddingModel extends AbstractEmbeddingModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiEmbeddingModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AzureOpenAiEmbeddingModel.class);
|
||||
|
||||
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@ 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;
|
||||
@@ -42,6 +40,7 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -58,7 +57,7 @@ public class AzureOpenAiImageModel implements ImageModel {
|
||||
|
||||
private static final String DEFAULT_DEPLOYMENT_NAME = AzureOpenAiImageOptions.DEFAULT_IMAGE_MODEL;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final LogAccessor logger = new LogAccessor(getClass());
|
||||
|
||||
private final OpenAIClient openAIClient;
|
||||
|
||||
@@ -91,14 +90,14 @@ public class AzureOpenAiImageModel implements ImageModel {
|
||||
ImageGenerationOptions imageGenerationOptions = toOpenAiImageOptions(imagePrompt);
|
||||
String deploymentOrModelName = getDeploymentName(imagePrompt);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Azure ImageGenerationOptions call {} with the following options : {} ", deploymentOrModelName,
|
||||
toPrettyJson(imageGenerationOptions));
|
||||
logger.trace("Azure ImageGenerationOptions call " + deploymentOrModelName + " with the following options : "
|
||||
+ 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 -> {
|
||||
|
||||
@@ -29,8 +29,6 @@ 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;
|
||||
@@ -51,6 +49,7 @@ 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;
|
||||
@@ -59,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@RequiresAzureCredentials
|
||||
class AzureOpenAiChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AzureOpenAiChatModelIT.class);
|
||||
|
||||
@Autowired
|
||||
private AzureOpenAiChatModel chatModel;
|
||||
|
||||
@@ -30,8 +30,6 @@ 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;
|
||||
@@ -39,6 +37,7 @@ 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;
|
||||
@@ -206,7 +205,7 @@ public class MockAiTestConfiguration {
|
||||
*/
|
||||
static class MockWebServerFactoryBean implements FactoryBean<MockWebServer>, InitializingBean, DisposableBean {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass().getName());
|
||||
private final LogAccessor logger = new LogAccessor(getClass().getName());
|
||||
|
||||
private final Queue<MockResponse> queuedResponses = new ConcurrentLinkedDeque<>();
|
||||
|
||||
@@ -222,7 +221,7 @@ public class MockAiTestConfiguration {
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
protected Logger getLogger() {
|
||||
protected LogAccessor getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@@ -256,8 +255,8 @@ public class MockAiTestConfiguration {
|
||||
this.mockWebServer.shutdown();
|
||||
}
|
||||
catch (IOException e) {
|
||||
getLogger().warn("MockWebServer was not shutdown correctly: {}", e.getMessage());
|
||||
getLogger().trace("MockWebServer shutdown failure", e);
|
||||
getLogger().warn("MockWebServer was not shutdown correctly: " + e.getMessage());
|
||||
getLogger().trace(e, "MockWebServer shutdown failure");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ 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;
|
||||
@@ -45,6 +43,7 @@ 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;
|
||||
@@ -53,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@RequiresAzureCredentials
|
||||
class AzureOpenAiChatModelFunctionCallIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiChatModelFunctionCallIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AzureOpenAiChatModelFunctionCallIT.class);
|
||||
|
||||
@Autowired
|
||||
private String selectedModel;
|
||||
@@ -79,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();
|
||||
@@ -108,7 +107,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");
|
||||
}
|
||||
@@ -140,7 +139,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");
|
||||
|
||||
@@ -170,7 +169,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);
|
||||
|
||||
@@ -207,7 +206,7 @@ class AzureOpenAiChatModelFunctionCallIT {
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(content).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ 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;
|
||||
@@ -101,6 +99,7 @@ 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;
|
||||
@@ -134,7 +133,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class BedrockProxyChatModel extends AbstractToolCallSupport implements ChatModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BedrockProxyChatModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(BedrockProxyChatModel.class);
|
||||
|
||||
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
|
||||
|
||||
@@ -200,7 +199,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);
|
||||
|
||||
@@ -655,7 +654,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();
|
||||
@@ -667,7 +666,7 @@ public class BedrockProxyChatModel extends AbstractToolCallSupport implements Ch
|
||||
logger.info("Completed streaming response.");
|
||||
})
|
||||
.onError(error -> {
|
||||
logger.error("Error handling Bedrock converse stream response", error);
|
||||
logger.error(error, "Error handling Bedrock converse stream response");
|
||||
eventSink.emitError(error, DEFAULT_EMIT_FAILURE_HANDLER);
|
||||
})
|
||||
.build();
|
||||
|
||||
@@ -26,8 +26,6 @@ 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;
|
||||
@@ -45,6 +43,7 @@ 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;
|
||||
@@ -53,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@RequiresAwsCredentials
|
||||
class BedrockConverseChatClientIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BedrockConverseChatClientIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(BedrockConverseChatClientIT.class);
|
||||
|
||||
@Value("classpath:/prompts/system-message.st")
|
||||
private Resource systemTextResource;
|
||||
@@ -220,7 +219,7 @@ class BedrockConverseChatClientIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -255,7 +254,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");
|
||||
}
|
||||
@@ -276,7 +275,7 @@ class BedrockConverseChatClientIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -298,7 +297,7 @@ class BedrockConverseChatClientIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -340,7 +339,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");
|
||||
}
|
||||
@@ -361,7 +360,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");
|
||||
}
|
||||
@@ -421,7 +420,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");
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ 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;
|
||||
@@ -54,6 +52,7 @@ 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;
|
||||
@@ -62,7 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@RequiresAwsCredentials
|
||||
class BedrockProxyChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BedrockProxyChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(BedrockProxyChatModelIT.class);
|
||||
|
||||
@Autowired
|
||||
protected ChatModel chatModel;
|
||||
@@ -262,7 +261,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");
|
||||
@@ -297,7 +296,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");
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@ 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;
|
||||
|
||||
@@ -38,6 +36,7 @@ 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;
|
||||
@@ -50,7 +49,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@RequiresAwsCredentials
|
||||
public class BedrockNovaChatClientIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BedrockNovaChatClientIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(BedrockNovaChatClientIT.class);
|
||||
|
||||
@Autowired
|
||||
ChatModel chatModel;
|
||||
@@ -167,7 +166,7 @@ public class BedrockNovaChatClientIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ 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;
|
||||
@@ -45,6 +43,7 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -67,7 +66,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class AbstractBedrockApi<I, O, SO> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractBedrockApi.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AbstractBedrockApi.class);
|
||||
|
||||
/**
|
||||
* Default emit failure handler.
|
||||
@@ -290,7 +289,7 @@ public abstract class AbstractBedrockApi<I, O, SO> {
|
||||
eventSink.emitNext(response, DEFAULT_EMIT_FAILURE_HANDLER);
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Failed to unmarshall", e);
|
||||
logger.error(e, "Failed to unmarshall");
|
||||
eventSink.emitError(e, DEFAULT_EMIT_FAILURE_HANDLER);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
* Copyright 2023-2025 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,8 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.ai.bedrock.titan.api.TitanEmbeddingBedrockApi;
|
||||
import org.springframework.ai.bedrock.titan.api.TitanEmbeddingBedrockApi.TitanEmbeddingRequest;
|
||||
@@ -32,6 +31,7 @@ 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 final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private static final LogAccessor logger = new LogAccessor(LogFactory.getLog(BedrockTitanEmbeddingModel.class));
|
||||
|
||||
private final TitanEmbeddingBedrockApi embeddingApi;
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ import java.util.stream.Collectors;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Flux;
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
@@ -51,6 +49,7 @@ 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;
|
||||
|
||||
@@ -58,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@RequiresAwsCredentials
|
||||
class BedrockAnthropicChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BedrockAnthropicChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(BedrockAnthropicChatModelIT.class);
|
||||
|
||||
@Autowired
|
||||
private BedrockAnthropicChatModel chatModel;
|
||||
|
||||
@@ -22,8 +22,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Flux;
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
@@ -32,6 +30,7 @@ import org.springframework.ai.bedrock.RequiresAwsCredentials;
|
||||
import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi.AnthropicChatModel;
|
||||
import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi.AnthropicChatRequest;
|
||||
import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi.AnthropicChatResponse;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -41,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@RequiresAwsCredentials
|
||||
public class AnthropicChatBedrockApiIT {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(AnthropicChatBedrockApiIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AnthropicChatBedrockApiIT.class);
|
||||
|
||||
private AnthropicChatBedrockApi anthropicChatApi = new AnthropicChatBedrockApi(AnthropicChatModel.CLAUDE_V2.id(),
|
||||
EnvironmentVariableCredentialsProvider.create(), Region.US_EAST_1.id(), new ObjectMapper(),
|
||||
|
||||
@@ -25,8 +25,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Flux;
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
@@ -53,6 +51,7 @@ 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;
|
||||
@@ -61,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@RequiresAwsCredentials
|
||||
class BedrockAnthropic3ChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BedrockAnthropic3ChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(BedrockAnthropic3ChatModelIT.class);
|
||||
|
||||
@Autowired
|
||||
private BedrockAnthropic3ChatModel chatModel;
|
||||
|
||||
@@ -22,8 +22,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Flux;
|
||||
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
@@ -36,6 +34,7 @@ import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi.An
|
||||
import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi.ChatCompletionMessage;
|
||||
import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi.ChatCompletionMessage.Role;
|
||||
import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi.MediaContent;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -45,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@RequiresAwsCredentials
|
||||
public class Anthropic3ChatBedrockApiIT {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(Anthropic3ChatBedrockApiIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(Anthropic3ChatBedrockApiIT.class);
|
||||
|
||||
private Anthropic3ChatBedrockApi anthropicChatApi = new Anthropic3ChatBedrockApi(
|
||||
AnthropicChatModel.CLAUDE_INSTANT_V1.id(), EnvironmentVariableCredentialsProvider.create(),
|
||||
|
||||
@@ -72,11 +72,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -60,11 +60,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
||||
@@ -26,8 +26,6 @@ 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;
|
||||
|
||||
@@ -66,6 +64,7 @@ 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;
|
||||
@@ -84,7 +83,7 @@ import org.springframework.util.CollectionUtils;
|
||||
*/
|
||||
public class MiniMaxChatModel extends AbstractToolCallSupport implements ChatModel, StreamingChatModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MiniMaxChatModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MiniMaxChatModel.class);
|
||||
|
||||
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
|
||||
|
||||
@@ -229,14 +228,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: {}, because: {}}", prompt,
|
||||
chatCompletion.baseResponse().message());
|
||||
logger.warn("No choices returned for prompt: " + prompt + ", because: "
|
||||
+ chatCompletion.baseResponse().message());
|
||||
return new ChatResponse(List.of());
|
||||
}
|
||||
|
||||
@@ -329,7 +328,7 @@ public class MiniMaxChatModel extends AbstractToolCallSupport implements ChatMod
|
||||
return new ChatResponse(generations, from(chatCompletion2));
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error processing chat completion", e);
|
||||
logger.error(e, "Error processing chat completion");
|
||||
return new ChatResponse(List.of());
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -20,8 +20,6 @@ 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;
|
||||
@@ -40,6 +38,7 @@ 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;
|
||||
@@ -53,7 +52,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MiniMaxEmbeddingModel extends AbstractEmbeddingModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MiniMaxEmbeddingModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MiniMaxEmbeddingModel.class);
|
||||
|
||||
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
|
||||
|
||||
@@ -167,7 +166,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());
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@ 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;
|
||||
@@ -33,6 +31,7 @@ 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;
|
||||
@@ -43,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".+")
|
||||
public class MiniMaxApiToolFunctionCallIT {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MiniMaxApiToolFunctionCallIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MiniMaxApiToolFunctionCallIT.class);
|
||||
|
||||
MockWeatherService weatherService = new MockWeatherService();
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ 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;
|
||||
@@ -36,6 +34,7 @@ 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;
|
||||
|
||||
@@ -45,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".+")
|
||||
public class MiniMaxChatOptionsTests {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MiniMaxChatOptionsTests.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MiniMaxChatOptionsTests.class);
|
||||
|
||||
private final MiniMaxChatModel chatModel = new MiniMaxChatModel(new MiniMaxApi(System.getenv("MINIMAX_API_KEY")));
|
||||
|
||||
@@ -135,7 +134,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");
|
||||
}
|
||||
|
||||
@@ -61,11 +61,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
||||
@@ -27,8 +27,6 @@ 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;
|
||||
|
||||
@@ -66,6 +64,7 @@ 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;
|
||||
@@ -88,7 +87,7 @@ public class MistralAiChatModel extends AbstractToolCallSupport implements ChatM
|
||||
|
||||
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final LogAccessor logger = new LogAccessor(getClass());
|
||||
|
||||
/**
|
||||
* The default options used for the chat completion requests.
|
||||
@@ -203,7 +202,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());
|
||||
}
|
||||
|
||||
@@ -300,7 +299,7 @@ public class MistralAiChatModel extends AbstractToolCallSupport implements ChatM
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error processing chat completion", e);
|
||||
logger.error(e, "Error processing chat completion");
|
||||
return new ChatResponse(List.of());
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -19,8 +19,6 @@ 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;
|
||||
@@ -39,6 +37,7 @@ 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;
|
||||
|
||||
@@ -52,7 +51,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MistralAiEmbeddingModel extends AbstractEmbeddingModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MistralAiEmbeddingModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MistralAiEmbeddingModel.class);
|
||||
|
||||
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
|
||||
|
||||
@@ -126,7 +125,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());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ 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;
|
||||
@@ -41,6 +39,7 @@ 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;
|
||||
|
||||
@@ -48,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "MISTRAL_AI_API_KEY", matches = ".+")
|
||||
class MistralAiChatClientIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MistralAiChatClientIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MistralAiChatClientIT.class);
|
||||
|
||||
@Autowired
|
||||
MistralAiChatModel chatModel;
|
||||
@@ -234,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");
|
||||
@@ -257,7 +256,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");
|
||||
@@ -281,7 +280,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");
|
||||
|
||||
@@ -28,8 +28,6 @@ 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;
|
||||
@@ -55,6 +53,7 @@ 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 +68,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "MISTRAL_AI_API_KEY", matches = ".+")
|
||||
class MistralAiChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MistralAiChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MistralAiChatModelIT.class);
|
||||
|
||||
@Autowired
|
||||
protected ChatModel chatModel;
|
||||
@@ -212,7 +211,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();
|
||||
@@ -246,7 +245,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");
|
||||
}
|
||||
@@ -303,7 +302,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");
|
||||
}
|
||||
@@ -327,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(800);
|
||||
|
||||
@@ -23,8 +23,6 @@ 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;
|
||||
@@ -35,6 +33,7 @@ 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;
|
||||
|
||||
@@ -49,7 +48,7 @@ public class MistralAiApiToolFunctionCallIT {
|
||||
|
||||
static final String MISTRAL_AI_CHAT_MODEL = MistralAiApi.ChatModel.LARGE.getValue();
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MistralAiApiToolFunctionCallIT.class);
|
||||
private final LogAccessor logger = new LogAccessor(MistralAiApiToolFunctionCallIT.class);
|
||||
|
||||
MockWeatherService weatherService = new MockWeatherService();
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ 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;
|
||||
@@ -38,6 +36,7 @@ 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;
|
||||
@@ -64,7 +63,7 @@ public class PaymentStatusFunctionCallingIT {
|
||||
static Map<String, Function<Transaction, ?>> functions = Map.of("retrieve_payment_status",
|
||||
new RetrievePaymentStatus(), "retrieve_payment_date", new RetrievePaymentDate());
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(PaymentStatusFunctionCallingIT.class);
|
||||
private final LogAccessor logger = new LogAccessor(PaymentStatusFunctionCallingIT.class);
|
||||
|
||||
private static <T> T jsonToObject(String json, Class<T> targetClass) {
|
||||
try {
|
||||
|
||||
@@ -61,11 +61,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
||||
@@ -25,8 +25,6 @@ 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,6 +65,7 @@ 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;
|
||||
@@ -81,7 +80,7 @@ import org.springframework.util.CollectionUtils;
|
||||
*/
|
||||
public class MoonshotChatModel extends AbstractToolCallSupport implements ChatModel, StreamingChatModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MoonshotChatModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MoonshotChatModel.class);
|
||||
|
||||
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
|
||||
|
||||
@@ -205,13 +204,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());
|
||||
}
|
||||
|
||||
@@ -312,7 +311,7 @@ public class MoonshotChatModel extends AbstractToolCallSupport implements ChatMo
|
||||
return new ChatResponse(generations, from(chatCompletion2, cumulativeUsage));
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error processing chat completion", e);
|
||||
logger.error(e, "Error processing chat completion");
|
||||
return new ChatResponse(List.of());
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@ 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;
|
||||
@@ -35,6 +33,7 @@ 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;
|
||||
@@ -71,7 +70,7 @@ public class MoonshotApiToolFunctionCallIT {
|
||||
}
|
||||
"""));
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MoonshotApiToolFunctionCallIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MoonshotApiToolFunctionCallIT.class);
|
||||
|
||||
private final MockWeatherService weatherService = new MockWeatherService();
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@ 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;
|
||||
@@ -42,6 +40,7 @@ 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;
|
||||
|
||||
@@ -49,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "MOONSHOT_API_KEY", matches = ".+")
|
||||
class MoonshotChatModelFunctionCallingIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MoonshotChatModelFunctionCallingIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MoonshotChatModelFunctionCallingIT.class);
|
||||
|
||||
@Autowired
|
||||
ChatModel chatModel;
|
||||
@@ -100,7 +99,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");
|
||||
}
|
||||
@@ -132,7 +131,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");
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ 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;
|
||||
@@ -45,6 +43,7 @@ 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;
|
||||
|
||||
@@ -55,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "MOONSHOT_API_KEY", matches = ".+")
|
||||
public class MoonshotChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MoonshotChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MoonshotChatModelIT.class);
|
||||
|
||||
@Autowired
|
||||
protected ChatModel chatModel;
|
||||
|
||||
@@ -64,10 +64,6 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
|
||||
@@ -62,11 +62,6 @@
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -18,14 +18,13 @@ 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;
|
||||
|
||||
@@ -38,7 +37,7 @@ import org.springframework.util.CollectionUtils;
|
||||
*/
|
||||
public class OllamaModelManager {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(OllamaModelManager.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OllamaModelManager.class);
|
||||
|
||||
private final OllamaApi ollamaApi;
|
||||
|
||||
@@ -81,13 +80,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 {} not found", modelName);
|
||||
logger.info("Model " + modelName + " not found");
|
||||
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) {
|
||||
@@ -101,20 +100,20 @@ public class OllamaModelManager {
|
||||
|
||||
if (PullModelStrategy.WHEN_MISSING.equals(pullModelStrategy)) {
|
||||
if (isModelAvailable(modelName)) {
|
||||
logger.debug("Model '{}' already available. Skipping pull operation.", modelName);
|
||||
logger.debug("Model '" + modelName + "' already available. Skipping pull operation.");
|
||||
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 '{}' model - Status: {}", modelName, progressResponses.get(progressResponses.size() - 1).status());
|
||||
logger.info("Pulling the '"+ modelName +"' model - Status: "+ progressResponses.get(progressResponses.size() - 1).status());
|
||||
}
|
||||
})
|
||||
.takeUntil(progressResponses ->
|
||||
@@ -122,7 +121,7 @@ public class OllamaModelManager {
|
||||
.timeout(this.options.timeout())
|
||||
.retryWhen(Retry.backoff(this.options.maxRetries(), Duration.ofSeconds(5)))
|
||||
.blockLast();
|
||||
logger.info("Completed pulling the '{}' model", modelName);
|
||||
logger.info("Completed pulling the '"+ modelName +"' model");
|
||||
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ 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;
|
||||
@@ -40,13 +38,14 @@ 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 Logger logger = LoggerFactory.getLogger(OllamaChatModelFunctionCallingIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OllamaChatModelFunctionCallingIT.class);
|
||||
|
||||
private static final String MODEL = "qwen2.5:3b";
|
||||
|
||||
@@ -72,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");
|
||||
}
|
||||
@@ -104,7 +103,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");
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ 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;
|
||||
@@ -32,6 +30,7 @@ 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;
|
||||
@@ -40,7 +39,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
@SpringBootTest
|
||||
class OllamaChatModelMultimodalIT extends BaseOllamaIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OllamaChatModelMultimodalIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OllamaChatModelMultimodalIT.class);
|
||||
|
||||
private static final String MODEL = "llava-phi3";
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ 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;
|
||||
@@ -33,6 +31,7 @@ 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;
|
||||
|
||||
@@ -44,7 +43,7 @@ public class OllamaApiToolFunctionCallIT extends BaseOllamaIT {
|
||||
|
||||
private static final String MODEL = "qwen2.5:3b";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OllamaApiToolFunctionCallIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OllamaApiToolFunctionCallIT.class);
|
||||
|
||||
static OllamaApi ollamaApi;
|
||||
|
||||
|
||||
@@ -75,10 +75,6 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
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;
|
||||
@@ -32,6 +30,7 @@ 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;
|
||||
@@ -53,7 +52,7 @@ public class OpenAiAudioSpeechModel implements SpeechModel, StreamingSpeechModel
|
||||
*/
|
||||
private static final Float SPEED = 1.0f;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final LogAccessor logger = new LogAccessor(getClass());
|
||||
|
||||
/**
|
||||
* The default options used for the audio completion requests.
|
||||
@@ -132,7 +131,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]));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
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;
|
||||
@@ -30,6 +27,7 @@ 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;
|
||||
@@ -47,7 +45,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class OpenAiAudioTranscriptionModel implements Model<AudioTranscriptionPrompt, AudioTranscriptionResponse> {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiAudioTranscriptionModel.class);
|
||||
|
||||
private final OpenAiAudioTranscriptionOptions defaultOptions;
|
||||
|
||||
@@ -118,7 +116,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);
|
||||
}
|
||||
|
||||
@@ -139,7 +137,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@ 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;
|
||||
|
||||
@@ -76,6 +74,7 @@ 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;
|
||||
@@ -108,7 +107,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class OpenAiChatModel extends AbstractToolCallSupport implements ChatModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiChatModel.class);
|
||||
|
||||
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
|
||||
|
||||
@@ -241,13 +240,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());
|
||||
}
|
||||
|
||||
@@ -358,7 +357,7 @@ public class OpenAiChatModel extends AbstractToolCallSupport implements ChatMode
|
||||
return new ChatResponse(generations, from(chatCompletion2, null, accumulatedUsage));
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error processing chat completion", e);
|
||||
logger.error(e, "Error processing chat completion");
|
||||
return new ChatResponse(List.of());
|
||||
}
|
||||
// When in stream mode and enabled to include the usage, the OpenAI
|
||||
|
||||
@@ -19,8 +19,6 @@ 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;
|
||||
@@ -40,6 +38,7 @@ 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;
|
||||
@@ -52,7 +51,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class OpenAiEmbeddingModel extends AbstractEmbeddingModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiEmbeddingModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiEmbeddingModel.class);
|
||||
|
||||
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
|
||||
|
||||
@@ -163,7 +162,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());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ 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;
|
||||
@@ -38,6 +36,7 @@ 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;
|
||||
@@ -55,7 +54,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class OpenAiImageModel implements ImageModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiImageModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiImageModel.class);
|
||||
|
||||
private static final ImageModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultImageModelObservationConvention();
|
||||
|
||||
@@ -165,7 +164,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());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,6 @@ 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;
|
||||
@@ -34,6 +31,7 @@ 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;
|
||||
@@ -47,7 +45,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class OpenAiModerationModel implements ModerationModel {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final LogAccessor logger = new LogAccessor(getClass());
|
||||
|
||||
private final OpenAiModerationApi openAiModerationApi;
|
||||
|
||||
@@ -106,7 +104,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());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,9 @@ 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;
|
||||
@@ -49,7 +47,7 @@ import static org.springframework.ai.openai.metadata.support.OpenAiApiResponseHe
|
||||
*/
|
||||
public final class OpenAiResponseHeaderExtractor {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiResponseHeaderExtractor.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiResponseHeaderExtractor.class);
|
||||
|
||||
private OpenAiResponseHeaderExtractor() {
|
||||
|
||||
@@ -98,8 +96,8 @@ public final class OpenAiResponseHeaderExtractor {
|
||||
return Long.parseLong(headerValue.trim());
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
logger.warn("Value [{}] for HTTP header [{}] is not valid: {}", headerName, headerValue,
|
||||
e.getMessage());
|
||||
logger.warn("Value [" + headerName + "] for HTTP header [" + headerValue + "] is not valid: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,6 @@ 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;
|
||||
@@ -43,6 +41,7 @@ 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;
|
||||
|
||||
@@ -50,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
|
||||
public class AcmeIT extends AbstractIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AcmeIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AcmeIT.class);
|
||||
|
||||
@Value("classpath:/data/acme/bikes.json")
|
||||
private Resource bikesResource;
|
||||
|
||||
@@ -23,8 +23,6 @@ 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;
|
||||
@@ -34,6 +32,7 @@ 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;
|
||||
@@ -48,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
|
||||
public class OpenAiApiToolFunctionCallIT {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(OpenAiApiToolFunctionCallIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiApiToolFunctionCallIT.class);
|
||||
|
||||
MockWeatherService weatherService = new MockWeatherService();
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ 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;
|
||||
@@ -49,6 +47,7 @@ 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;
|
||||
|
||||
@@ -56,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
|
||||
class OpenAiChatModelFunctionCallingIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatModelFunctionCallingIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiChatModelFunctionCallingIT.class);
|
||||
|
||||
@Autowired
|
||||
ChatModel chatModel;
|
||||
@@ -76,7 +75,7 @@ class OpenAiChatModelFunctionCallingIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
assertThat(state).containsEntry("Light", "ON");
|
||||
}
|
||||
|
||||
@@ -137,7 +136,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");
|
||||
}
|
||||
@@ -209,7 +208,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");
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ 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;
|
||||
@@ -67,6 +65,7 @@ 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;
|
||||
@@ -76,7 +75,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
|
||||
public class OpenAiChatModelIT extends AbstractIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiChatModelIT.class);
|
||||
|
||||
@Value("classpath:/prompts/system-message.st")
|
||||
private Resource systemResource;
|
||||
@@ -349,7 +348,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");
|
||||
@@ -382,7 +381,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");
|
||||
@@ -406,10 +405,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);
|
||||
@@ -438,7 +437,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);
|
||||
@@ -502,7 +501,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");
|
||||
}
|
||||
|
||||
@@ -577,7 +576,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");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,6 @@ 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;
|
||||
@@ -52,6 +50,7 @@ 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;
|
||||
@@ -60,7 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
|
||||
class OpenAiChatModelProxyToolCallsIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatModelProxyToolCallsIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiChatModelProxyToolCallsIT.class);
|
||||
|
||||
private static final String DEFAULT_MODEL = "gpt-4o-mini";
|
||||
|
||||
@@ -186,7 +185,7 @@ class OpenAiChatModelProxyToolCallsIT {
|
||||
}
|
||||
while (isToolCall);
|
||||
|
||||
logger.info("Response: {}", chatResponse);
|
||||
logger.info("Response: " + chatResponse);
|
||||
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
@@ -223,7 +222,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");
|
||||
|
||||
@@ -304,7 +303,7 @@ class OpenAiChatModelProxyToolCallsIT {
|
||||
return functionResponse;
|
||||
});
|
||||
|
||||
logger.info("Response: {}", chatResponse);
|
||||
logger.info("Response: " + chatResponse);
|
||||
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
@@ -344,7 +343,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");
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ 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;
|
||||
@@ -40,6 +38,7 @@ 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;
|
||||
|
||||
@@ -53,7 +52,7 @@ public class OpenAiChatModelResponseFormatIT {
|
||||
|
||||
private static ObjectMapper MAPPER = new ObjectMapper().enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final LogAccessor logger = new LogAccessor(getClass());
|
||||
|
||||
@Autowired
|
||||
private OpenAiChatModel openAiChatModel;
|
||||
@@ -91,7 +90,7 @@ public class OpenAiChatModelResponseFormatIT {
|
||||
|
||||
String content = response.getResult().getOutput().getText();
|
||||
|
||||
logger.info("Response content: {}", content);
|
||||
logger.info("Response content: " + content);
|
||||
|
||||
assertThat(isValidJson(content)).isTrue();
|
||||
}
|
||||
@@ -134,7 +133,7 @@ public class OpenAiChatModelResponseFormatIT {
|
||||
|
||||
String content = response.getResult().getOutput().getText();
|
||||
|
||||
logger.info("Response content: {}", content);
|
||||
logger.info("Response content: " + content);
|
||||
|
||||
assertThat(isValidJson(content)).isTrue();
|
||||
}
|
||||
@@ -215,7 +214,7 @@ public class OpenAiChatModelResponseFormatIT {
|
||||
|
||||
String content = response.getResult().getOutput().getText();
|
||||
|
||||
logger.info("Response content: {}", content);
|
||||
logger.info("Response content: " + content);
|
||||
|
||||
assertThat(isValidJson(content)).isTrue();
|
||||
|
||||
|
||||
@@ -22,8 +22,6 @@ 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;
|
||||
@@ -35,6 +33,7 @@ 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;
|
||||
|
||||
@@ -42,8 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
|
||||
class OpenAiChatModelTypeReferenceBeanOutputConverterIT extends AbstractIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(OpenAiChatModelTypeReferenceBeanOutputConverterIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiChatModelTypeReferenceBeanOutputConverterIT.class);
|
||||
|
||||
@Test
|
||||
void typeRefOutputConverterRecords() {
|
||||
|
||||
@@ -24,8 +24,6 @@ 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;
|
||||
@@ -48,6 +46,7 @@ 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;
|
||||
|
||||
@@ -58,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".*")
|
||||
public class OpenAiPaymentTransactionIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiPaymentTransactionIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(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"));
|
||||
@@ -132,7 +131,7 @@ public class OpenAiPaymentTransactionIT {
|
||||
|
||||
private static class LoggingAdvisor implements CallAroundAdvisor {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(LoggingAdvisor.class);
|
||||
private static final LogAccessor logger = new LogAccessor(LoggingAdvisor.class);
|
||||
|
||||
public String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
|
||||
@@ -25,8 +25,6 @@ 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;
|
||||
@@ -64,6 +62,7 @@ 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;
|
||||
@@ -84,7 +83,7 @@ import static org.mockito.BDDMockito.given;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class OpenAiRetryTests {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiRetryTests.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiRetryTests.class);
|
||||
|
||||
private TestRetryListener retryListener;
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ 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;
|
||||
@@ -50,6 +48,7 @@ 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;
|
||||
|
||||
@@ -60,7 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ActiveProfiles("logging-test")
|
||||
class OpenAiChatClientIT extends AbstractIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiChatClientIT.class);
|
||||
|
||||
@Value("classpath:/prompts/system-message.st")
|
||||
private Resource systemTextResource;
|
||||
@@ -260,7 +259,7 @@ class OpenAiChatClientIT extends AbstractIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -280,7 +279,7 @@ class OpenAiChatClientIT extends AbstractIT {
|
||||
.prompt().call().content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -301,7 +300,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");
|
||||
}
|
||||
@@ -363,7 +362,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");
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ 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;
|
||||
@@ -32,6 +30,7 @@ import org.springframework.ai.model.function.FunctionCallback;
|
||||
import org.springframework.ai.openai.OpenAiTestConfiguration;
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -42,8 +41,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
@ActiveProfiles("logging-test")
|
||||
class OpenAiChatClientMethodInvokingFunctionCallbackIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(OpenAiChatClientMethodInvokingFunctionCallbackIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiChatClientMethodInvokingFunctionCallbackIT.class);
|
||||
|
||||
public static Map<String, Object> arguments = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -69,7 +67,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -91,7 +89,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);
|
||||
@@ -114,7 +112,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -137,7 +135,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");
|
||||
@@ -181,7 +179,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(arguments).containsEntry("turnLivingRoomLightOn", true);
|
||||
}
|
||||
@@ -234,7 +232,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
|
||||
public void turnLight(String roomName, boolean on) {
|
||||
arguments.put("roomName", roomName);
|
||||
arguments.put("on", on);
|
||||
logger.info("Turn light in room: {} to: {}", roomName, on);
|
||||
logger.info("Turn light in room: " + roomName + " to: " + on);
|
||||
}
|
||||
|
||||
public void turnLivingRoomLightOn() {
|
||||
|
||||
@@ -25,8 +25,6 @@ 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;
|
||||
@@ -40,6 +38,7 @@ import org.springframework.ai.openai.testutils.AbstractIT;
|
||||
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;
|
||||
@@ -49,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ActiveProfiles("logging-test")
|
||||
class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientMultipleFunctionCallsIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiChatClientMultipleFunctionCallsIT.class);
|
||||
|
||||
@Value("classpath:/prompts/system-message.st")
|
||||
private Resource systemTextResource;
|
||||
@@ -77,7 +76,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).doesNotContain("30", "10", "15");
|
||||
|
||||
@@ -93,7 +92,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
|
||||
@@ -104,7 +103,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
|
||||
.content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).doesNotContain("30", "10", "15");
|
||||
|
||||
@@ -125,7 +124,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
|
||||
.prompt().call().content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -169,7 +168,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
|
||||
.prompt().call().content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -214,7 +213,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
|
||||
.call().content();
|
||||
// @formatter:on
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
logger.info("Response: " + response);
|
||||
|
||||
assertThat(response).contains("30", "10", "15");
|
||||
}
|
||||
@@ -235,7 +234,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");
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ 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;
|
||||
@@ -49,6 +47,7 @@ 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;
|
||||
|
||||
@@ -59,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ActiveProfiles("logging-test")
|
||||
class OpenAiChatClientProxyFunctionCallsIT extends AbstractIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientMultipleFunctionCallsIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OpenAiChatClientMultipleFunctionCallsIT.class);
|
||||
|
||||
@Value("classpath:/prompts/system-message.st")
|
||||
private Resource systemTextResource;
|
||||
@@ -177,7 +176,7 @@ class OpenAiChatClientProxyFunctionCallsIT extends AbstractIT {
|
||||
}
|
||||
while (isToolCall);
|
||||
|
||||
logger.info("Response: {}", chatResponse);
|
||||
logger.info("Response: " + chatResponse);
|
||||
|
||||
assertThat(chatResponse.getResult().getOutput().getText()).contains("30", "10", "15");
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ 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;
|
||||
@@ -60,6 +58,7 @@ 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;
|
||||
@@ -69,7 +68,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 Logger logger = LoggerFactory.getLogger(GroqWithOpenAiChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(GroqWithOpenAiChatModelIT.class);
|
||||
|
||||
private static final String GROQ_BASE_URL = "https://api.groq.com/openai";
|
||||
|
||||
@@ -258,7 +257,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");
|
||||
}
|
||||
@@ -289,7 +288,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");
|
||||
}
|
||||
@@ -351,7 +350,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");
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ 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;
|
||||
@@ -60,6 +58,7 @@ 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 +67,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "MISTRAL_AI_API_KEY", matches = ".+")
|
||||
class MistralWithOpenAiChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MistralWithOpenAiChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(MistralWithOpenAiChatModelIT.class);
|
||||
|
||||
private static final String MISTRAL_BASE_URL = "https://api.mistral.ai";
|
||||
|
||||
@@ -260,7 +259,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");
|
||||
}
|
||||
@@ -293,7 +292,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");
|
||||
}
|
||||
@@ -355,7 +354,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");
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ 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;
|
||||
@@ -54,6 +52,7 @@ 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;
|
||||
|
||||
@@ -66,7 +65,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@Disabled("Requires NVIDIA credits")
|
||||
class NvidiaWithOpenAiChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NvidiaWithOpenAiChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(NvidiaWithOpenAiChatModelIT.class);
|
||||
|
||||
private static final String NVIDIA_BASE_URL = "https://integrate.api.nvidia.com";
|
||||
|
||||
@@ -255,7 +254,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");
|
||||
}
|
||||
@@ -286,7 +285,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");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
* Copyright 2023-2025 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,8 +29,6 @@ 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;
|
||||
@@ -63,6 +61,7 @@ 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;
|
||||
@@ -72,7 +71,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@SpringBootTest(classes = OllamaWithOpenAiChatModelIT.Config.class)
|
||||
class OllamaWithOpenAiChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OllamaWithOpenAiChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(OllamaWithOpenAiChatModelIT.class);
|
||||
|
||||
private static final String DEFAULT_OLLAMA_MODEL = "mistral";
|
||||
|
||||
@@ -281,7 +280,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");
|
||||
}
|
||||
@@ -317,7 +316,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");
|
||||
}
|
||||
@@ -380,7 +379,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");
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ 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;
|
||||
@@ -55,6 +53,7 @@ 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;
|
||||
|
||||
@@ -77,7 +76,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@Disabled("Requires Perplexity credits")
|
||||
class PerplexityWithOpenAiChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PerplexityWithOpenAiChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(PerplexityWithOpenAiChatModelIT.class);
|
||||
|
||||
private static final String PERPLEXITY_BASE_URL = "https://api.perplexity.ai";
|
||||
|
||||
@@ -267,7 +266,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();
|
||||
}
|
||||
@@ -297,7 +296,7 @@ class PerplexityWithOpenAiChatModelIT {
|
||||
.map(Generation::getOutput)
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
logger.info("Response: {}", content);
|
||||
logger.info("Response: " + content);
|
||||
|
||||
assertThat(content).doesNotContain("toolCalls");
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ 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;
|
||||
@@ -38,13 +35,14 @@ 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 Logger logger = LoggerFactory.getLogger(AbstractIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AbstractIT.class);
|
||||
|
||||
@Autowired
|
||||
protected ChatModel chatModel;
|
||||
|
||||
@@ -60,11 +60,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
||||
@@ -23,8 +23,6 @@ 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;
|
||||
|
||||
@@ -52,6 +50,7 @@ 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;
|
||||
@@ -69,7 +68,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class QianFanChatModel implements ChatModel, StreamingChatModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(QianFanChatModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(QianFanChatModel.class);
|
||||
|
||||
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
|
||||
|
||||
@@ -169,7 +168,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());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ 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;
|
||||
@@ -40,6 +38,7 @@ 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;
|
||||
@@ -53,7 +52,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class QianFanEmbeddingModel extends AbstractEmbeddingModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(QianFanEmbeddingModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(QianFanEmbeddingModel.class);
|
||||
|
||||
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
|
||||
|
||||
@@ -165,12 +164,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());
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ 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;
|
||||
@@ -36,6 +34,7 @@ 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;
|
||||
@@ -50,7 +49,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class QianFanImageModel implements ImageModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(QianFanImageModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(QianFanImageModel.class);
|
||||
|
||||
private static final ImageModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultImageModelObservationConvention();
|
||||
|
||||
@@ -175,7 +174,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());
|
||||
}
|
||||
|
||||
|
||||
@@ -60,11 +60,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
||||
@@ -37,8 +37,6 @@ 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;
|
||||
@@ -55,6 +53,7 @@ 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;
|
||||
|
||||
@@ -89,7 +88,7 @@ public class TransformersEmbeddingModel extends AbstractEmbeddingModel implement
|
||||
|
||||
public static final String DEFAULT_MODEL_OUTPUT_NAME = "last_hidden_state";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TransformersEmbeddingModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(TransformersEmbeddingModel.class);
|
||||
|
||||
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
|
||||
|
||||
|
||||
@@ -83,11 +83,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-observation-test</artifactId>
|
||||
|
||||
@@ -29,8 +29,6 @@ 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;
|
||||
@@ -49,6 +47,7 @@ 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;
|
||||
@@ -64,7 +63,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class VertexAiMultimodalEmbeddingModel implements DocumentEmbeddingModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(VertexAiMultimodalEmbeddingModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(VertexAiMultimodalEmbeddingModel.class);
|
||||
|
||||
private static final MimeType TEXT_MIME_TYPE = MimeTypeUtils.parseMimeType("text/*");
|
||||
|
||||
@@ -164,7 +163,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());
|
||||
}
|
||||
}
|
||||
@@ -179,7 +178,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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,11 +84,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
||||
@@ -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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
|
||||
/**
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
public class MockWeatherService implements Function<MockWeatherService.Request, MockWeatherService.Response> {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final LogAccessor logger = new LogAccessor(getClass());
|
||||
|
||||
@Override
|
||||
public Response apply(Request request) {
|
||||
@@ -47,7 +47,7 @@ public class MockWeatherService implements Function<MockWeatherService.Request,
|
||||
temperature = 30;
|
||||
}
|
||||
|
||||
logger.info("Request is {}, response temperature is {}", request, temperature);
|
||||
logger.info("Request is " + request + ", response temperature is " + temperature);
|
||||
return new Response(temperature, Unit.C);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ 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;
|
||||
@@ -43,6 +41,7 @@ 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;
|
||||
|
||||
@@ -51,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "VERTEX_AI_GEMINI_LOCATION", matches = ".*")
|
||||
public class VertexAiGeminiChatModelFunctionCallingIT {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final LogAccessor logger = new LogAccessor(getClass());
|
||||
|
||||
@Autowired
|
||||
private VertexAiGeminiChatModel chatModel;
|
||||
@@ -93,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");
|
||||
}
|
||||
@@ -125,14 +124,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()).containsAnyOf("15.0", "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,14 +165,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");
|
||||
|
||||
@@ -208,7 +207,7 @@ public class VertexAiGeminiChatModelFunctionCallingIT {
|
||||
.map(AssistantMessage::getText)
|
||||
.collect(Collectors.joining());
|
||||
|
||||
logger.info("Response: {}", responseString);
|
||||
logger.info("Response: " + responseString);
|
||||
|
||||
assertThat(responseString).contains("30", "10", "15");
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ 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;
|
||||
@@ -46,6 +44,7 @@ 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;
|
||||
|
||||
@@ -57,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "VERTEX_AI_GEMINI_LOCATION", matches = ".*")
|
||||
public class VertexAiGeminiPaymentTransactionIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(VertexAiGeminiPaymentTransactionIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(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"));
|
||||
@@ -117,7 +116,7 @@ public class VertexAiGeminiPaymentTransactionIT {
|
||||
|
||||
private static class LoggingAdvisor implements CallAroundAdvisor {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(LoggingAdvisor.class);
|
||||
private static final LogAccessor logger = new LogAccessor(LoggingAdvisor.class);
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
||||
@@ -50,11 +50,6 @@
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ibm.cloud</groupId>
|
||||
<artifactId>sdk-core</artifactId>
|
||||
|
||||
@@ -19,9 +19,6 @@ 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;
|
||||
@@ -32,6 +29,7 @@ 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;
|
||||
|
||||
@@ -51,7 +49,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class WatsonxAiEmbeddingModel extends AbstractEmbeddingModel {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private static final LogAccessor logger = new LogAccessor(WatsonxAiEmbeddingModel.class);
|
||||
|
||||
private final WatsonxAiApi watsonxAiApi;
|
||||
|
||||
|
||||
@@ -58,11 +58,6 @@
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
||||
@@ -27,8 +27,6 @@ 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;
|
||||
|
||||
@@ -69,6 +67,7 @@ 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;
|
||||
@@ -88,7 +87,7 @@ import org.springframework.util.MimeType;
|
||||
*/
|
||||
public class ZhiPuAiChatModel extends AbstractToolCallSupport implements ChatModel, StreamingChatModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZhiPuAiChatModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(ZhiPuAiChatModel.class);
|
||||
|
||||
private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();
|
||||
|
||||
@@ -212,7 +211,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());
|
||||
}
|
||||
|
||||
@@ -297,7 +296,7 @@ public class ZhiPuAiChatModel extends AbstractToolCallSupport implements ChatMod
|
||||
return new ChatResponse(generations, from(chatCompletion2));
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error processing chat completion", e);
|
||||
logger.error(e, "Error processing chat completion");
|
||||
return new ChatResponse(List.of());
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@ 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;
|
||||
@@ -41,6 +39,7 @@ 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;
|
||||
@@ -53,7 +52,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ZhiPuAiEmbeddingModel extends AbstractEmbeddingModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZhiPuAiEmbeddingModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(ZhiPuAiEmbeddingModel.class);
|
||||
|
||||
private static final EmbeddingModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultEmbeddingModelObservationConvention();
|
||||
|
||||
@@ -175,7 +174,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 {
|
||||
|
||||
@@ -18,9 +18,6 @@ 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;
|
||||
@@ -30,6 +27,7 @@ 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;
|
||||
@@ -43,7 +41,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ZhiPuAiImageModel implements ImageModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZhiPuAiImageModel.class);
|
||||
private static final LogAccessor logger = new LogAccessor(ZhiPuAiImageModel.class);
|
||||
|
||||
public final RetryTemplate retryTemplate;
|
||||
|
||||
@@ -101,7 +99,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());
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@ 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;
|
||||
@@ -34,6 +32,7 @@ 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;
|
||||
@@ -44,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "ZHIPU_AI_API_KEY", matches = ".+")
|
||||
public class ZhiPuAiApiToolFunctionCallIT {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ZhiPuAiApiToolFunctionCallIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(ZhiPuAiApiToolFunctionCallIT.class);
|
||||
|
||||
MockWeatherService weatherService = new MockWeatherService();
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@ 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;
|
||||
@@ -58,6 +56,7 @@ 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 +68,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@EnabledIfEnvironmentVariable(named = "ZHIPU_AI_API_KEY", matches = ".+")
|
||||
class ZhiPuAiChatModelIT {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZhiPuAiChatModelIT.class);
|
||||
private static final LogAccessor logger = new LogAccessor(ZhiPuAiChatModelIT.class);
|
||||
|
||||
@Autowired
|
||||
protected ChatModel chatModel;
|
||||
@@ -239,7 +238,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");
|
||||
@@ -272,7 +271,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");
|
||||
@@ -333,7 +332,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");
|
||||
}
|
||||
|
||||
@@ -25,11 +25,10 @@ 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;
|
||||
|
||||
@@ -43,7 +42,7 @@ import org.springframework.core.type.filter.TypeFilter;
|
||||
*/
|
||||
public abstract class AiRuntimeHints {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AiRuntimeHints.class);
|
||||
private static final LogAccessor logger = new LogAccessor(AiRuntimeHints.class);
|
||||
|
||||
/**
|
||||
* Finds classes in a package that are annotated with JsonInclude or have Jackson
|
||||
@@ -91,8 +90,8 @@ public abstract class AiRuntimeHints {
|
||||
.stream()//
|
||||
.map(bd -> TypeReference.of(Objects.requireNonNull(bd.getBeanClassName())))//
|
||||
.peek(tr -> {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("registering [" + tr.getName() + ']');
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("registering [" + tr.getName() + ']');
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
|
||||
@@ -18,8 +18,6 @@ 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;
|
||||
@@ -31,6 +29,7 @@ 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.
|
||||
@@ -44,7 +43,7 @@ public class SimpleLoggerAdvisor implements CallAroundAdvisor, StreamAroundAdvis
|
||||
public static final Function<ChatResponse, String> DEFAULT_RESPONSE_TO_STRING = response -> ModelOptionsUtils
|
||||
.toJsonStringPrettyPrinter(response);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SimpleLoggerAdvisor.class);
|
||||
private static final LogAccessor logger = new LogAccessor(SimpleLoggerAdvisor.class);
|
||||
|
||||
private final Function<AdvisedRequest, String> requestToString;
|
||||
|
||||
@@ -78,12 +77,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
|
||||
|
||||
@@ -19,11 +19,9 @@ 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.
|
||||
@@ -36,7 +34,7 @@ import org.springframework.ai.model.ResponseMetadata;
|
||||
*/
|
||||
public class ChatResponseMetadata extends AbstractResponseMetadata implements ResponseMetadata {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ChatResponseMetadata.class);
|
||||
private static final LogAccessor logger = new LogAccessor(ChatResponseMetadata.class);
|
||||
|
||||
private String id = ""; // Set to blank to preserve backward compat with previous
|
||||
|
||||
@@ -140,7 +138,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;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user