Skip to main content

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

  1. Set up your OpenAI API key:
export OPENAI_API_KEY='your-api-key-here'
  1. 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:

  1. OpenAI API Key Not Found
Error: OpenAI API key not found
Solution: Ensure OPENAI_API_KEY environment variable is set correctly
  1. API Connection Issues
# Enable debug logging for API calls
import logging
logging.basicConfig(level=logging.DEBUG)
  1. 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:

  1. Input validation ensures only integers are processed
  2. OpenAI client sends formatted prompts to the API
  3. API responses are parsed using Pydantic models
  4. Error handling manages API failures and invalid inputs
  5. Results are returned as boolean values
  6. The IsEven model validates the API response structure
  7. The core module handles the main business logic and API interaction

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

realiseven-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

realiseven-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

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

Hashes for realiseven-0.1.0.tar.gz
Algorithm Hash digest
SHA256 25f110decf178e95c08b90e0a2b4bb675bf5081951fd532f4ba83f340494cc73
MD5 a7fe1cf86c83b01e8928d92ee16a483d
BLAKE2b-256 392fb522cb28bf6c4079ba74fa695f01684d3d582fbcdf9c77109d2ff1765767

See more details on using hashes here.

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

Hashes for realiseven-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbc95907cc2c27b52c554350a241a68c2939c5784e0c524d2d6683b4b123490e
MD5 fa8a3cea9201028e2b0a32353bb214b7
BLAKE2b-256 89e51f6a459b1e2bf4ae1159f46908e3f634979040a2f1dcd852f0123b7e25cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page