partitech/php-tei-client
Composer 安装命令:
composer require partitech/php-tei-client
包简介
Simple php client for text embeddings inference from Hugging face
README 文档
README
This is a very simple PHP client for the Text Embeddings Inference (TEI) server from Huggingface , which is a blazing fast inference solution for text embeddings models. This client allows you to easily interact with the TEI server's API endpoints for embedding, reranking, and prediction.
Installation
You can install this package via Composer:
composer require partitech/php-tei-client
Usage
Here's a basic example of how to use the TEI client:
Embedding
<?php use Partitech\PhpTeiClient\TeiClient; $client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey'); // Embed a single string $result = $client->embed(content: 'What is Deep Learning?'); // Embed an array of strings $contents = ['What is Deep Learning?', 'What is Machine Learning?']; $result = $client->embed(content: $contents);
Result:
Array ( [0] => Array ( [0] => 0.007737029 [1] => -0.06754478 [2] => -0.0380035 ----- [1023] => 0.026126498 ) )
Using Re-rankers
<?php use Partitech\PhpTeiClient\TeiClient; $client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey'); // Rerank an array of texts based on a query $content = ['Deep learning is...', 'cheese is made of', 'Deep Learning is not...']; $result = $client->rerank('What is the difference between Deep Learning and Machine Learning?', $content);
Result:
Array ( [0] => Array ( [index] => 0 [score] => 0.94238955 ) [1] => Array ( [index] => 2 [score] => 0.120219156 ) [2] => Array ( [index] => 1 [score] => 3.7323738E-5 ) )
You can also get associated text in the result and limit to the top n result:
<?php use Partitech\PhpTeiClient\TeiClient; $client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey'); // Rerank an array of texts based on a query $content = ['Deep learning is...', 'cheese is made of', 'Deep Learning is not...']; $result = $client->getRerankedContent('What is the difference between Deep Learning and Machine Learning?', $content);
Result:
Array ( [0] => Array ( [index] => 0 [score] => 0.94238955 [content] => Deep learning is... ) [1] => Array ( [index] => 2 [score] => 0.120219156 [content] => Deep Learning is not... ) )
Using Sequence Classification
<?php use Partitech\PhpTeiClient\TeiClient; $client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey'); // Predict the sentiment of a string $result = $client->predict('I love this product!');
Result:
Array ( [0] => Array ( [score] => 0.986059 [label] => love ) [1] => Array ( [score] => 0.006502793 [label] => admiration ) [2] => Array ( [score] => 0.0020027023 [label] => approval ) [3] => Array ( [score] => 0.0008381181 [label] => neutral ) [4] => Array ( [score] => 0.0005737838 [label] => joy ) --------- [27] => Array ( [score] => 2.2074879E-5 [label] => grief ) )
Using SPLADE pooling
<?php use Partitech\PhpTeiClient\TeiClient; $client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey'); $result = $client->embedSparse(content: 'What is Deep Learning?');
Result:
Array ( [0] => Array ( [0] => Array ( [index] => 1012 [value] => 1.0751953 ) [1] => Array ( [index] => 2003 [value] => 1.5722656 ) [2] => Array ( [index] => 2784 [value] => 2.9082031 ) [3] => Array ( [index] => 4083 [value] => 2.7929688 ) ) )
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
partitech/php-tei-client 适用场景与选型建议
partitech/php-tei-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 73 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 07 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 partitech/php-tei-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 partitech/php-tei-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 73
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-19