mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Propagate safety buffering learn-more link
This commit is contained in:
@@ -2591,6 +2591,12 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"learnMoreLink": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"model": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
+6
@@ -12648,6 +12648,12 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"learnMoreLink": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"model": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
+6
@@ -9052,6 +9052,12 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"learnMoreLink": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"model": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
+6
@@ -7,6 +7,12 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"learnMoreLink": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"model": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
Generated
+1
-1
@@ -2,4 +2,4 @@
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type ModelSafetyBufferingUpdatedNotification = { threadId: string, turnId: string, model: string, useCases: Array<string>, reasons: Array<string>, showBufferingUi: boolean, fasterModel: string | null, };
|
||||
export type ModelSafetyBufferingUpdatedNotification = { threadId: string, turnId: string, model: string, useCases: Array<string>, reasons: Array<string>, showBufferingUi: boolean, fasterModel: string | null, learnMoreLink: string | null, };
|
||||
|
||||
@@ -3397,6 +3397,7 @@ mod tests {
|
||||
reasons: vec!["user_risk".to_string()],
|
||||
show_buffering_ui: true,
|
||||
faster_model: Some("faster-model".to_string()),
|
||||
learn_more_link: Some("https://example.com/safety".to_string()),
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -3409,7 +3410,8 @@ mod tests {
|
||||
"useCases": ["cyber"],
|
||||
"reasons": ["user_risk"],
|
||||
"showBufferingUi": true,
|
||||
"fasterModel": "faster-model"
|
||||
"fasterModel": "faster-model",
|
||||
"learnMoreLink": "https://example.com/safety"
|
||||
}
|
||||
}),
|
||||
serde_json::to_value(¬ification)?,
|
||||
|
||||
@@ -174,4 +174,5 @@ pub struct ModelSafetyBufferingUpdatedNotification {
|
||||
pub reasons: Vec<String>,
|
||||
pub show_buffering_ui: bool,
|
||||
pub faster_model: Option<String>,
|
||||
pub learn_more_link: Option<String>,
|
||||
}
|
||||
|
||||
@@ -361,6 +361,7 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
reasons: event.reasons,
|
||||
show_buffering_ui: event.show_buffering_ui,
|
||||
faster_model: event.faster_model,
|
||||
learn_more_link: event.learn_more_link,
|
||||
};
|
||||
outgoing
|
||||
.send_server_notification(ServerNotification::ModelSafetyBufferingUpdated(
|
||||
|
||||
@@ -123,12 +123,15 @@ pub struct SafetyBuffering {
|
||||
pub show_buffering_ui: bool,
|
||||
#[serde(skip)]
|
||||
pub faster_model: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub learn_more_link: Option<String>,
|
||||
}
|
||||
|
||||
impl SafetyBuffering {
|
||||
pub(crate) fn with_treatment(mut self, treatment: &SafetyBufferingTreatment) -> Self {
|
||||
self.show_buffering_ui = treatment.show_buffering_ui;
|
||||
self.faster_model.clone_from(&treatment.faster_model);
|
||||
self.learn_more_link.clone_from(&treatment.learn_more_link);
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -137,6 +140,7 @@ impl SafetyBuffering {
|
||||
pub(crate) struct SafetyBufferingTreatment {
|
||||
pub show_buffering_ui: bool,
|
||||
pub faster_model: Option<String>,
|
||||
pub learn_more_link: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Clone, PartialEq)]
|
||||
|
||||
@@ -4,24 +4,26 @@ use http::HeaderMap;
|
||||
pub(crate) const X_CODEX_SAFETY_BUFFERING_ENABLED_HEADER: &str = "x-codex-safety-buffering-enabled";
|
||||
pub(crate) const X_CODEX_SAFETY_BUFFERING_FASTER_MODEL_HEADER: &str =
|
||||
"x-codex-safety-buffering-faster-model";
|
||||
pub(crate) const X_CODEX_SAFETY_BUFFERING_LEARN_MORE_LINK_HEADER: &str =
|
||||
"x-codex-safety-buffering-learn-more-link";
|
||||
|
||||
pub(crate) fn treatment_from_headers(headers: &HeaderMap) -> Option<SafetyBufferingTreatment> {
|
||||
let show_buffering_ui = headers
|
||||
.get(X_CODEX_SAFETY_BUFFERING_ENABLED_HEADER)
|
||||
.and_then(|value| value.to_str().ok())?
|
||||
.eq_ignore_ascii_case("true");
|
||||
let faster_model = if show_buffering_ui {
|
||||
headers
|
||||
.get(X_CODEX_SAFETY_BUFFERING_FASTER_MODEL_HEADER)
|
||||
let treatment_value = |header| {
|
||||
show_buffering_ui
|
||||
.then(|| headers.get(header))
|
||||
.flatten()
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.map(str::to_string)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Some(SafetyBufferingTreatment {
|
||||
show_buffering_ui,
|
||||
faster_model,
|
||||
faster_model: treatment_value(X_CODEX_SAFETY_BUFFERING_FASTER_MODEL_HEADER),
|
||||
learn_more_link: treatment_value(X_CODEX_SAFETY_BUFFERING_LEARN_MORE_LINK_HEADER),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -42,12 +44,17 @@ mod tests {
|
||||
X_CODEX_SAFETY_BUFFERING_FASTER_MODEL_HEADER,
|
||||
HeaderValue::from_static("faster-model"),
|
||||
);
|
||||
headers.insert(
|
||||
X_CODEX_SAFETY_BUFFERING_LEARN_MORE_LINK_HEADER,
|
||||
HeaderValue::from_static("https://example.com/safety"),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
treatment_from_headers(&headers),
|
||||
Some(SafetyBufferingTreatment {
|
||||
show_buffering_ui: true,
|
||||
faster_model: Some("faster-model".to_string()),
|
||||
learn_more_link: Some("https://example.com/safety".to_string()),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2237,6 +2237,7 @@ async fn try_run_sampling_request(
|
||||
reasons: buffering.reasons,
|
||||
show_buffering_ui: buffering.show_buffering_ui,
|
||||
faster_model: buffering.faster_model,
|
||||
learn_more_link: buffering.learn_more_link,
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -17,6 +17,7 @@ use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
|
||||
const FASTER_MODEL: &str = "faster-model";
|
||||
const LEARN_MORE_LINK: &str = "https://example.com/safety";
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn emits_safety_buffering_with_the_requested_model() -> anyhow::Result<()> {
|
||||
@@ -32,7 +33,8 @@ async fn emits_safety_buffering_with_the_requested_model() -> anyhow::Result<()>
|
||||
&server,
|
||||
sse_response(sse(vec![created, ev_completed("resp-1")]))
|
||||
.insert_header("x-codex-safety-buffering-enabled", "true")
|
||||
.insert_header("x-codex-safety-buffering-faster-model", FASTER_MODEL),
|
||||
.insert_header("x-codex-safety-buffering-faster-model", FASTER_MODEL)
|
||||
.insert_header("x-codex-safety-buffering-learn-more-link", LEARN_MORE_LINK),
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -63,6 +65,7 @@ async fn emits_safety_buffering_with_the_requested_model() -> anyhow::Result<()>
|
||||
reasons: vec!["policy-check".to_string()],
|
||||
show_buffering_ui: true,
|
||||
faster_model: Some(FASTER_MODEL.to_string()),
|
||||
learn_more_link: Some(LEARN_MORE_LINK.to_string()),
|
||||
}
|
||||
);
|
||||
wait_for_event(&test.codex, |event| {
|
||||
|
||||
@@ -1955,6 +1955,7 @@ pub struct SafetyBufferingEvent {
|
||||
pub reasons: Vec<String>,
|
||||
pub show_buffering_ui: bool,
|
||||
pub faster_model: Option<String>,
|
||||
pub learn_more_link: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
|
||||
|
||||
Reference in New Issue
Block a user