llmcosts/llm-cost-logger
最新稳定版本:1.0.5
Composer 安装命令:
composer require llmcosts/llm-cost-logger
包简介
Reference code to log LLM Call metadata to the llmcosts.fyi service
README 文档
README
This repo contains the source code for the PHP class you might need to log into llmcosts.fyi
We wouldn't normally expect you to need to install from source, and this code is typically very simple
You need an API key from llmcosts.fyi. Reference code, prepopulated with your API key is available to users of that site, but the quick version is here.
For use with other clients, you will also need to replace the name "OpenAI" in the ->logCall function with a provider supported by the service.
Installation
The best way is to install via Composer, by adding to the "require" section of your composer.json file
{... other requirements ...}
"llmcosts/llm-cost-logger": "1.0.0"
Using with the OpenAI client:
/**
* Your existing code
*/
$client = \OpenAI::Client("<your OpenAI token>");
$result = $client->chat()->create([
'model' => self::MODEL,
'messages' => [
['role' => 'user', 'content' => '<your query string>'],
],
]);
$resultArray = $result->toArray();
/**
* The two lines you need to add logging
* The <provider> can be anything, but see above
*/
+ $costLogger = new LLMCostLogger("{{key}}");
+ $costLogger->logCall("OpenAI", $resultArray);
统计信息
- 总下载量: 138
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-2.1-only
- 更新时间: 2025-02-07