Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
cfaa6008
Unverified
Commit
cfaa6008
authored
Oct 09, 2024
by
Cyrus Leung
Committed by
GitHub
Oct 09, 2024
Browse files
[Bugfix] Access `get_vocab` instead of `vocab` in tool parsers (#9188)
parent
21906a6f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
6 deletions
+11
-6
vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
+7
-0
vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
+3
-4
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
+1
-2
No files found.
vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
View file @
cfaa6008
import
importlib
import
importlib
import
importlib.util
import
importlib.util
import
os
import
os
from
functools
import
cached_property
from
typing
import
Callable
,
Dict
,
List
,
Optional
,
Sequence
,
Type
,
Union
from
typing
import
Callable
,
Dict
,
List
,
Optional
,
Sequence
,
Type
,
Union
from
vllm.entrypoints.openai.protocol
import
(
ChatCompletionRequest
,
from
vllm.entrypoints.openai.protocol
import
(
ChatCompletionRequest
,
...
@@ -29,6 +30,12 @@ class ToolParser:
...
@@ -29,6 +30,12 @@ class ToolParser:
self
.
model_tokenizer
=
tokenizer
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
(
def
adjust_request
(
self
,
request
:
ChatCompletionRequest
)
->
ChatCompletionRequest
:
self
,
request
:
ChatCompletionRequest
)
->
ChatCompletionRequest
:
"""
"""
...
...
vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
View file @
cfaa6008
...
@@ -50,10 +50,9 @@ class Hermes2ProToolParser(ToolParser):
...
@@ -50,10 +50,9 @@ class Hermes2ProToolParser(ToolParser):
raise
ValueError
(
raise
ValueError
(
"The model tokenizer must be passed to the ToolParser "
"The model tokenizer must be passed to the ToolParser "
"constructor during construction."
)
"constructor during construction."
)
self
.
tool_call_start_token_id
:
int
=
self
.
model_tokenizer
.
vocab
.
get
(
self
.
tool_call_start_token_id
=
self
.
vocab
.
get
(
self
.
tool_call_start_token
,
None
)
self
.
tool_call_start_token
)
self
.
tool_call_end_token_id
:
int
=
self
.
model_tokenizer
.
vocab
.
get
(
self
.
tool_call_end_token_id
=
self
.
vocab
.
get
(
self
.
tool_call_end_token
)
self
.
tool_call_end_token
,
None
)
if
not
self
.
tool_call_start_token_id
or
not
self
.
tool_call_end_token_id
:
if
not
self
.
tool_call_start_token_id
or
not
self
.
tool_call_end_token_id
:
raise
RuntimeError
(
raise
RuntimeError
(
"Hermes 2 Pro Tool parser could not locate tool call start/end "
"Hermes 2 Pro Tool parser could not locate tool call start/end "
...
...
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
View file @
cfaa6008
...
@@ -61,8 +61,7 @@ class MistralToolParser(ToolParser):
...
@@ -61,8 +61,7 @@ class MistralToolParser(ToolParser):
self
.
streamed_args_for_tool
:
List
[
str
]
=
[
self
.
streamed_args_for_tool
:
List
[
str
]
=
[
]
# map what has been streamed for each tool so far to a list
]
# map what has been streamed for each tool so far to a list
self
.
bot_token
=
"[TOOL_CALLS]"
self
.
bot_token
=
"[TOOL_CALLS]"
self
.
bot_token_id
=
self
.
model_tokenizer
.
get_vocab
().
get
(
self
.
bot_token_id
=
self
.
vocab
.
get
(
self
.
bot_token
)
self
.
bot_token
,
None
)
self
.
tool_call_regex
=
re
.
compile
(
r
"\[{.*?}\]"
,
re
.
DOTALL
)
self
.
tool_call_regex
=
re
.
compile
(
r
"\[{.*?}\]"
,
re
.
DOTALL
)
if
not
self
.
bot_token_id
:
if
not
self
.
bot_token_id
:
raise
RuntimeError
(
raise
RuntimeError
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment