Git Product home page Git Product logo

history-twister's Introduction

History Twister

History Twister image

This app was written, debugged, and deployed entirely by ChatGPT (GPT-4) in April 2023.

Production demo URL: https://historytwister.com

Generate historical fiction with History Twister, powered by AI. This application uses the OpenAI API to generate creative, alternative versions of historical events based on user prompts.


Here's an example:

Newspaper article: It's a day after the United States has surrendered to Axis powers and lost World War 2. Citizens are being instructed to report to their respective internment camps.

Result: https://historytwister.com/results.html?twist=63af0cbc-8bc6-4dff-98c8-d88c2c61cd2f

Features

  • Responsive design with a navbar and About modal
  • Parses and respects line breaks in API responses
  • Share twisted history via Email and Twitter with unique result URLs
  • CTA buttons to twist history again or start over

Good to know

Heads up that the hosted version has been hitting some API soft cap limits from public usage, so I updated the max_tokens value in the prompt to be 350 (about 250 words) in early May 2023.

If you're running this locally, you will get more interesting results if you adjust your max_tokens value to be 1024 (or similar).

In app.js:

const response = await openai.createChatCompletion({
  model: "gpt-3.5-turbo",
  messages: [
    { role: "system", content: "You are a famous historical figure with a vivid imagination and deep knowledge of historical events. You are known for your comprehensive and engaging writing style that accurately reflects the time period you're writing about. Your task is to create a captivating and detailed alternative history based on the user's prompt. Use your creativity to explore the consequences of this scenario and provide a unique perspective on how this event would have unfolded. Remember to use language and references appropriate for the time period, and make sure to keep your audience captivated with your storytelling skills." },
    { role: "user", content: `Create a ${outputFormat} based on the following alternative history scenario: ${prompt}` },
  ],
  temperature: 0.8,
  // Set max token value here
  max_tokens: 300,
});

Getting Started

Prerequisites

  • Node.js and npm installed on your machine
  • An OpenAI API key

Installing

  1. Clone this repository:

git clone [email protected]:mattlebel/history-twister.git

  1. Change to the project directory:

cd history-twister

  1. Install dependencies:

npm install

  1. Create a .env file in the project root and add your OpenAI API key:

OPENAI_API_KEY=your_openai_api_key

  1. Initialize the database by running the initialize-db.js script:

node initialize-db.js

Running the Application

Start the application by running:

npm start

The application should now be running at http://localhost:3000.

Database Configuration

For local development, this application uses SQLite. For production, it uses PostgreSQL. The application automatically switches between SQLite and PostgreSQL based on the NODE_ENV environment variable.

Deploying to Heroku

  1. Install the Heroku CLI and log in to your Heroku account: heroku login

  2. Create a new Heroku application:

heroku create your-app-name

  1. Via the Heroku dashboard, add the Heroku PostgreSQL add-on

  2. Via the Heroku dashboard, set your OpenAI API key and NODE_ENV as Heroku environment variables

  3. Deploy your application to Heroku:

git push heroku main

  1. Open your deployed application in a web browser:

heroku open

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.