Name | isnt_that_odd JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | A Python library that determines if a number is even using LLM APIs |
upload_time | 2025-08-10 18:02:06 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License Copyright (c) 2025 Launch Platform Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# isn't that odd
A Python library that determines if a given number is even or not by sending prompts to LLM APIs. Built with LiteLLM for universal LLM support and structured output for reliable responses.
## Features
- ๐ค **LLM-Powered**: Uses Large Language Models to determine if numbers are even or odd
- ๐ **Universal Support**: Built on LiteLLM to support any LLM provider (OpenAI, Anthropic, local models, etc.)
- ๐ **Structured Output**: Forces LLM responses to be structured JSON for reliability
- ๐งช **Comprehensive Testing**: Full test suite with pytest and promptfoo integration
- ๐ **Modern Python**: Type hints, Pydantic models, and modern Python practices
- ๐ฆ **Easy Installation**: Simple setup with uv package manager
## Installation
### Using uv (Recommended)
```bash
# Install uv if you haven't already
pip install uv
# Clone the repository
git clone https://github.com/yourusername/isnt_that_odd.git
cd isnt_that_odd
# Install dependencies
uv sync
# Install in development mode
uv pip install -e .
```
## Quick Start
```python
from isnt_that_odd import is_even
# Check if a number is even
result = is_even(42)
print(result) # True
result = is_even(43)
print(result) # False
```
## Usage
### Command Line Interface
The library provides a command-line interface with two main commands:
#### Check a single number
```bash
# Basic usage
isnt-that-odd check 42
# With custom model
isnt-that-odd check --model gpt-4 42
# With verbose output
isnt-that-odd check --verbose 42
# With custom API key
isnt-that-odd check --api-key YOUR_KEY 42
```
#### Run benchmark mode
```bash
# Run benchmark with 20 random numbers
isnt-that-odd benchmark --count 20
# Run benchmark with custom range and verbose output
isnt-that-odd benchmark --count 50 --min -5000 --max 5000 --verbose
# Run benchmark with specific model
isnt-that-odd benchmark --count 100 --model claude-3-sonnet-20240229
```
The benchmark mode:
- Generates random numbers within a specified range
- Tests the LLM's accuracy in determining even/odd numbers
- Provides detailed statistics including accuracy percentage and timing
- Shows breakdown by even vs odd numbers
- Reports examples of incorrect predictions (with verbose mode)
### Basic Usage
```python
from isnt_that_odd import is_even, EvenChecker
# Simple function call
is_even(10) # True
is_even(11) # False
is_even(0) # True
is_even(-4) # True
is_even(-7) # False
is_even(10.5) # True (integer part 10 is even)
```
### Advanced Usage
```python
from isnt_that_odd import EvenChecker
# Create a custom checker
checker = EvenChecker(
model="gpt-4",
api_key="your-api-key-here"
)
# Check multiple numbers
numbers = [2, 3, 4, 5, 6, 7, 8, 9, 10]
results = [checker.check(num) for num in numbers]
print(results) # [True, False, True, False, True, False, True, False, True]
```
### Using Different LLM Providers
```python
from isnt_that_odd import EvenChecker
# OpenAI
checker = EvenChecker(
model="gpt-4",
api_key="your-openai-key"
)
# Anthropic
checker = EvenChecker(
model="claude-3-sonnet-20240229",
api_key="your-anthropic-key"
)
# Local models (e.g., Ollama)
checker = EvenChecker(
model="llama2",
base_url="http://localhost:11434/v1"
)
# Azure OpenAI
checker = EvenChecker(
model="gpt-4",
api_key="your-azure-key",
base_url="https://your-resource.openai.azure.com/openai/deployments/your-deployment"
)
```
## API Reference
### `is_even(number, model="gpt-3.5-turbo", api_key=None, base_url=None)`
Convenience function to check if a number is even.
**Parameters:**
- `number`: The number to check (int, float, or string)
- `model`: LLM model to use (default: "gpt-3.5-turbo")
- `api_key`: API key for the LLM service
- `base_url`: Base URL for the LLM service (for open-source models)
**Returns:**
- `bool`: True if the number is even, False if odd
### `EvenChecker(model="gpt-3.5-turbo", api_key=None, base_url=None)`
Main class for checking if numbers are even.
**Methods:**
- `check(number)`: Check if a number is even
- `_create_prompt(number)`: Create the prompt for the LLM
### Benchmark Functions
The CLI module also provides programmatic access to benchmark functionality:
```python
from isnt_that_odd.cli import run_benchmark, generate_random_numbers
# Generate random numbers for testing
numbers = generate_random_numbers(count=100, min_val=-1000, max_val=1000)
# Run benchmark programmatically
run_benchmark(
count=50,
model="gpt-3.5-turbo",
api_key="your-key",
verbose=True,
min_val=-500,
max_val=500
)
```
## How It Works
1. **Prompt Engineering**: The library creates a carefully crafted prompt that instructs the LLM to determine if a number is even or odd
2. **Structured Output**: Uses JSON response format to ensure the LLM returns structured data
3. **Fallback Parsing**: If JSON parsing fails, falls back to text analysis
4. **Error Handling**: Comprehensive error handling for API failures and parsing issues
### Example Prompt
```
You are a mathematical assistant. Your task is to determine if the given number is even or odd.
Number: 42
Instructions:
1. A number is even if it is divisible by 2 with no remainder
2. A number is odd if it is not divisible by 2
3. For decimal numbers, only the integer part matters
4. For negative numbers, the same rules apply
5. Zero (0) is considered even
Please respond with ONLY a JSON object containing a boolean field "is_even":
- Set "is_even" to true if the number is even
- Set "is_even" to false if the number is odd
Example response format:
{"is_even": true}
Your response:
```
## Testing
### Running Tests
```bash
# Run all tests
pytest
# Run with coverage
pytest --cov=src/isnt_that_odd
# Run specific test file
pytest tests/test_core.py
```
### Prompt Testing with promptfoo
```bash
# Install promptfoo
npm install -g promptfoo
# Run prompt tests
promptfoo eval -c promptfoo.yaml
```
## Development
### Setting up Development Environment
```bash
# Install development dependencies
uv sync --group dev
# Install pre-commit hooks
pre-commit install
# Run code formatting
black src/ tests/
isort src/ tests/
# Run linting
ruff check src/ tests/
# Run type checking
mypy src/
```
### Project Structure
```
isnt_that_odd/
โโโ src/
โ โโโ isnt_that_odd/
โ โโโ __init__.py
โ โโโ core.py
โ โโโ cli.py
โโโ examples/
โ โโโ basic_usage.py
โ โโโ benchmark_example.py
โโโ tests/
โ โโโ __init__.py
โ โโโ test_core.py
โ โโโ test_cli.py
โโโ pyproject.toml
โโโ promptfoo.yaml
โโโ README.md
```
## Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- **Inspired by** [vibesort](https://github.com/abyesilyurt/vibesort) - GPT-powered array sorting using structured output
- Built with [LiteLLM](https://github.com/BerriAI/litellm) for universal LLM support
- Uses [Pydantic](https://github.com/pydantic/pydantic) for data validation
- Tested with [pytest](https://github.com/pytest-dev/pytest) and [promptfoo](https://github.com/promptfoo/promptfoo)
## Why "isn't that odd"?
The name is a playful reference to the library's purpose of determining whether numbers are even or odd. It's also a bit of a pun - when you ask if something "isn't that odd," you're questioning whether it's unusual, just like the library questions whether a number is odd!
Raw data
{
"_id": null,
"home_page": null,
"name": "isnt_that_odd",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Fang-Pen Lin <hello@fangpenlin.com>",
"download_url": "https://files.pythonhosted.org/packages/db/11/f7e14c0dbeb739e161014408896aaa8a883875a71d64e9fd56b7951759e3/isnt_that_odd-0.1.0.tar.gz",
"platform": null,
"description": "# isn't that odd\n\nA Python library that determines if a given number is even or not by sending prompts to LLM APIs. Built with LiteLLM for universal LLM support and structured output for reliable responses.\n\n## Features\n\n- \ud83e\udd16 **LLM-Powered**: Uses Large Language Models to determine if numbers are even or odd\n- \ud83d\udd0c **Universal Support**: Built on LiteLLM to support any LLM provider (OpenAI, Anthropic, local models, etc.)\n- \ud83d\udcca **Structured Output**: Forces LLM responses to be structured JSON for reliability\n- \ud83e\uddea **Comprehensive Testing**: Full test suite with pytest and promptfoo integration\n- \ud83d\ude80 **Modern Python**: Type hints, Pydantic models, and modern Python practices\n- \ud83d\udce6 **Easy Installation**: Simple setup with uv package manager\n\n## Installation\n\n### Using uv (Recommended)\n\n```bash\n# Install uv if you haven't already\npip install uv\n\n# Clone the repository\ngit clone https://github.com/yourusername/isnt_that_odd.git\ncd isnt_that_odd\n\n# Install dependencies\nuv sync\n\n# Install in development mode\nuv pip install -e .\n```\n\n## Quick Start\n\n```python\nfrom isnt_that_odd import is_even\n\n# Check if a number is even\nresult = is_even(42)\nprint(result) # True\n\nresult = is_even(43)\nprint(result) # False\n```\n\n## Usage\n\n### Command Line Interface\n\nThe library provides a command-line interface with two main commands:\n\n#### Check a single number\n```bash\n# Basic usage\nisnt-that-odd check 42\n\n# With custom model\nisnt-that-odd check --model gpt-4 42\n\n# With verbose output\nisnt-that-odd check --verbose 42\n\n# With custom API key\nisnt-that-odd check --api-key YOUR_KEY 42\n```\n\n#### Run benchmark mode\n```bash\n# Run benchmark with 20 random numbers\nisnt-that-odd benchmark --count 20\n\n# Run benchmark with custom range and verbose output\nisnt-that-odd benchmark --count 50 --min -5000 --max 5000 --verbose\n\n# Run benchmark with specific model\nisnt-that-odd benchmark --count 100 --model claude-3-sonnet-20240229\n```\n\nThe benchmark mode:\n- Generates random numbers within a specified range\n- Tests the LLM's accuracy in determining even/odd numbers\n- Provides detailed statistics including accuracy percentage and timing\n- Shows breakdown by even vs odd numbers\n- Reports examples of incorrect predictions (with verbose mode)\n\n### Basic Usage\n\n```python\nfrom isnt_that_odd import is_even, EvenChecker\n\n# Simple function call\nis_even(10) # True\nis_even(11) # False\nis_even(0) # True\nis_even(-4) # True\nis_even(-7) # False\nis_even(10.5) # True (integer part 10 is even)\n```\n\n### Advanced Usage\n\n```python\nfrom isnt_that_odd import EvenChecker\n\n# Create a custom checker\nchecker = EvenChecker(\n model=\"gpt-4\",\n api_key=\"your-api-key-here\"\n)\n\n# Check multiple numbers\nnumbers = [2, 3, 4, 5, 6, 7, 8, 9, 10]\nresults = [checker.check(num) for num in numbers]\nprint(results) # [True, False, True, False, True, False, True, False, True]\n```\n\n### Using Different LLM Providers\n\n```python\nfrom isnt_that_odd import EvenChecker\n\n# OpenAI\nchecker = EvenChecker(\n model=\"gpt-4\",\n api_key=\"your-openai-key\"\n)\n\n# Anthropic\nchecker = EvenChecker(\n model=\"claude-3-sonnet-20240229\",\n api_key=\"your-anthropic-key\"\n)\n\n# Local models (e.g., Ollama)\nchecker = EvenChecker(\n model=\"llama2\",\n base_url=\"http://localhost:11434/v1\"\n)\n\n# Azure OpenAI\nchecker = EvenChecker(\n model=\"gpt-4\",\n api_key=\"your-azure-key\",\n base_url=\"https://your-resource.openai.azure.com/openai/deployments/your-deployment\"\n)\n```\n\n## API Reference\n\n### `is_even(number, model=\"gpt-3.5-turbo\", api_key=None, base_url=None)`\n\nConvenience function to check if a number is even.\n\n**Parameters:**\n- `number`: The number to check (int, float, or string)\n- `model`: LLM model to use (default: \"gpt-3.5-turbo\")\n- `api_key`: API key for the LLM service\n- `base_url`: Base URL for the LLM service (for open-source models)\n\n**Returns:**\n- `bool`: True if the number is even, False if odd\n\n### `EvenChecker(model=\"gpt-3.5-turbo\", api_key=None, base_url=None)`\n\nMain class for checking if numbers are even.\n\n**Methods:**\n- `check(number)`: Check if a number is even\n- `_create_prompt(number)`: Create the prompt for the LLM\n\n### Benchmark Functions\n\nThe CLI module also provides programmatic access to benchmark functionality:\n\n```python\nfrom isnt_that_odd.cli import run_benchmark, generate_random_numbers\n\n# Generate random numbers for testing\nnumbers = generate_random_numbers(count=100, min_val=-1000, max_val=1000)\n\n# Run benchmark programmatically\nrun_benchmark(\n count=50,\n model=\"gpt-3.5-turbo\",\n api_key=\"your-key\",\n verbose=True,\n min_val=-500,\n max_val=500\n)\n```\n\n## How It Works\n\n1. **Prompt Engineering**: The library creates a carefully crafted prompt that instructs the LLM to determine if a number is even or odd\n2. **Structured Output**: Uses JSON response format to ensure the LLM returns structured data\n3. **Fallback Parsing**: If JSON parsing fails, falls back to text analysis\n4. **Error Handling**: Comprehensive error handling for API failures and parsing issues\n\n### Example Prompt\n\n```\nYou are a mathematical assistant. Your task is to determine if the given number is even or odd.\n\nNumber: 42\n\nInstructions:\n1. A number is even if it is divisible by 2 with no remainder\n2. A number is odd if it is not divisible by 2\n3. For decimal numbers, only the integer part matters\n4. For negative numbers, the same rules apply\n5. Zero (0) is considered even\n\nPlease respond with ONLY a JSON object containing a boolean field \"is_even\":\n- Set \"is_even\" to true if the number is even\n- Set \"is_even\" to false if the number is odd\n\nExample response format:\n{\"is_even\": true}\n\nYour response:\n```\n\n## Testing\n\n### Running Tests\n\n```bash\n# Run all tests\npytest\n\n# Run with coverage\npytest --cov=src/isnt_that_odd\n\n# Run specific test file\npytest tests/test_core.py\n```\n\n### Prompt Testing with promptfoo\n\n```bash\n# Install promptfoo\nnpm install -g promptfoo\n\n# Run prompt tests\npromptfoo eval -c promptfoo.yaml\n```\n\n## Development\n\n### Setting up Development Environment\n\n```bash\n# Install development dependencies\nuv sync --group dev\n\n# Install pre-commit hooks\npre-commit install\n\n# Run code formatting\nblack src/ tests/\nisort src/ tests/\n\n# Run linting\nruff check src/ tests/\n\n# Run type checking\nmypy src/\n```\n\n### Project Structure\n\n```\nisnt_that_odd/\n\u251c\u2500\u2500 src/\n\u2502 \u2514\u2500\u2500 isnt_that_odd/\n\u2502 \u251c\u2500\u2500 __init__.py\n\u2502 \u251c\u2500\u2500 core.py\n\u2502 \u2514\u2500\u2500 cli.py\n\u251c\u2500\u2500 examples/\n\u2502 \u251c\u2500\u2500 basic_usage.py\n\u2502 \u2514\u2500\u2500 benchmark_example.py\n\u251c\u2500\u2500 tests/\n\u2502 \u251c\u2500\u2500 __init__.py\n\u2502 \u251c\u2500\u2500 test_core.py\n\u2502 \u2514\u2500\u2500 test_cli.py\n\u251c\u2500\u2500 pyproject.toml\n\u251c\u2500\u2500 promptfoo.yaml\n\u2514\u2500\u2500 README.md\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n- **Inspired by** [vibesort](https://github.com/abyesilyurt/vibesort) - GPT-powered array sorting using structured output\n- Built with [LiteLLM](https://github.com/BerriAI/litellm) for universal LLM support\n- Uses [Pydantic](https://github.com/pydantic/pydantic) for data validation\n- Tested with [pytest](https://github.com/pytest-dev/pytest) and [promptfoo](https://github.com/promptfoo/promptfoo)\n\n## Why \"isn't that odd\"?\n\nThe name is a playful reference to the library's purpose of determining whether numbers are even or odd. It's also a bit of a pun - when you ask if something \"isn't that odd,\" you're questioning whether it's unusual, just like the library questions whether a number is odd!\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2025 Launch Platform Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "A Python library that determines if a number is even using LLM APIs",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/yourusername/isnt_that_odd",
"Issues": "https://github.com/yourusername/isnt_that_odd/issues",
"Repository": "https://github.com/yourusername/isnt_that_odd.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "424d220430c3704bc0176f10b0103bd140bc7008cddf22235beb8bd365cf164b",
"md5": "e9b57e9cc25171b09dcac2a4b67a3726",
"sha256": "b0e1753e1efaca4914a692cacbb61595fa2c07cc8ea30b804282ee099eddf9e6"
},
"downloads": -1,
"filename": "isnt_that_odd-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e9b57e9cc25171b09dcac2a4b67a3726",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10511,
"upload_time": "2025-08-10T18:02:05",
"upload_time_iso_8601": "2025-08-10T18:02:05.231814Z",
"url": "https://files.pythonhosted.org/packages/42/4d/220430c3704bc0176f10b0103bd140bc7008cddf22235beb8bd365cf164b/isnt_that_odd-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "db11f7e14c0dbeb739e161014408896aaa8a883875a71d64e9fd56b7951759e3",
"md5": "8b8195ceff823105ac0c199bc483a48d",
"sha256": "9b6a47ca47fac0d77f7323513a1e76550cdebe3895a3ccfdce7c3f693a007a7c"
},
"downloads": -1,
"filename": "isnt_that_odd-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "8b8195ceff823105ac0c199bc483a48d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 143559,
"upload_time": "2025-08-10T18:02:06",
"upload_time_iso_8601": "2025-08-10T18:02:06.601064Z",
"url": "https://files.pythonhosted.org/packages/db/11/f7e14c0dbeb739e161014408896aaa8a883875a71d64e9fd56b7951759e3/isnt_that_odd-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-10 18:02:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "yourusername",
"github_project": "isnt_that_odd",
"github_not_found": true,
"lcname": "isnt_that_odd"
}