Streamline Dialogue Summarization with nateraw/samsum-llama-7b Cognitive Actions

25 Apr 2025
Streamline Dialogue Summarization with nateraw/samsum-llama-7b Cognitive Actions

In today’s fast-paced digital world, being able to quickly summarize dialogues can greatly enhance user experience across applications. The nateraw/samsum-llama-7b API offers powerful Cognitive Actions that perform dialogue summarization using the LLaMA-2-7b model, fine-tuned specifically on the Samsum dataset. This integration helps developers generate concise, accurate summaries rapidly, making it an invaluable tool for applications that handle conversational data.

Prerequisites

Before you start using the nateraw/samsum-llama-7b Cognitive Actions, make sure you have the following:

  • An API key for the Cognitive Actions platform.
  • A working environment where you can make HTTP requests, such as Python or Postman.

Authentication is typically handled by including your API key in the header of your requests, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Summarize Dialogue with Samsum LLaMA-2-7b

The Summarize Dialogue with Samsum LLaMA-2-7b action is designed to produce summaries of dialogues, enhancing both speed and accuracy. This action falls under the text-summarization category.

Input

The input for this action requires a structured JSON object with the following fields:

{
  "prompt": "string (required)",
  "seed": "integer (optional)",
  "topK": "integer (optional, default: 50)",
  "topP": "number (optional, default: 0.9)",
  "debug": "boolean (optional, default: false)",
  "temperature": "number (optional, default: 0.75)",
  "maximumTokenCount": "integer (optional, default: 128)",
  "minimumTokenCount": "integer (optional, default: -1)",
  "terminationSequences": "string (optional)"
}

Example Input:

{
  "topK": 50,
  "topP": 0.95,
  "debug": false,
  "prompt": "[INST] <<SYS>>\nUse the Input to provide a summary of a conversation.\n<</SYS>>\n\nInput:\nHarry: Who are you?\nHagrid: Rubeus Hagrid, Keeper of Keys and Grounds at Hogwarts. Of course, you know all about Hogwarts.\nHarry: Sorry, no.\nHagrid: No? Blimey, Harry, did you never wonder where yer parents learned it all?\nHarry: All what?\nHagrid: Yer a wizard, Harry.\nHarry: I-- I'm a what?\nHagrid: A wizard! And a thumpin' good 'un, I'll wager, once you've been trained up a bit. [/INST]\n\nSummary: ",
  "temperature": 0.4,
  "maximumTokenCount": 256,
  "minimumTokenCount": -1,
  "terminationSequences": "</s>"
}

Output

The output generated by this action will typically be a concise summary of the dialogue provided in the prompt.

Example Output:

Harry is confused by Hagrid’s statement that he is a wizard.

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet illustrating how you might call the Cognitive Actions execution endpoint for this summarization 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 = "7329f13c-f03b-45cf-b0d7-454d703c3da2" # Action ID for Summarize Dialogue with Samsum LLaMA-2-7b

# Construct the input payload based on the action's requirements
payload = {
    "topK": 50,
    "topP": 0.95,
    "debug": false,
    "prompt": "[INST] <<SYS>>\nUse the Input to provide a summary of a conversation.\n<</SYS>>\n\nInput:\nHarry: Who are you?\nHagrid: Rubeus Hagrid, Keeper of Keys and Grounds at Hogwarts. Of course, you know all about Hogwarts.\nHarry: Sorry, no.\nHagrid: No? Blimey, Harry, did you never wonder where yer parents learned it all?\nHarry: All what?\nHagrid: Yer a wizard, Harry.\nHarry: I-- I'm a what?\nHagrid: A wizard! And a thumpin' good 'un, I'll wager, once you've been trained up a bit. [/INST]\n\nSummary: ",
    "temperature": 0.4,
    "maximumTokenCount": 256,
    "minimumTokenCount": -1,
    "terminationSequences": "</s>"
}

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 snippet, you will replace the API key and endpoint with your actual values. The action_id is specific to the summarization action. The payload is constructed using the example input format to ensure proper execution.

Conclusion

The nateraw/samsum-llama-7b Cognitive Actions provide a robust solution for summarizing dialogues quickly and effectively. By integrating these actions into your applications, you can enhance user engagement and streamline the processing of conversational data. Explore potential use cases like chatbots, customer support interactions, or any application that benefits from dialogue summarization. Happy coding!