A Python library that provides various utils using OpenAI and Anthropic APIs
Project description
vibeutils
A Python utils library that counts letter frequency, compares numbers, and evaluates mathematical expressions using OpenAI and Anthropic APIs.
Features
- Count frequency of specific letters in text
- Compare two numbers using AI
- Evaluate mathematical expressions safely
- Support for both OpenAI and Anthropic APIs
- Environment variable support for default provider selection
Quick Start
from vibeutils import vibecount, vibecompare, vibeeval
# Set your preferred provider globally (optional)
# export VIBEUTILS_PROVIDER=anthropic
# Now all function calls use your preferred provider automatically
count = vibecount("strawberry", "r") # Count letter frequency
comparison = vibecompare(5, 10) # Compare numbers
result = vibeeval("(2 + 3) * 4") # Evaluate expressions
Upcoming
vibelength()viebtime- ...
Performance
- Time complexity: O(luck) and I use API calls to prevent prompt injection.
Installation
Install the package using pip:
pip install vibeutils
For Anthropic support, install with the optional dependency:
pip install "vibeutils[anthropic]"
Setup
Set up vibeutils in 3 easy steps:
- Install the package (see Installation section)
- Set API keys for your chosen provider(s)
- Optionally set default provider to avoid specifying it in every call
API Keys
You need to provide API keys for the services you want to use.
OpenAI (Default Provider)
Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY=your_openai_api_key_here
Anthropic (Optional)
To use Anthropic's Claude, set your Anthropic API key:
export ANTHROPIC_API_KEY=your_anthropic_api_key_here
Default Provider (Optional)
To avoid specifying the provider in every function call, you can set a default provider:
export VIBEUTILS_PROVIDER=anthropic # Use Anthropic as default
# or
export VIBEUTILS_PROVIDER=openai # Use OpenAI as default (same as not setting it)
Provider Selection
By default, all functions use OpenAI. You can specify a provider in multiple ways:
Method 1: Environment Variable (Recommended)
Set the VIBEUTILS_PROVIDER environment variable to avoid specifying the provider in every function call:
# Use Anthropic as the default provider
export VIBEUTILS_PROVIDER=anthropic
# Use OpenAI as the default provider (or just unset the variable)
export VIBEUTILS_PROVIDER=openai
# or
unset VIBEUTILS_PROVIDER
Method 2: Provider Parameter
You can still override the environment variable by using the provider parameter:
provider="openai"provider="anthropic"
Priority Order
- Explicit provider parameter (highest priority)
- VIBEUTILS_PROVIDER environment variable
- Default to "openai" (lowest priority)
Usage
Letter Counting - vibecount()
from vibeutils import vibecount
# Count letter 'r' in "strawberry" (uses default provider)
result = vibecount("strawberry", "r")
print(result) # 2 ;)
# Using environment variable to set default provider
# export VIBEUTILS_PROVIDER=anthropic
result = vibecount("strawberry", "r") # Now uses Anthropic automatically
print(result) # 2 ;)
# Override environment variable with explicit provider
result = vibecount("strawberry", "r", provider="openai") # Forces OpenAI
print(result) # 2 ;)
# Case-insensitive counting
result = vibecount("Strawberry", "R", case_sensitive=False)
print(result) # 2 ;)
# Case-insensitive counting with explicit provider
result = vibecount("Strawberry", "R", case_sensitive=False, provider="anthropic")
print(result) # 2 ;)
# Case-sensitive counting (explicit)
result = vibecount("Strawberry", "R", case_sensitive=True, provider="openai")
print(result) # 0 (no uppercase 'R' in "Strawberry")
Number Comparison - vibecompare()
from vibeutils import vibecompare
# Compare two integers (uses default provider)
result = vibecompare(5, 10)
print(result) # -1 (first number is smaller)
# Using environment variable to set default provider
# export VIBEUTILS_PROVIDER=anthropic
result = vibecompare(5, 10) # Now uses Anthropic automatically
print(result) # -1 (first number is smaller)
# Compare two floats
result = vibecompare(5.11, 5.9)
print(result) # -1 ;)
# Override environment variable with explicit provider
result = vibecompare(7, 7, provider="openai") # Forces OpenAI
print(result) # 0 (numbers are equal)
Mathematical Expression Evaluation - vibeeval()
from vibeutils import vibeeval
# Basic arithmetic operations (uses default provider)
result = vibeeval("2 + 3")
print(result) # 5.0
# Using environment variable to set default provider
# export VIBEUTILS_PROVIDER=anthropic
result = vibeeval("3 * 4") # Now uses Anthropic automatically
print(result) # 12.0
# Complex expressions with parentheses
result = vibeeval("(2 + 3) * 4")
print(result) # 20.0
# Override environment variable with explicit provider
result = vibeeval("5 / 2", provider="openai") # Forces OpenAI
print(result) # 2.5
# Error handling for invalid expressions
try:
result = vibeeval("2 +") # Invalid syntax
except ValueError as e:
print(f"Error: {e}")
try:
result = vibeeval("1 / 0") # Division by zero
except ValueError as e:
print(f"Error: {e}")
Parameters
vibecount(text, target_letter, case_sensitive=True, provider=None)
text(str): The input string to analyzetarget_letter(str): The letter to count (must be a single character)case_sensitive(bool, optional): Whether to perform case-sensitive counting (default: True)provider(str, optional): AI provider to use ("openai" or "anthropic"). If None, uses VIBEUTILS_PROVIDER environment variable, defaulting to "openai" if not set.
vibecompare(num1, num2, provider=None)
num1(Union[int, float]): The first number to comparenum2(Union[int, float]): The second number to compareprovider(str, optional): AI provider to use ("openai" or "anthropic"). If None, uses VIBEUTILS_PROVIDER environment variable, defaulting to "openai" if not set.
vibeeval(expression, provider=None)
expression(str): Mathematical expression containing numbers, operators (+, -, *, /, **), and parenthesesprovider(str, optional): AI provider to use ("openai" or "anthropic"). If None, uses VIBEUTILS_PROVIDER environment variable, defaulting to "openai" if not set.
Return Values
- vibecount(): Returns an integer representing the count of the target letter
- vibecompare(): Returns an integer:
-1if the first number is smaller than the second0if the numbers are equal1if the first number is larger than the second
- vibeeval(): Returns a float representing the result of the mathematical expression
Error Handling
All functions raise:
ValueError: If API key is not set for the chosen provider, invalid arguments provided, or invalid mathematical expression (vibeeval only)ImportError: If the anthropic package is not installed when using provider="anthropic"Exception: If AI API call fails or response validation fails
Requirements
- Python 3.8+
- OpenAI API key (for OpenAI provider)
- Anthropic API key (for Anthropic provider, optional)
- Internet connection for API calls
Dependencies
Required
openai>=1.0.0
Optional (for Anthropic support)
anthropic>=0.3.0
Development
Running Tests
Install test dependencies:
pip install -r test-requirements.txt
Run tests:
pytest
Run tests with coverage:
pytest --cov=vibeutils
Run specific test file:
pytest tests/test_vibeutils.py
Test Structure
The test suite includes:
- Unit tests for all function parameters and edge cases
- Mock tests for OpenAI API calls (no actual API calls during testing)
- Error handling validation
- Input validation tests
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Note
This package uses AI APIs for processing, which require API keys and internet connection. Each function call will make multiple requests to the chosen AI provider's servers and will consume API credits.
Provider-Specific Notes
- OpenAI: Uses GPT-4o-mini model for all operations
- Anthropic: Uses Claude-3.5-Sonnet model for all operations
- All providers implement the same security checks and response validation
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 vibeutils-0.5.0.tar.gz.
File metadata
- Download URL: vibeutils-0.5.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78c2f45471ab00d4261a4d680068af89aee78e7849f1b364ff9ff7e9a4b3ab9e
|
|
| MD5 |
aaddc6cee1ee2b3849d5b6eb0b1534b8
|
|
| BLAKE2b-256 |
6852d7b7b147141f66cc1b3d233bc135a16ebdbda03924a5d975345911c9668e
|
File details
Details for the file vibeutils-0.5.0-py3-none-any.whl.
File metadata
- Download URL: vibeutils-0.5.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c4f7336716650cd85e85face8eddd955647ec6b5e236cfdf15586851fe80712
|
|
| MD5 |
e163b4689468c91788eaab92cc8e7157
|
|
| BLAKE2b-256 |
0304ac0aaf8c616181f29de3fc3d1435ba42970bf6e8eba0eac1c8d4e80832df
|