WIP v0.2.0: pannello /endpoint e nomi abbreviati dei modelli (in pausa, non compilato)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -203,6 +203,10 @@ struct ModelClientState {
|
||||
cached_websocket_session: StdMutex<WebsocketSession>,
|
||||
/// Last full tool list used for sampling, retained across turns and connection resets.
|
||||
last_inference_tools: StdMutex<Option<Arc<[ToolSpec]>>>,
|
||||
/// Per-model settings of the provider (sampling values), refreshed with the user config.
|
||||
model_settings: StdMutex<
|
||||
std::collections::BTreeMap<String, akode_model_provider_info::ProviderModelSettings>,
|
||||
>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ModelClientState {
|
||||
@@ -403,6 +407,7 @@ fn responses_request_properties_mismatch(
|
||||
prompt_cache_options: previous_prompt_cache_options,
|
||||
text: previous_text,
|
||||
client_metadata: _,
|
||||
sampling: previous_sampling,
|
||||
} = previous;
|
||||
let ResponsesApiRequest {
|
||||
model: current_model,
|
||||
@@ -420,12 +425,15 @@ fn responses_request_properties_mismatch(
|
||||
prompt_cache_options: current_prompt_cache_options,
|
||||
text: current_text,
|
||||
client_metadata: _,
|
||||
sampling: current_sampling,
|
||||
} = current;
|
||||
|
||||
// Stream options control delivery for this response, not the context
|
||||
// referenced by `previous_response_id`.
|
||||
let reason = if previous_model != current_model {
|
||||
"model_changed"
|
||||
} else if previous_sampling != current_sampling {
|
||||
"sampling_changed"
|
||||
} else if previous_tools != current_tools {
|
||||
"tools_changed"
|
||||
} else if previous_tool_choice != current_tool_choice {
|
||||
@@ -562,6 +570,7 @@ impl ModelClient {
|
||||
let reasoning_effort_override_enabled = reasoning_effort_override_enabled
|
||||
&& !crate::guardian::is_basic_session_source(&session_source)
|
||||
&& !memory_consolidation;
|
||||
let model_settings = StdMutex::new(model_provider.info().models.clone());
|
||||
Self {
|
||||
state: Arc::new(ModelClientState {
|
||||
thread_id,
|
||||
@@ -580,6 +589,7 @@ impl ModelClient {
|
||||
disable_websockets: AtomicBool::new(false),
|
||||
cached_websocket_session: StdMutex::new(WebsocketSession::default()),
|
||||
last_inference_tools: StdMutex::new(None),
|
||||
model_settings,
|
||||
}),
|
||||
prompt_cache_key_policy: PromptCacheKey::default(),
|
||||
session_id_override: None,
|
||||
@@ -591,6 +601,35 @@ impl ModelClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Replace the per-model settings used for new requests (after a config reload).
|
||||
pub(crate) fn set_model_settings(
|
||||
&self,
|
||||
settings: std::collections::BTreeMap<String, akode_model_provider_info::ProviderModelSettings>,
|
||||
) {
|
||||
*self
|
||||
.state
|
||||
.model_settings
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) = settings;
|
||||
}
|
||||
|
||||
/// Sampling values configured for `model` (unset values are not sent).
|
||||
fn sampling_params(&self, model: &str) -> akode_api::SamplingParams {
|
||||
let settings = self
|
||||
.state
|
||||
.model_settings
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
settings
|
||||
.get(model)
|
||||
.map(|settings| akode_api::SamplingParams {
|
||||
temperature: settings.temperature,
|
||||
top_p: settings.top_p,
|
||||
max_output_tokens: settings.max_output_tokens,
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub(crate) fn with_executed_tool_calls(mut self, recorder: ExecutedToolCalls) -> Self {
|
||||
self.executed_tool_calls = Some(recorder);
|
||||
self
|
||||
@@ -1133,6 +1172,7 @@ impl ModelClient {
|
||||
.map(|ttl| akode_api::PromptCacheOptions { ttl }),
|
||||
text,
|
||||
client_metadata: Some(client_metadata),
|
||||
sampling: self.sampling_params(&model_info.slug),
|
||||
};
|
||||
Ok(request)
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ fn serializes_text_verbosity_when_set() {
|
||||
format: None,
|
||||
}),
|
||||
client_metadata: None,
|
||||
sampling: Default::default(),
|
||||
};
|
||||
|
||||
let v = serde_json::to_value(&req).expect("json");
|
||||
@@ -175,6 +176,7 @@ fn serializes_text_schema_with_strict_format() {
|
||||
service_tier: None,
|
||||
text: Some(text_controls),
|
||||
client_metadata: None,
|
||||
sampling: Default::default(),
|
||||
};
|
||||
|
||||
let v = serde_json::to_value(&req).expect("json");
|
||||
@@ -236,6 +238,7 @@ fn omits_text_when_not_set() {
|
||||
service_tier: None,
|
||||
text: None,
|
||||
client_metadata: None,
|
||||
sampling: Default::default(),
|
||||
};
|
||||
|
||||
let v = serde_json::to_value(&req).expect("json");
|
||||
@@ -260,6 +263,7 @@ fn serializes_flex_service_tier_when_set() {
|
||||
service_tier: Some(ServiceTier::Flex.to_string()),
|
||||
text: None,
|
||||
client_metadata: None,
|
||||
sampling: Default::default(),
|
||||
};
|
||||
|
||||
let v = serde_json::to_value(&req).expect("json");
|
||||
|
||||
@@ -58,6 +58,7 @@ fn request_with_metadata_and_source(
|
||||
prompt_cache_options: None,
|
||||
text: None,
|
||||
client_metadata: Some(HashMap::from([("padding".to_string(), "x".to_string())])),
|
||||
sampling: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1856,9 +1856,24 @@ impl Config {
|
||||
workspace_roots
|
||||
}
|
||||
|
||||
/// Per-model context windows of the active provider, keyed by model id.
|
||||
pub fn model_context_windows(&self) -> std::collections::HashMap<String, i64> {
|
||||
self.model_provider
|
||||
.models
|
||||
.iter()
|
||||
.filter_map(|(model, settings)| {
|
||||
settings
|
||||
.context_window
|
||||
.filter(|window| *window > 0)
|
||||
.map(|window| (model.clone(), window))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn to_models_manager_config(&self) -> ModelsManagerConfig {
|
||||
ModelsManagerConfig {
|
||||
model_context_window: self.model_context_window,
|
||||
model_context_windows: self.model_context_windows(),
|
||||
model_auto_compact_token_limit: self.model_auto_compact_token_limit,
|
||||
tool_output_token_limit: self.tool_output_token_limit,
|
||||
base_instructions: self.base_instructions.clone().filter(|_| {
|
||||
@@ -4593,6 +4608,12 @@ impl Config {
|
||||
)
|
||||
.map_err(std::io::Error::from)?;
|
||||
let otel = otel::resolve_config(cfg.otel.unwrap_or_default());
|
||||
// A reasoning effort configured for the selected model wins over the global one.
|
||||
let model_reasoning_effort = model
|
||||
.as_deref()
|
||||
.and_then(|model| model_provider.model_settings(model))
|
||||
.and_then(|settings| settings.reasoning_effort.clone())
|
||||
.or(cfg.model_reasoning_effort);
|
||||
let mut config = Self {
|
||||
plugins: cfg.plugins,
|
||||
prefer_mxc,
|
||||
@@ -4749,7 +4770,7 @@ impl Config {
|
||||
.as_ref()
|
||||
.and_then(|auto_review| auto_review.circuit_break_action)
|
||||
.unwrap_or_default(),
|
||||
model_reasoning_effort: cfg.model_reasoning_effort,
|
||||
model_reasoning_effort,
|
||||
plan_mode_reasoning_effort: cfg.plan_mode_reasoning_effort,
|
||||
model_reasoning_summary: cfg.model_reasoning_summary,
|
||||
model_catalog,
|
||||
|
||||
@@ -76,6 +76,17 @@ impl Session {
|
||||
{
|
||||
warn!("failed to refresh critical path timing config: {err}");
|
||||
}
|
||||
// Per-model settings of the active provider apply to new turns without a restart.
|
||||
let refresh_model_settings = !matches!(scope, RuntimeConfigRefresh::Mcp);
|
||||
if refresh_model_settings
|
||||
&& let Some(next) = next_config.model_providers.get(&config.model_provider_id)
|
||||
{
|
||||
let models = next.models.clone();
|
||||
if let Some(provider) = config.model_providers.get_mut(&config.model_provider_id) {
|
||||
provider.models = models.clone();
|
||||
}
|
||||
config.model_provider.models = models;
|
||||
}
|
||||
let config = Arc::new(config);
|
||||
let notify_contributors = !matches!(scope, RuntimeConfigRefresh::Mcp)
|
||||
&& !self.services.extensions.config_contributors().is_empty();
|
||||
@@ -108,6 +119,13 @@ impl Session {
|
||||
let previous_config = notify_contributors
|
||||
.then(|| self.build_effective_session_config(&state.session_configuration));
|
||||
state.session_configuration.original_config_do_not_use = Arc::clone(&config);
|
||||
if refresh_model_settings {
|
||||
state.session_configuration.model_info_overrides.context_windows =
|
||||
config.model_context_windows();
|
||||
self.services
|
||||
.model_client
|
||||
.set_model_settings(config.model_provider.models.clone());
|
||||
}
|
||||
if matches!(scope, RuntimeConfigRefresh::Mcp) {
|
||||
self.services.mcp_runtime.invalidate_resource_caches();
|
||||
}
|
||||
|
||||
@@ -176,6 +176,8 @@ impl ResolvedStepSettings {
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub(crate) struct ModelInfoOverrides {
|
||||
pub(crate) context_window: Option<i64>,
|
||||
/// Per-model context windows of the active provider; refreshed with the user config.
|
||||
pub(crate) context_windows: std::collections::HashMap<String, i64>,
|
||||
pub(crate) auto_compact_token_limit: Option<i64>,
|
||||
pub(crate) tool_output_token_limit: Option<usize>,
|
||||
pub(crate) base_instructions: Option<String>,
|
||||
@@ -185,6 +187,7 @@ impl From<ModelsManagerConfig> for ModelInfoOverrides {
|
||||
fn from(config: ModelsManagerConfig) -> Self {
|
||||
Self {
|
||||
context_window: config.model_context_window,
|
||||
context_windows: config.model_context_windows,
|
||||
auto_compact_token_limit: config.model_auto_compact_token_limit,
|
||||
tool_output_token_limit: config.tool_output_token_limit,
|
||||
base_instructions: config.base_instructions,
|
||||
@@ -199,6 +202,7 @@ impl ModelInfoOverrides {
|
||||
) -> ModelsManagerConfig {
|
||||
ModelsManagerConfig {
|
||||
model_context_window: self.context_window,
|
||||
model_context_windows: self.context_windows.clone(),
|
||||
model_auto_compact_token_limit: self.auto_compact_token_limit,
|
||||
tool_output_token_limit: self.tool_output_token_limit,
|
||||
base_instructions: self.base_instructions.clone(),
|
||||
|
||||
@@ -96,6 +96,7 @@ async fn responses_stream_includes_subagent_header_on_review() {
|
||||
merge_system_messages: None,
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
};
|
||||
|
||||
let codex_home = TempDir::new().expect("failed to create TempDir");
|
||||
@@ -241,6 +242,7 @@ async fn responses_stream_includes_subagent_header_on_other() {
|
||||
merge_system_messages: None,
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
};
|
||||
|
||||
let codex_home = TempDir::new().expect("failed to create TempDir");
|
||||
@@ -367,6 +369,7 @@ async fn responses_respects_model_info_overrides_from_config() {
|
||||
merge_system_messages: None,
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
};
|
||||
|
||||
let codex_home = TempDir::new().expect("failed to create TempDir");
|
||||
|
||||
@@ -1693,6 +1693,7 @@ async fn send_provider_auth_request(server: &MockServer, auth: ModelProviderAuth
|
||||
merge_system_messages: None,
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
};
|
||||
|
||||
send_request_with_provider(provider).await;
|
||||
@@ -2927,6 +2928,7 @@ async fn azure_responses_request_does_not_store_and_preserves_prefixed_item_ids(
|
||||
merge_system_messages: Some(false),
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
};
|
||||
|
||||
let codex_home = TempDir::new().unwrap();
|
||||
@@ -3773,6 +3775,7 @@ async fn azure_overrides_assign_properties_used_for_responses_url() {
|
||||
merge_system_messages: None,
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
};
|
||||
|
||||
// Init session
|
||||
@@ -3863,6 +3866,7 @@ async fn env_var_overrides_loaded_auth() {
|
||||
merge_system_messages: None,
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
};
|
||||
|
||||
// Init session
|
||||
|
||||
@@ -2803,6 +2803,7 @@ fn websocket_provider_with_connect_timeout(
|
||||
merge_system_messages: Some(false),
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ async fn continue_after_stream_error() {
|
||||
merge_system_messages: None,
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
};
|
||||
|
||||
let TestCodex { codex, .. } = test_codex()
|
||||
|
||||
@@ -74,6 +74,7 @@ async fn retries_on_early_close() {
|
||||
merge_system_messages: None,
|
||||
keyring_account: None,
|
||||
include_internal_metadata: false,
|
||||
models: Default::default(),
|
||||
};
|
||||
|
||||
let TestCodex { codex, .. } = test_codex()
|
||||
|
||||
Reference in New Issue
Block a user