Unverified Commit 60e37f80 authored by Lianmin Zheng's avatar Lianmin Zheng Committed by GitHub
Browse files

Move parsers under a single folder (#9912)

parent 369b1433
import re import re
from typing import Dict, Optional, Tuple, Type from typing import Dict, Optional, Tuple, Type
from sglang.srt.harmony_parser import HarmonyParser from sglang.srt.parser.harmony_parser import HarmonyParser
class StreamingParseResult: class StreamingParseResult:
......
...@@ -26,7 +26,7 @@ from typing import List, Literal, Optional, Union ...@@ -26,7 +26,7 @@ from typing import List, Literal, Optional, Union
from sglang.srt.function_call.function_call_parser import FunctionCallParser from sglang.srt.function_call.function_call_parser import FunctionCallParser
from sglang.srt.hf_transformers_utils import check_gguf_file, get_config from sglang.srt.hf_transformers_utils import check_gguf_file, get_config
from sglang.srt.lora.lora_registry import LoRARef from sglang.srt.lora.lora_registry import LoRARef
from sglang.srt.reasoning_parser import ReasoningParser from sglang.srt.parser.reasoning_parser import ReasoningParser
from sglang.srt.utils import ( from sglang.srt.utils import (
LORA_TARGET_ALL_MODULES, LORA_TARGET_ALL_MODULES,
SUPPORTED_LORA_TARGET_MODULES, SUPPORTED_LORA_TARGET_MODULES,
......
...@@ -64,7 +64,7 @@ class TestSeparateReasoningExecution(CustomTestCase): ...@@ -64,7 +64,7 @@ class TestSeparateReasoningExecution(CustomTestCase):
for ev in self.events: for ev in self.events:
ev.set() ev.set()
@patch("sglang.srt.reasoning_parser.ReasoningParser") @patch("sglang.srt.parser.reasoning_parser.ReasoningParser")
def test_execute_separate_reasoning(self, mock_parser_class): def test_execute_separate_reasoning(self, mock_parser_class):
"""Test that _execute_separate_reasoning correctly calls the ReasoningParser.""" """Test that _execute_separate_reasoning correctly calls the ReasoningParser."""
# Setup mock parser # Setup mock parser
...@@ -136,7 +136,7 @@ class TestSeparateReasoningExecution(CustomTestCase): ...@@ -136,7 +136,7 @@ class TestSeparateReasoningExecution(CustomTestCase):
# Verify that the text was updated # Verify that the text was updated
self.assertEqual(executor.text_, f"[NORMAL from deepseek-r1]: {var_value}") self.assertEqual(executor.text_, f"[NORMAL from deepseek-r1]: {var_value}")
@patch("sglang.srt.reasoning_parser.ReasoningParser") @patch("sglang.srt.parser.reasoning_parser.ReasoningParser")
def test_reasoning_parser_integration(self, mock_parser_class): def test_reasoning_parser_integration(self, mock_parser_class):
"""Test the integration between separate_reasoning and ReasoningParser.""" """Test the integration between separate_reasoning and ReasoningParser."""
# Setup mock parsers for different model types # Setup mock parsers for different model types
...@@ -167,7 +167,7 @@ class TestSeparateReasoningExecution(CustomTestCase): ...@@ -167,7 +167,7 @@ class TestSeparateReasoningExecution(CustomTestCase):
self.assertEqual(reasoning, f"[REASONING from qwen3]: {test_text}") self.assertEqual(reasoning, f"[REASONING from qwen3]: {test_text}")
self.assertEqual(normal_text, f"[NORMAL from qwen3]: {test_text}") self.assertEqual(normal_text, f"[NORMAL from qwen3]: {test_text}")
@patch("sglang.srt.reasoning_parser.ReasoningParser") @patch("sglang.srt.parser.reasoning_parser.ReasoningParser")
def test_reasoning_parser_invalid_model(self, mock_parser_class): def test_reasoning_parser_invalid_model(self, mock_parser_class):
"""Test that ReasoningParser raises an error for invalid model types.""" """Test that ReasoningParser raises an error for invalid model types."""
......
import unittest import unittest
from sglang.srt.harmony_parser import ( from sglang.srt.parser.harmony_parser import (
CanonicalStrategy, CanonicalStrategy,
Event, Event,
HarmonyParser, HarmonyParser,
......
...@@ -4,7 +4,7 @@ Unit tests for Jinja chat template utils. ...@@ -4,7 +4,7 @@ Unit tests for Jinja chat template utils.
import unittest import unittest
from sglang.srt.jinja_template_utils import ( from sglang.srt.parser.jinja_template_utils import (
detect_jinja_template_content_format, detect_jinja_template_content_format,
process_content_for_template_format, process_content_for_template_format,
) )
......
import unittest import unittest
from sglang.srt.reasoning_parser import ( from sglang.srt.parser.reasoning_parser import (
BaseReasoningFormatDetector, BaseReasoningFormatDetector,
DeepSeekR1Detector, DeepSeekR1Detector,
KimiDetector, KimiDetector,
......
...@@ -13,7 +13,6 @@ from PIL import Image ...@@ -13,7 +13,6 @@ from PIL import Image
from transformers import AutoModel, AutoProcessor, AutoTokenizer from transformers import AutoModel, AutoProcessor, AutoTokenizer
from sglang.srt.configs.model_config import ModelConfig from sglang.srt.configs.model_config import ModelConfig
from sglang.srt.conversation import generate_chat_conv
from sglang.srt.entrypoints.openai.protocol import ChatCompletionRequest from sglang.srt.entrypoints.openai.protocol import ChatCompletionRequest
from sglang.srt.managers.mm_utils import embed_mm_inputs, init_embedding_cache from sglang.srt.managers.mm_utils import embed_mm_inputs, init_embedding_cache
from sglang.srt.managers.schedule_batch import ( from sglang.srt.managers.schedule_batch import (
...@@ -23,6 +22,7 @@ from sglang.srt.managers.schedule_batch import ( ...@@ -23,6 +22,7 @@ from sglang.srt.managers.schedule_batch import (
) )
from sglang.srt.model_executor.model_runner import ModelRunner from sglang.srt.model_executor.model_runner import ModelRunner
from sglang.srt.multimodal.processors.base_processor import BaseMultimodalProcessor from sglang.srt.multimodal.processors.base_processor import BaseMultimodalProcessor
from sglang.srt.parser.conversation import generate_chat_conv
from sglang.srt.server_args import ServerArgs from sglang.srt.server_args import ServerArgs
......
...@@ -14,8 +14,8 @@ from transformers import ( ...@@ -14,8 +14,8 @@ from transformers import (
) )
from sglang import Engine from sglang import Engine
from sglang.srt.conversation import generate_chat_conv
from sglang.srt.entrypoints.openai.protocol import ChatCompletionRequest from sglang.srt.entrypoints.openai.protocol import ChatCompletionRequest
from sglang.srt.parser.conversation import generate_chat_conv
TEST_IMAGE_URL = "https://github.com/sgl-project/sglang/blob/main/test/lang/example_image.png?raw=true" TEST_IMAGE_URL = "https://github.com/sgl-project/sglang/blob/main/test/lang/example_image.png?raw=true"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment