jinaai_rerank_client.py 1.03 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5
6
7
8
"""
Example of using the OpenAI entrypoint's rerank API which is compatible with
Jina and Cohere https://jina.ai/reranker

run: vllm serve BAAI/bge-reranker-base
"""
9

10
11
12
13
14
15
16
17
18
import json

import requests

url = "http://127.0.0.1:8000/rerank"

headers = {"accept": "application/json", "Content-Type": "application/json"}

data = {
19
20
    "model": "BAAI/bge-reranker-base",
    "query": "What is the capital of France?",
21
22
    "documents": [
        "The capital of Brazil is Brasilia.",
23
24
25
        "The capital of France is Paris.",
        "Horses and cows are both animals",
    ],
26
}
Reid's avatar
Reid committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


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

    # Check the response
    if response.status_code == 200:
        print("Request successful!")
        print(json.dumps(response.json(), indent=2))
    else:
        print(f"Request failed with status code: {response.status_code}")
        print(response.text)


if __name__ == "__main__":
    main()