@@ -16,17 +16,23 @@ const testDocuments = [
1616]
1717
1818describe ( "doRerank" , ( ) => {
19+ let requestUrl : string
1920 let requestBody : any
2021 let requestHeaders : Record < string , string >
2122 let responseBody : any
2223 let responseHeaders : Record < string , string >
2324
2425 beforeEach ( ( ) => {
26+ requestUrl = ""
2527 requestBody = undefined
2628 requestHeaders = { }
29+ // DashScope native API response format
2730 responseBody = {
28- results : dummyRankingResults ,
31+ output : {
32+ results : dummyRankingResults ,
33+ } ,
2934 usage : { total_tokens : 100 } ,
35+ request_id : "test-request-id-123" ,
3036 }
3137 responseHeaders = {
3238 "content-type" : "application/json" ,
@@ -35,13 +41,14 @@ describe("doRerank", () => {
3541
3642 function createTestProvider ( overrides ?: any ) {
3743 return createQwen ( {
38- baseURL : "https://my.api.com/v1/ " ,
44+ baseURL : "https://my.api.com/compatible-mode/v1 " ,
3945 headers : {
4046 Authorization : `Bearer test-api-key` ,
4147 } ,
4248 ...overrides ,
43- fetch : async ( _url , init ) => {
49+ fetch : async ( url , init ) => {
4450 // Capture request
51+ requestUrl = url as string
4552 if ( init ?. body ) {
4653 requestBody = JSON . parse ( init . body as string )
4754 }
@@ -61,6 +68,21 @@ describe("doRerank", () => {
6168 } )
6269 }
6370
71+ it ( "should use DashScope native API endpoint (not compatible mode)" , async ( ) => {
72+ const provider = createTestProvider ( )
73+ const model = provider . rerankingModel ( "gte-rerank-v2" )
74+
75+ await model . doRerank ( {
76+ documents : { type : "text" , values : testDocuments } ,
77+ query : "talk about rain" ,
78+ } )
79+
80+ // Should use native API endpoint, not compatible mode
81+ expect ( requestUrl ) . toBe (
82+ "https://my.api.com/api/v1/services/rerank/text-rerank/text-rerank" ,
83+ )
84+ } )
85+
6486 it ( "should extract ranking results" , async ( ) => {
6587 const provider = createTestProvider ( )
6688 const model = provider . rerankingModel ( "gte-rerank-v2" )
@@ -77,6 +99,18 @@ describe("doRerank", () => {
7799 ] )
78100 } )
79101
102+ it ( "should return request_id in response" , async ( ) => {
103+ const provider = createTestProvider ( )
104+ const model = provider . rerankingModel ( "gte-rerank-v2" )
105+
106+ const { response } = await model . doRerank ( {
107+ documents : { type : "text" , values : testDocuments } ,
108+ query : "talk about rain" ,
109+ } )
110+
111+ expect ( response ?. id ) . toBe ( "test-request-id-123" )
112+ } )
113+
80114 it ( "should expose the raw response headers" , async ( ) => {
81115 responseHeaders = {
82116 ...responseHeaders ,
@@ -97,7 +131,7 @@ describe("doRerank", () => {
97131 } )
98132 } )
99133
100- it ( "should pass the model, query, and documents" , async ( ) => {
134+ it ( "should pass the model, query, and documents in DashScope native format " , async ( ) => {
101135 const provider = createTestProvider ( )
102136 const model = provider . rerankingModel ( "gte-rerank-v2" )
103137
@@ -108,12 +142,15 @@ describe("doRerank", () => {
108142
109143 expect ( requestBody ) . toStrictEqual ( {
110144 model : "gte-rerank-v2" ,
111- query : "talk about rain" ,
112- documents : testDocuments ,
145+ input : {
146+ query : "talk about rain" ,
147+ documents : testDocuments ,
148+ } ,
149+ parameters : { } ,
113150 } )
114151 } )
115152
116- it ( "should pass topN parameter" , async ( ) => {
153+ it ( "should pass topN parameter in parameters object " , async ( ) => {
117154 const provider = createTestProvider ( )
118155 const model = provider . rerankingModel ( "gte-rerank-v2" )
119156
@@ -125,13 +162,17 @@ describe("doRerank", () => {
125162
126163 expect ( requestBody ) . toStrictEqual ( {
127164 model : "gte-rerank-v2" ,
128- query : "talk about rain" ,
129- documents : testDocuments ,
130- top_n : 2 ,
165+ input : {
166+ query : "talk about rain" ,
167+ documents : testDocuments ,
168+ } ,
169+ parameters : {
170+ top_n : 2 ,
171+ } ,
131172 } )
132173 } )
133174
134- it ( "should pass returnDocuments setting" , async ( ) => {
175+ it ( "should pass returnDocuments setting in parameters object " , async ( ) => {
135176 const provider = createTestProvider ( )
136177 const model = provider . rerankingModel ( "gte-rerank-v2" , {
137178 returnDocuments : true ,
@@ -144,9 +185,13 @@ describe("doRerank", () => {
144185
145186 expect ( requestBody ) . toStrictEqual ( {
146187 model : "gte-rerank-v2" ,
147- query : "talk about rain" ,
148- documents : testDocuments ,
149- return_documents : true ,
188+ input : {
189+ query : "talk about rain" ,
190+ documents : testDocuments ,
191+ } ,
192+ parameters : {
193+ return_documents : true ,
194+ } ,
150195 } )
151196 } )
152197
@@ -164,7 +209,7 @@ describe("doRerank", () => {
164209 query : "talk about rain" ,
165210 } )
166211
167- expect ( requestBody . documents ) . toStrictEqual ( [
212+ expect ( requestBody . input . documents ) . toStrictEqual ( [
168213 JSON . stringify ( objectDocs [ 0 ] ) ,
169214 JSON . stringify ( objectDocs [ 1 ] ) ,
170215 ] )
0 commit comments