Skip to content

Commit

Permalink
doc(example): update jina example to reflect lack of SDK, add cohere …
Browse files Browse the repository at this point in the history
…example

Signed-off-by: Kyle Mistele <[email protected]>
  • Loading branch information
K-Mistele committed Jan 24, 2025
1 parent cce2873 commit a38060f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
37 changes: 37 additions & 0 deletions examples/online_serving/cohere_rerank_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Example of using the OpenAI entrypoint's rerank API which is compatible with
the Cohere SDK: https://github.com/cohere-ai/cohere-python
run: vllm serve --model BAAI/bge-reranker-base
"""
import cohere

# cohere v1 client
co = cohere.Client(base_url="http://localhost:8000", api_key="sk-fake-key")
rerank_v1_result = co.rerank(
model="BAAI/bge-reranker-base",
query="What is the capital of France?",
documents=[
"The capital of France is Paris",
"Reranking is fun!",
"vLLM is an open-source framework for fast AI serving"
]
)

print(rerank_v1_result)

# or the v2
co2 = cohere.ClientV2("sk-fake-key", base_url="http://localhost:8000")

v2_rerank_result = co2.rerank(
model="BAAI/bge-reranker-base",
query="What is the capital of France?",
documents=[
"The capital of France is Paris",
"Reranking is fun!",
"vLLM is an open-source framework for fast AI serving"
]
)

print(v2_rerank_result)

4 changes: 2 additions & 2 deletions examples/online_serving/jinjaai_rerank_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Example of using the OpenAI entrypoint's rerank API which is compatible with
Jina and Cohere
Jina and Cohere https://jina.ai/reranker
run: vllm serve --model BAAI/bge-reranker-base
"""
import json
Expand All @@ -21,7 +22,6 @@
"The capital of France is Paris.", "Horses and cows are both animals"
]
}

response = requests.post(url, headers=headers, json=data)

# Check the response
Expand Down

0 comments on commit a38060f

Please sign in to comment.