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 | 類型 | 說明 |
|---|---|---|
query | str | 要據以重新排序文件的查詢 |
documents | list[str] | 要重新排序的文件 |
top_n | int | 要回傳的文件數量 |
return_documents | bool | 是否在回應中回傳文件 |
使用方式 - 回傳文件
- SDK
- PROXY
response = rerank(
model="infinity/rerank",
query="What is the capital of France?",
documents=["Paris", "London", "Berlin", "Madrid"],
return_documents=True,
)
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 France?",
"documents": [
"Paris",
"London",
"Berlin",
"Madrid"
],
"return_documents": True,
}'
傳遞提供者專屬參數
任何未對應的參數都會原樣傳遞給提供者。
- SDK
- PROXY
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
)
- 設定 config.yaml
model_list:
- model_name: custom-infinity-rerank
litellm_params:
model: infinity/rerank
api_base: https://localhost:8080
raw_scores: True # 👈 EITHER SET PROVIDER-SPECIFIC PARAMS HERE OR IN REQUEST BODY
- 啟動 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."
],
"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 | 類型 | 說明 |
|---|---|---|
model | str | 要使用的 embedding 模型 |
input | list[str] | 要為其產生 embeddings 的文字輸入 |
encoding_format | str | 回傳 embeddings 的格式(例如「float」、「base64」) |
modality | str | 輸入類型(例如「text」、「image」、「audio」) |
使用方式 - 基本範例
- SDK
- PROXY
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'])
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"]
}'
使用方式 - OpenAI Client
- SDK
- PROXY
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)
curl http://0.0.0.0:4000/embeddings \
-H "Authorization: Bearer sk-1234" \
-H "Content-Type: application/json" \
-d '{
"model": "bge-small",
"input": ["The food was delicious and the waiter..."],
"encoding_format": "float"
}'