Skip to main content

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
  • Custom model selection via parameters or environment variables

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:

  1. Install the package (see Installation section)
  2. Set API keys for your chosen provider(s)
  3. 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)

Custom Models (Optional)

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 default

Provider and Model Selection

By default, all functions use OpenAI with the default model. You can specify both provider and model in multiple ways:

Method 1: Environment Variables (Recommended)

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 model

Method 2: Function Parameters

You 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")

Priority Order for Provider Selection

  1. Explicit provider parameter (highest priority)
  2. VIBEUTILS_PROVIDER environment variable
  3. Default to "openai" (lowest priority)

Priority Order for Model Selection

  1. Explicit model parameter (highest priority)
  2. Environment variable (VIBEUTILS_OPENAI_MODEL or VIBEUTILS_ANTHROPIC_MODEL)
  3. Built-in defaults (gpt-4o-mini for OpenAI, claude-sonnet-4-20250514 for Anthropic)

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")

# 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)

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)

# 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)

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}")

# 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 understanding

Parameters

vibecount(text, target_letter, case_sensitive=True, provider=None, model=None)

  • text (str): The input string to analyze
  • target_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.

vibecompare(num1, num2, provider=None, model=None)

  • num1 (Union[int, float]): The first number to compare
  • num2 (Union[int, float]): The second number to compare
  • 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.

vibeeval(expression, provider=None, model=None)

  • expression (str): Mathematical expression containing numbers, operators (+, -, *, /, **), and parentheses
  • 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.

Return Values

  • vibecount(): Returns an integer representing the count of the target letter
  • vibecompare(): Returns an integer:
    • -1 if the first number is smaller than the second
    • 0 if the numbers are equal
    • 1 if 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 and Model-Specific Notes

Default Models

  • OpenAI: Uses gpt-4o-mini model by default
  • Anthropic: Uses claude-sonnet-4-20250514 model by default

Custom Model Support

  • 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)

Model Selection Methods

  1. Function parameter: model="gpt-4" (highest priority)
  2. Environment variable: VIBEUTILS_OPENAI_MODEL=gpt-4 (medium priority)
  3. Built-in default: Uses package defaults (lowest priority)

Model Compatibility and API Parameters

  • 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_tokens parameter, support temperature=0
  • Newer Models (gpt-4o, gpt-4o-mini): Use max_completion_tokens parameter, support temperature=0
  • o1 Models: Special handling - use max_completion_tokens, no temperature parameter supported
  • Future-Proof: Automatically handles new OpenAI models with updated API requirements

Security and Validation

  • 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

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

vibeutils-0.6.0.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

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

vibeutils-0.6.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file vibeutils-0.6.0.tar.gz.

File metadata

  • Download URL: vibeutils-0.6.0.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for vibeutils-0.6.0.tar.gz
Algorithm Hash digest
SHA256 5feb87402359e9d614caed8f9be338271568f21d6339dd6c3f6b4a87fb05b0fe
MD5 0504b2264b9f256e8ce5188e845e6aa2
BLAKE2b-256 7ee14becb55c474ab306bdcbce2deac6b722be12e4dc5aa99f7901e93b17534e

See more details on using hashes here.

File details

Details for the file vibeutils-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: vibeutils-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for vibeutils-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 26823121fc5bd5809b294a20e0ae28baab011b96fd6c8c279f1efea3a3a5b71e
MD5 c0ab72d0240da3b5d6d54959cc85385d
BLAKE2b-256 7fb846d2549dd626d785b0e622e5df8f4ba5e0ced72af89003c4507b8e427fa8

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