A Python utils library that counts letter frequency, gets string length, compares numbers, and evaluates mathematical expressions using OpenAI and Anthropic APIs.
- Count frequency of specific letters in text
- Get the length of a string
- Compare two numbers using AI
- Evaluate mathematical expressions safely
- Support for both OpenAI and Anthropic APIs
- Environment variable support for default provider selection
- Custom model selection via parameters or environment variables
from vibeutils import vibecount, vibecompare, vibeeval, vibelength
# 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
length = vibelength("strawberry") # Get string length
comparison = vibecompare(5, 10) # Compare numbers
result = vibeeval("(2 + 3) * 4") # Evaluate expressionsviebtime- ...
- Time complexity: O(luck) and I use API calls to prevent prompt injection.
Install the package using pip:
pip install vibeutilsFor Anthropic support, install with the optional dependency:
pip install "vibeutils[anthropic]"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
You need to provide API keys for the services you want to use.
Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY=your_openai_api_key_hereTo use Anthropic's Claude, set your Anthropic API key:
export ANTHROPIC_API_KEY=your_anthropic_api_key_hereTo 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)You can specify custom models for each provider:
export VIBEUTILS_OPENAI_MODEL=gpt-4 # Use GPT-4 instead of default
export VIBEUTILS_ANTHROPIC_MODEL=claude-opus-4-20250514 # Use Claude Opus instead of defaultBy default, all functions use OpenAI with the default model. You can specify both provider and model in multiple ways:
Set environment variables to avoid specifying the provider and model in every function call:
# Provider selection
export VIBEUTILS_PROVIDER=anthropic # Use Anthropic as default provider
export VIBEUTILS_PROVIDER=openai # Use OpenAI as default provider (or just unset)
# Model selection
export VIBEUTILS_OPENAI_MODEL=gpt-4 # Custom OpenAI model
export VIBEUTILS_ANTHROPIC_MODEL=claude-3-opus-20240229 # Custom Anthropic modelYou can override environment variables using function parameters:
# Provider and model parameters
vibecount("test", "t", provider="openai", model="gpt-4")
vibecompare(5, 10, provider="anthropic", model="claude-3-haiku-20240307")
vibeeval("2+3", provider="openai", model="gpt-4-turbo")- Explicit provider parameter (highest priority)
- VIBEUTILS_PROVIDER environment variable
- Default to "openai" (lowest priority)
- Explicit model parameter (highest priority)
- Environment variable (VIBEUTILS_OPENAI_MODEL or VIBEUTILS_ANTHROPIC_MODEL)
- Built-in defaults (gpt-4o-mini for OpenAI, claude-sonnet-4-20250514 for Anthropic)
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")
# Using custom models
result = vibecount("strawberry", "r", provider="openai", model="gpt-4")
print(result) # 2 (using GPT-4 model)
result = vibecount("strawberry", "r", provider="anthropic", model="claude-3-opus-20240229")
print(result) # 2 (using Claude Opus model)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)
# Using custom models
result = vibecompare(15, 10, provider="openai", model="gpt-4-turbo")
print(result) # 1 (using GPT-4 Turbo model)
result = vibecompare(3.14, 2.71, provider="anthropic", model="claude-3-haiku-20240307")
print(result) # 1 (using Claude Haiku model)from vibeutils import vibelength
# Get length (uses default provider)
result = vibelength("strawberry")
print(result) # 10
# Using environment variable to set default provider
# export VIBEUTILS_PROVIDER=anthropic
result = vibelength("strawberry") # Now uses Anthropic automatically
print(result) # 10
# Override environment variable with explicit provider
result = vibelength("strawberry", provider="openai") # Forces OpenAI
print(result) # 10
# Using custom models
result = vibelength("hello world", provider="openai", model="gpt-4")
print(result) # 11
result = vibelength("HELLO", provider="anthropic", model="claude-3-haiku-20240307")
print(result) # 5from 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}")
# Using custom models
result = vibeeval("2 ** 8", provider="openai", model="gpt-4")
print(result) # 256.0 (using GPT-4 model)
result = vibeeval("sqrt(16)", provider="anthropic", model="claude-3-sonnet-20240229")
# Note: sqrt function may not be supported - depends on model understandingtext(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.model(str, optional): The model to use for the provider. If None, uses environment variables VIBEUTILS_OPENAI_MODEL or VIBEUTILS_ANTHROPIC_MODEL, defaulting to built-in constants if not set.
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.model(str, optional): The model to use for the provider. If None, uses environment variables VIBEUTILS_OPENAI_MODEL or VIBEUTILS_ANTHROPIC_MODEL, defaulting to built-in constants if not set.
text(str): The input string to measure the length ofprovider(str, optional): AI provider to use ("openai" or "anthropic"). If None, uses VIBEUTILS_PROVIDER environment variable, defaulting to "openai" if not set.model(str, optional): The model to use for the provider. If None, uses environment variables VIBEUTILS_OPENAI_MODEL or VIBEUTILS_ANTHROPIC_MODEL, defaulting to built-in constants if not set.
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.model(str, optional): The model to use for the provider. If None, uses environment variables VIBEUTILS_OPENAI_MODEL or VIBEUTILS_ANTHROPIC_MODEL, defaulting to built-in constants if not set.
- vibecount(): Returns an integer representing the count of the target letter
- vibelength(): Returns an integer representing the number of characters in the input string
- 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
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
- Python 3.8+
- OpenAI API key (for OpenAI provider)
- Anthropic API key (for Anthropic provider, optional)
- Internet connection for API calls
openai>=1.0.0
anthropic>=0.3.0
Install test dependencies:
pip install -r test-requirements.txtRun tests:
pytestRun tests with coverage:
pytest --cov=vibeutilsRun specific test file:
pytest tests/test_vibeutils.pyThe 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
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
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.
- OpenAI: Uses
gpt-4o-minimodel by default - Anthropic: Uses
claude-sonnet-4-20250514model by default
- OpenAI: Supports available OpenAI models (e.g.,
gpt-4,gpt-4o,gpt-4-turbo,gpt-3.5-turbo,o1-preview,o1-mini) - Anthropic: Supports any valid Anthropic model (e.g.,
claude-3-opus-20240229,claude-3-sonnet-20240229,claude-3-haiku-20240307)
- Function parameter:
model="gpt-4"(highest priority) - Environment variable:
VIBEUTILS_OPENAI_MODEL=gpt-4(medium priority) - Built-in default: Uses package defaults (lowest priority)
- Automatic Parameter Handling: The library automatically detects model capabilities and uses the appropriate API parameters
- Legacy Models (gpt-3.5-turbo, gpt-4, gpt-4-turbo): Use
max_tokensparameter, supporttemperature=0 - Newer Models (gpt-4o, gpt-4o-mini): Use
max_completion_tokensparameter, supporttemperature=0 - o1 Models: Special handling - use
max_completion_tokens, notemperatureparameter supported - Future-Proof: Automatically handles new OpenAI models with updated API requirements
- All providers implement the same security checks and response validation
- Model selection does not affect security features
- Custom models must still support the expected input/output format
- API parameter compatibility is handled automatically based on model type