Skip to main content

generate

The generate function creates various types of content using AI.

Import

from openstackai import generate

Basic Usage

# Generate content
content = generate("blog post about Python")

# With type specification
email = generate("thank you email", type="email")

# Async version
content = await generate.async_("product description")

Parameters

ParameterTypeDefaultDescription
promptstrrequiredDescription of content to generate
typestrNoneContent type: "email", "blog", "code", "story"
tonestr"professional"Tone: "formal", "casual", "professional"
lengthstr"medium"Length: "short", "medium", "long"
formatstrNoneOutput format: "markdown", "html", "plain"

Content Types

TypeDescription
emailProfessional emails
blogBlog posts and articles
codeCode snippets
storyCreative stories
reportBusiness reports
documentationTechnical docs

Examples

Generate Email

from openstackai import generate

email = generate(
"thank customer for purchase",
type="email",
tone="friendly"
)
print(email)

Generate Blog Post

blog = generate(
"introduction to machine learning",
type="blog",
length="long",
format="markdown"
)

Generate Documentation

docs = generate(
"API documentation for user authentication",
type="documentation"
)

Generate Code

code = generate(
"Python function to validate email addresses",
type="code"
)

Async Usage

import asyncio
from openstackai import generate

async def main():
content = await generate.async_(
"product launch announcement",
type="email"
)
print(content)

asyncio.run(main())

Templates

# Use predefined templates
content = generate.from_template(
"newsletter",
topic="Monthly Update",
highlights=["Feature A", "Feature B"]
)

See Also

  • [[ask]] - Question answering
  • [[code]] - Code operations
  • [[translate]] - Translation