mirror of
https://github.com/katanemo/plano.git
synced 2026-05-18 13:45:15 +02:00
feat: add http_headers support to LlmProvider for custom upstream headers (fixes #592)
Allows users to specify custom HTTP request headers per LLM provider in
plano_config.yaml, useful for providers requiring non-standard auth or
telemetry headers:
model_providers:
- model: provider/model
access_key: $API_KEY
http_headers:
X-Custom-Header: "custom-value"
X-API-Version: "v1"
This commit is contained in:
parent
aa16a6dc4b
commit
b85fab8696
4 changed files with 22 additions and 0 deletions
|
|
@ -445,6 +445,7 @@ pub struct LlmProvider {
|
|||
pub base_url_path_prefix: Option<String>,
|
||||
pub internal: Option<bool>,
|
||||
pub passthrough_auth: Option<bool>,
|
||||
pub http_headers: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
pub trait IntoModels {
|
||||
|
|
@ -488,6 +489,7 @@ impl Default for LlmProvider {
|
|||
base_url_path_prefix: None,
|
||||
internal: None,
|
||||
passthrough_auth: None,
|
||||
http_headers: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -277,6 +277,7 @@ mod tests {
|
|||
internal: None,
|
||||
stream: None,
|
||||
passthrough_auth: None,
|
||||
http_headers: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -232,6 +232,14 @@ impl StreamContext {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn set_custom_provider_headers(&mut self) {
|
||||
if let Some(http_headers) = self.llm_provider().http_headers.clone() {
|
||||
for (key, value) in &http_headers {
|
||||
self.set_http_request_header(key.as_str(), Some(value.as_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn delete_content_length_header(&mut self) {
|
||||
// Remove the Content-Length header because further body manipulations in the gateway logic will invalidate it.
|
||||
// Server's generally throw away requests whose body length do not match the Content-Length header.
|
||||
|
|
@ -879,6 +887,7 @@ impl HttpContext for StreamContext {
|
|||
self.send_server_error(error, Some(StatusCode::BAD_REQUEST));
|
||||
}
|
||||
}
|
||||
self.set_custom_provider_headers();
|
||||
}
|
||||
|
||||
self.delete_content_length_header();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue