Package com.axelor.ai.chat
Class AiUsageLogger
java.lang.Object
com.axelor.ai.chat.AiUsageLogger
Records AI usage metrics. All logging is fire-and-forget in a background thread.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidlog(AiUsageSource source, String modelCode, String providerCode, String agentCode, String chatId, Integer inputTokens, Integer outputTokens, Integer cacheReadTokens, Integer cacheWriteTokens, Integer latencyMs, AiUsageStatus status, String errorMessage) static voidlogError(AiUsageSource source, String modelCode, String providerCode, String agentCode, String chatId, Integer latencyMs, String errorMessage) static <T> Tlogged(AiUsageSource source, String modelCode, String providerCode, String agentCode, String chatId, Supplier<T> call, Function<T, dev.langchain4j.model.output.TokenUsage> tokens) Makes a model call outside the chat stream, writing its usage row: the tokens the response reports, or the error it failed with.static voidlogSuccess(AiUsageSource source, String modelCode, String providerCode, String agentCode, String chatId, Integer inputTokens, Integer outputTokens, Integer cacheReadTokens, Integer cacheWriteTokens, Integer latencyMs) static voidrefused(AiUsageSource source, ChatRequest request) A turn refused, before its first model call or between two: its model may not receive what the chat holds.static voidrefused(AiUsageSource source, ChatRequest request, String reason) A call refused for what the chat holds, said as the given reason: a consultation's differs from a turn's, the turn going on without it.
-
Constructor Details
-
AiUsageLogger
public AiUsageLogger()
-
-
Method Details
-
log
-
refused
A turn refused, before its first model call or between two: its model may not receive what the chat holds. Logged under the model it would have gone to. -
refused
A call refused for what the chat holds, said as the given reason: a consultation's differs from a turn's, the turn going on without it. -
logSuccess
-
logError
-
logged
public static <T> T logged(AiUsageSource source, String modelCode, String providerCode, String agentCode, String chatId, Supplier<T> call, Function<T, dev.langchain4j.model.output.TokenUsage> tokens) Makes a model call outside the chat stream, writing its usage row: the tokens the response reports, or the error it failed with.
-