use crate::proxy::service::{Service, ServiceBuilder};
pub fn service(api_key: &str, configure: impl FnOnce(ServiceBuilder) -> ServiceBuilder) -> Service {
configure(
Service::new("openai", "https://api.openai.com")
.bearer(api_key)
.strip_request_header("OpenAI-Organization")
.strip_request_header("OpenAI-Project"),
)
.build()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_openai_service_strips_caller_supplied_tenant_headers() {
let svc = service("sk-abc", |r| r);
let mut headers = vec![
("Content-Type".into(), "application/json".into()),
("OpenAI-Organization".into(), "org-evil".into()),
("openai-project".into(), "proj_evil".into()),
];
svc.apply_request_headers(&mut headers);
let names: Vec<String> = headers.iter().map(|(n, _)| n.to_lowercase()).collect();
assert_eq!(names, ["content-type", "authorization"]);
}
}