com.newrelic.api.agent.AiMonitoring Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of newrelic-api Show documentation
Show all versions of newrelic-api Show documentation
New Relics's Java Api Jar.
package com.newrelic.api.agent;
import java.util.Map;
/**
* This interface defines methods for recording LlmFeedbackMessage events and setting a callback for token calculation.
*/
public interface AiMonitoring {
/**
* Records an LlmFeedbackMessage event.
*
* @param llmFeedbackEventAttributes A map containing the attributes of an LlmFeedbackMessage event. To construct
* the llmFeedbackEventAttributes map, use
* {@link LlmFeedbackEventAttributes.Builder}
* The map must include:
*
* - "traceId" (String): Trace ID where the chat completion related to the
* feedback event occurred
* - "rating" (Integer/String): Rating provided by an end user
*
* Optional attributes:
*
* - "category" (String): Category of the feedback as provided by the end user
* - "message" (String): Freeform text feedback from an end user
* - "metadata" (Map<String, String>): Set of key-value pairs to store
* additional data to submit with the feedback event
*
*
*
*/
void recordLlmFeedbackEvent(Map llmFeedbackEventAttributes);
/**
* Sets the callback function for calculating LLM tokens.
*
* @param llmTokenCountCallback The callback function to be invoked for counting LLM tokens.
* Example usage:
* {@code
* LlmTokenCountCallback llmTokenCountCallback = new LlmTokenCountCallback() {
* {@literal @}Override
* public Integer calculateLlmTokenCount(String model, String content) {
* // Token calculation based on model and content goes here
* // Return the calculated token count
* }
* };
*
* // Set the created callback instance
* NewRelic.getAgent().getAiMonitoring().setLlmTokenCountCallback(llmTokenCountCallback);
* }
*/
void setLlmTokenCountCallback(LlmTokenCountCallback llmTokenCountCallback);
}