A Python library that provides various utils using OpenAI API
Project description
vibeutils
A Python utils library that counts letter frequency, compares numbers, and evaluates mathematical expressions using OpenAI API.
Features
- Count frequency of specific letters in text
- Compare two numbers using AI
- Evaluate mathematical expressions safely
- Case-sensitive and case-insensitive counting options
- Uses OpenAI API for prompt injection detection
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
Setup
You need to provide your own OpenAI API key. Set it as an environment variable:
export OPENAI_API_KEY=your_openai_api_key_here
Usage
Letter Counting - vibecount()
from vibeutils import vibecount
# Count letter 'r' in "strawberry" (case-sensitive by default)
result = vibecount("strawberry", "r")
print(result) # 2 ;)
# Case-insensitive counting
result = vibecount("Strawberry", "R", case_sensitive=False)
print(result) # 2 ;)
# Case-sensitive counting (explicit)
result = vibecount("Strawberry", "R", case_sensitive=True)
print(result) # 0 (no uppercase 'R' in "Strawberry")
Number Comparison - vibecompare()
from vibeutils import vibecompare
# Compare two integers
result = vibecompare(5, 10)
print(result) # -1 (first number is smaller)
# Compare two floats
result = vibecompare(5.11, 5.9)
print(result) # -1 ;)
# Compare equal numbers
result = vibecompare(7, 7)
print(result) # 0 (numbers are equal)
Mathematical Expression Evaluation - vibeeval()
from vibeutils import vibeeval
# Basic arithmetic operations
result = vibeeval("2 + 3")
print(result) # 5.0
result = vibeeval("3 * 4")
print(result) # 12.0
# Complex expressions with parentheses
result = vibeeval("(2 + 3) * 4")
print(result) # 20.0
# Decimal results
result = vibeeval("5 / 2")
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("2 ** 3") # Unsupported operator
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)
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)
vibecompare(num1, num2)
num1(Union[int, float]): The first number to comparenum2(Union[int, float]): The second number to compare
vibeeval(expression)
expression(str): Mathematical expression containing numbers, operators (+, -, *, /), and parentheses
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 OpenAI API key is not set, invalid arguments provided, or invalid mathematical expression (vibeeval only)Exception: If OpenAI API call fails or response validation fails
Requirements
- Python 3.8+
- OpenAI API key
- Internet connection for API calls
Dependencies
openai>=1.0.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 the OpenAI API for processing, which requires an API key and internet connection. Each function call will make more than 1 request to OpenAI's servers and will consume API credits.
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.4.0.tar.gz.
File metadata
- Download URL: vibeutils-0.4.0.tar.gz
- Upload date:
- Size: 20.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 |
41bd528fe6e52c4e816870ec732ed7d95634f575adeb000f041c5ef3a346345a
|
|
| MD5 |
ffa18348476ddbe3125f88b9eda8226a
|
|
| BLAKE2b-256 |
b7e2aca7da8a82c92e53deb8aff222b8c2233e234ec79079b947ca913b5c8bd1
|
File details
Details for the file vibeutils-0.4.0-py3-none-any.whl.
File metadata
- Download URL: vibeutils-0.4.0-py3-none-any.whl
- Upload date:
- Size: 14.6 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 |
ce1eaae1b0fae395546613f40c374a3f4d7e2aa7f55c2d84f4eb22368ee66a80
|
|
| MD5 |
2be4af0c5e05a25a1f7db741a2045a80
|
|
| BLAKE2b-256 |
d40db4e18b6d7e817e2dbd7ef338f096682cce379d462ffcbef908d3776ca5d2
|