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模型使用独立的服务地址及密码。

Project details


Download files

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

Source Distribution

openai-simple-rerank-0.1.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

openai_simple_rerank-0.1.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file openai-simple-rerank-0.1.1.tar.gz.

File metadata

  • Download URL: openai-simple-rerank-0.1.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for openai-simple-rerank-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ff4e0151d5d73a466dd41d3eb8368d7e9e3a02dd8117e1bd4a881dbd11cb6245
MD5 deb0444ad8be79b6b40377baccd9cc83
BLAKE2b-256 07c1fb673ce9e245d447429dafae1f2c95594ba8f283c050ac9e93828fe4f746

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openai_simple_rerank-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d96a307a2b8fefeee00e29d293ca69cb829f7862fbbe1cbb0881a39069161b61
MD5 7016c9a744f5943c6be03adf5442a307
BLAKE2b-256 9889433837618f31423c3a6f6cc9698471342153990ecba58f4759e71b6d01b9

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