Skip to main content

A custom Step for LLM API cost calculation for the distilabel library.

Project description

Description

A custom step for LLM API cost calculation for the distilabel library. This library allows you to calculate API usage costs based on token consumption and supports customizable pricing models for different LLMs.

Requirements

  • Python: ^3.10.15
  • Distilabel: >=1.3.2

Installation

pip install distilabel-cost-calculator

Example

from distilabel_cost_calculator import GenerationCostCalculator

with Pipeline("data_generation_with_cost_calculator") as pipeline:
    model = OpenAILLM(model="gpt-4o-mini", api_key=OPENAI_API_KEY)

    data = LoadDataFromDicts(data=[{"instruction": "Generate me a quote."}])
    task = TextGeneration(name="text-generation", llm=model, num_generations=2)

    # You can provide custom pricing for the API model
    custom_pricing = {
        "input_pricing": 0.15,  # Custom price per token for inputs
        "output_pricing": 0.6  # Custom price per token for outputs
    }

    cost_step = GenerationCostCalculator(
        api_model_name="gpt-4o-mini",
        api_pricing=custom_pricing  # Optional: Override default pricing
    )

    data >> task >> cost_step
pipeline.run(use_cache=False)

# API cost details will be found in the 'api_cost' column in the Distiset.
# 'api_cost': {'inputs': 7.5e-07, 'outputs': 1.019e-05, 'total_cost_str': '0.000011$'}

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

distilabel_cost_calculator-0.2.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

distilabel_cost_calculator-0.2.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file distilabel_cost_calculator-0.2.1.tar.gz.

File metadata

  • Download URL: distilabel_cost_calculator-0.2.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Darwin/23.6.0

File hashes

Hashes for distilabel_cost_calculator-0.2.1.tar.gz
Algorithm Hash digest
SHA256 88f0d54a8c96cc978b84af1931be7dc93c65eb75c8f2af41534b19aa118b158e
MD5 68839c37be2cfb930d020a5cb825060c
BLAKE2b-256 921ffb4f558c0f6262ac0fb83ecdfcee5f83f213bfe163a769ed46ff62988ada

See more details on using hashes here.

File details

Details for the file distilabel_cost_calculator-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for distilabel_cost_calculator-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c3bd72a1807db52d76d9eabcd708bfb0ff57e1e16fabbfbbe2df6f2dd4f116a9
MD5 07d5212df05e651e809f397eb6bb9942
BLAKE2b-256 e1289d847f7e33fbec26e325649726e617e2508f2a6aae8400a661a1abb229e0

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