Skip to main content

GrandJury SDK — submit LLM traces for human evaluation + analytics client

Project description

grandjury

Python client for the GrandJury ML evaluation and verdict analysis API.

This package provides comprehensive access to the GrandJury server for ML model evaluation and voting analysis, supporting:

  • Model scoring with decay-adjusted algorithms
  • Vote analysis across multiple dimensions (time, completeness, confidence)
  • Multiple data formats (pandas, polars, CSV, parquet, dict/list)
  • Performance optimizations with optional dependencies
  • Backward compatibility with existing code

Patent Pending.

Installation

pip install grandjury

Optional performance dependencies:

pip install grandjury[performance]  # Installs msgspec, pyarrow, polars

Quick Start

Basic Model Evaluation

from grandjury import GrandJuryClient

# Initialize client
client = GrandJuryClient(api_key="your-api-key")

# Evaluate model performance
result = client.evaluate_model(
    previous_score=0.7,
    votes=[0.9, 0.8, 0.6],
    reputations=[1.0, 1.0, 0.8]
)
print(f"Score: {result['score']:.4f}")

Vote Analysis with Multiple Data Formats

import pandas as pd
import polars as pl

# Your vote data
vote_data = [
    {
        "inference_id": 1,
        "vote": True,
        "voter_id": 101,
        "vote_time": "2024-07-07T19:22:30",
        # ... other fields
    }
    # ... more votes
]

# No authentication needed for analysis endpoints  
client = GrandJuryClient()

# Use with different data formats
histogram = client.vote_histogram(vote_data)  # dict/list
histogram = client.vote_histogram(pd.DataFrame(vote_data))  # pandas
histogram = client.vote_histogram(pl.DataFrame(vote_data))  # polars
histogram = client.vote_histogram("votes.csv")  # CSV file
histogram = client.vote_histogram("votes.parquet")  # Parquet file

# Vote completeness analysis
completeness = client.vote_completeness(
    data=vote_data,
    voter_list=[101, 102, 103]
)

# Population confidence
confidence = client.population_confidence(
    data=vote_data,
    voter_list=[101, 102, 103]
)

# Majority vote analysis
majority = client.majority_good_votes(
    data=vote_data,
    good_vote=True,
    threshold=0.5
)

# Vote distribution per inference
distribution = client.votes_distribution(vote_data)

Backward Compatibility

# Original function still works
from grandjury import evaluate_model

result = evaluate_model(
    predictions=["Model output 1", "Model output 2"],
    references=["Expected 1", "Expected 2"],
    api_key="your-api-key"
)

API Endpoints

Method Description Authentication
evaluate_model() Model scoring with decay algorithms Required
vote_histogram() Vote time distribution analysis Optional
vote_completeness() Voting completeness metrics Optional
population_confidence() Population confidence analysis Optional
majority_good_votes() Majority vote counting Optional
votes_distribution() Vote distribution per inference Optional

Performance Features

The client automatically uses performance optimizations when available:

  • msgspec: Faster JSON serialization
  • PyArrow: Efficient Parquet file reading
  • Polars: Native DataFrame support

Install with: pip install msgspec pyarrow polars

Error Handling

try:
    result = client.vote_histogram(invalid_data)
except Exception as e:
    print(f"API Error: {e}")

Server URL Configuration

# Default: https://grandjury-server.onrender.com/api/v1
client = GrandJuryClient()

# Custom server
client = GrandJuryClient(base_url="https://your-server.com")
# Automatically appends /api/v1 if missing
pip install grandjury

Optional performance dependencies:

pip install grandjury[performance]  # Installs msgspec, pyarrow, polars

Quick Start

Basic Model Evaluation

from grandjury import GrandJuryClient

# Initialize client
client = GrandJuryClient(api_key="your-api-key")

# Evaluate model performance
result = client.evaluate_model(
    previous_score=0.7,
    votes=[0.9, 0.8, 0.6],
    reputations=[1.0, 1.0, 0.8]
)
print(f"Score: {result['score']:.4f}")

Vote Analysis with Multiple Data Formats

import pandas as pd
import polars as pl

# Your vote data
vote_data = [
    {
        "inference_id": 1,
        "vote": True,
        "voter_id": 101,
        "vote_time": "2024-07-07T19:22:30",
        # ... other fields
    }
    # ... more votes
]

# No authentication needed for analysis endpoints  
client = GrandJuryClient()

# Use with different data formats
histogram = client.vote_histogram(vote_data)  # dict/list
histogram = client.vote_histogram(pd.DataFrame(vote_data))  # pandas
histogram = client.vote_histogram(pl.DataFrame(vote_data))  # polars
histogram = client.vote_histogram("votes.csv")  # CSV file
histogram = client.vote_histogram("votes.parquet")  # Parquet file

# Vote completeness analysis
completeness = client.vote_completeness(
    data=vote_data,
    voter_list=[101, 102, 103]
)

# Population confidence
confidence = client.population_confidence(
    data=vote_data,
    voter_list=[101, 102, 103]
)

# Majority vote analysis
majority = client.majority_good_votes(
    data=vote_data,
    good_vote=True,
    threshold=0.5
)

# Vote distribution per inference
distribution = client.votes_distribution(vote_data)

Backward Compatibility

# Original function still works
from grandjury import evaluate_model

result = evaluate_model(
    predictions=["Model output 1", "Model output 2"],
    references=["Expected 1", "Expected 2"],
    api_key="your-api-key"
)

API Endpoints

Method Description Authentication
evaluate_model() Model scoring with decay algorithms Required
vote_histogram() Vote time distribution analysis Optional
vote_completeness() Voting completeness metrics Optional
population_confidence() Population confidence analysis Optional
majority_good_votes() Majority vote counting Optional
votes_distribution() Vote distribution per inference Optional

Performance Features

The client automatically uses performance optimizations when available:

  • msgspec: Faster JSON serialization
  • PyArrow: Efficient Parquet file reading
  • Polars: Native DataFrame support

Install with: pip install msgspec pyarrow polars

Error Handling

try:
    result = client.vote_histogram(invalid_data)
except Exception as e:
    print(f"API Error: {e}")

Server URL Configuration

# Default: https://grandjury-server.onrender.com/api/v1
client = GrandJuryClient()

# Custom server
client = GrandJuryClient(base_url="https://your-server.com")
# Automatically appends /api/v1 if missing

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

grandjury-2.0.0.tar.gz (184.8 kB view details)

Uploaded Source

Built Distribution

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

grandjury-2.0.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file grandjury-2.0.0.tar.gz.

File metadata

  • Download URL: grandjury-2.0.0.tar.gz
  • Upload date:
  • Size: 184.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for grandjury-2.0.0.tar.gz
Algorithm Hash digest
SHA256 6e7091ce4a7a2d36e1ab5dc55c44ad14edabb8243433b23cec9f07217ddb5724
MD5 1396357fa0cfeabd3dbb9652681eea8e
BLAKE2b-256 9c4423e3fd949ec8cc4c86ad607fbd25990a5d8535834e1ed7b24d53e32838e0

See more details on using hashes here.

File details

Details for the file grandjury-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: grandjury-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for grandjury-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7224a6d26789dc777a010760547be98ff12ef76002391c8f26065676a4fac87
MD5 11953d488f04caaa9ad70f59d7c20972
BLAKE2b-256 e59d90b8fc798eba121eea126f43ea33ec3f3364b6cda0cd54d5661890b42d44

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