ai-for-java / openai4j

Java client library for OpenAI API
Apache License 2.0
85 stars 34 forks source link

Allow the user to change log levels to info, warning, error or debug. #8

Closed mateusscheper closed 10 months ago

mateusscheper commented 10 months ago

The goal of this change is to allow the user to change log levels to info, warning, error or debug when logging requests and responses. When using langchain4j in a Spring Boot application, the user must set the debug level of the application to debug because the original code uses the log.debug() method. This change helps to simplify the logging process so the user doesn't have to change its application.

Example:

CompletionRequest request = CompletionRequest.builder()
                .prompt(PROMPT)
                .build();

        OpenAiClient client = OpenAiClient.builder()
                .openAiApiKey(System.getenv("OPENAI_API_KEY"))
                .logRequests()
                .logRequestsLevel(LogLevelEnum.INFO)
                .logResponses()
                .logResponsesLevel(LogLevelEnum.INFO)
                .build();

        CompletionResponse response = client.completion(request).execute();