^ anthropic - updated the default max_token to the max for given the model (i.e. 3-5 will be 8k)

This commit is contained in:
Jeremy Chone
2024-11-04 18:39:40 -08:00
parent 001b124381
commit d946290be4
4 changed files with 27 additions and 5 deletions

View File

@ -5,6 +5,13 @@
> - Version `0.2.x` will follow semver more strictly.
> - API changes will be denoted as "`!` - **API CHANGE** ...."
## 2024-11-04 - `0.1.11`
- `^` anthropic - updated the default max_token to the max for given the model (i.e. 3-5 will be 8k)
- `+` tool - First pass at adding Function Calling for OpenAI and Anthropic (rel #24)
- **NOTE**: The tool is still work in progress, but this should be a good first start.
- `.` update version to 0.1.11-WIP
## 2024-10-05 - `0.1.10`
(minor release)

View File

@ -28,5 +28,5 @@ reqwest-eventsource = "0.6"
eventsource-stream = "0.2"
bytes = "1.6"
# -- Others
derive_more = { version = "1.0.0-beta", features = ["from", "display"] }
derive_more = { version = "1.0.0", features = ["from", "display"] }
value-ext = "0.0.3" # JC Authored. Early release (API might change). Be cautious when using in other projects.

View File

@ -16,11 +16,17 @@ use value_ext::JsonValueExt;
pub struct AnthropicAdapter;
const BASE_URL: &str = "https://api.anthropic.com/v1/";
const MAX_TOKENS: u32 = 1024;
// NOTE: For Anthropic, the max_tokens must be specified.
// To avoid surprises, the default value for genai is the maximum for a given model.
// The 3-5 models have an 8k max token limit, while the 3 models have a 4k limit.
const MAX_TOKENS_8K: u32 = 8192;
const MAX_TOKENS_4K: u32 = 4096;
const ANTRHOPIC_VERSION: &str = "2023-06-01";
const MODELS: &[&str] = &[
"claude-3-5-sonnet-20241022",
"claude-3-5-sonnet-20240620",
"claude-3-5-haiku-20241022",
"claude-3-opus-20240229",
"claude-3-haiku-20240307",
];
@ -66,7 +72,7 @@ impl Adapter for AnthropicAdapter {
system,
messages,
tools,
} = Self::into_anthropic_request_parts(model_iden, chat_req)?;
} = Self::into_anthropic_request_parts(model_iden.clone(), chat_req)?;
// -- Build the basic payload
let mut payload = json!({
@ -88,7 +94,13 @@ impl Adapter for AnthropicAdapter {
payload.x_insert("temperature", temperature)?;
}
let max_tokens = options_set.max_tokens().unwrap_or(MAX_TOKENS);
let max_tokens = options_set.max_tokens().unwrap_or_else(|| {
if model_iden.model_name.contains("3-5") {
MAX_TOKENS_8K
} else {
MAX_TOKENS_4K
}
});
payload.x_insert("max_tokens", max_tokens)?; // required for Anthropic
if let Some(top_p) = options_set.top_p() {

View File

@ -5,7 +5,10 @@ use genai::resolver::AuthData;
type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>; // For tests.
// 4k
const MODEL: &str = "claude-3-haiku-20240307";
// 8k output context
// const MODEL: &str = "claude-3-5-haiku-20241022";
// region: --- Chat