@@ -33,6 +33,8 @@ class BailianNetworkError(BailianRerankError):
3333class BailianRerankProvider (RerankProvider ):
3434 """阿里云百炼文本重排序适配器."""
3535
36+ QWEN3_RERANK_MODEL = "qwen3-rerank"
37+
3638 def __init__ (self , provider_config : dict , provider_settings : dict ) -> None :
3739 super ().__init__ (provider_config , provider_settings )
3840 self .provider_config = provider_config
@@ -83,19 +85,35 @@ def _build_payload(
8385 Returns:
8486 请求载荷字典
8587 """
88+ normalized_model = self .model .strip ().lower ()
89+ normalized_top_n = top_n if top_n is not None and top_n > 0 else None
90+
91+ # qwen3-rerank follows a model-specific payload:
92+ # query/documents/top_n/instruct should be at the top level.
93+ if normalized_model == self .QWEN3_RERANK_MODEL :
94+ payload = {
95+ "model" : self .model ,
96+ "query" : query ,
97+ "documents" : documents ,
98+ }
99+ if normalized_top_n is not None :
100+ payload ["top_n" ] = normalized_top_n
101+ if self .instruct :
102+ payload ["instruct" ] = self .instruct
103+ if self .return_documents :
104+ logger .warning (
105+ "qwen3-rerank does not support return_documents; "
106+ "this option will be ignored."
107+ )
108+ return payload
109+
86110 base = {"model" : self .model , "input" : {"query" : query , "documents" : documents }}
87111
88112 params = {
89113 k : v
90114 for k , v in [
91- ("top_n" , top_n if top_n is not None and top_n > 0 else None ),
115+ ("top_n" , normalized_top_n ),
92116 ("return_documents" , True if self .return_documents else None ),
93- (
94- "instruct" ,
95- self .instruct
96- if self .instruct and self .model == "qwen3-rerank"
97- else None ,
98- ),
99117 ]
100118 if v is not None
101119 }
0 commit comments