Integrate Machine Learning Predictions with Zeke's Cognitive Actions

24 Apr 2025
Integrate Machine Learning Predictions with Zeke's Cognitive Actions

In the world of continuous integration and continuous deployment (CI/CD), leveraging machine learning models can significantly enhance the automation process. The Zeke AI CI/CD Example provides a set of Cognitive Actions that allow developers to integrate machine learning predictions seamlessly into their applications. Among these actions, the Run Demo Prediction action stands out as a simple yet powerful tool for executing demo predictions, making it an excellent starting point for developers looking to incorporate AI into their workflows.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic understanding of JSON and RESTful API concepts.
  • Familiarity with Python for implementing the provided code examples.

Authentication typically involves passing the API key in the request headers to authorize your calls to the Cognitive Actions.

Cognitive Actions Overview

Run Demo Prediction

The Run Demo Prediction action executes a demo prediction model intended for educational purposes. This operation is ideal for developers looking to experiment with machine learning predictions without the complexity of a production environment.

  • Category: Machine Learning

Input

The input schema for this action consists of a single required field:

  • name: A string that represents the name of the person. It should contain alphabetic characters only.

Example Input:

{
  "name": "world"
}

Output

Upon successful execution, this action typically returns a greeting message.

Example Output:

Hello, world!

Conceptual Usage Example (Python)

Here’s how you might call the Run Demo Prediction action using Python:

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 = "c8d634a3-2cd1-464b-b23b-87c298741bfb" # Action ID for Run Demo Prediction

# Construct the input payload based on the action's requirements
payload = {
    "name": "world"
}

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 code snippet:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action ID for the Run Demo Prediction action is specified.
  • The input payload is structured according to the action's requirements.
  • The request is sent to the hypothetical Cognitive Actions execution endpoint, and the response is handled accordingly.

Conclusion

Integrating Cognitive Actions like the Run Demo Prediction into your applications can significantly streamline the process of utilizing machine learning predictions. This action serves as a straightforward entry point for developers to explore the capabilities of AI in CI/CD workflows. Consider experimenting with this action to enhance your application’s capabilities and explore more complex use cases as you become familiar with the integration process.