Generate Coherent Text Using Mamba 1.4B Cognitive Actions

23 Apr 2025
Generate Coherent Text Using Mamba 1.4B Cognitive Actions

Integrating advanced AI capabilities into your applications has never been easier with the adirik/mamba-1.4b Cognitive Actions. This set of pre-built actions allows developers to leverage the powerful Mamba 1.4B language model to generate coherent and contextually relevant text outputs. With customizable parameters for randomness and token generation, these actions can enhance user interactions, automate content creation, and more.

Prerequisites

Before diving into the Cognitive Actions, ensure you have access to the Cognitive Actions platform with an API key. You will need to include this key in the request headers for authentication. Typically, this is done by including a bearer token in your HTTP request.

Cognitive Actions Overview

Generate Text with Mamba 1.4B

The Generate Text with Mamba 1.4B action allows you to utilize the state-of-the-art Mamba 1.4B model to generate text based on a provided prompt. This action gives you granular control over the generation process, including randomness and repetition penalties.

Input

The input for this action is structured as follows:

  • prompt (required): The initial text input for processing (e.g., "How are you doing today?").
  • seed (optional): An integer seed value for repeatable results.
  • topK (optional): An integer specifying the number of most likely tokens to sample from during decoding (default: 1).
  • topP (optional): A number between 0.01 and 1, indicating the percentage of top tokens to sample from (default: 1).
  • maxLength (optional): An integer that specifies the maximum number of tokens to generate (default: 100; range: 1-5000).
  • temperature (optional): A number controlling the randomness of the output (default: 1; range: 0.1-5).
  • repetitionPenalty (optional): A number that applies a penalty to repeated words (default: 1.2).

Example Input:

{
  "topK": 1,
  "topP": 1,
  "prompt": "How are you doing today?",
  "maxLength": 100,
  "temperature": 1,
  "repetitionPenalty": 1.2
}

Output

The output will typically be an array of strings representing the generated text tokens. For example:

Example Output:

[
  "\n",
  "",
  "",
  "I'm ",
  "",
  "fine. ",
  "",
  "I'm ",
  "just ",
  "a ",
  "little ",
  "bit ",
  "",
  "tired, ",
  "but ",
  "other ",
  "than ",
  "",
  "that...\n",
  "",
  "",
  "What's ",
  "the ",
  "matter ",
  "with ",
  "your ",
  "",
  "leg?\n",
  "",
  "",
  "Nothing. ",
  "It ",
  "was ",
  "",
  "nothing. ",
  "Just ",
  "some ",
  "minor ",
  "injuries ",
  "from ",
  "last ",
  "",
  "night.\n"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Generate Text with Mamba 1.4B 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 = "f8419f8f-3e8f-4937-b3b3-8c161f681a6a"  # Action ID for Generate Text with Mamba 1.4B

# Construct the input payload based on the action's requirements
payload = {
    "topK": 1,
    "topP": 1,
    "prompt": "How are you doing today?",
    "maxLength": 100,
    "temperature": 1,
    "repetitionPenalty": 1.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 code snippet, replace the COGNITIVE_ACTIONS_API_KEY with your API key and utilize the action ID for generating text. The payload is structured according to the action's requirements.

Conclusion

The adirik/mamba-1.4b Cognitive Actions offer powerful capabilities for text generation, making it easier for developers to enhance their applications with sophisticated AI features. With customizable parameters, you can fine-tune the output to fit your specific needs, whether it's for chatbots, content creation, or any other application requiring natural language processing. Explore these capabilities today and unlock new possibilities in your software projects!