Files
railseek6/test_ollama_rerank_endpoint.py
2026-01-13 09:51:35 +08:00

65 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""Test if Ollama has a rerank endpoint"""
import requests
import json
def test_ollama_rerank_endpoint():
print("=== Testing Ollama Rerank Endpoint ===")
# Test if Ollama has a rerank endpoint
# Based on Ollama documentation, it might use /api/embed with rerank models
test_data = {
"model": "jina-reranker-v2:latest",
"prompt": "What is the capital of France?",
"documents": [
"The capital of France is Paris.",
"Tokyo is the capital of Japan.",
"London is the capital of England."
]
}
# Try different endpoints
endpoints = [
"http://localhost:11434/api/rerank",
"http://localhost:11434/api/embed",
"http://localhost:11434/v1/rerank",
"http://localhost:11434/api/generate" # Ollama's generate endpoint
]
for endpoint in endpoints:
print(f"\nTrying endpoint: {endpoint}")
try:
response = requests.post(endpoint, json=test_data, timeout=10)
print(f" Status: {response.status_code}")
if response.status_code == 200:
print(f" Response: {response.text[:200]}...")
# Try to parse as JSON
try:
result = response.json()
print(f" JSON parsed successfully")
print(f" Result keys: {list(result.keys())}")
except:
print(f" Not valid JSON")
elif response.status_code == 404:
print(f" Endpoint not found")
else:
print(f" Error: {response.text[:200]}")
except requests.exceptions.ConnectionError:
print(f" Connection error")
except Exception as e:
print(f" Error: {e}")
print("\n=== Checking Ollama API Documentation ===")
# Get Ollama API routes
try:
# Try to get Ollama API info
response = requests.get("http://localhost:11434", timeout=5)
print(f"Ollama root: Status {response.status_code}")
print(f"Response: {response.text[:500]}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
test_ollama_rerank_endpoint()