Jina AI
Jina AI
Jina AI의 임베딩과 rerank 모델을 LiteLLM으로 호출해요. 지원 엔드포인트: /embeddings, /rerank.
출처: 문서
본문
API 키
# env variable
os.environ['JINA_AI_API_KEY']
샘플 사용법 - Embedding
SDK:
from litellm import embedding
import os
os.environ['JINA_AI_API_KEY'] = ""
response = embedding(
model="jina_ai/jina-embeddings-v3",
input=["good morning from litellm"],
)
print(response)
config.yaml에 추가:
model_list:
- model_name: embedding-model
litellm_params:
model: jina_ai/jina-embeddings-v3
api_key: os.environ/JINA_AI_API_KEY
Proxy 시작 후 테스트:
litellm --config /path/to/config.yaml
# RUNNING on http://0.0.0.0:4000/
curl -L -X POST 'http://0.0.0.0:4000/embeddings' \
-H "Authorization: Bearer ***" \
-H 'Content-Type: application/json' \
-d '{"input": ["hello world"], "model": "embedding-model"}'
샘플 사용법 - Rerank
SDK:
from litellm import rerank
import os
os.environ["JINA_AI_API_KEY"] = "sk-..."
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.",
]
response = rerank(
model="jina_ai/jina-reranker-v2-base-multilingual",
query=query,
documents=documents,
top_n=3,
)
print(response)
config.yaml에 추가:
model_list:
- model_name: rerank-model
litellm_params:
model: jina_ai/jina-reranker-v2-base-multilingual
api_key: os.environ/JINA_AI_API_KEY
Proxy 시작 후 테스트:
litellm --config /path/to/config.yaml
curl -L -X POST 'http://0.0.0.0:4000/rerank' \
-H "Authorization: Bearer ***" \
-H 'Content-Type: application/json' \
-d '{
"model": "rerank-model",
"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
}'
지원 모델 (Supported Models)
https://jina.ai/embeddings/ 에 나열된 모든 모델이 지원돼요.
지원 선택적 Rerank 파라미터
모든 Cohere rerank 파라미터가 지원돼요.
지원 선택적 Embeddings 파라미터
dimensions 파라미터가 지원돼요.
response = embedding(
model="jina_ai/jina-embeddings-v3",
input=["good morning from litellm"],
dimensions=1536,
my_custom_param="my_custom_value", # any other jina ai specific parameters
)
curl -L -X POST 'http://0.0.0.0:4000/embeddings' \
-H "Authorization: Bearer ***" \
-H 'Content-Type: application/json' \
-d '{
"input": ["good morning from litellm"],
"model": "jina_ai/jina-embeddings-v3",
"dimensions": 1536,
"my_custom_param": "my_custom_value"
}'