fix(openrouter): do not set transforms field unconditionally (#11374)
Co-authored-by: vishal veerareddy <vishalveera.reddy@servicenow.com>
This commit is contained in:
committed by
GitHub
parent
7bdeadb916
commit
a6b03f6962
@@ -568,8 +568,11 @@ impl Provider for OpenRouterProvider {
|
||||
let sent_reasoning_disable =
|
||||
openrouter_format::apply_reasoning_config(&mut payload, model_config);
|
||||
|
||||
// `transforms` is intentionally not set: OpenRouter defaults to applying
|
||||
// `middle-out` for endpoints with <=8k context, and large-context models
|
||||
// don't benefit from it. Users who want to force a transform can opt in
|
||||
// via `OPENROUTER_PARAMETERS`.
|
||||
if let Some(obj) = payload.as_object_mut() {
|
||||
obj.insert("transforms".to_string(), json!(["middle-out"]));
|
||||
obj.insert("usage".to_string(), json!({ "include": true }));
|
||||
}
|
||||
|
||||
@@ -695,6 +698,51 @@ mod tests {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stream_does_not_set_transforms_field() {
|
||||
use wiremock::matchers::{method, path};
|
||||
use wiremock::{Mock, MockServer, ResponseTemplate};
|
||||
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/api/v1/chat/completions"))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(200)
|
||||
.insert_header("content-type", "text/event-stream")
|
||||
.set_body_string("data: [DONE]\n\n"),
|
||||
)
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
let provider = OpenRouterProvider::new(
|
||||
ApiClient::new_with_tls(
|
||||
server.uri(),
|
||||
crate::api_client::AuthMethod::BearerToken("test-key".to_string()),
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
let config = model_config("z-ai/glm-5.2");
|
||||
|
||||
let _stream = provider
|
||||
.stream(&config, "system", &[Message::user().with_text("hi")], &[])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let received = server.received_requests().await.unwrap();
|
||||
assert_eq!(received.len(), 1);
|
||||
let body: serde_json::Value = serde_json::from_slice(&received[0].body).unwrap();
|
||||
assert!(
|
||||
body.get("transforms").is_none(),
|
||||
"transforms must not be set unconditionally, got body: {}",
|
||||
body
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gemini_tool_result_schema_ref_keys_are_escaped_reversibly() {
|
||||
let mut payload = json!({
|
||||
|
||||
Reference in New Issue
Block a user