|
|
@@ -292,6 +292,41 @@ async def test_embedding_exception_and_close(tmp_path, monkeypatch):
|
|
|
assert session.closed is True
|
|
|
|
|
|
|
|
|
+def test_rerank_build_url(tmp_path):
|
|
|
+ config = DataModulesConfig.from_project_root(tmp_path)
|
|
|
+ config.rerank_api_type = "openai"
|
|
|
+
|
|
|
+ # Jina/Cohere: bare URL
|
|
|
+ config.rerank_base_url = "https://api.jina.ai"
|
|
|
+ client = RerankAPIClient(config)
|
|
|
+ assert client._build_url() == "https://api.jina.ai/v1/rerank"
|
|
|
+
|
|
|
+ # Jina/Cohere: URL ending with /v1
|
|
|
+ config.rerank_base_url = "https://api.jina.ai/v1"
|
|
|
+ assert client._build_url() == "https://api.jina.ai/v1/rerank"
|
|
|
+
|
|
|
+ # Jina/Cohere: URL already ending with /rerank
|
|
|
+ config.rerank_base_url = "https://api.jina.ai/v1/rerank"
|
|
|
+ assert client._build_url() == "https://api.jina.ai/v1/rerank"
|
|
|
+
|
|
|
+ # DashScope: bare URL
|
|
|
+ config.rerank_base_url = "https://dashscope.aliyuncs.com"
|
|
|
+ assert client._build_url() == "https://dashscope.aliyuncs.com/v1/reranks"
|
|
|
+
|
|
|
+ # DashScope: URL ending with /v1
|
|
|
+ config.rerank_base_url = "https://dashscope.aliyuncs.com/v1"
|
|
|
+ assert client._build_url() == "https://dashscope.aliyuncs.com/v1/reranks"
|
|
|
+
|
|
|
+ # DashScope: URL already ending with /reranks
|
|
|
+ config.rerank_base_url = "https://dashscope.aliyuncs.com/v1/reranks"
|
|
|
+ assert client._build_url() == "https://dashscope.aliyuncs.com/v1/reranks"
|
|
|
+
|
|
|
+ # Modal: passthrough
|
|
|
+ config.rerank_api_type = "modal"
|
|
|
+ config.rerank_base_url = "https://modal.example.com/rerank"
|
|
|
+ assert client._build_url() == "https://modal.example.com/rerank"
|
|
|
+
|
|
|
+
|
|
|
def test_rerank_headers_payload_and_stats(tmp_path, capsys):
|
|
|
config = DataModulesConfig.from_project_root(tmp_path)
|
|
|
config.rerank_api_key = "rk-test"
|