Skip to content

Uses OpenAI API to generate and play a trivia game based on a user-provided topic.

Notifications You must be signed in to change notification settings

dblinkhorn/go-ai-trivia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Trivia Game

An interactive command-line trivia game powered by OpenAI's GPT model. The program generates customized trivia questions based on user-specified topics, or random topics (if the topic prompt is left blank). The topics can range from very broad (e.g. sports) to very precise (e.g. 16th century French politics). It also provides intelligent answer validation.

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/go-ai-trivia.git
    cd go-ai-trivia
  2. Install dependencies:

    go mod tidy
  3. Set up your OpenAI API key either:

    • Create a .env file with OPENAI_API_KEY=your-api-key
    • Or provide it via command line flag:
      go run main.go --apiKey=your-api-key

Usage

Run the program:

go run main.go

Or with API key flag (if you did not create a .env file containing your API key):

go run main.go -apiKey=your-api-key

Follow the prompts to:

  1. Enter a topic (or leave blank for random topics)
  2. Answer the generated questions
  3. See your final score

Answer Validation

The program uses a combination of:

  • Word matching for multi-word answers (e.g. William Shakespeare)
  • Jaro-Winkler distance algorithm for typo tolerance
  • Case-insensitive comparison

About

Uses OpenAI API to generate and play a trivia game based on a user-provided topic.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages