openai-simple-rerank
一个简单的rank模型的OPENAI兼容API服务的客户端访问工具。
安装
pip install openai-simple-rerank
使用
建议使用xinference启动rerank模型
验证过的模型列表
- bge-reranker-v2-m3
配置变量设置
# OPENAI兼容API服务,可以xinference提供
# 使用OPENAI_RERANK_BASE_URL或RERANK_BASE_URL设置独立的服务地址
export OPENAI_BASE_URL="http://localhost/v1"
# OPENAI兼容API服务密钥,一般以sk-开头,共16位长
# 使用OPENAI_RERANK_API_KEY或RERANK_API_KEY设置独立的服务密码
export OPENAI_API_KEY=""
# 默认的文本重排序模型
export OPENAI_RERANK_MODEL="bge-reranker-v2-m3"
# 默认的最大字符串长度控制
export OPENAI_RERANK_MAX_SIZE=1024
获取文本向量
代码
from openai_simple_rerank.base import get_rerank_scores
s1, s2 = get_rerank_scores("hello", ["hi", "world"])
print(s1, s2)
输出
0.9953891038894653 0.40583446621894836
关于字符串长度控制
- 模型本身一般没有字符串长度控制。
- 但过长的字符串会导入模型占用内存的增长。
- 所以默认将字符串长度控制在:1024字。
- 通过
OPENAI_RERANK_MAX_SIZE设置默认最大字符串长度。 - 也可以函数调用中指定最大字符串长度。
- 注意:所有超过最大长度的字符串将被截断。
版本记录
v0.1.0
- 版本首发。
v0.1.1
- 允许rerank模型使用独立的服务地址及密码。
v0.1.2
- 使用RuntimeError替换自定义错误类。
v0.1.3
- 修正
OPENAI_RERANK_MODEL默认值。
Metadata
Release files for openai-simple-rerank 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| openai_simple_rerank-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for openai_simple_rerank-0.1.3-py3-none-any.whl |
Release files / openai_simple_rerank-0.1.3-py3-none-any.whl
| Download URL | openai_simple_rerank-0.1.3-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83b86409335fef7d38c1e1b4dc8916cf1b6ca5877769125151866ccac794f70d
|
|
BLAKE2b-256 checksum How to use checksums |
7ddb8b6990b0ec98c11f943689555675c32707149b9742d239001e158601b6ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Security for openai-simple-rerank 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.