|
6 | 6 | import time
|
7 | 7 | from collections.abc import AsyncGenerator, AsyncIterator
|
8 | 8 | from http import HTTPStatus
|
9 |
| -from typing import Callable, Final, Optional, Union |
| 9 | +from typing import Final, Optional, Union |
10 | 10 |
|
11 | 11 | import jinja2
|
12 | 12 | from fastapi import Request
|
| 13 | +from openai.types.chat import (ChatCompletionAssistantMessageParam, |
| 14 | + ChatCompletionMessageToolCallParam, |
| 15 | + ChatCompletionToolMessageParam) |
| 16 | +from openai.types.chat.chat_completion_message_tool_call_param import ( |
| 17 | + Function as FunctionCallTool) |
13 | 18 | from openai.types.responses import (ResponseFunctionToolCall,
|
14 | 19 | ResponseOutputMessage, ResponseOutputText,
|
15 | 20 | ToolChoiceFunction)
|
|
32 | 37 | # yapf: enable
|
33 | 38 | from vllm.entrypoints.openai.serving_engine import OpenAIServing
|
34 | 39 | from vllm.entrypoints.openai.serving_models import OpenAIServingModels
|
35 |
| -from vllm.entrypoints.openai.tool_parsers import ToolParser, ToolParserManager |
36 | 40 | from vllm.logger import init_logger
|
37 | 41 | from vllm.outputs import RequestOutput
|
38 |
| -from vllm.reasoning import ReasoningParser, ReasoningParserManager |
39 | 42 | from vllm.sampling_params import SamplingParams
|
40 | 43 | from vllm.transformers_utils.tokenizer import AnyTokenizer
|
41 | 44 | from vllm.utils import random_fc_uuid, random_uuid
|
@@ -73,30 +76,14 @@ def __init__(
|
73 | 76 | self.enable_auto_tools = enable_auto_tools
|
74 | 77 | self.expand_tools_even_if_tool_choice_none = (
|
75 | 78 | expand_tools_even_if_tool_choice_none)
|
76 |
| - self.tool_parser: Optional[Callable[[AnyTokenizer], ToolParser]] = None |
77 |
| - if self.enable_auto_tools: |
78 |
| - try: |
79 |
| - self.tool_parser = ToolParserManager.get_tool_parser( |
80 |
| - tool_parser) |
81 |
| - except Exception as e: |
82 |
| - raise TypeError("Error: --enable-auto-tool-choice requires " |
83 |
| - f"tool_parser:'{tool_parser}' which has not " |
84 |
| - "been registered") from e |
85 | 79 | self.chat_template = chat_template
|
86 | 80 | self.chat_template_content_format: Final = chat_template_content_format
|
87 | 81 |
|
88 |
| - self.reasoning_parser: Optional[Callable[[AnyTokenizer], |
89 |
| - ReasoningParser]] = None |
90 |
| - if reasoning_parser: |
91 |
| - try: |
92 |
| - self.reasoning_parser = ( |
93 |
| - ReasoningParserManager.get_reasoning_parser( |
94 |
| - reasoning_parser)) |
95 |
| - assert self.reasoning_parser is not None |
96 |
| - except Exception as e: |
97 |
| - raise TypeError( |
98 |
| - f"{reasoning_parser=} has not been registered") from e |
| 82 | + self.reasoning_parser = self._get_reasoning_parser( |
| 83 | + reasoning_parser_name=reasoning_parser) |
99 | 84 |
|
| 85 | + self.tool_parser = self._get_tool_parser( |
| 86 | + tool_parser_name=tool_parser, enable_auto_tools=enable_auto_tools) |
100 | 87 | self.enable_prompt_tokens_details = enable_prompt_tokens_details
|
101 | 88 | self.enable_force_include_usage = enable_force_include_usage
|
102 | 89 | self.default_sampling_params = (
|
@@ -481,25 +468,28 @@ def _construct_input_messages(
|
481 | 468 | for item in request.input:
|
482 | 469 | if item.get("type") == "function_call":
|
483 | 470 | # Append the function call as a tool call.
|
484 |
| - messages.append({ |
485 |
| - "role": |
486 |
| - "assistant", |
487 |
| - "tool_calls": [{ |
488 |
| - "id": item.get("call_id"), |
489 |
| - "function": { |
490 |
| - "name": item.get("name"), |
491 |
| - "arguments": item.get("arguments", "{}"), |
492 |
| - }, |
493 |
| - "type": "function", |
494 |
| - }] |
495 |
| - }) |
| 471 | + messages.append( |
| 472 | + ChatCompletionAssistantMessageParam( |
| 473 | + role="assistant", |
| 474 | + tool_calls=[ |
| 475 | + ChatCompletionMessageToolCallParam( |
| 476 | + id=item.get("call_id"), |
| 477 | + function=FunctionCallTool( |
| 478 | + name=item.get("name"), |
| 479 | + arguments=item.get("arguments", "{}"), |
| 480 | + ), |
| 481 | + type="function", |
| 482 | + ) |
| 483 | + ], |
| 484 | + )) |
496 | 485 | elif item.get("type") == "function_call_output":
|
497 | 486 | # Append the function call output as a tool message.
|
498 |
| - messages.append({ |
499 |
| - "role": "tool", |
500 |
| - "content": item.get("output", ""), |
501 |
| - "tool_call_id": item.get("call_id"), |
502 |
| - }) |
| 487 | + messages.append( |
| 488 | + ChatCompletionToolMessageParam( |
| 489 | + role="tool", |
| 490 | + content=item.get("output", ""), |
| 491 | + tool_call_id=item.get("call_id"), |
| 492 | + )) |
503 | 493 | else:
|
504 | 494 | messages.append(item) # type: ignore
|
505 | 495 | return messages
|
|
0 commit comments