Create Haikus Dynamically with the Zeke/Haiku-Progressive Cognitive Actions

22 Apr 2025
Create Haikus Dynamically with the Zeke/Haiku-Progressive Cognitive Actions

In the realm of creative coding, the ability to generate poetry dynamically can add a unique touch to applications. The Zeke/Haiku-Progressive Cognitive Actions allow developers to integrate a text-generation model that crafts Haiku poetry word by word, offering a progressive experience that can captivate users. In this article, we'll explore how to leverage this action, its inputs, and outputs, along with a conceptual example of how to implement it in your applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of making HTTP requests in your preferred programming language.

Conceptually, authentication typically involves passing the API key in the headers of your requests, which helps in securing your interaction with the cognitive services.

Cognitive Actions Overview

Generate Haiku Word by Word

The Generate Haiku Word by Word action provides a unique experience by generating Haiku poetry progressively, one word at a time. This allows users to engage with the creation process as it unfolds, making each word a surprise.

Input

The input for this action requires the following fields:

  • Seed Value (optional): An integer seed used to generate consistent and repeatable results. It must be a non-negative value (e.g., 5).
  • Pause Duration (optional): A number indicating the duration in seconds to pause between each word when using progressive output. The default is 0.1 seconds.

Example Input:

{
  "seed": 5,
  "pauseDuration": 0.1
}

Output

The output of this action is a progressive list of strings, each representing the Haiku being formed word by word. The example output demonstrates how the Haiku evolves with each step:

Example Output:

[
  "21-gun",
  "21-gun salute-\n",
  "21-gun salute-\nmortar",
  "21-gun salute-\nmortar fire",
  "21-gun salute-\nmortar fire echoes\n",
  "21-gun salute-\nmortar fire echoes\nin",
  "21-gun salute-\nmortar fire echoes\nin his",
  "21-gun salute-\nmortar fire echoes\nin his eyes"
]

Conceptual Usage Example (Python)

Here's a conceptual example of how you might call this action using Python. This snippet constructs the input payload based on the action's requirements and makes a request to the hypothetical Cognitive Actions execution endpoint.

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 = "302bc8c1-614c-4cf9-a8fe-b1e17aa61e09" # Action ID for Generate Haiku Word by Word

# Construct the input payload based on the action's requirements
payload = {
    "seed": 5,
    "pauseDuration": 0.1
}

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 variable holds the ID for the "Generate Haiku Word by Word" action.
  • The input payload is structured according to the action's schema.

Conclusion

The Zeke/Haiku-Progressive Cognitive Actions provide a unique way to engage users with dynamic poetry generation. By utilizing the "Generate Haiku Word by Word" action, developers can create interactive applications that surprise and delight users with each word of a Haiku. Consider exploring other creative applications, and don't hesitate to experiment with different seed values and pause durations to enhance the user experience!