From 7ad6b766c589cc51f4716b1d2052d66ac1a135fb Mon Sep 17 00:00:00 2001 From: Ying Wang <83981870+ynwang007@users.noreply.github.com> Date: Thu, 24 Jul 2025 23:11:32 -0700 Subject: [PATCH] fix: Fix failed functional tests https://github.com/meta-llama/llama-stack-evals (#8266) --- .../sglang/srt/entrypoints/openai/serving_chat.py | 14 ++++++++++++++ python/sglang/srt/utils.py | 10 +++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/entrypoints/openai/serving_chat.py b/python/sglang/srt/entrypoints/openai/serving_chat.py index 9889cb2ed..ca090e060 100644 --- a/python/sglang/srt/entrypoints/openai/serving_chat.py +++ b/python/sglang/srt/entrypoints/openai/serving_chat.py @@ -55,6 +55,20 @@ class OpenAIServingChat(OpenAIServingBase): def _request_id_prefix(self) -> str: return "chatcmpl-" + def _validate_request(self, request: ChatCompletionRequest) -> Optional[str]: + """Validate that the input is valid.""" + if not request.messages: + return "Messages cannot be empty." + + if ( + isinstance(request.tool_choice, str) + and request.tool_choice.lower() == "required" + and not request.tools + ): + return "Tools cannot be empty if tool choice is set to required." + + return None + def _convert_to_internal_request( self, request: ChatCompletionRequest, diff --git a/python/sglang/srt/utils.py b/python/sglang/srt/utils.py index 23960a8c1..01e54392a 100644 --- a/python/sglang/srt/utils.py +++ b/python/sglang/srt/utils.py @@ -744,9 +744,13 @@ def load_image( image = Image.open(BytesIO(image_file)) elif image_file.startswith("http://") or image_file.startswith("https://"): timeout = int(os.getenv("REQUEST_TIMEOUT", "3")) - response = requests.get(image_file, stream=True, timeout=timeout).raw - image = Image.open(response) - response.close() + response = requests.get(image_file, stream=True, timeout=timeout) + try: + response.raise_for_status() + image = Image.open(response.raw) + image.load() # Force loading to avoid issues after closing the stream + finally: + response.close() elif image_file.lower().endswith(("png", "jpg", "jpeg", "webp", "gif")): image = Image.open(image_file) elif image_file.startswith("data:"):