跳至主要內容

Infinity

屬性詳細資訊
說明Infinity 是一個高吞吐量、低延遲的 REST API,用於提供 text-embeddings、reranking models 和 clip
LiteLLM 提供者路由infinity/
支援的操作/rerank, /embeddings
提供者文件連結Infinity ↗

使用方式 - LiteLLM Python SDK

from litellm import rerank, embedding
import os

os.environ["INFINITY_API_BASE"] = "http://localhost:8080"

response = rerank(
model="infinity/rerank",
query="What is the capital of France?",
documents=["Paris", "London", "Berlin", "Madrid"],
)

使用方式 - LiteLLM Proxy

LiteLLM 提供與 cohere api 相容的 /rerank 端點,用於 Rerank 請求。

設定

將以下內容新增至您的 litellm proxy config.yaml

model_list:
- model_name: custom-infinity-rerank
litellm_params:
model: infinity/rerank
api_base: https://localhost:8080
api_key: os.environ/INFINITY_API_KEY

啟動 litellm

litellm --config /path/to/config.yaml

# RUNNING on http://0.0.0.0:4000

測試請求:

重新排序

curl http://0.0.0.0:4000/rerank \
-H "Authorization: Bearer sk-1234" \
-H "Content-Type: application/json" \
-d '{
"model": "custom-infinity-rerank",
"query": "What is the capital of the United States?",
"documents": [
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. is the capital of the United States.",
"Capital punishment has existed in the United States since before it was a country."
],
"top_n": 3
}'

支援的 Cohere Rerank API 參數

Param類型說明
querystr要據以重新排序文件的查詢
documentslist[str]要重新排序的文件
top_nint要回傳的文件數量
return_documentsbool是否在回應中回傳文件

使用方式 - 回傳文件

response = rerank(
model="infinity/rerank",
query="What is the capital of France?",
documents=["Paris", "London", "Berlin", "Madrid"],
return_documents=True,
)

傳遞提供者專屬參數

任何未對應的參數都會原樣傳遞給提供者。

from litellm import rerank
import os

os.environ["INFINITY_API_BASE"] = "http://localhost:8080"

response = rerank(
model="infinity/rerank",
query="What is the capital of France?",
documents=["Paris", "London", "Berlin", "Madrid"],
raw_scores=True, # 👈 PROVIDER-SPECIFIC PARAM
)

嵌入

LiteLLM 提供與 OpenAI api 相容的 /embeddings 端點,用於 embedding 請求。

設定

將以下內容新增至您的 litellm proxy config.yaml

model_list:
- model_name: custom-infinity-embedding
litellm_params:
model: infinity/provider/custom-embedding-v1
api_base: http://localhost:8080
api_key: os.environ/INFINITY_API_KEY

測試請求:

curl http://0.0.0.0:4000/embeddings \
-H "Authorization: Bearer sk-1234" \
-H "Content-Type: application/json" \
-d '{
"model": "custom-infinity-embedding",
"input": ["hello"]
}'

支援的 Embedding API 參數

Param類型說明
modelstr要使用的 embedding 模型
inputlist[str]要為其產生 embeddings 的文字輸入
encoding_formatstr回傳 embeddings 的格式(例如「float」、「base64」)
modalitystr輸入類型(例如「text」、「image」、「audio」)

使用方式 - 基本範例

from litellm import embedding
import os

os.environ["INFINITY_API_BASE"] = "http://localhost:8080"

response = embedding(
model="infinity/bge-small",
input=["good morning from litellm"]
)

print(response.data[0]['embedding'])

使用方式 - OpenAI Client

from openai import OpenAI

client = OpenAI(
api_key="<LITELLM_MASTER_KEY>",
base_url="<LITELLM_URL>"
)

response = client.embeddings.create(
model="bge-small",
input=["The food was delicious and the waiter..."],
encoding_format="float"
)

print(response.data[0].embedding)