ロギング
LangChain4jはSLF4Jをロギングに使用しており、 LogbackやLog4jなど、 お好みのロギングバックエンドを接続できます。
純粋なJava
モデルのインスタンスを作成する際に.logRequests(true)
と.logResponses(true)
を設定することで、
LLMへの各リクエストとレスポンスのロギングを有効にできます:
OpenAiChatModel.builder()
...
.logRequests(true)
.logResponses(true)
.build();
依存関係にSLF4Jロギングバックエンドの1つがあることを確認してください。例えば、Logback:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.8</version>
</dependency>
Quarkus
Quarkus統合を使用する場合、
ロギングはapplication.properties
ファイルで設定されます:
...
quarkus.langchain4j.openai.chat-model.log-requests = true
quarkus.langchain4j.openai.chat-model.log-responses = true
quarkus.log.console.enable = true
quarkus.log.file.enable = false
これらのプロパティは、アプリケーションを開発モード(mvn quarkus:dev
)で実行している場合、
Quarkus Dev UIでも設定および変更できます。
Dev UIはhttp://localhost:8080/q/dev-ui
で利用できます。
Spring Boot
Spring Boot統合を使用する場合、
ロギングはapplication.properties
ファイルで設定されます:
...
langchain4j.open-ai.chat-model.log-requests = true
langchain4j.open-ai.chat-model.log-responses = true
logging.level.dev.langchain4j = DEBUG