@@ -158,6 +158,14 @@ D.prepare_payload = function(messages, model, provider)
158158 temperature = model .temperature and math.max (0 , math.min (2 , model .temperature )) or nil ,
159159 top_p = model .top_p and math.max (0 , math.min (1 , model .top_p )) or nil ,
160160 }
161+
162+ if model .thinking_budget ~= nil then
163+ payload .thinking = {
164+ type = " enabled" ,
165+ budget_tokens = model .thinking_budget
166+ }
167+ end
168+
161169 return payload
162170 end
163171
@@ -230,6 +238,7 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
230238
231239 local out_reader = function ()
232240 local buffer = " "
241+ local anthropic_thinking = false -- local state for Anthropic thinking blocks
233242
234243 --- @param lines_chunk string
235244 local function process_lines (lines_chunk )
@@ -252,14 +261,24 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
252261 end
253262 end
254263
255- if qt .provider == " anthropic" and line :match (' "text":' ) then
264+ if qt .provider == " anthropic" and ( line :match (' "text":' ) or line : match ( ' "thinking" ' ) ) then
256265 if line :match (" content_block_start" ) or line :match (" content_block_delta" ) then
257266 line = vim .json .decode (line )
258- if line .delta and line .delta .text then
259- content = line .delta .text
267+ if line .content_block then
268+ if line .content_block .type == " thinking" then
269+ anthropic_thinking = true
270+ content = " <think>"
271+ elseif line .content_block .type == " text" and anthropic_thinking then
272+ anthropic_thinking = false
273+ content = " </think>\n\n "
274+ end
260275 end
261- if line .content_block and line .content_block .text then
262- content = line .content_block .text
276+ if line .delta then
277+ if line .delta .type == " thinking_delta" then
278+ content = line .delta .thinking or " "
279+ elseif line .delta .type == " text_delta" then
280+ content = line .delta .text or " "
281+ end
263282 end
264283 end
265284 end
@@ -382,8 +401,6 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
382401 " x-api-key: " .. bearer ,
383402 " -H" ,
384403 " anthropic-version: 2023-06-01" ,
385- " -H" ,
386- " anthropic-beta: messages-2023-12-15" ,
387404 }
388405 elseif provider == " azure" then
389406 headers = {
0 commit comments