Skip to content

Commit

Permalink
feat: anthropic provider can take options.headers
Browse files Browse the repository at this point in the history
Lets us set the beta 8k output token header as an option
`anthropic-beta: "max-tokens-3-5-sonnet-2024-07-15"`
  • Loading branch information
gsuuon committed Aug 9, 2024
1 parent 42b0908 commit e2cfccb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lua/model/providers/anthropic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ local sse = require('model.util.sse')

---@type Provider
local M = {
request_completion = function(handler, params)
request_completion = function(handler, params, options)
options = options or {}

return sse.curl_client({
url = 'https://api.anthropic.com/v1/messages',
headers = {
headers = vim.tbl_extend('force', {
['Content-Type'] = 'application/json',
['x-api-key'] = util.env('ANTHROPIC_API_KEY'),
['anthropic-beta'] = 'messages-2023-12-15',
['anthropic-version'] = '2023-06-01',
},
}, options.headers or {}),
body = vim.tbl_deep_extend('force', {
max_tokens = 1024, -- required field
}, params, { stream = true }),
Expand All @@ -24,7 +26,9 @@ local M = {
elseif msg.event == 'content_block_delta' then
handler.on_partial(data.delta.text)
elseif msg.event == 'message_delta' then
-- util.show(data.usage.output_tokens)
util.show(data.usage.output_tokens, 'output tokens')
-- else
-- util.show(msg, 'msg')
end
end,
on_error = handler.on_error,
Expand Down

0 comments on commit e2cfccb

Please sign in to comment.