Skip to main content

一个简单的rank模型的OPENAI兼容API服务的客户端访问工具。

Project description

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替换自定义错误类。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

openai_simple_rerank-0.1.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file openai_simple_rerank-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_simple_rerank-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 55325c955303791029da085a36183332ab0b491e0f3985391b81e43cf82b1ced
MD5 aaf91236511d7561fe3bf0a270aad02c
BLAKE2b-256 865a53efc5d1652f836132690ac33e434b4437cdfeae4f00839a97ab143e884c

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