Go AI IsEven 🚀

Welcome to Go AI IsEven, a whimsical Go package that leverages the power of artificial intelligence (ChatGPT) to answer a timeless question: Is this number even or odd? Why do the math yourself when you can ask an AI? 🤖
✨ Features
- AI-Powered: Queries ChatGPT via OpenAI's API to determine if a number is even or odd.
- Simple API: Easy-to-use client with a single method:
IsEven(number int).
- Robust: Includes error handling and testing with a mock server.
- Fancy: Because who doesn’t love over-engineering a simple problem?
🛠️ Installation
Get the package with:
go get github.com/volodymyrkatkalov/go-ai-iseven
You'll need an OpenAI API key. Set it as an environment variable:
export OPENAI_API_KEY='your-api-key-here'
🚀 Usage
Here's how to use it in your Go code:
package main
import (
"fmt"
"os"
"github.com/yourusername/go-ai-iseven"
)
func main() {
apiKey := os.Getenv("OPENAI_API_KEY")
if apiKey == "" {
fmt.Println("Please set OPENAI_API_KEY environment variable")
return
}
client := iseven.NewChatGPTClient(apiKey)
result, err := client.IsEven(42)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Is 42 even? %v\n", result)
}
Output:
ChatGPT says: 42 is yes
Is 42 even? true
Run it:
go run main.go
🧪 Testing
The package includes unit tests with a mock server to simulate ChatGPT responses:
go test
Test cases cover positive, negative, and zero inputs to ensure reliability.
📋 Requirements
- Go: 1.21 or higher
- OpenAI API Key: Obtainable from platform.openai.com
- Dependencies:
- github.com/sashabaranov/go-openai (automatically fetched with go get)
🎨 Example Output
Asking ChatGPT about various numbers:
client.IsEven(2) → ChatGPT says: 2 is yes → true
client.IsEven(3) → ChatGPT says: 3 is no → false
client.IsEven(0) → ChatGPT says: 0 is yes → true
🤝 Contributing
Contributions are welcome! Here’s how to get involved:
- Fork the repository
- Create a feature branch (git checkout -b feature/awesome-thing)
- Commit your changes (git commit -m "Add awesome thing")
- Push to the branch (git push origin feature/awesome-thing)
- Open a Pull Request
Please include tests and follow Go conventions.
📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgements
- OpenAI for the ChatGPT API
- sashabaranov/go-openai for the excellent Go client
- You, for checking out this awesome project!
⭐ Star this repo if you find it amusing or useful! ⭐
Created with ❤️ by volodymyrkatkalov