This code can be a good start to learn to use the OpenAI API to generate content with a simple prompt and includes some ways to customize output.
This application generates concise stories for a 10-year-old audience, featuring two brothers, Pat and Jack, who embark on adventures in rural western Pennsylvania. It was inspired by stories my grandfather told when I was a kid. The stories are generated using OpenAI's GPT-4 model, with the ability to customize elements of the story by selecting specific story elements.
To run this project locally, follow these steps:
-
Clone the repository:
git clone [email protected]:markstephenburnham/patandjackweb.git cd pat-and-jack-stories
-
Install dependencies:
Make sure you have Node.js installed, then run:
npm install
-
Set up environment variables:
Create a
.env
file in the root of the project and add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key_here
-
Start the server:
node app.js
The application will be running on
http://localhost:3000
.
- Open a web browser and navigate to
http://localhost:3000
. - Select a story element from the provided options.
- Click "Create Your Story!" to generate a new story.
- The story will be generated using OpenAI's GPT-4 model and displayed on the page.
- Feature Selection: Users can select a story element, which will be incorporated into the generated story.
- Random Elements: Occasionally, an additional character ("The Old Trapper") is added to the story.
- Dynamic Story Generation: Stories are generated on-demand via AJAX requests to a local server, which proxies requests to OpenAI.
The application requires the following environment variables:
OPENAI_API_KEY
: Your OpenAI API key to access the GPT-4 model.
index.html
: The main HTML file containing the structure of the web page.styles.css
: The CSS file that styles the application.story.js
: The JavaScript file that handles front-end logic, including the AJAX request to generate stories.app.js
: The Node.js server that handles incoming requests and communicates with the OpenAI API.public/
: Directory containing static assets, such as images and additional HTML files (e.g.,404.html
).
If you'd like to contribute to this project:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch-name
). - Make your changes and commit them (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch-name
). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE
file for details.