Skip to content

generate

gitpavleenbali edited this page Feb 17, 2026 · 2 revisions

generate

The generate function creates various types of content using AI.

Import

from pyai 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

Parameter Type Default Description
prompt str required Description of content to generate
type str None Content type: "email", "blog", "code", "story"
tone str "professional" Tone: "formal", "casual", "professional"
length str "medium" Length: "short", "medium", "long"
format str None Output format: "markdown", "html", "plain"

Content Types

Type Description
email Professional emails
blog Blog posts and articles
code Code snippets
story Creative stories
report Business reports
documentation Technical docs

Examples

Generate Email

from pyai 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 pyai 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

🧠 PYAI Wiki

Home


πŸš€ Getting Started


πŸ’‘ Core Concepts


🎯 One-Liner APIs


πŸ€– Agent Framework


πŸ”— Multi-Agent


πŸ› οΈ Tools & Skills


🏒 Enterprise


πŸŽ™οΈ Voice


πŸ–ΌοΈ Multimodal


πŸ“Š Vector DB


🌐 OpenAPI


πŸ”Œ Plugins


🀝 A2A Protocol


πŸ”’ Security


πŸ“š Reference


Intelligence, Embedded.

Clone this wiki locally