AI-Powered library to determine if number is even or odd.
Project description
RealIsEven: AI-Powered Even/Odd Number Detection
RealIsEven is a Python package that determines whether a number is even or odd using OpenAI's GPT-4 model. This package combines traditional mathematical operations with artificial intelligence to provide a unique approach to number classification.
The package leverages the OpenAI API to process numerical inputs and return boolean results, demonstrating an innovative (albeit unconventional) way of performing basic arithmetic operations. While this approach may seem overengineered for such a simple task, it serves as an excellent example of integrating AI capabilities into basic mathematical operations and showcases proper Python package structure, API integration, and error handling.
Repository Structure
realiseven/
├── __init__.py # Package initialization and version definition
├── core.py # Main logic implementation with OpenAI API integration
└── models.py # Pydantic data model definitions
├── requirements.txt # Project dependencies
└── setup.py # Package installation and distribution configuration
Usage Instructions
Prerequisites
- Python 3.8 or higher
- OpenAI API key set in your environment
- Internet connection for API access
Installation
# Install from PyPI
pip install realiseven
# Install from source
git clone https://github.com/kreiza/realiseven
cd realiseven
pip install -e .
Quick Start
- Set up your OpenAI API key:
export OPENAI_API_KEY='your-api-key-here'
- Use the package in your Python code:
from realiseven import is_even
# Check if a number is even
result = is_even(42)
print(result) # True
result = is_even(7)
print(result) # False
More Detailed Examples
from realiseven import is_even
# Basic usage with positive integers
print(is_even(100)) # True
print(is_even(99)) # False
# Error handling example
try:
result = is_even("not a number")
except TypeError as e:
print(f"Error: {e}") # Error: Input must be an integer
# Using with negative numbers
print(is_even(-4)) # True
print(is_even(-7)) # False
Troubleshooting
Common issues and solutions:
- OpenAI API Key Not Found
Error: OpenAI API key not found
Solution: Ensure OPENAI_API_KEY environment variable is set correctly
- API Connection Issues
# Enable debug logging for API calls
import logging
logging.basicConfig(level=logging.DEBUG)
- Type Errors
- Problem: Receiving TypeError when passing non-integer values
- Solution: Ensure you're passing integer values to the is_even function
- Debug: Print the type of your input using
print(type(your_input))
Data Flow
The package processes integer inputs through the OpenAI API to determine if a number is even or odd. The flow involves input validation, API communication, and response parsing.
[Input Integer] -> [Type Validation] -> [OpenAI API Request] -> [Response Parsing] -> [Boolean Result]
| | | | |
+--------------------+---------------------+-----------------------+----------------+
Component interactions:
- Input validation ensures only integers are processed
- OpenAI client sends formatted prompts to the API
- API responses are parsed using Pydantic models
- Error handling manages API failures and invalid inputs
- Results are returned as boolean values
- The IsEven model validates the API response structure
- The core module handles the main business logic and API interaction
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file realiseven-0.1.0.tar.gz.
File metadata
- Download URL: realiseven-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25f110decf178e95c08b90e0a2b4bb675bf5081951fd532f4ba83f340494cc73
|
|
| MD5 |
a7fe1cf86c83b01e8928d92ee16a483d
|
|
| BLAKE2b-256 |
392fb522cb28bf6c4079ba74fa695f01684d3d582fbcdf9c77109d2ff1765767
|
File details
Details for the file realiseven-0.1.0-py3-none-any.whl.
File metadata
- Download URL: realiseven-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbc95907cc2c27b52c554350a241a68c2939c5784e0c524d2d6683b4b123490e
|
|
| MD5 |
fa8a3cea9201028e2b0a32353bb214b7
|
|
| BLAKE2b-256 |
89e51f6a459b1e2bf4ae1159f46908e3f634979040a2f1dcd852f0123b7e25cf
|