Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/openshell-router/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::RouterError;
use crate::config::{AuthHeader, ResolvedRoute};
use crate::mock;
use std::collections::HashSet;
use tracing::warn;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ValidatedEndpoint {
Expand Down Expand Up @@ -190,9 +191,22 @@ fn prepare_backend_request(

// Set the "model" field in the JSON body to the route's configured model so the
// backend receives the correct model ID regardless of what the client sent.
// When the caller supplied a non-empty model that differs from the configured
// route, emit a warning so the rewrite is visible to operators and silent
// model-typo / stale-reference bugs do not get masked by the rewrite.
let body = match serde_json::from_slice::<serde_json::Value>(&body) {
Ok(mut json) => {
if let Some(obj) = json.as_object_mut() {
if let Some(serde_json::Value::String(client_model)) = obj.get("model") {
if !client_model.is_empty() && client_model != &route.model {
warn!(
client_model = %client_model,
route_model = %route.model,
endpoint = %route.endpoint,
"router is rewriting client-supplied model to the configured route model",
);
}
}
obj.insert(
"model".to_string(),
serde_json::Value::String(route.model.clone()),
Expand Down
Loading