climate-tech-handbook / data-magic

Scripts and other fun tricks to enhance the site
MIT License
10 stars 5 forks source link

Data Magic (OpenAI Utility API)

This project provides an API for generating content using OpenAI's completion models. It includes a ContentGenerator class, utility functions, and a simple Flask app to generate content based on prompts, templates, and other configurations. Overall, a dumping ground of experiments and code for the Climate Tech Handbook Website.


Current Goals

1. API Development
2. CLI Commands
3. Error Handling
4. Advanced File Editing
5. Improved Prompts
6. Enhanced Templates
7. Unsplash Integration

Future Plans

1. Integration of Additional OpenAI Services
2. RSS Bridge for Climate Data Fine-Tuning
3. Climate Tech Chatbot


Using Flask App

Installation

1. Clone this repository to your local machine.
git clone git@github.com:climate-tech-handbook/data-magic.git
2. Change working directory to data-magic/app/
cd data-magic/app/
3. Create a virtual environment.

Python 3.4 or above:

python -m venv venv

otherwise you can use:

pip install virtualenv
virtualenv venv
3. Activate virtual environment.

Linux or MacOS:

source venv/bin/activate

Windows (cmd.exe):

venv\Scripts\activate.bat

Windows (Powershell):

venv\Scripts\Activate.ps1
4. Install the required packages.
pip install -r requirements.txt

Setting up .env (API Keys)

Ensure you are still in the data-magic/app/ directory

To use the content generator, you will need an OpenAI API key:

1. Obtain your OpenAI API key from the OpenAI Dashboard.
2. Create a .env file in the root directory of your project (if it does not yet already exist)
3. Add your OpenAI API key to the .env file in the following format:
OPENAI_SECRET_KEY=your_api_key_here

Replace your_api_key_here with the actual key you obtained from OpenAI.

We use Unsplash Photos as our stock image provider:

UNSPLASH_ACCESS_KEY=your_api_key_here
4. In your Python code, you can use the dotenv library to load API keys from the .env file:
from dotenv import load_dotenv
import os

load_dotenv()
api_key = os.getenv("ENVIRONMENT_VAR_NAME")

Running the Flask App

If you completed the installation process without any persisting errors, you can continue. If you need further assistance, open an issue.

1. Run the Flask app with flask run or try python app.py
2. The app will create a file for a specific topic using the prompts, templates, and configurations provided in the data folder.


Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

If you are lost on how to start contributing or don't understand how a certain class or file works, try checking out our Contributing Guide


License

This project is licensed under the MIT License. See the LICENSE file for more details.

This README provides an overview of the project, installation instructions, usage examples, and contribution guidelines. You can customize the content as needed to better suit your project.


Acknowledgments

This project is in active development and is currently in an MVP stage, stay tuned to see how it grows!