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
},
"Article Image": {
"content_type": "image", # Specify content type as image
"instructions": "A vibrant illustration of a futuristic city with flying cars and holographic billboards, in a synthwave art style.", # This is the image prompt
# For image sections, response_format is mainly for clarity; the actual data passed to html_template is {"image_url": ...}
"response_format": {"image_url": "URL of the AI-generated image"},
"html_template": "<figure>\n <img src='{image_url}' alt='AI-generated image for the article' style='max-width:100%; height:auto;' />\n <figcaption style='text-align:center; font-style:italic; color:#555;'>A vivid, AI-generated illustration.</figcaption>\n</figure>",
# Optional: specify DALL·E model, size, quality for the image
# "image_model": "dall-e-3",
# "image_size": "1024x1024", # Or other DALL·E supported sizes like "1792x1024", "1024x1792"
# "image_quality": "standard" # or "hd" for DALL·E 3
}
}
# 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")
# Image sections also return HTML strings, they are handled by the isinstance(str) check above
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
)
Metadata
Release files for ai-article-generator 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_article_generator-0.1.7.tar.gz | 9.1 kB | Without provenance | Details for ai_article_generator-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_article_generator-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for ai_article_generator-0.1.7-py3-none-any.whl |
Total release size: 17.0 kB
Release files / ai_article_generator-0.1.7.tar.gz
| Download URL | ai_article_generator-0.1.7.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3581051ada0ab6c21f6aa35e355dcad4646470d0af550b848ef7fef7b80db0ba
|
|
BLAKE2b-256 checksum How to use checksums |
ce7c89b27795f0af04ad3e5b285326ea80897661b9b5470500510fb423639960
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.17
|
Release files / ai_article_generator-0.1.7-py3-none-any.whl
| Download URL | ai_article_generator-0.1.7-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
630ae8f3da76143809eed4cff72a57d03ad758641e7ab07d3c109c14e5226b1f
|
|
BLAKE2b-256 checksum How to use checksums |
fbe1ea91689c7704286dce17bf1f195b95ca2d1ee8ac6693e8f06d505d28a730
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.17
|
Security for ai-article-generator 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.