Detect AI-Generated Text with havocy28/ai-detector Cognitive Actions

In today's digital landscape, distinguishing between AI-generated content and human-written text is more crucial than ever. The havocy28/ai-detector API offers developers a powerful Cognitive Action designed to identify whether a given text is produced by AI or composed by a human. This capability can enhance applications across various domains, from content moderation to educational tools, allowing for improved user experiences and trust.
In this article, we will explore how to utilize the Detect AI Generated Text action, detailing its functionality, input requirements, expected output, and providing a conceptual example of how to integrate it into your applications.
Prerequisites
Before diving into the usage of the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform. This key is essential for authenticating your requests.
- Basic familiarity with JSON and RESTful API concepts, as you will be sending JSON payloads to the API endpoint.
Authentication typically involves passing your API key in the headers of your HTTP requests.
Cognitive Actions Overview
Detect AI Generated Text
The Detect AI Generated Text action identifies whether the provided text has been generated by AI or created by humans. Leveraging the Fast-DetectGPT model, it can assess longer texts with speed and accuracy, making it an invaluable tool for content verification.
Input
This action requires a structured JSON object as input. The schema is outlined below:
{
"inputText": "string"
}
- inputText (required): This is the text content that you need to evaluate. It should be a string containing the content you want to analyze for AI generation.
Example Input:
{
"inputText": "We tend to think of training as just a means to make our fur-friends well-mannered and keep them safe. But training has another role, in that it provides vital mental stimulation that stops your pet getting bored..."
}
Output
The expected output from this action is a numerical value indicating the likelihood that the text was generated by AI. The output schema is as follows:
{
"likelihood": "number"
}
- likelihood: A floating-point number representing the probability that the text is AI-generated, where lower values indicate a higher probability of human authorship.
Example Output:
0.02
Conceptual Usage Example (Python)
Here is a conceptual Python code snippet demonstrating how to execute the Detect AI Generated Text action:
import requests
import json
# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint
action_id = "0a120118-d82b-4b2c-819e-dc32e6e33c71" # Action ID for Detect AI Generated Text
# Construct the input payload based on the action's requirements
payload = {
"inputText": "We tend to think of training as just a means to make our fur-friends well-mannered and keep them safe. But training has another role, in that it provides vital mental stimulation that stops your pet getting bored..."
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json"
}
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json={"action_id": action_id, "inputs": payload}
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body: {e.response.text}")
In this code snippet:
- Replace
YOUR_COGNITIVE_ACTIONS_API_KEYwith your actual API key. - Ensure you adjust the endpoint URL accordingly.
- The
payloadis constructed based on the input requirements, where theinputTextis provided for analysis. - The response is processed to handle both successful outcomes and potential errors.
Conclusion
The Detect AI Generated Text action from the havocy28/ai-detector API offers a straightforward yet powerful method for distinguishing between AI-generated and human-created text. By integrating this Cognitive Action into your applications, you can enhance content verification processes, bolster user trust, and ensure greater content integrity.
As the capabilities of AI continue to evolve, leveraging such tools will be essential for maintaining quality and authenticity in digital content. Consider exploring additional use cases or combining this action with other Cognitive Actions to expand your application's functionality.