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:
andrea.difonzo
2026-11-11 21:27:36 +01:00
parent 1a3ab89277
commit 4da5b66563
41 changed files with 636 additions and 34 deletions

View File

@@ -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)
}