@@ -158,6 +158,14 @@ D.prepare_payload = function(messages, model, provider)
158
158
temperature = model .temperature and math.max (0 , math.min (2 , model .temperature )) or nil ,
159
159
top_p = model .top_p and math.max (0 , math.min (1 , model .top_p )) or nil ,
160
160
}
161
+
162
+ if model .thinking_budget ~= nil then
163
+ payload .thinking = {
164
+ type = " enabled" ,
165
+ budget_tokens = model .thinking_budget
166
+ }
167
+ end
168
+
161
169
return payload
162
170
end
163
171
@@ -230,6 +238,7 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
230
238
231
239
local out_reader = function ()
232
240
local buffer = " "
241
+ local anthropic_thinking = false -- local state for Anthropic thinking blocks
233
242
234
243
--- @param lines_chunk string
235
244
local function process_lines (lines_chunk )
@@ -252,14 +261,24 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
252
261
end
253
262
end
254
263
255
- if qt .provider == " anthropic" and line :match (' "text":' ) then
264
+ if qt .provider == " anthropic" and ( line :match (' "text":' ) or line : match ( ' "thinking" ' ) ) then
256
265
if line :match (" content_block_start" ) or line :match (" content_block_delta" ) then
257
266
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
260
275
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
263
282
end
264
283
end
265
284
end
@@ -382,8 +401,6 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
382
401
" x-api-key: " .. bearer ,
383
402
" -H" ,
384
403
" anthropic-version: 2023-06-01" ,
385
- " -H" ,
386
- " anthropic-beta: messages-2023-12-15" ,
387
404
}
388
405
elseif provider == " azure" then
389
406
headers = {
0 commit comments