@@ -13,18 +13,18 @@ T["DeepSeek adapter"] = new_set({
1313 },
1414})
1515
16- T [" DeepSeek adapter" ][" form_messages " ] = new_set ()
16+ T [" DeepSeek adapter" ][" build_messages " ] = new_set ()
1717
18- T [" DeepSeek adapter" ][" form_messages " ][" it can form messages to be sent to the API" ] = function ()
18+ T [" DeepSeek adapter" ][" build_messages " ][" it can form messages to be sent to the API" ] = function ()
1919 local messages = { {
2020 content = " Explain Ruby in two words" ,
2121 role = " user" ,
2222 } }
2323
24- h .eq ({ messages = messages }, adapter .handlers .form_messages (adapter , messages ))
24+ h .eq ({ messages = messages }, adapter .handlers .request . build_messages (adapter , messages ))
2525end
2626
27- T [" DeepSeek adapter" ][" form_messages " ][" merges consecutive messages with the same role" ] = function ()
27+ T [" DeepSeek adapter" ][" build_messages " ][" merges consecutive messages with the same role" ] = function ()
2828 local input = {
2929 { role = " user" , content = " A" },
3030 { role = " user" , content = " B" },
@@ -41,10 +41,10 @@ T["DeepSeek adapter"]["form_messages"]["merges consecutive messages with the sam
4141 },
4242 }
4343
44- h .eq (expected , adapter .handlers .form_messages (adapter , input ))
44+ h .eq (expected , adapter .handlers .request . build_messages (adapter , input ))
4545end
4646
47- T [" DeepSeek adapter" ][" form_messages " ][" merges system messages together at the start of the message chain" ] = function ()
47+ T [" DeepSeek adapter" ][" build_messages " ][" merges system messages together at the start of the message chain" ] = function ()
4848 local input = {
4949 { role = " system" , content = " System Prompt 1" },
5050 { role = " user" , content = " User1" },
@@ -65,10 +65,10 @@ T["DeepSeek adapter"]["form_messages"]["merges system messages together at the s
6565 },
6666 }
6767
68- h .eq (expected , adapter .handlers .form_messages (adapter , input ))
68+ h .eq (expected , adapter .handlers .request . build_messages (adapter , input ))
6969end
7070
71- T [" DeepSeek adapter" ][" form_messages " ][" ensures message content is a string and not a list" ] = function ()
71+ T [" DeepSeek adapter" ][" build_messages " ][" ensures message content is a string and not a list" ] = function ()
7272 -- Ref: https://github.com/BerriAI/litellm/issues/6642
7373 local input = {
7474 { role = " user" , content = " Describe Ruby in two words" },
@@ -88,10 +88,10 @@ T["DeepSeek adapter"]["form_messages"]["ensures message content is a string and
8888 },
8989 }
9090
91- h .eq (expected , adapter .handlers .form_messages (adapter , input ))
91+ h .eq (expected , adapter .handlers .request . build_messages (adapter , input ))
9292end
9393
94- T [" DeepSeek adapter" ][" form_messages " ][" it can form messages with tools" ] = function ()
94+ T [" DeepSeek adapter" ][" build_messages " ][" it can form messages with tools" ] = function ()
9595 local input = {
9696 { role = " system" , content = " System Prompt 1" },
9797 { role = " user" , content = " User1" },
@@ -157,10 +157,10 @@ T["DeepSeek adapter"]["form_messages"]["it can form messages with tools"] = func
157157 },
158158 }
159159
160- h .eq (expected , adapter .handlers .form_messages (adapter , input ))
160+ h .eq (expected , adapter .handlers .request . build_messages (adapter , input ))
161161end
162162
163- T [" DeepSeek adapter" ][" form_messages " ][" it can form tools to be sent to the API" ] = function ()
163+ T [" DeepSeek adapter" ][" build_messages " ][" it can form tools to be sent to the API" ] = function ()
164164 adapter = require (" codecompanion.adapters" ).extend (" deepseek" , {
165165 schema = {
166166 model = {
@@ -172,7 +172,20 @@ T["DeepSeek adapter"]["form_messages"]["it can form tools to be sent to the API"
172172 local weather = require (" tests.interactions.chat.tools.builtin.stubs.weather" ).schema
173173 local tools = { weather = { weather } }
174174
175- h .eq ({ tools = { weather } }, adapter .handlers .form_tools (adapter , tools ))
175+ h .eq ({ tools = { weather } }, adapter .handlers .request .build_tools (adapter , tools ))
176+ end
177+
178+ T [" DeepSeek adapter" ][" build_messages" ][" includes reasoning_content in messages" ] = function ()
179+ local input = {
180+ { role = " user" , content = " What is Ruby?" },
181+ { role = " assistant" , content = " " , reasoning = " Let me think about Ruby..." },
182+ { role = " user" , content = " In two words" },
183+ }
184+
185+ local result = adapter .handlers .request .build_messages (adapter , input )
186+
187+ -- reasoning is normalized to a string by build_reasoning before message storage
188+ h .eq (" Let me think about Ruby..." , result .messages [2 ].reasoning_content )
176189end
177190
178191T [" DeepSeek adapter" ][" Streaming" ] = new_set ()
@@ -181,12 +194,12 @@ T["DeepSeek adapter"]["Streaming"]["can output streamed data into a format for t
181194 local lines = vim .fn .readfile (" tests/adapters/http/stubs/deepseek_streaming.txt" )
182195 local output = " "
183196 for _ , line in ipairs (lines ) do
184- output = output .. (adapter .handlers .chat_output (adapter , line ).output .content or " " )
197+ local chat_output = adapter .handlers .response .parse_chat (adapter , line )
198+ if chat_output then
199+ output = output .. (chat_output .output .content or " " )
200+ end
185201 end
186- h .eq (
187- " Dynamic. Expressive.\n\n Next, you might ask about Ruby's key features or how it compares to other languages." ,
188- output
189- )
202+ h .eq (" Elegant simplicity" , output )
190203end
191204
192205T [" DeepSeek adapter" ][" Streaming" ][" can handle reasoning content when streaming" ] = function ()
@@ -196,12 +209,11 @@ T["DeepSeek adapter"]["Streaming"]["can handle reasoning content when streaming"
196209 content = " " ,
197210 },
198211 }
199-
200212 local lines = vim .fn .readfile (" tests/adapters/http/stubs/deepseek_streaming.txt" )
201213 for _ , line in ipairs (lines ) do
202- local chat_output = adapter .handlers .chat_output (adapter , line )
203- if adapter .handlers .parse_message_meta and chat_output .extra then
204- chat_output = adapter .handlers .parse_message_meta (adapter , chat_output )
214+ local chat_output = adapter .handlers .response . parse_chat (adapter , line )
215+ if chat_output and adapter .handlers .response . parse_meta and chat_output .extra then
216+ chat_output = adapter .handlers .response . parse_meta (adapter , chat_output )
205217 end
206218 if chat_output then
207219 if chat_output .output .reasoning and chat_output .output .reasoning .content then
@@ -212,34 +224,86 @@ T["DeepSeek adapter"]["Streaming"]["can handle reasoning content when streaming"
212224 end
213225 end
214226 end
227+ h .expect_starts_with (" We need to explain Ruby in two words." , output .reasoning .content )
228+ end
215229
216- h .expect_starts_with (" Okay, the user wants me to explain Ruby in two words. " , output .reasoning .content )
230+ T [" DeepSeek adapter" ][" Streaming" ][" can output streamed data without reasoning" ] = function ()
231+ local lines = vim .fn .readfile (" tests/adapters/http/stubs/deepseek_streaming_reasoning_disabled.txt" )
232+ local output = " "
233+ local reasoning = " "
234+ for _ , line in ipairs (lines ) do
235+ local chat_output = adapter .handlers .response .parse_chat (adapter , line )
236+ if chat_output then
237+ if chat_output .extra and adapter .handlers .response .parse_meta then
238+ chat_output = adapter .handlers .response .parse_meta (adapter , chat_output )
239+ end
240+ if chat_output .output .content then
241+ output = output .. chat_output .output .content
242+ end
243+ if chat_output .output .reasoning and chat_output .output .reasoning .content then
244+ reasoning = reasoning .. chat_output .output .reasoning .content
245+ end
246+ end
247+ end
248+ h .eq (" Elegant syntax." , output )
249+ h .eq (" " , reasoning ) -- No reasoning content when thinking is disabled
217250end
218251
219252T [" DeepSeek adapter" ][" Streaming" ][" can process tools" ] = function ()
220253 local tools = {}
221254 local lines = vim .fn .readfile (" tests/adapters/http/stubs/deepseek_tools_streaming.txt" )
222255 for _ , line in ipairs (lines ) do
223- adapter .handlers .chat_output (adapter , line , tools )
256+ adapter .handlers .response . parse_chat (adapter , line , tools )
224257 end
225258
226259 local tool_output = {
227260 {
228261 _index = 0 ,
229262 [" function" ] = {
230- arguments = ' {"location": "London", "units": "celsius"}' ,
263+ arguments = ' {"location": "London, UK ", "units": "celsius"}' ,
231264 name = " weather" ,
232265 },
233- id = " call_0_bb2a2194-a723-44a6-a1f8-bd05e9829eea " ,
266+ id = " call_00_xzVVyar4M7TXmqAvwt5lz3v2 " ,
234267 type = " function" ,
235268 },
236269 {
237270 _index = 1 ,
238271 [" function" ] = {
239- arguments = ' {"location": "Paris", "units": "celsius"}' ,
272+ arguments = ' {"location": "Paris, France ", "units": "celsius"}' ,
240273 name = " weather" ,
241274 },
242- id = " call_1_a460d461-60a7-468c-a699-ef9e2dced125" ,
275+ id = " call_01_FiLq2fgCjbR43jdNrxI4OYGD" ,
276+ type = " function" ,
277+ },
278+ }
279+
280+ h .eq (tool_output , tools )
281+ end
282+
283+ T [" DeepSeek adapter" ][" Streaming" ][" can process tools without params" ] = function ()
284+ local tools = {}
285+ local lines = vim .fn .readfile (" tests/adapters/http/stubs/deepseek_tools_no_params_streaming.txt" )
286+ for _ , line in ipairs (lines ) do
287+ adapter .handlers .response .parse_chat (adapter , line , tools )
288+ end
289+
290+ local tool_output = {
291+ {
292+ _index = 0 ,
293+ [" function" ] = {
294+ arguments = " {}" ,
295+ name = " weather_with_default" ,
296+ },
297+ id = " call_00_YOblREljHrrLmGtaHE72LNh3" ,
298+ type = " function" ,
299+ },
300+ {
301+ _index = 1 ,
302+ [" function" ] = {
303+ arguments = ' {"location": "Paris, France", "units": "celsius"}' ,
304+ name = " weather_with_default" ,
305+ },
306+ id = " call_01_bKIQfFOpGabMlK7midnRZaBQ" ,
243307 type = " function" ,
244308 },
245309 }
@@ -265,7 +329,7 @@ T["DeepSeek adapter"]["No Streaming"]["can output for the chat buffer"] = functi
265329 local data = vim .fn .readfile (" tests/adapters/http/stubs/deepseek_no_streaming.txt" )
266330 data = table.concat (data , " \n " )
267331
268- h .eq (" Elegant simplicity. " , adapter .handlers .chat_output (adapter , data ).output .content )
332+ h .eq (" ** Elegant syntax.** " , adapter .handlers .response . parse_chat (adapter , data ).output .content )
269333end
270334
271335T [" DeepSeek adapter" ][" No Streaming" ][" can process tools" ] = function ()
@@ -276,7 +340,7 @@ T["DeepSeek adapter"]["No Streaming"]["can process tools"] = function()
276340
277341 -- Match the format of the actual request
278342 local json = { body = data }
279- adapter .handlers .chat_output (adapter , json , tools )
343+ adapter .handlers .response . parse_chat (adapter , json , tools )
280344
281345 local tool_output = {
282346 {
@@ -309,7 +373,7 @@ T["DeepSeek adapter"]["No Streaming"]["can output for the inline assistant"] = f
309373 -- Match the format of the actual request
310374 local json = { body = data }
311375
312- h .eq (" Elegant simplicity. " , adapter .handlers .inline_output (adapter , json ).output )
376+ h .eq (" ** Elegant syntax.** " , adapter .handlers .response . parse_inline (adapter , json ).output )
313377end
314378
315379return T
0 commit comments