Generate High-Quality Images with rmosimann1/energia.chat Cognitive Actions

In today’s digital landscape, the ability to generate high-quality images on demand can significantly enhance user engagement and content presentation. The rmosimann1/energia.chat API provides powerful Cognitive Actions for image generation, allowing developers to create stunning visuals based on customizable text prompts. This blog post will guide you through the usage of the Generate Customizable Image action, detailing its capabilities and how to integrate it into your applications.
Prerequisites
To get started with the Cognitive Actions, you'll need:
- An API key for the rmosimann1/energia.chat platform.
- A basic understanding of JSON and HTTP requests.
- Python installed on your machine for testing the conceptual code examples.
Authentication typically involves passing the API key in the headers of your requests, ensuring secure access to the Cognitive Actions.
Cognitive Actions Overview
Generate Customizable Image
The Generate Customizable Image action allows users to create high-quality images using a text prompt, with options to customize aspects such as the image's aspect ratio, output format, and even apply an image mask. This action is categorized under image-generation and supports two models for fast generation.
Input
The input for this action requires a JSON object, with the following fields:
- prompt (required): The text prompt that describes the image to be generated.
- mask (optional): A URI for an image mask used for inpainting.
- seed (optional): A random seed for reproducible generation.
- image (optional): A URI for an input image for image-to-image transformations.
- width (optional): The width of the generated image (only if aspect ratio is custom).
- height (optional): The height of the generated image (only if aspect ratio is custom).
- imageAspectRatio (optional): The desired aspect ratio of the image.
- imageOutputFormat (optional): The desired file format for the output image (e.g., 'webp', 'jpg', 'png').
- numberOfOutputs (optional): Specifies how many images to generate (default is 1).
Here’s an example input JSON payload for the action:
{
"seed": 123456,
"width": 1440,
"prompt": "ngia \nThis image will be published on the blog of a company that develops artificial intelligence chatbots...",
"loraScale": 1,
"guidanceScale": 3,
"extraLoraScale": 1,
"inferenceModel": "dev",
"inferenceSteps": 28,
"promptStrength": 0.8,
"numberOfOutputs": 1,
"imageAspectRatio": "16:9",
"imageOutputFormat": "png",
"imageOutputQuality": 100
}
Output
The output of the action is a JSON array containing URLs to the generated images. Here’s an example of what the output may look like:
[
"https://assets.cognitiveactions.com/invocations/5520c290-61f5-4fcb-a101-f5743859eb39/831b8cf2-0d3f-43d0-acc3-675fa1c7f14e.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet demonstrating how to call the Generate Customizable Image 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 = "2616e51f-ae48-4acd-ab3c-13f43fd58e61" # Action ID for Generate Customizable Image
# Construct the input payload based on the action's requirements
payload = {
"seed": 123456,
"width": 1440,
"prompt": "ngia \nThis image will be published on the blog of a company that develops artificial intelligence chatbots...",
"loraScale": 1,
"guidanceScale": 3,
"extraLoraScale": 1,
"inferenceModel": "dev",
"inferenceSteps": 28,
"promptStrength": 0.8,
"numberOfOutputs": 1,
"imageAspectRatio": "16:9",
"imageOutputFormat": "png",
"imageOutputQuality": 100
}
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 replace the COGNITIVE_ACTIONS_API_KEY and endpoint with your own values. The payload is constructed according to the action requirements, and the API call is made using the requests library.
Conclusion
The Generate Customizable Image action in the rmosimann1/energia.chat API empowers developers to create high-quality images tailored to their needs quickly. By leveraging customizable prompts and various options, you can enhance your applications and provide rich visual content. Explore the potential of image generation in your projects today, and consider experimenting with different prompts and settings to see the creative possibilities unfold!