|
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
|
@@ -72,30 +75,14 @@ def __init__(
|
72 | 75 | self.enable_auto_tools = enable_auto_tools
|
73 | 76 | self.expand_tools_even_if_tool_choice_none = (
|
74 | 77 | expand_tools_even_if_tool_choice_none)
|
75 |
| - self.tool_parser: Optional[Callable[[AnyTokenizer], ToolParser]] = None |
76 |
| - if self.enable_auto_tools: |
77 |
| - try: |
78 |
| - self.tool_parser = ToolParserManager.get_tool_parser( |
79 |
| - tool_parser) |
80 |
| - except Exception as e: |
81 |
| - raise TypeError("Error: --enable-auto-tool-choice requires " |
82 |
| - f"tool_parser:'{tool_parser}' which has not " |
83 |
| - "been registered") from e |
84 | 78 | self.chat_template = chat_template
|
85 | 79 | self.chat_template_content_format: Final = chat_template_content_format
|
86 | 80 |
|
87 |
| - self.reasoning_parser: Optional[Callable[[AnyTokenizer], |
88 |
| - ReasoningParser]] = None |
89 |
| - if reasoning_parser: |
90 |
| - try: |
91 |
| - self.reasoning_parser = ( |
92 |
| - ReasoningParserManager.get_reasoning_parser( |
93 |
| - reasoning_parser)) |
94 |
| - assert self.reasoning_parser is not None |
95 |
| - except Exception as e: |
96 |
| - raise TypeError( |
97 |
| - f"{reasoning_parser=} has not been registered") from e |
| 81 | + self.reasoning_parser = self._get_reasoning_parser( |
| 82 | + reasoning_parser_name=reasoning_parser) |
98 | 83 |
|
| 84 | + self.tool_parser = self._get_tool_parser( |
| 85 | + tool_parser_name=tool_parser, enable_auto_tools=enable_auto_tools) |
99 | 86 | self.enable_prompt_tokens_details = enable_prompt_tokens_details
|
100 | 87 | self.enable_force_include_usage = enable_force_include_usage
|
101 | 88 | self.default_sampling_params = (
|
@@ -480,25 +467,28 @@ def _construct_input_messages(
|
480 | 467 | for item in request.input:
|
481 | 468 | if item.get("type") == "function_call":
|
482 | 469 | # Append the function call as a tool call.
|
483 |
| - messages.append({ |
484 |
| - "role": |
485 |
| - "assistant", |
486 |
| - "tool_calls": [{ |
487 |
| - "id": item.get("call_id"), |
488 |
| - "function": { |
489 |
| - "name": item.get("name"), |
490 |
| - "arguments": item.get("arguments", "{}"), |
491 |
| - }, |
492 |
| - "type": "function", |
493 |
| - }] |
494 |
| - }) |
| 470 | + messages.append( |
| 471 | + ChatCompletionAssistantMessageParam( |
| 472 | + role="assistant", |
| 473 | + tool_calls=[ |
| 474 | + ChatCompletionMessageToolCallParam( |
| 475 | + id=item.get("call_id"), |
| 476 | + function=FunctionCallTool( |
| 477 | + name=item.get("name"), |
| 478 | + arguments=item.get("arguments", "{}"), |
| 479 | + ), |
| 480 | + type="function", |
| 481 | + ) |
| 482 | + ], |
| 483 | + )) |
495 | 484 | elif item.get("type") == "function_call_output":
|
496 | 485 | # Append the function call output as a tool message.
|
497 |
| - messages.append({ |
498 |
| - "role": "tool", |
499 |
| - "content": item.get("output", ""), |
500 |
| - "tool_call_id": item.get("call_id"), |
501 |
| - }) |
| 486 | + messages.append( |
| 487 | + ChatCompletionToolMessageParam( |
| 488 | + role="tool", |
| 489 | + content=item.get("output", ""), |
| 490 | + tool_call_id=item.get("call_id"), |
| 491 | + )) |
502 | 492 | else:
|
503 | 493 | messages.append(item) # type: ignore
|
504 | 494 | return messages
|
|
0 commit comments