.. image:: https://img.shields.io/badge/chatGPT-74aa9c.svg?logo=openai
.. image:: https://img.shields.io/pypi/pyversions/setuptools.svg
==================
OpenAI Cost Logger
==================
* Simple **cost logger** for **OpenAI requests**.
* Track the cost of every request you make to OpenAI and visualize them in a user-friendly way.
* Homepage on `PyPI <https://pypi.org/project/openai-cost-logger/>`_.
* `Demo file <https://github.com/drudilorenzo/track-openai-cost/blob/master/demo.ipynb>`_ with a usage example.
How to install:
---------------
* .. code-block:: python
pip install openai-cost-logger
* .. code-block:: python
from openai_cost_logger import OpenAICostLogger
from openai_cost_logger import OpenAICostLoggerViz
from openai_cost_logger import OpenAICostLoggerUtils
from openai_cost_logger import OpenAICostLogger_Singleton
from openai_cost_logger import DEFAULT_LOG_PATH, MODELS_COST
Key Features:
-------------
* Track the cost of every request you make and save them in a JSON file.
* Choose the feature you want to track (prompt_tokens, completion_tokens, completion, prompt, etc.).
* Check the cost of your requests filtering by model or strftime aggregation (see the docs).
Models supported:
-------------------
* The generation of responses is totally up to the user. The library supports every model whose response contains the fields **usage.prompt_tokens** and **usage.total_tokens** (e.g. chat completions, embeddings, etc.).
Multithreading:
---------------
* Be aware that the classic cost logger is not thread-safe.
* If you want to use it in a multithreading environment, you should use the **thread-safe** version of the logger: ``OpenAICostLogger_Singleton``. The interface is the same as the classic logger. This will prevent multiple threads from writing to the same file at the same time.
Note:
-----
* Every cost is specified per **million tokens**.
* If you don't specify the cost, the library will look to the **MODELS_COST** dictionary and get the cost of the model you are using. Be aware that if the model is not in the dictionary, an exception will be raised.
Viz example:
-------------
.. image:: images/example.png
:alt: Viz example (prints + plot)
:align: center
Raw data
{
"_id": null,
"home_page": "https://github.com/drudilorenzo/openai-cost-tracker",
"name": "openai-cost-logger",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "openai, cost, logger, tracker, viz, llms",
"author": "Lorenzo Drudi | Mikolaj Boronski | Ivan Zakazov",
"author_email": "lorenzodrudi11@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/1a/7b/539891456e444e4b7bc4370dee4e5e6364687660f4e2ae95d3101969ea36/openai-cost-logger-0.5.1.tar.gz",
"platform": null,
"description": ".. image:: https://img.shields.io/badge/chatGPT-74aa9c.svg?logo=openai\n.. image:: https://img.shields.io/pypi/pyversions/setuptools.svg\n\n==================\nOpenAI Cost Logger\n==================\n\n* Simple **cost logger** for **OpenAI requests**.\n* Track the cost of every request you make to OpenAI and visualize them in a user-friendly way.\n* Homepage on `PyPI <https://pypi.org/project/openai-cost-logger/>`_.\n* `Demo file <https://github.com/drudilorenzo/track-openai-cost/blob/master/demo.ipynb>`_ with a usage example.\n\nHow to install:\n---------------\n* .. code-block:: python\n\n pip install openai-cost-logger\n\n* .. code-block:: python\n\n from openai_cost_logger import OpenAICostLogger\n from openai_cost_logger import OpenAICostLoggerViz\n from openai_cost_logger import OpenAICostLoggerUtils\n from openai_cost_logger import OpenAICostLogger_Singleton\n from openai_cost_logger import DEFAULT_LOG_PATH, MODELS_COST\n\nKey Features:\n-------------\n* Track the cost of every request you make and save them in a JSON file.\n* Choose the feature you want to track (prompt_tokens, completion_tokens, completion, prompt, etc.).\n* Check the cost of your requests filtering by model or strftime aggregation (see the docs).\n\nModels supported:\n-------------------\n* The generation of responses is totally up to the user. The library supports every model whose response contains the fields **usage.prompt_tokens** and **usage.total_tokens** (e.g. chat completions, embeddings, etc.).\n\nMultithreading:\n---------------\n* Be aware that the classic cost logger is not thread-safe.\n* If you want to use it in a multithreading environment, you should use the **thread-safe** version of the logger: ``OpenAICostLogger_Singleton``. The interface is the same as the classic logger. This will prevent multiple threads from writing to the same file at the same time.\n\nNote:\n-----\n* Every cost is specified per **million tokens**.\n* If you don't specify the cost, the library will look to the **MODELS_COST** dictionary and get the cost of the model you are using. Be aware that if the model is not in the dictionary, an exception will be raised.\n\nViz example:\n-------------\n.. image:: images/example.png\n :alt: Viz example (prints + plot)\n :align: center\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "OpenAI Cost Logger",
"version": "0.5.1",
"project_urls": {
"Homepage": "https://github.com/drudilorenzo/openai-cost-tracker"
},
"split_keywords": [
"openai",
" cost",
" logger",
" tracker",
" viz",
" llms"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1a7b539891456e444e4b7bc4370dee4e5e6364687660f4e2ae95d3101969ea36",
"md5": "adffb3c56c0c548890fa601245b93f13",
"sha256": "768ed1e7470d4eadff0e75f9a54c82bd7d29521d34ac0a495f4ff193bfbd7b7a"
},
"downloads": -1,
"filename": "openai-cost-logger-0.5.1.tar.gz",
"has_sig": false,
"md5_digest": "adffb3c56c0c548890fa601245b93f13",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7793,
"upload_time": "2024-05-28T14:24:13",
"upload_time_iso_8601": "2024-05-28T14:24:13.150494Z",
"url": "https://files.pythonhosted.org/packages/1a/7b/539891456e444e4b7bc4370dee4e5e6364687660f4e2ae95d3101969ea36/openai-cost-logger-0.5.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-28 14:24:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "drudilorenzo",
"github_project": "openai-cost-tracker",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "openai",
"specs": [
[
"==",
"1.13.3"
]
]
},
{
"name": "matplotlib",
"specs": [
[
"==",
"3.6.3"
]
]
},
{
"name": "pytest",
"specs": [
[
"==",
"7.4.2"
]
]
}
],
"lcname": "openai-cost-logger"
}