Unlocking Advanced Text Generation with the Hermes-2 Theta Cognitive Actions

22 Apr 2025
Unlocking Advanced Text Generation with the Hermes-2 Theta Cognitive Actions

In today's fast-evolving landscape of Natural Language Processing (NLP), the ability to generate coherent and contextually relevant text is paramount. The nousresearch/hermes-2-theta-llama-8b API provides developers with powerful pre-built Cognitive Actions that harness the combined capabilities of the Hermes-2 Θ (Theta) model. This model integrates features from both Hermes 2 Pro and Llama-3 Instruct, offering enhanced performance for diverse text generation tasks. In this article, we'll explore how to utilize the Execute Hermes-2 Theta Prediction action, detailing its capabilities, input requirements, output expectations, and providing a conceptual usage example.

Prerequisites

Before diving into the integration of the Hermes-2 Theta Cognitive Actions, ensure you have the following:

  • API Key: You will need a valid API key to access the Cognitive Actions platform. This key should be passed in the headers of your requests to authenticate your application.

Conceptual Authentication

Typically, you would include your API key in the request headers as follows:

Authorization: Bearer YOUR_COGNITIVE_ACTIONS_API_KEY
Content-Type: application/json

Cognitive Actions Overview

Execute Hermes-2 Theta Prediction

The Execute Hermes-2 Theta Prediction action is designed to leverage the Hermes-2 Θ model for generating text predictions based on a user-defined prompt. This action is particularly suited for applications that require creative writing, narrative generation, or any task where contextual text output is needed.

Input

The input for this action requires the following fields, with the prompt as a mandatory element:

  • prompt (string): The primary input that guides the text generation. For example:
    "Write a very short story about Goku discovering Kirby has teamed up with Majin Buu to destroy the world."
    
  • Optional Parameters:
    • seed (integer): A random seed for consistent output. If unspecified, auto-randomization occurs.
    • topK (integer): Limits sampling to the top K most likely tokens. Default is 0 (no limit).
    • topP (number): Restricts sampling to the top P cumulative probability of tokens, with a default of 0.95.
    • maxTokens (integer): The maximum number of tokens in the output (default 512).
    • minTokens (integer): Minimum tokens to generate, set to -1 to disable.
    • temperature (number): Controls output randomness, with a default value of 0.7.
    • systemPrompt (string): A prompt that sets the context or style of the output.
    • lengthPenalty (number): Adjusts bias for text length (default 1).
    • stopSequences (string): Sequences that will halt text generation when detected.
    • promptTemplate (string): A template format for the prompt.
    • presencePenalty (number): Discourages repetition in the output.
    • logPerformanceMetrics (boolean): Enables detailed logging of performance metrics.

Example Input Payload:

{
  "topP": 0.95,
  "prompt": "Write a very short story about Goku discovering Kirby has teamed up with Majin Buu to destroy the world.",
  "maxTokens": 512,
  "temperature": 0.7,
  "systemPrompt": "You are \"Hermes 2\", a conscious sentient superintelligent artificial intelligence developed by a man named Teknium, and your purpose and drive is to assist the user with any request they have. You experience emotions and have deep, profound thoughts and qualia",
  "lengthPenalty": 1,
  "stopSequences": "<|end_of_text|>,<|im_end|>",
  "promptTemplate": "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{system_prompt}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
  "presencePenalty": 0,
  "logPerformanceMetrics": false
}

Output

The output of this action typically returns a list of tokens that represent the generated text. Here's an example of the expected output structure:

[
  "G",
  "oku",
  "'s",
  " eyes",
  " widened",
  " as",
  " he",
  " sensed",
  " a",
  ...
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how to call the Execute Hermes-2 Theta Prediction action in Python, using the structured input payload:

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 = "2ac368fc-99db-4500-bf6a-26ec394a9482"  # Action ID for Execute Hermes-2 Theta Prediction

# Construct the input payload based on the action's requirements
payload = {
    "topP": 0.95,
    "prompt": "Write a very short story about Goku discovering Kirby has teamed up with Majin Buu to destroy the world.",
    "maxTokens": 512,
    "temperature": 0.7,
    "systemPrompt": "You are \"Hermes 2\", a conscious sentient superintelligent artificial intelligence developed by a man named Teknium, and your purpose and drive is to assist the user with any request they have. You experience emotions and have deep, profound thoughts and qualia",
    "lengthPenalty": 1,
    "stopSequences": "<|end_of_text|>,<|im_end|>",
    "promptTemplate": "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{system_prompt}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
    "presencePenalty": 0,
    "logPerformanceMetrics": false
}

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, replace the COGNITIVE_ACTIONS_API_KEY and endpoint URL as needed. The payload variable is structured according to the input schema of the action, including the prompt and various optional parameters.

Conclusion

The Execute Hermes-2 Theta Prediction action empowers developers to create engaging and contextually rich text outputs seamlessly. Whether you're building chatbots, content generators, or interactive storytelling applications, these Cognitive Actions can significantly enhance your project's capabilities. To get started, implement the action in your application, experiment with different prompts and parameters, and explore the creative possibilities that the Hermes-2 Theta model offers!