main
py 41 lines 1.03 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 """Example of using the OpenAI entrypoint's rerank API which is compatible with
4 Jina and Cohere https://jina.ai/reranker
5
6 run: vllm serve BAAI/bge-reranker-base
7 """
8
9 import json
10
11 import requests
12
13 url = "http://127.0.0.1:8000/rerank"
14
15 headers = {"accept": "application/json", "Content-Type": "application/json"}
16
17 data = {
18 "model": "BAAI/bge-reranker-base",
19 "query": "What is the capital of France?",
20 "documents": [
21 "The capital of Brazil is Brasilia.",
22 "The capital of France is Paris.",
23 "Horses and cows are both animals",
24 ],
25 }
26
27
28 def main():
29 response = requests.post(url, headers=headers, json=data)
30
31 # Check the response
32 if response.status_code == 200:
33 print("Request successful!")
34 print(json.dumps(response.json(), indent=2))
35 else:
36 print(f"Request failed with status code: {response.status_code}")
37 print(response.text)
38
39
40 if __name__ == "__main__":
41 main()