diff --git a/crates/brightstaff/src/handlers/function_calling.rs b/crates/brightstaff/src/handlers/function_calling.rs index 14260d44..8f641df6 100644 --- a/crates/brightstaff/src/handlers/function_calling.rs +++ b/crates/brightstaff/src/handlers/function_calling.rs @@ -1081,7 +1081,7 @@ impl ArchFunctionHandler { let model_message = if response_dict .response .as_ref() - .map_or(false, |s| !s.is_empty()) + .is_some_and(|s| !s.is_empty()) { // When arch-fc returns a "response" field, it means no intent was matched // Return empty content and empty tool_calls so prompt_gateway routes to default target @@ -1735,7 +1735,7 @@ impl HallucinationState { if self.state.as_deref() == Some("function_name") { if !FUNC_NAME_END_TOKEN .iter() - .any(|&t| self.tokens.last().map_or(false, |tok| tok == t)) + .any(|&t| self.tokens.last().is_some_and(|tok| tok == t)) { self.mask.push(MaskToken::FunctionName); } else { diff --git a/crates/brightstaff/src/handlers/llm.rs b/crates/brightstaff/src/handlers/llm.rs index 93094370..53dde66d 100644 --- a/crates/brightstaff/src/handlers/llm.rs +++ b/crates/brightstaff/src/handlers/llm.rs @@ -123,8 +123,8 @@ pub async fn llm_chat( // Do this BEFORE routing since routing consumes the request // Only process state if state_storage is configured let mut should_manage_state = false; - if is_responses_api_client && state_storage.is_some() { - if let ProviderRequestType::ResponsesAPIRequest(ref mut responses_req) = client_request { + if is_responses_api_client { + if let (ProviderRequestType::ResponsesAPIRequest(ref mut responses_req), Some(ref state_store)) = (&mut client_request, &state_storage) { // Extract original input once original_input_items = extract_input_items(&responses_req.input); @@ -150,7 +150,7 @@ pub async fn llm_chat( // Retrieve and combine conversation history if previous_response_id exists if let Some(ref prev_resp_id) = responses_req.previous_response_id { match retrieve_and_combine_input( - state_storage.as_ref().unwrap().clone(), + state_store.clone(), prev_resp_id, original_input_items, // Pass ownership instead of cloning ) @@ -293,7 +293,7 @@ pub async fn llm_chat( // === v1/responses state management: Wrap with ResponsesStateProcessor === // Only wrap if we need to manage state (client is ResponsesAPI AND upstream is NOT ResponsesAPI AND state_storage is configured) let streaming_response = - if should_manage_state && !original_input_items.is_empty() && state_storage.is_some() { + if let (true, false, Some(state_store)) = (should_manage_state, original_input_items.is_empty(), state_storage) { // Extract Content-Encoding header to handle decompression for state parsing let content_encoding = response_headers .get("content-encoding") @@ -303,7 +303,7 @@ pub async fn llm_chat( // Wrap with state management processor to store state after response completes let state_processor = ResponsesStateProcessor::new( base_processor, - state_storage.unwrap(), + state_store, original_input_items, resolved_model.clone(), model_name.clone(), diff --git a/crates/brightstaff/src/handlers/response_handler.rs b/crates/brightstaff/src/handlers/response_handler.rs index b91c7297..26d1efd8 100644 --- a/crates/brightstaff/src/handlers/response_handler.rs +++ b/crates/brightstaff/src/handlers/response_handler.rs @@ -133,7 +133,7 @@ impl ResponseHandler { let response_headers = llm_response.headers(); let is_sse_streaming = response_headers .get(hyper::header::CONTENT_TYPE) - .map_or(false, |v| { + .is_some_and(|v| { v.to_str().unwrap_or("").contains("text/event-stream") }); diff --git a/crates/brightstaff/src/tracing/constants.rs b/crates/brightstaff/src/tracing/constants.rs index 1edc4d3d..aac48802 100644 --- a/crates/brightstaff/src/tracing/constants.rs +++ b/crates/brightstaff/src/tracing/constants.rs @@ -2,11 +2,9 @@ /// /// This module defines standard attribute keys following OTEL semantic conventions. /// See: https://opentelemetry.io/docs/specs/semconv/ - // ============================================================================= // Span Attributes - HTTP // ============================================================================= - /// Semantic conventions for HTTP-related span attributes pub mod http { /// HTTP request method diff --git a/crates/common/src/traces/constants.rs b/crates/common/src/traces/constants.rs index 09bdecd5..9e637c57 100644 --- a/crates/common/src/traces/constants.rs +++ b/crates/common/src/traces/constants.rs @@ -1,7 +1,6 @@ /// OpenTelemetry semantic convention constants for tracing /// /// These constants ensure consistency across the codebase and prevent typos - /// Resource attribute keys following OTEL semantic conventions pub mod resource { /// Logical name of the service diff --git a/crates/hermesllm/src/apis/openai.rs b/crates/hermesllm/src/apis/openai.rs index 79d99f21..834c33ec 100644 --- a/crates/hermesllm/src/apis/openai.rs +++ b/crates/hermesllm/src/apis/openai.rs @@ -286,7 +286,6 @@ pub struct ImageUrl { } /// A single message in a chat conversation - /// A tool call made by the assistant #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct ToolCall { @@ -569,7 +568,6 @@ pub enum OpenAIError { // ============================================================================ /// Trait Implementations /// =========================================================================== - /// Parameterized conversion for ChatCompletionsRequest impl TryFrom<&[u8]> for ChatCompletionsRequest { type Error = OpenAIStreamError; diff --git a/crates/hermesllm/src/apis/streaming_shapes/amazon_bedrock_binary_frame.rs b/crates/hermesllm/src/apis/streaming_shapes/amazon_bedrock_binary_frame.rs index 7f68bb26..5156cd52 100644 --- a/crates/hermesllm/src/apis/streaming_shapes/amazon_bedrock_binary_frame.rs +++ b/crates/hermesllm/src/apis/streaming_shapes/amazon_bedrock_binary_frame.rs @@ -34,10 +34,7 @@ where } pub fn decode_frame(&mut self) -> Option { - match self.decoder.decode_frame(&mut self.buffer) { - Ok(frame) => Some(frame), - Err(_e) => None, // Fatal decode error - } + self.decoder.decode_frame(&mut self.buffer).ok() } pub fn buffer_mut(&mut self) -> &mut B { diff --git a/crates/hermesllm/src/providers/streaming_response.rs b/crates/hermesllm/src/providers/streaming_response.rs index 3b470d41..29bc739e 100644 --- a/crates/hermesllm/src/providers/streaming_response.rs +++ b/crates/hermesllm/src/providers/streaming_response.rs @@ -11,7 +11,6 @@ use crate::apis::streaming_shapes::{ anthropic_streaming_buffer::AnthropicMessagesStreamBuffer, chat_completions_streaming_buffer::OpenAIChatCompletionsStreamBuffer, passthrough_streaming_buffer::PassthroughStreamBuffer, - responses_api_streaming_buffer::ResponsesAPIStreamBuffer, }; use crate::clients::endpoints::SupportedAPIsFromClient; @@ -82,7 +81,7 @@ impl TryFrom<(&SupportedAPIsFromClient, &SupportedUpstreamAPIs)> for SseStreamBu SseStreamBuffer::AnthropicMessages(AnthropicMessagesStreamBuffer::new()), ), SupportedAPIsFromClient::OpenAIResponsesAPI(_) => Ok(SseStreamBuffer::OpenAIResponses( - Box::new(ResponsesAPIStreamBuffer::new()), + Box::default(), )), } } diff --git a/crates/prompt_gateway/src/http_context.rs b/crates/prompt_gateway/src/http_context.rs index fc66de12..4b2f2716 100644 --- a/crates/prompt_gateway/src/http_context.rs +++ b/crates/prompt_gateway/src/http_context.rs @@ -141,9 +141,7 @@ impl HttpContext for StreamContext { let last_user_prompt = match deserialized_body .messages - .iter() - .filter(|msg| msg.role == USER_ROLE) - .last() + .iter().rfind(|msg| msg.role == USER_ROLE) { Some(content) => content, None => { @@ -156,9 +154,7 @@ impl HttpContext for StreamContext { // convert prompt targets to ChatCompletionTool let tool_calls: Vec = self - .prompt_targets - .iter() - .map(|(_, pt)| pt.into()) + .prompt_targets.values().map(|pt| pt.into()) .collect(); let mut metadata = deserialized_body.metadata.clone(); diff --git a/crates/prompt_gateway/src/stream_context.rs b/crates/prompt_gateway/src/stream_context.rs index e4a0f1c2..5f464930 100644 --- a/crates/prompt_gateway/src/stream_context.rs +++ b/crates/prompt_gateway/src/stream_context.rs @@ -630,10 +630,10 @@ impl StreamContext { } }; - if system_prompt.is_some() { + if let Some(system_prompt_text) = system_prompt { let system_prompt_message = Message { role: SYSTEM_ROLE.to_string(), - content: Some(ContentType::Text(system_prompt.unwrap())), + content: Some(ContentType::Text(system_prompt_text)), model: None, tool_calls: None, tool_call_id: None,