Skip to main content

A Python library for generating articles using AI.

Project description

ai_article_generator

A Python library for generating articles using AI. This library provides tools and utilities to automate the creation of articles, leveraging machine learning and natural language processing techniques.

Installation

Install the library from PyPI:

pip install ai-article-generator

Or, for development, clone the repository and install dependencies:

pip install -r requirements.txt

API Key Setup

You must create a .env file in your project directory with your OpenAI API key:

OPENAI_API_KEY=your-openai-api-key-here

This is required for the library to access the OpenAI API.

Usage

Import and use the library in your Python code:

from ai_article_generator.generator import ArticleGenerator

Example Usage

from ai_article_generator.generator import ArticleGenerator

# Example instructions for article sections
instructions = {
    "Article Header": {
        "instructions": "Write a header for a tech article about AI in journalism.",
        "response_format": {"title": "Article Main Title", "subtitle": "Catchy Subtitle"},
        "html_template": "<h1>{title}: {subtitle}</h1>",
    },
    "SEO Data": {
        "instructions": "Generate an SEO title (around 60 characters) and meta description (around 155 characters) for an article about AI in journalism.",
        "response_format": {
            "seo_title": "SEO Optimized Title",
            "meta_description": "Compelling meta description for search engines",
        },
        # No html_template here, so it will return the structured data as a dictionary
    }
}

# Any additional data your sections might need
additional_data = {"keywords": ["AI", "journalism", "technology"]}

# Create the generator (article_type can be 'review', 'news', 'guide', 'feature', or 'generic')
generator = ArticleGenerator(
    instructions=instructions,
    additional_data=additional_data
)

# Generate the article sections as HTML
try:
    generated_outputs = generator.generate() # Output can be HTML or structured data
    for section_name, output_content in generated_outputs.items():
        print(f"Section: {section_name}")
        if isinstance(output_content, str): # HTML content
            print(f"HTML Output:\\n{output_content}\\n")
        elif isinstance(output_content, dict): # Structured data (e.g., SEO)
            print("Structured Data Output:")
            for key, value in output_content.items():
                print(f"  {key}: {value}")
            print("\\n")
except Exception as e:
    print(f"Error generating article: {e}")

Arguments and Options

The ArticleGenerator class accepts the following arguments:

Argument Required? Default Description
instructions Yes Section instructions (dict)
additional_data Yes Extra data for sections (dict)
article_type No "generic" Type of article (affects system prompt)
system_prompt No None Custom system prompt
model No "gpt-4o-mini" OpenAI model to use

Example with optional fields

generator = ArticleGenerator(
    instructions=instructions,
    additional_data=additional_data,
    article_type="feature",      # optional
    system_prompt=None,          # optional
    model="gpt-4o-mini"          # optional
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_article_generator-0.1.6.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_article_generator-0.1.6-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file ai_article_generator-0.1.6.tar.gz.

File metadata

  • Download URL: ai_article_generator-0.1.6.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for ai_article_generator-0.1.6.tar.gz
Algorithm Hash digest
SHA256 64402597f832491b1f9883ae34aace0890015b0ca5cb6ad3e4454e9a8d9c0e52
MD5 3a2f0dc3bd80e11d0f9a7f45aca9afb2
BLAKE2b-256 aa81ab231d20efe88f7f07efb871ca1ab058e69647fd6c9444640644bdb872c5

See more details on using hashes here.

File details

Details for the file ai_article_generator-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_article_generator-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 23ae0a587bc16fced87061120bf8e74ce2ce3d458697594bda9c1663391df0cc
MD5 369d1306b61dfae5cebbab5c0cd95dc5
BLAKE2b-256 b571762415f3e224018023e38c10454abcb50371df5907db8cec263df1b743d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page