forked from phoenix/litellm-mirror
docs add rerank api to docs
This commit is contained in:
parent
afe62c4808
commit
a5a17c120b
2 changed files with 116 additions and 0 deletions
115
docs/my-website/docs/rerank.md
Normal file
115
docs/my-website/docs/rerank.md
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
# Rerank
|
||||||
|
|
||||||
|
:::tip
|
||||||
|
|
||||||
|
LiteLLM Follows the [cohere api request / response for the rerank api](https://cohere.com/rerank)
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
## **LiteLLM Python SDK Usage**
|
||||||
|
### Quick Start
|
||||||
|
|
||||||
|
```python
|
||||||
|
from litellm import rerank
|
||||||
|
import os
|
||||||
|
|
||||||
|
os.environ["COHERE_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="cohere/rerank-english-v3.0",
|
||||||
|
query=query,
|
||||||
|
documents=documents,
|
||||||
|
top_n=3,
|
||||||
|
)
|
||||||
|
print(response)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Async Usage
|
||||||
|
|
||||||
|
```python
|
||||||
|
from litellm import arerank
|
||||||
|
import os, asyncio
|
||||||
|
|
||||||
|
os.environ["COHERE_API_KEY"] = "sk-.."
|
||||||
|
|
||||||
|
async def test_async_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.",
|
||||||
|
]
|
||||||
|
|
||||||
|
response = await arerank(
|
||||||
|
model="cohere/rerank-english-v3.0",
|
||||||
|
query=query,
|
||||||
|
documents=documents,
|
||||||
|
top_n=3,
|
||||||
|
)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
asyncio.run(test_async_rerank())
|
||||||
|
```
|
||||||
|
|
||||||
|
## **LiteLLM Proxy Usage**
|
||||||
|
|
||||||
|
LiteLLM provides an cohere api compatible `/rerank` endpoint for Rerank calls.
|
||||||
|
|
||||||
|
**Setup**
|
||||||
|
|
||||||
|
Add this to your litellm proxy config.yaml
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
model_list:
|
||||||
|
- model_name: Salesforce/Llama-Rank-V1
|
||||||
|
litellm_params:
|
||||||
|
model: together_ai/Salesforce/Llama-Rank-V1
|
||||||
|
api_key: os.environ/TOGETHERAI_API_KEY
|
||||||
|
- model_name: rerank-english-v3.0
|
||||||
|
litellm_params:
|
||||||
|
model: cohere/rerank-english-v3.0
|
||||||
|
api_key: os.environ/COHERE_API_KEY
|
||||||
|
```
|
||||||
|
|
||||||
|
Start litellm
|
||||||
|
|
||||||
|
```bash
|
||||||
|
litellm --config /path/to/config.yaml
|
||||||
|
|
||||||
|
# RUNNING on http://0.0.0.0:4000
|
||||||
|
```
|
||||||
|
|
||||||
|
Test request
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl http://0.0.0.0:4000/rerank \
|
||||||
|
-H "Authorization: Bearer sk-1234" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"model": "rerank-english-v3.0",
|
||||||
|
"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 Providers**
|
||||||
|
|
||||||
|
| Provider | Link to Usage |
|
||||||
|
|-------------|--------------------|
|
||||||
|
| Cohere | [Usage](#quick-start) |
|
||||||
|
| Together AI| [Usage](../docs/providers/togetherai) |
|
|
@ -202,6 +202,7 @@ const sidebars = {
|
||||||
"image_generation",
|
"image_generation",
|
||||||
"audio_transcription",
|
"audio_transcription",
|
||||||
"text_to_speech",
|
"text_to_speech",
|
||||||
|
"rerank",
|
||||||
"assistants",
|
"assistants",
|
||||||
"batches",
|
"batches",
|
||||||
"fine_tuning",
|
"fine_tuning",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue