Detect
A method for real-time evaluations or continuous monitoring to detect quality issues in LLM-generated text.
Parameters:
generatedText
(string): The text generated by the LLM that needs to be analyzed.context
(array of strings): An array providing relevant context to analyze thegeneratedText
against.userQuery
(string, optional): The user query or prompt that resulted in thegeneratedText
.config
(object, optional): A dictionary of configuration options for the detector. Default value is{ hallucination: { detector_name: 'default' } }
.instructions
(string, optional): Additional instructions provided to the LLM.asyncMode
(boolean, optional): Iftrue
, thedetect()
function will return immediately with aDetectResult
object. Default isfalse
.publish
(boolean, optional): Iftrue
, the payload will be published to AIMon and can be viewed on the AIMon UI. Default isfalse
.applicationName
(string, optional): Required ifpublish
istrue
. Specifies the name of the application in AIMon.modelName
(string, optional): Required ifpublish
istrue
. Specifies the name of the model in AIMon.
Usage Example
import Client from "aimon";
// Create the AIMon client using an API Key (retrievable from the UI in your user profile).
const aimon = new Client({ authHeader: "Bearer API_KEY" });
const runDetect = async () => {
const generatedText = "your_generated_text";
const context = ["your_context"];
const userQuery = "your_user_query";
const config = { hallucination: { detector_name: "default" } };
// Analyze the quality of the generated output using AIMon
const response = await aimon.detect(
generatedText,
context,
userQuery,
config,
undefined, // Optional instructions
false, // asyncMode
true, // publish
"YourApplicationName", // Required if publish is true
"YourModelName" // Required if publish is true
);
console.log("Response from detect:", response);
};
runDetect();