API-only Rails 7 app handling AI generated questions for Brain Defrost trivia game
This API-only Rails app handles triva question creation for Brain Defrost. Questions are received from an external API, processed as plain old ruby objects (POROs), then sent to this repository where they are associated with a game. The trivia topic and question count are provided by this repository.
Brain Defrost is a web application designed to help people become more connected and engaged virtually via a trivia game. Generative AI is used to create custom trivia questions based on the topic and desired question count provided.
To play, a user inputs a topic, number of questions, number of players, a time limit to answer questions, and what they'd like their display name to be. The user is then taken to the game's lobby and provided with a shareable link other players may use to join. Once everyone joins, players may start the game and enjoy answering trivia questions. The correct answer and a list of players who answered correctly is displayed after each question.
This project was completed for Turing's Capstone Project for Mod 4. Part 1 of the project pertained planning and completing our app's minimum viable product (MVP). Part 2 will focus on adding additional features.
Repo | Deployment | Description |
---|---|---|
FE Repo | FE Github.io | Play a game of trivia |
BE Repo 1 | BE Heroku | Game, player, stats API |
BE Repo 2 (you're here) | BE Render | Questions API |
git clone <ssh or https path>
cd Brain-Defrost_BE-Questions
bundle install
to install gems used for this projectTrivia question's are created using OpenAI's API. You must use your own API key in order to access it.
To acquire an Open AI API key:
To add your OpenAI API key to the rails app:
config/master.key
fileEDITOR="code --wait" rails credentials:edit
config/master.key
file and opens a credentials file (config/credentials.yml.enc
)open_ai_key:
Bearer <your_open_ai_api_key_here>
[!important] Don't hard code your API key or share it with anyone. It's secret. The steps above help ensure it stays that way. Your master key is also secret as it's required to access the encrypted credentials file you setup. The master key's file is already configured to be excluded from GitHub via the
/config/master.key
code in the.gitignore
file.You can think of Rails' credentials file as similar to a
.env
file. If you need to update the credentials file for any reason, simply use theEDITOR="code --wait" rails credentials:edit
terminal command again.
This app uses http://localhost:5000
.
To start the local server run rails server
in the terminal while in the app's base directory (Brain-Defrost_BE-Questions folder).
To stop the local rails server use Ctrl
+ C
in the open terminal.
Rspec was used for testing. This project currently uses rspec-rails v6.1 and rspec-core v3.13. The vcr and webmock gems are setup to help limit tests' external API calls.
Terminal commands
bundle exec rspec spec
bundle exec rspec spec/folder_name
# ex: bundle exec rspec spec/models
bundle exec rspec <path/to/test/file>
# ex: bundle exec rspec spec/poros/question_spec.rb
bundle exec rspec <path/to/test/file>:test_line
# ex: bundle exec rspec spec/requests/api/v1/questions_spec.rb:20
API documentation may be accessed here. Documentation was setup using the rswag gem and SwaggerUI.
To access the API documentation on the local server. Start the server and navigate to http://localhost:5000/api-docs/index.html
in a browser.
If preferred, you can also use Postman to run endpoints, but you will still need to startup the local server using the rails server
command.
[!caution] Every time you run the POST questions endpoint via SwaggerUI or Postman you are making an actual API call to OpenAI using your API key
Martin Chavez - Github | LinkedIn Jessica Kohl - Github | LinkedIn Laura Vega - Github | LinkedIn
Ethan Duvall - Github | LinkedIn Tayla Phillips - Github | LinkedIn