mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(rust): simplify provider debug request inputs
Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>
This commit is contained in:
parent
95d594a0fe
commit
78ec7a6ba3
3 changed files with 25 additions and 44 deletions
|
|
@ -21,8 +21,6 @@ pub enum LogEvent {
|
|||
}
|
||||
|
||||
pub struct RequestEventInput {
|
||||
pub call_id: String,
|
||||
pub provider: String,
|
||||
pub model: String,
|
||||
pub stream: bool,
|
||||
pub url: String,
|
||||
|
|
@ -114,12 +112,16 @@ pub struct ProviderErrorEvent {
|
|||
pub body: Option<Value>,
|
||||
}
|
||||
|
||||
pub(crate) fn request_event(input: RequestEventInput) -> LogEvent {
|
||||
pub(crate) fn request_event(
|
||||
call_id: String,
|
||||
provider: String,
|
||||
input: RequestEventInput,
|
||||
) -> LogEvent {
|
||||
let snapshot = snapshot_json(input.body);
|
||||
LogEvent::Request(ProviderRequestEvent {
|
||||
source: "litellm-rust",
|
||||
call_id: input.call_id,
|
||||
provider: input.provider,
|
||||
call_id,
|
||||
provider,
|
||||
model: input.model,
|
||||
stream: input.stream,
|
||||
method: "POST",
|
||||
|
|
@ -221,15 +223,17 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn redacts_credentials_recursively() {
|
||||
let event = request_event(RequestEventInput {
|
||||
call_id: "call_01".to_string(),
|
||||
provider: "anthropic".to_string(),
|
||||
model: "claude".to_string(),
|
||||
stream: false,
|
||||
url: "https://example.test?signature=secret&x=ok".to_string(),
|
||||
headers: vec![("Authorization".to_string(), "Bearer secret".to_string())],
|
||||
body: serde_json::json!({"nested": {"token": "secret"}, "prompt": "visible"}),
|
||||
});
|
||||
let event = request_event(
|
||||
"call_01".to_string(),
|
||||
"anthropic".to_string(),
|
||||
RequestEventInput {
|
||||
model: "claude".to_string(),
|
||||
stream: false,
|
||||
url: "https://example.test?signature=secret&x=ok".to_string(),
|
||||
headers: vec![("Authorization".to_string(), "Bearer secret".to_string())],
|
||||
body: serde_json::json!({"nested": {"token": "secret"}, "prompt": "visible"}),
|
||||
},
|
||||
);
|
||||
let json = serde_json::to_string(&event).expect("serializes");
|
||||
assert!(!json.contains("secret"));
|
||||
assert!(json.contains("visible"));
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ pub async fn execute_json<T: DeserializeOwned>(
|
|||
request
|
||||
.logger
|
||||
.request_about_to_be_sent(super::RequestEventInput {
|
||||
call_id: request.logger.call_id().to_string(),
|
||||
provider: request.logger.provider().to_string(),
|
||||
model: request.model,
|
||||
stream: request.stream,
|
||||
url: request.url.clone(),
|
||||
|
|
@ -105,20 +103,9 @@ pub async fn execute_json<T: DeserializeOwned>(
|
|||
CoreError::InvalidResponse(format!("invalid provider response JSON: {error}"))
|
||||
})?;
|
||||
let typed = T::deserialize(&value);
|
||||
let response_body = if media_type
|
||||
.as_deref()
|
||||
.is_some_and(|value| value.to_ascii_lowercase().contains("json"))
|
||||
{
|
||||
ResponseBody::Json(value)
|
||||
} else {
|
||||
ResponseBody::Binary {
|
||||
media_type,
|
||||
bytes: text.len(),
|
||||
}
|
||||
};
|
||||
request
|
||||
.logger
|
||||
.response_received(status.as_u16(), headers, response_body);
|
||||
.response_received(status.as_u16(), headers, ResponseBody::Json(value));
|
||||
let typed = typed.map_err(|error| {
|
||||
request.logger.failure(
|
||||
Some(status.as_u16()),
|
||||
|
|
@ -140,8 +127,6 @@ pub async fn execute_stream(
|
|||
request
|
||||
.logger
|
||||
.request_about_to_be_sent(super::RequestEventInput {
|
||||
call_id: request.logger.call_id().to_string(),
|
||||
provider: request.logger.provider().to_string(),
|
||||
model: request.model,
|
||||
stream: true,
|
||||
url: request.url.clone(),
|
||||
|
|
|
|||
|
|
@ -35,18 +35,12 @@ impl CallLogger {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn call_id(&self) -> &str {
|
||||
&self.context.litellm_call_id
|
||||
}
|
||||
|
||||
pub(crate) fn provider(&self) -> &str {
|
||||
&self.context.custom_llm_provider
|
||||
}
|
||||
|
||||
pub fn request_about_to_be_sent(&self, mut input: events::RequestEventInput) {
|
||||
input.call_id = self.context.litellm_call_id.clone();
|
||||
input.provider = self.context.custom_llm_provider.clone();
|
||||
self.emit(events::request_event(input));
|
||||
pub fn request_about_to_be_sent(&self, input: events::RequestEventInput) {
|
||||
self.emit(events::request_event(
|
||||
self.context.litellm_call_id.clone(),
|
||||
self.context.custom_llm_provider.clone(),
|
||||
input,
|
||||
));
|
||||
}
|
||||
|
||||
pub fn response_received(
|
||||
|
|
@ -143,8 +137,6 @@ mod tests {
|
|||
let context = CallLifecycleContext::new("messages", "claude", "anthropic", "req_123");
|
||||
let logger = CallLogger::new(&context, Some(Arc::new(sink.clone())));
|
||||
logger.request_about_to_be_sent(events::RequestEventInput {
|
||||
call_id: String::new(),
|
||||
provider: String::new(),
|
||||
model: "claude".to_string(),
|
||||
stream: false,
|
||||
url: "https://example.test/v1/messages".to_string(),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue