-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore: sync main into staging #855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1440ec7
b53986f
6e12ce6
bcef04b
2016693
40664a8
aff1c1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |||||||||||
| //! | ||||||||||||
| //! Pattern follows `nearai_chat.rs`: direct HTTP calls via `reqwest::Client`. | ||||||||||||
|
|
||||||||||||
| use std::collections::HashSet; | ||||||||||||
|
|
||||||||||||
| use async_trait::async_trait; | ||||||||||||
| use reqwest::Client; | ||||||||||||
| use rust_decimal::Decimal; | ||||||||||||
|
|
@@ -35,6 +37,8 @@ pub struct AnthropicOAuthProvider { | |||||||||||
| model: String, | ||||||||||||
| base_url: Option<String>, | ||||||||||||
| active_model: std::sync::RwLock<String>, | ||||||||||||
| /// Parameter names that this provider does not support. | ||||||||||||
| unsupported_params: HashSet<String>, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| impl AnthropicOAuthProvider { | ||||||||||||
|
|
@@ -61,15 +65,45 @@ impl AnthropicOAuthProvider { | |||||||||||
| Some(config.base_url.clone()) | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| let unsupported_params: HashSet<String> = | ||||||||||||
| config.unsupported_params.iter().cloned().collect(); | ||||||||||||
|
|
||||||||||||
| Ok(Self { | ||||||||||||
| client, | ||||||||||||
| token, | ||||||||||||
| model: config.model.clone(), | ||||||||||||
| base_url, | ||||||||||||
| active_model, | ||||||||||||
| unsupported_params, | ||||||||||||
| }) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /// Strip unsupported fields from a `CompletionRequest` in place. | ||||||||||||
| fn strip_unsupported_completion_params(&self, req: &mut CompletionRequest) { | ||||||||||||
| if self.unsupported_params.is_empty() { | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
| if self.unsupported_params.contains("temperature") { | ||||||||||||
| req.temperature = None; | ||||||||||||
| } | ||||||||||||
| if self.unsupported_params.contains("max_tokens") { | ||||||||||||
| req.max_tokens = None; | ||||||||||||
| } | ||||||||||||
|
||||||||||||
| } | |
| } | |
| if self.unsupported_params.contains("stop_sequences") { | |
| req.stop_sequences = None; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functions strip_unsupported_completion_params and strip_unsupported_tool_params contain duplicated logic for stripping temperature and max_tokens. This can be refactored to improve maintainability. You could use a trait to abstract the common fields of CompletionRequest and ToolCompletionRequest, or a macro.
Here's an example using a private helper function with a trait:
trait StripUnsupported {
fn temperature_mut(&mut self) -> &mut Option<f32>;
fn max_tokens_mut(&mut self) -> &mut Option<u32>;
}
impl StripUnsupported for CompletionRequest {
fn temperature_mut(&mut self) -> &mut Option<f32> { &mut self.temperature }
fn max_tokens_mut(&mut self) -> &mut Option<u32> { &mut self.max_tokens }
}
impl StripUnsupported for ToolCompletionRequest {
fn temperature_mut(&mut self) -> &mut Option<f32> { &mut self.temperature }
fn max_tokens_mut(&mut self) -> &mut Option<u32> { &mut self.max_tokens }
}
impl AnthropicOAuthProvider {
// ...
fn strip_common_unsupported_params<T: StripUnsupported>(&self, req: &mut T) {
if self.unsupported_params.contains("temperature") {
*req.temperature_mut() = None;
}
if self.unsupported_params.contains("max_tokens") {
*req.max_tokens_mut() = None;
}
}
fn strip_unsupported_completion_params(&self, req: &mut CompletionRequest) {
if self.unsupported_params.is_empty() {
return;
}
self.strip_common_unsupported_params(req);
}
fn strip_unsupported_tool_params(&self, req: &mut ToolCompletionRequest) {
if self.unsupported_params.is_empty() {
return;
}
self.strip_common_unsupported_params(req);
}
// ...
}
<details>
<summary>References</summary>
1. When an issue is found in duplicated code, prefer refactoring into a shared function over applying localized fixes.
</details>| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -87,6 +87,10 @@ pub struct RegistryProviderConfig { | |||||||||||
| pub oauth_token: Option<SecretString>, | ||||||||||||
| /// Prompt cache retention (Anthropic-specific). | ||||||||||||
| pub cache_retention: CacheRetention, | ||||||||||||
| /// Parameter names that this provider does not support (e.g., `["temperature"]`). | ||||||||||||
| /// Supported keys: `"temperature"`, `"max_tokens"`, `"stop_sequences"`. | ||||||||||||
| /// Listed parameters are stripped from requests before sending to avoid 400 errors. | ||||||||||||
|
Comment on lines
+91
to
+92
|
||||||||||||
| /// Supported keys: `"temperature"`, `"max_tokens"`, `"stop_sequences"`. | |
| /// Listed parameters are stripped from requests before sending to avoid 400 errors. | |
| /// Recognized keys (currently): `"temperature"`, `"max_tokens"`, `"stop_sequences"`. | |
| /// Recognized parameters are stripped from requests before sending to avoid 400 errors; | |
| /// unrecognized entries are ignored. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -152,6 +152,11 @@ pub struct ProviderDefinition { | |||||
| /// Setup wizard hints. | ||||||
| #[serde(default)] | ||||||
| pub setup: Option<SetupHint>, | ||||||
| /// Parameter names that this provider does not support (e.g., `["temperature"]`). | ||||||
| /// Supported keys: `"temperature"`, `"max_tokens"`, `"stop_sequences"`. | ||||||
|
||||||
| /// Supported keys: `"temperature"`, `"max_tokens"`, `"stop_sequences"`. | |
| /// Recognized keys include: `"temperature"`, `"max_tokens"`, `"stop_sequences"`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
openaiprovider is configured to not support thetemperatureparameter. This is incorrect, as the OpenAI Chat Completions API does supporttemperature. This change will cause thetemperatureparameter to be silently ignored for all OpenAI requests, which can lead to unexpected model behavior and removes a key feature for controlling model output. This seems like a configuration error and should be removed or set to an empty list.