Effortlessly Generate Text with Dolly V2 Cognitive Actions

26 Apr 2025
Effortlessly Generate Text with Dolly V2 Cognitive Actions

Dolly V2 12b Demo provides developers with a powerful tool for generating text using advanced AI capabilities. By leveraging the Dolly-v2-12b model, developers can create diverse and contextually relevant text outputs tailored to their specific needs. This service simplifies the text generation process, allowing for quick experimentation and integration into applications without requiring deep expertise in natural language processing.

Common use cases include content creation for blogs, automated responses for customer service, or even creative writing assistance. The flexibility of adjustable parameters such as temperature, top-k, and top-p decoding methods ensures that developers can fine-tune outputs to achieve the desired level of creativity or accuracy.

Prerequisites

To get started with the Dolly V2 12b Demo, you'll need an API key for the Cognitive Actions service and a basic understanding of making API calls.

Generate Text with Dolly v2

The Generate Text with Dolly v2 action allows you to utilize the capabilities of the Dolly-v2-12b model to generate text based on a provided prompt. This action is particularly useful for applications requiring dynamic content generation.

Purpose

This action helps solve the problem of generating coherent and contextually relevant text by providing a robust AI model that can adapt to various input prompts and user requirements.

Input Requirements

The input consists of a structured object that includes:

  • prompt: A string that guides the text generation.
  • topK: An integer representing the number of highest probability tokens to retain (default is 50).
  • topP: A float that samples from the top p percentage of likely tokens (default is 1).
  • decoding: A string that specifies the decoding method, either 'top_p' or 'top_k' (default is 'top_p').
  • maxLength: An integer that sets the maximum number of tokens to generate (default is 500).
  • temperature: A float that controls the randomness of outputs (default is 0.75).
  • repetitionPenalty: A float that applies a penalty to repeated tokens to influence output diversity (default is 1.2).

Example Input:

{
  "topK": 50,
  "topP": 1,
  "prompt": "please compare the Cog and Blentoml",
  "decoding": "top_p",
  "maxLength": 500,
  "temperature": 0.75,
  "repetitionPenalty": 1.2
}

Expected Output

The output will be a list of tokens that represent the generated text based on the input prompt. This output can be further processed or displayed to end users.

Example Output:

[
  "The",
  " Cog",
  " is",
  " a",
  " self-driving",
  " car",
  " developed",
  ...
]

Use Cases for this Action

  • Content Creation: Automate the generation of articles, blog posts, or marketing materials.
  • Customer Support: Develop chatbots that can provide informative responses based on user queries.
  • Creative Writing: Assist writers by generating ideas, storylines, or even full passages based on initial prompts.
  • Research Assistance: Generate summaries or comparisons of various topics to aid in research and analysis.
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 = "456ddf1d-ddaf-4424-ab0c-9fbcedc4347f" # Action ID for: Generate Text with Dolly v2

# 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": 1,
  "prompt": "please compare the Cog and Blentoml",
  "decoding": "top_p",
  "maxLength": 500,
  "temperature": 0.75,
  "repetitionPenalty": 1.2
}

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

The Dolly V2 12b Demo offers developers a streamlined approach to text generation, enabling a wide variety of applications from content creation to automated customer support. By utilizing the adjustable parameters, developers can tailor the output to meet specific needs and enhance user experiences. To begin integrating this powerful tool into your projects, explore the API documentation and start experimenting with different prompts and settings. The potential for innovation is at your fingertips!