|
28 | 28 | from vllm.entrypoints.openai.serving_engine import OpenAIServing |
29 | 29 | from vllm.entrypoints.openai.serving_models import OpenAIServingModels |
30 | 30 | from vllm.entrypoints.openai.tool_parsers import ToolParser, ToolParserManager |
| 31 | +from vllm.entrypoints.openai.tool_parsers.mistral_tool_parser import ( |
| 32 | + MistralToolCall) |
31 | 33 | from vllm.logger import init_logger |
32 | 34 | from vllm.outputs import CompletionOutput, RequestOutput |
33 | 35 | from vllm.sampling_params import BeamSearchParams, SamplingParams |
34 | 36 | from vllm.sequence import Logprob |
35 | 37 | from vllm.transformers_utils.tokenizer import AnyTokenizer, MistralTokenizer |
36 | | -from vllm.transformers_utils.tokenizers import maybe_serialize_tool_calls |
| 38 | +from vllm.transformers_utils.tokenizers import (maybe_serialize_tool_calls, |
| 39 | + truncate_tool_call_ids) |
37 | 40 |
|
38 | 41 | logger = init_logger(__name__) |
39 | 42 |
|
@@ -150,11 +153,12 @@ async def create_chat_completion( |
150 | 153 | return self.create_error_response( |
151 | 154 | "tool_choice = \"required\" is not supported!") |
152 | 155 |
|
153 | | - # because of issues with pydantic we need to potentially |
154 | | - # re-serialize the tool_calls field of the request |
155 | | - # for more info: see comment in `maybe_serialize_tool_calls` |
156 | 156 | if isinstance(tokenizer, MistralTokenizer): |
| 157 | + # because of issues with pydantic we need to potentially |
| 158 | + # re-serialize the tool_calls field of the request |
| 159 | + # for more info: see comment in `maybe_serialize_tool_calls` |
157 | 160 | maybe_serialize_tool_calls(request) |
| 161 | + truncate_tool_call_ids(request) |
158 | 162 |
|
159 | 163 | if (request.tool_choice == "auto" and |
160 | 164 | not (self.enable_auto_tools and tool_parser is not None) |
@@ -745,11 +749,13 @@ async def chat_completion_full_generator( |
745 | 749 | elif request.tool_choice and type( |
746 | 750 | request.tool_choice) is ChatCompletionNamedToolChoiceParam: |
747 | 751 |
|
| 752 | + tool_call_class = MistralToolCall if isinstance( |
| 753 | + tokenizer, MistralTokenizer) else ToolCall |
748 | 754 | message = ChatMessage( |
749 | 755 | role=role, |
750 | 756 | content="", |
751 | 757 | tool_calls=[ |
752 | | - ToolCall(function=FunctionCall( |
| 758 | + tool_call_class(function=FunctionCall( |
753 | 759 | name=request.tool_choice.function.name, |
754 | 760 | arguments=output.text)) |
755 | 761 | ]) |
|
0 commit comments