Effortless Text Summarization with Samsum Cognitive Actions

In today’s fast-paced world, the ability to digest large volumes of information quickly is crucial. Samsum offers a powerful Cognitive Action designed for developers looking to generate concise and informative text summaries. By leveraging the advanced capabilities of the Samsum model, this action provides a streamlined approach to text summarization that enhances productivity and improves content accessibility.
With customizable parameters, developers can tailor the output based on specific needs, whether that’s adjusting the randomness of the summary, setting token limits, or defining stop sequences. This flexibility makes Samsum an ideal solution for various applications, from creating executive summaries of reports to condensing lengthy articles into digestible snippets. Imagine effortlessly transforming complex dialogues or dense documents into clear, actionable insights—this is the power of Samsum.
Prerequisites
To get started with Samsum’s Cognitive Actions, you’ll need a valid API key and a basic understanding of making API calls.
Generate Text Summaries
The Generate Text Summaries action is designed to produce short, coherent summaries from larger text inputs. This functionality is particularly beneficial for users who need to quickly understand the essence of a conversation, article, or any lengthy document.
Input Requirements: To use this action, you must provide a structured input object that includes:
- prompt: The text you want summarized. For example, a dialogue or a long paragraph.
- You can also specify optional parameters such as:
- topK: Controls the number of top tokens to consider.
- topP: Sets the cumulative probability for token selection.
- temperature: Adjusts the randomness of the output.
- maxGeneratedTokens: Limits the number of tokens in the output.
- minGeneratedTokens: Defines the minimum number of tokens to be generated.
- generationStopSequences: Specifies sequences that will halt generation.
Expected Output: The output will be a concise summary of the input text, providing a clear and straightforward rendition of the original content. For example, given the input dialogue about baking cookies, the output might summarize the agreement to deliver cookies in a simple sentence.
Use Cases for this specific action:
- Content Creation: Quickly generate summaries for articles, reports, or research papers to aid in content curation.
- Customer Support: Summarize customer interactions or feedback to highlight key points and trends.
- Education: Help students condense lecture notes or textbook chapters into manageable summaries for study purposes.
- Social Media: Create brief summaries of lengthy posts or discussions to share key insights with followers.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "bcbe43ba-c6b8-4291-a334-003e4f840a26" # Action ID for: Generate Text Summaries
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"topK": 50,
"topP": 0.9,
"debug": false,
"prompt": "Input:\nAmanda: I baked cookies. Do you want some?\nJerry: Sure!\nAmanda: I'll bring you tomorrow :-) [/INST]\n\nSummary: ",
"temperature": 0.75,
"maxGeneratedTokens": 128,
"minGeneratedTokens": -1
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
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 (non-JSON): {e.response.text}")
print("------------------------------------------------")
Conclusion
Samsum’s Cognitive Actions empower developers to create meaningful text summaries with ease and precision. By harnessing the flexibility and efficiency of this tool, you can enhance your applications, making complex information more accessible and actionable. Whether for business intelligence, educational tools, or content management, Samsum is a valuable asset in your development toolkit. Start integrating Samsum today and elevate how your applications interact with text data!