Classifai
Classifai is a powerful and user-friendly command-line tool for AI-powered classification tasks. It leverages the capabilities of large language models to provide accurate and efficient classification of various types of content.
Features
- Easy-to-use command-line interface
- Supports multiple classification categories
- Utilizes advanced language models for high accuracy
- Customizable prompts and examples
- Supports both OpenAI and OpenRouter models
Installation
pip install pipx
pipx install classifai
Usage Examples
-
Multiple classification with Examples:
classifai 'news.ycombinator.com' 'facebook.com' 'ai.meta.com' \ --classes 'signal' 'noise' 'neutral' \ --examples "github.com:signal" "arxiv.org:signal" "instagram.com:noise" \ "pintrest.com:noise" "anthropic.ai:signal" "twitter.com:noise" \ --model openrouter/openai/gpt-4-0314[ { "content": "news.ycombinator.com", "classification": "signal", "score": 1.0 }, { "content": "facebook.com", "classification": "noise", "score": 1.0 }, { "content": "ai.meta.com", "classification": "signal", "score": 1.0 } ]
-
Terminal commands classification:
'df -h' 'chown -R user:user /' -c 'safe' 'danger' 'neutral' -e "ls:safe" "rm:danger" "echo:neutral" --m gpt-4o-mini[ { "content": "df -h", "classification": "safe", "score": 1.0 }, { "content": "chown -R user:user /", "classification": "danger", "score": 1.0 } ]
-
Classify a tweet
classifai $tweet --classes 'AI' 'ASI' 'AGI' -m gpt-4o-mini
[ { "content": "Superintelligence is within reach.\n\nBuilding safe superintelligence (SSI) is the most important technical problem of our\u200b\u200b time.\n\nWe've started the world\u2019s first straight-shot SSI lab, with one goal and one product: a safe superintelligence.", "classification": "ASI", "score": 1.0 } ]
classifai $tweet --classes 'PROGRAMING' 'MACHINE-LEARNING' -m gpt-4o-mini
[ { "content": "Superintelligence is within reach.\n\nBuilding safe superintelligence (SSI) is the most important technical problem of our\u200b\u200b time.\n\nWe've started the world\u2019s first straight-shot SSI lab, with one goal and one product: a safe superintelligence.", "classification": "MACHINE-LEARNING", "score": 0.833334466588825 } ]
-
Verify facts
classifai "<source>$(curl -s docs.jina.ai)</source><statement>Jina ai has an image generation api" -c True False -m gpt-4o --no-content
[ { "class": "false", "score": 0.99997334352929 } ]
Advanced scripts
Acting on the classification
class-tweet() {
local tweet="$1"
local threshold=0.6
local class="MACHINE-LEARNING"
result=$(classifai "$tweet" -c 'PROGRAMMING' 'MACHINE-LEARNING' \
-m openrouter/openai/gpt-4o-mini \
| jq -r '.[0] | select(.classification == "'"$class"'" and .score > '"$threshold"') | .classification')
if [ -n "$result" ]; then
echo "Tweet classified as $class with high confidence. Executing demo..."
echo "Demo: This is a highly relevant tweet about $class"
else
echo "Tweet does not meet classification criteria."
fi
}
Classifai now supports reading from stdin and writing to stdout, making it easier to use in pipelines and shell scripts.
You can pipe content into classifai:
echo "This is a test sentence" | classifai -c 'positive' 'negative' 'neutral'
Or use heredoc for multiple lines:
cat <<EOF | classifai -c 'tech' 'sports' 'politics' -f simple
AI makes rapid progress
Football season starts soon
New tax policy announced
EOF
By default, classifai outputs JSON, which can be easily parsed by other tools:
echo "OpenAI releases GPT-4" | classifai -c 'tech' 'business' | jq '.[0].class'
For simpler output that's easier to use in shell scripts, use the -f simple option:
echo "Breaking news: earthquake hits city" | classifai -c 'world' 'local' 'sports' -f simple | cut -f2
This will output only the classified class, making it easy to use in conditionals:
if [[ == "world" ]]; then
echo "This is world news"
fi
These enhancements make classifai more versatile and easier to integrate into complex data processing pipelines and shell scripts.
Using Classifai as a Python Module
Classifai can also be used as a Python module for more advanced use cases. Here's an example of how to use it in your Python code:
from classifai import Classifai
# Initialize the Classifai model
model = Classifai(model_name='openrouter/openai/gpt-4-0314')
# Classify a single piece of content
content = "OpenAI releases GPT-4"
classes = ['tech', 'business']
result = model.classify(content, classes)
print(result)
This allows you to integrate Classifai's powerful classification capabilities directly into your Python applications.
Metadata
Release files for classifai 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| classifai-0.1.1.tar.gz | 5.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| classifai-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.4 kB
Release files / classifai-0.1.1.tar.gz
| Download URL | classifai-0.1.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b183325fea0e270f319c49e161fea899f516af0d2c2c2070224c50ff8e943fa4
|
|
BLAKE2b-256 checksum How to use checksums |
d0cd863d85998213519dd97341216801ed97dea99c37a46b4a667242f294ac2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / classifai-0.1.1-py3-none-any.whl
| Download URL | classifai-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7077df876183edf5044d4b1d17b01dde9cc629beda649146f0ba49c9ea993c6c
|
|
BLAKE2b-256 checksum How to use checksums |
bc9e5599a4c555110b7b44d0ed89f84f1f666de482ab4ea104513222120b416a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Security for classifai 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.