{%- if not add_generation_prompt is defined -%}
{%- set add_generation_prompt = false -%}
{%- endif -%}
{%- if messages[0]['role'] == 'system' -%}
{%- set loop_messages = messages[1:] -%}
{%- set system_message = messages[0]['content'] -%}
{%- else -%}
{%- set loop_messages = messages -%}
{%- set system_message = 'You are a helpful assistant.' -%}
{%- endif -%}
{{ '<|im_start|>' + 'system' + '\n' + system_message + '<|im_end|>' + '\n' }}
{%- for message in loop_messages -%}
{{ '<|im_start|>' + message['role'] + '\n' + message['content']}}
{%- if (loop.last and add_generation_prompt) or not loop.last -%}
{{ '<|im_end|>' + '\n' }}
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt and messages[-1]['role'] != 'assistant' -%}
{{ '<|im_start|>' + 'assistant' + '\n' }}
{%- endif -%}
When I make a request using the React template for tool invocation, I encounter an error at the end of the response phase. The error occurs at line 959 in vllm.engine.llm_engine.py.
if not sampling_params.include_stop_str_in_output and stop_string:
The error is caused by the stop_string "\bObserv" here, which leads to the following error message.
error msg
Traceback (most recent call last):
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in call
return await self.app(scope, receive, send)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in call
await super().call(scope, receive, send)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/applications.py", line 123, in call
await self.middleware_stack(scope, receive, send)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in call
raise exc
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in call
await self.app(scope, receive, _send)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 758, in call
await self.middleware_stack(scope, receive, send)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 778, in app
await route.handle(scope, receive, send)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 299, in handle
await self.app(scope, receive, send)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 79, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 74, in app
response = await func(request)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/fastapi/routing.py", line 278, in app
raw_response = await run_endpoint_function(
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
return await dependant.call(**values)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/imitater/service/chat.py", line 97, in create_chat_completion
return await _create_local_chat_completion(request, model)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/imitater/service/chat.py", line 61, in _create_local_chat_completion
result, prompt_tokens, completion_tokens = await model.function_call(**input_kwargs)
File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/imitater/model/chat_model.py", line 218, in function_call
if generated_text.endswith(stop_token):
TypeError: endswith first arg must be str or a tuple of str, not bytes
My code:
async def _generate(self, messages: List[Dict[str, str]], request_id: str, **gen_kwargs):
input_ids = self._tokenizer.apply_chat_template(
conversation=messages, tokenize=True, add_generation_prompt=True
)
sampling_params = SamplingParams(
temperature=gen_kwargs.pop("temperature", None) or self._generation_config.temperature,
top_p=gen_kwargs.pop("top_p", None) or self._generation_config.top_p,
max_tokens=gen_kwargs.pop("max_tokens", None) or self._generation_config.max_new_tokens,
stop_token_ids=self._generation_config.eos_token_id + gen_kwargs.pop("stop_token_ids", []),
)
result_generator = self._engine.generate(
prompt=None, sampling_params=sampling_params, request_id=request_id, prompt_token_ids=input_ids
)
return result_generator
......other code
final_result = None
generator = await self._generate(messages, request_id, **gen_kwargs)
async for result in generator:
print(result.outputs[0].text)
final_result = result
Your current environment
🐛 Describe the bug
The model I am using is Qwen-7B-Chat, and the configuration file is as follows:
The Jinja template is as follows:
When I make a request using the React template for tool invocation, I encounter an error at the end of the response phase. The error occurs at line 959 in vllm.engine.llm_engine.py.
The error is caused by the stop_string "\bObserv" here, which leads to the following error message.
error msg
Traceback (most recent call last): File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi result = await app( # type: ignore[func-returns-value] File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in call return await self.app(scope, receive, send) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in call await super().call(scope, receive, send) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/applications.py", line 123, in call await self.middleware_stack(scope, receive, send) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in call raise exc File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in call await self.app(scope, receive, _send) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in call await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 758, in call await self.middleware_stack(scope, receive, send) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 778, in app await route.handle(scope, receive, send) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 299, in handle await self.app(scope, receive, send) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 79, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/starlette/routing.py", line 74, in app response = await func(request) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/fastapi/routing.py", line 278, in app raw_response = await run_endpoint_function( File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/imitater/service/chat.py", line 97, in create_chat_completion return await _create_local_chat_completion(request, model) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/imitater/service/chat.py", line 61, in _create_local_chat_completion result, prompt_tokens, completion_tokens = await model.function_call(**input_kwargs) File "/opt/anaconda3/envs/chat2bi/lib/python3.10/site-packages/imitater/model/chat_model.py", line 218, in function_call if generated_text.endswith(stop_token): TypeError: endswith first arg must be str or a tuple of str, not bytesMy code: