Validate and Store Results with wglint/1_test Cognitive Actions

24 Apr 2025
Validate and Store Results with wglint/1_test Cognitive Actions

In today's software development landscape, integrating pre-built functionalities can significantly accelerate your application development process. The wglint/1_test API offers a straightforward Cognitive Action designed to validate the addition of two integers and store the results in a Supabase database. This action serves as a simple yet effective demonstration of how you can leverage Cognitive Actions to simplify your data handling processes without diving deep into complex algorithms.

Prerequisites

To get started with the Cognitive Actions, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform, which you will use to authenticate your requests.
  • Basic understanding of JSON structure for input and output.

Authentication typically involves passing your API key in the headers of your HTTP requests, ensuring secure and authorized access to the Cognitive Actions.

Cognitive Actions Overview

Validate and Store Addition Result

This action is designed to validate the addition of two integers and then record the result in a Supabase database. It focuses on providing immediate feedback on whether the user’s provided sum was correct.

  • Category: Data

Input

The input for this action requires three fields:

  1. firstInteger (integer): The first integer in the addition operation. Default value is 8.
  2. secondInteger (integer): The second integer in the addition operation. Default value is 1.
  3. sumOfIntegers (integer): The sum that the user believes is the result of adding the two integers.

Here’s an example of a valid input JSON payload:

{
  "firstInteger": 8,
  "secondInteger": 1,
  "sumOfIntegers": 2
}

Output

Upon execution, the action returns a message indicating whether the provided sum is correct or not. For example:

Hello ! You wrong... Good answer of 8 + 1 is 9 and not 2 !
Supabase send : Error

This output provides a direct response regarding the validation of the sum and mentions the Supabase interaction status.

Conceptual Usage Example (Python)

To use the Validate and Store Addition Result action, you can implement the following Python code snippet, which demonstrates how to structure your request:

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 = "5871e298-a308-4e90-ad9c-0c35bd00ca9f"  # Action ID for Validate and Store Addition Result

# Construct the input payload based on the action's requirements
payload = {
    "firstInteger": 8,
    "secondInteger": 1,
    "sumOfIntegers": 2
}

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}  # Hypothetical structure
    )
    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 example, you'll need to replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload are structured as specified, ensuring you can validate and store results effectively.

Conclusion

The Validate and Store Addition Result action in the wglint/1_test API provides a straightforward method for validating arithmetic operations and can be easily integrated into your applications. By utilizing this action, you can enhance your app's functionality while minimizing the complexity of code you need to write.

Next steps could involve exploring additional Cognitive Actions or integrating this functionality into larger workflows that require data validation and storage solutions. Happy coding!