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
},
"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
)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_article_generator-0.1.7.tar.gz.
File metadata
- Download URL: ai_article_generator-0.1.7.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3581051ada0ab6c21f6aa35e355dcad4646470d0af550b848ef7fef7b80db0ba
|
|
| MD5 |
397c437d6725a74baad0057d1fb7dafd
|
|
| BLAKE2b-256 |
ce7c89b27795f0af04ad3e5b285326ea80897661b9b5470500510fb423639960
|
File details
Details for the file ai_article_generator-0.1.7-py3-none-any.whl.
File metadata
- Download URL: ai_article_generator-0.1.7-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
630ae8f3da76143809eed4cff72a57d03ad758641e7ab07d3c109c14e5226b1f
|
|
| MD5 |
67ed812408add96e6c670ea5d756b610
|
|
| BLAKE2b-256 |
fbe1ea91689c7704286dce17bf1f195b95ca2d1ee8ac6693e8f06d505d28a730
|