[Bugfix] Access get_vocab instead of vocab in tool parsers (#9188)

This commit is contained in:
Cyrus Leung
2024-10-09 08:59:57 -06:00
committed by GitHub
parent 21906a6f50
commit cfaa6008e6
3 changed files with 11 additions and 6 deletions
@@ -1,6 +1,7 @@
import importlib
import importlib.util
import os
from functools import cached_property
from typing import Callable, Dict, List, Optional, Sequence, Type, Union
from vllm.entrypoints.openai.protocol import (ChatCompletionRequest,
@@ -29,6 +30,12 @@ class ToolParser:
self.model_tokenizer = tokenizer
@cached_property
def vocab(self) -> Dict[str, int]:
# NOTE: Only PreTrainedTokenizerFast is guaranteed to have .vocab
# whereas all tokenizers have .get_vocab()
return self.model_tokenizer.get_vocab()
def adjust_request(
self, request: ChatCompletionRequest) -> ChatCompletionRequest:
"""