feat(anthropic): update model params + better max_token handling #151
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Updates model
const
s to link to latest models (didn't exist prior). Also adds a function to calculate a default max token size based on the model name when not provided.Rant
Anthropic unfortuntely has two annoying thorns:
Anthropic docs about models only lists the "latest" snapshots for each of the available models. They also only recently added the
-latest
as an override over the specific snapshot number, though only for the top models. This means that the constants can't reliably keep a history of all of the available snapshots available, even though the docs recommend using snapshots for stability purposes.-latest
for testing but leverage a specific snapshot for a model for stability purposes in production.Anthropic endpoints for
messages
requires amax_tokens
argument to be specified, which is unlike other providers. This is even more frustrating since, thismax_tokens
argument that needs to be specified has a different cap per model being used (and specifying too high of a number causes the request to fail).max_tokens
is a non-starter since users using specific snapshot models (as the docs recommend) wouldn't match.4096
would cut off half of the available token space for the most common models.max_tokens
argument to be specified at compile time (onAgentBuilder
and manually when creatingCompletionRequestBuilder
s) is also tough because it would require some really ugly refactoring to enforce that these builders can only build specifically for Anthropic clients (basically a customAnthropicAgentBuilder
and aAnthropicCompletionRequestBuilder
).The solution to the last thorn is to match the beginning of the model string to the model names and hardcode a default value for token size based on that. The user can override this by specifying
max_tokens
onAgentBuilder
, etc. This would error onagent.completion
if a default max token cannot be determined, most likely due to an invalid anthropic model (which probably doesn't exist).There might be a better solution, but I deemed this "good enough" after going in circles a bit.