mirror of
https://github.com/danielmiessler/fabric.git
synced 2026-09-10 07:36:44 -04:00
Merge pull request #2161 from ksylvan/anthropic-max-tokens-fix
fix: respect Anthropic chat option max token overrides
This commit is contained in:
commit
c7f07b6f1b
11
cmd/generate_changelog/incoming/2161.txt
Normal file
11
cmd/generate_changelog/incoming/2161.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
### PR [#2161](https://github.com/danielmiessler/Fabric/pull/2161) by [ksylvan](https://github.com/ksylvan): fix: respect Anthropic chat option max token overrides
|
||||
|
||||
- Fix: respect Anthropic chat option max token overrides
|
||||
|
||||
- Use configured Anthropic max tokens as default
|
||||
- Apply chat option max tokens when provided
|
||||
|
||||
- Preserve existing behavior for missing token overrides
|
||||
- Add tests for default max token selection
|
||||
|
||||
- Add tests for explicit max token overrides
|
||||
|
|
@ -233,9 +233,14 @@ func (an *Client) SendStream(
|
|||
func (an *Client) buildMessageParams(msgs []anthropic.MessageParam, opts *domain.ChatOptions) (
|
||||
params anthropic.MessageNewParams) {
|
||||
|
||||
maxTokens := an.maxTokens
|
||||
if opts.MaxTokens > 0 {
|
||||
maxTokens = opts.MaxTokens
|
||||
}
|
||||
|
||||
params = anthropic.MessageNewParams{
|
||||
Model: anthropic.Model(opts.Model),
|
||||
MaxTokens: int64(an.maxTokens),
|
||||
MaxTokens: int64(maxTokens),
|
||||
Messages: msgs,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,6 +99,43 @@ func TestBuildMessageParams_WithoutSearch(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuildMessageParams_UsesConfiguredMaxTokensByDefault(t *testing.T) {
|
||||
client := NewClient()
|
||||
opts := &domain.ChatOptions{
|
||||
Model: "claude-3-5-sonnet-latest",
|
||||
Temperature: domain.DefaultTemperature,
|
||||
TopP: domain.DefaultTopP,
|
||||
}
|
||||
messages := []anthropic.MessageParam{
|
||||
anthropic.NewUserMessage(anthropic.NewTextBlock("Hello")),
|
||||
}
|
||||
|
||||
params := client.buildMessageParams(messages, opts)
|
||||
|
||||
if params.MaxTokens != int64(client.maxTokens) {
|
||||
t.Errorf("Expected default max_tokens %d, got %d", client.maxTokens, params.MaxTokens)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildMessageParams_UsesChatOptionsMaxTokens(t *testing.T) {
|
||||
client := NewClient()
|
||||
opts := &domain.ChatOptions{
|
||||
Model: "claude-3-5-sonnet-latest",
|
||||
Temperature: domain.DefaultTemperature,
|
||||
TopP: domain.DefaultTopP,
|
||||
MaxTokens: 8192,
|
||||
}
|
||||
messages := []anthropic.MessageParam{
|
||||
anthropic.NewUserMessage(anthropic.NewTextBlock("Hello")),
|
||||
}
|
||||
|
||||
params := client.buildMessageParams(messages, opts)
|
||||
|
||||
if params.MaxTokens != int64(opts.MaxTokens) {
|
||||
t.Errorf("Expected max_tokens %d, got %d", opts.MaxTokens, params.MaxTokens)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildMessageParams_WithSearch(t *testing.T) {
|
||||
client := NewClient()
|
||||
opts := &domain.ChatOptions{
|
||||
|
|
|
|||
Loading…
Reference in a new issue