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
fdf59d30
"docs/vscode:/vscode.git/clone" did not exist on "071d863e208b40fa1bb986ad230e322b2bbbbcf5"
Unverified
Commit
fdf59d30
authored
Oct 06, 2024
by
Yanyi Liu
Committed by
GitHub
Oct 06, 2024
Browse files
[Bugfix] fix tool_parser error handling when serve a model not support it (#8709)
parent
b22b7984
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
10 deletions
+31
-10
vllm/entrypoints/openai/serving_chat.py
vllm/entrypoints/openai/serving_chat.py
+21
-5
vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
+4
-4
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
+6
-1
No files found.
vllm/entrypoints/openai/serving_chat.py
View file @
fdf59d30
...
...
@@ -302,10 +302,6 @@ class OpenAIServingChat(OpenAIServing):
finish_reason_sent
=
[
False
]
*
num_choices
num_prompt_tokens
=
0
tool_parsers
:
List
[
Optional
[
ToolParser
]]
=
[
self
.
tool_parser
(
tokenizer
)
if
self
.
tool_parser
else
None
]
*
num_choices
if
isinstance
(
request
.
tool_choice
,
ChatCompletionNamedToolChoiceParam
):
tool_choice_function_name
=
request
.
tool_choice
.
function
.
name
else
:
...
...
@@ -324,6 +320,21 @@ class OpenAIServingChat(OpenAIServing):
else
:
previous_texts
,
all_previous_token_ids
=
None
,
None
# Prepare the tool parser if it's needed
try
:
if
tool_choice_auto
and
self
.
tool_parser
:
tool_parsers
:
List
[
Optional
[
ToolParser
]]
=
[
self
.
tool_parser
(
tokenizer
)
]
*
num_choices
else
:
tool_parsers
=
[
None
]
*
num_choices
except
RuntimeError
as
e
:
logger
.
error
(
"Error in tool parser creation: %s"
,
e
)
data
=
self
.
create_streaming_error_response
(
str
(
e
))
yield
f
"data:
{
data
}
\n\n
"
yield
"data: [DONE]
\n\n
"
return
try
:
async
for
res
in
result_generator
:
if
res
.
prompt_token_ids
is
not
None
:
...
...
@@ -704,7 +715,12 @@ class OpenAIServingChat(OpenAIServing):
or
request
.
tool_choice
is
None
)
and
self
.
enable_auto_tools
\
and
self
.
tool_parser
:
tool_parser
=
self
.
tool_parser
(
tokenizer
)
try
:
tool_parser
=
self
.
tool_parser
(
tokenizer
)
except
RuntimeError
as
e
:
logger
.
error
(
"Error in tool parser creation: %s"
,
e
)
return
self
.
create_error_response
(
str
(
e
))
tool_call_info
=
tool_parser
.
extract_tool_calls
(
output
.
text
,
request
=
request
)
tools_called
=
tool_call_info
.
tools_called
...
...
vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
View file @
fdf59d30
...
...
@@ -50,10 +50,10 @@ class Hermes2ProToolParser(ToolParser):
raise
ValueError
(
"The model tokenizer must be passed to the ToolParser "
"constructor during construction."
)
self
.
tool_call_start_token_id
:
int
=
self
.
model_tokenizer
.
vocab
[
self
.
tool_call_start_token
]
self
.
tool_call_end_token_id
:
int
=
self
.
model_tokenizer
.
vocab
[
self
.
tool_call_end_token
]
self
.
tool_call_start_token_id
:
int
=
self
.
model_tokenizer
.
vocab
.
get
(
self
.
tool_call_start_token
,
None
)
self
.
tool_call_end_token_id
:
int
=
self
.
model_tokenizer
.
vocab
.
get
(
self
.
tool_call_end_token
,
None
)
if
not
self
.
tool_call_start_token_id
or
not
self
.
tool_call_end_token_id
:
raise
RuntimeError
(
"Hermes 2 Pro Tool parser could not locate tool call start/end "
...
...
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
View file @
fdf59d30
...
...
@@ -61,8 +61,13 @@ class MistralToolParser(ToolParser):
self
.
streamed_args_for_tool
:
List
[
str
]
=
[
]
# map what has been streamed for each tool so far to a list
self
.
bot_token
=
"[TOOL_CALLS]"
self
.
bot_token_id
=
self
.
model_tokenizer
.
get_vocab
()[
self
.
bot_token
]
self
.
bot_token_id
=
self
.
model_tokenizer
.
get_vocab
().
get
(
self
.
bot_token
,
None
)
self
.
tool_call_regex
=
re
.
compile
(
r
"\[{.*?}\]"
,
re
.
DOTALL
)
if
not
self
.
bot_token_id
:
raise
RuntimeError
(
"Mistral Tool Parser could not locate the tool call token in "
"the tokenizer!"
)
def
extract_tool_calls
(
self
,
...
...
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