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.
-
Clone the repository:
git clone https://github.com/yourusername/go-ai-trivia.git cd go-ai-trivia
-
Install dependencies:
go mod tidy
-
Set up your OpenAI API key either:
- Create a
.env
file withOPENAI_API_KEY=your-api-key
- Or provide it via command line flag:
go run main.go --apiKey=your-api-key
- Create a
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:
- Enter a topic (or leave blank for random topics)
- Answer the generated questions
- See your final score
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