lmdeploy icon indicating copy to clipboard operation
lmdeploy copied to clipboard

[Bug] 启用 --tool-call-parser qwen3 ,使用 claude code 报告错误 KeyError: 'content'

Open KevinLiuMY opened this issue 3 months ago • 1 comments

Checklist

  • [x] 1. I have searched related issues but cannot get the expected help.
  • [x] 2. The bug has not been fixed in the latest version.
  • [x] 3. Please note that if the bug-related issue you submitted lacks corresponding environment info and a minimal reproducible demo, it will be challenging for us to reproduce and resolve the issue, reducing the likelihood of receiving feedback.

Describe the bug

当启用 --tool-call-parser qwen3 并使用 qwen3 32b 模型时, 使用 claude code 发送含有 tool call 的请求, 报告错误 KeyError: 'content'

Reproduction

claude code

Environment

lmdeploy check_env
sys.platform: linux
Python: 3.11.11 (main, Dec 11 2024, 16:28:39) [GCC 11.2.0]
CUDA available: True
MUSA available: False
numpy_random_seed: 2147483648
GPU 0,1,2,3: Tesla T10
CUDA_HOME: /usr/local/cuda-12.4
NVCC: Cuda compilation tools, release 12.4, V12.4.131
GCC: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0
PyTorch: 2.6.0+cu124
PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201703
  - Intel(R) oneAPI Math Kernel Library Version 2024.2-Product Build 20240605 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v3.5.3 (Git Hash 66f0cb9eb66affd2da3bf5f8d897376f04aae6af)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 12.4
  - NVCC architecture flags: -gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_90,code=sm_90
  - CuDNN 90.1
  - Magma 2.6.1
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, COMMIT_SHA=2236df1770800ffea5697b11b0bb0d910b2e59e1, CUDA_VERSION=12.4, CUDNN_VERSION=9.1.0, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=0 -fabi-version=11 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DLIBKINETO_NOXPUPTI=ON -DUSE_FBGEMM -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wsuggest-override -Wno-psabi -Wno-error=old-style-cast -Wno-missing-braces -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, TORCH_VERSION=2.6.0, USE_CUDA=ON, USE_CUDNN=ON, USE_CUSPARSELT=1, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_GLOO=ON, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=1, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, USE_ROCM_KERNEL_ASSERT=OFF, 

TorchVision: 0.21.0+cu124
LMDeploy: 0.10.0+
transformers: 4.51.3
fastapi: 0.115.12
pydantic: 2.11.4
triton: 3.2.0
NVIDIA Topology: 
        GPU0    GPU1    GPU2    GPU3    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      PHB     PHB     SYS     0,2,4,6,8,10    0               N/A
GPU1    PHB      X      PHB     SYS     0,2,4,6,8,10    0               N/A
GPU2    PHB     PHB      X      SYS     0,2,4,6,8,10    0               N/A
GPU3    SYS     SYS     SYS      X      1,3,5,7,9,11    1               N/A

Legend:

  X    = Self
  SYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
  NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
  PHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
  PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
  PIX  = Connection traversing at most a single PCIe bridge
  NV#  = Connection traversing a bonded set of # NVLinks

Error traceback

ERROR:    Exception in ASGI application
  + Exception Group Traceback (most recent call last):
  |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_utils.py", line 76, in collapse_excgroups
  |     yield
  |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 263, in __call__
  |     async with anyio.create_task_group() as task_group:
  |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 772, in __aexit__
  |     raise BaseExceptionGroup(
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi
    |     result = await app(  # type: ignore[func-returns-value]
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    |     return await self.app(scope, receive, send)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    |     await super().__call__(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/applications.py", line 112, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 187, in __call__
    |     raise exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in __call__
    |     await self.app(scope, receive, _send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/base.py", line 183, in __call__
    |     raise app_exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro
    |     await self.app(scope, receive_or_disconnect, send_no_error)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
    |     await self.app(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    |     raise exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 714, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 734, in app
    |     await route.handle(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle
    |     await self.app(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 76, in app
    |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    |     raise exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 74, in app
    |     await response(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 262, in __call__
    |     with collapse_excgroups():
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/contextlib.py", line 158, in __exit__
    |     self.gen.throw(typ, value, traceback)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    |     raise exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 266, in wrap
    |     await func()
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 246, in stream_response
    |     async for chunk in self.body_iterator:
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/openai/api_server.py", line 475, in completion_stream_generator
    |     async for res in result_generator:
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 719, in generate
    |     prompt_input = await self._get_prompt_input(prompt,
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 607, in _get_prompt_input
    |     prompt = [
    |              ^
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 608, in <listcomp>
    |     msg if isinstance(msg['content'], str) else dict(role=msg['role'], content=msg['content'][0]['text'])
    |                       ~~~^^^^^^^^^^^
    | KeyError: 'content'
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/base.py", line 183, in __call__
    raise app_exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
    await self.app(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 714, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 734, in app
    await route.handle(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 74, in app
    await response(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 262, in __call__
    with collapse_excgroups():
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    raise exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 266, in wrap
    await func()
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 246, in stream_response
    async for chunk in self.body_iterator:
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/openai/api_server.py", line 475, in completion_stream_generator
    async for res in result_generator:
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 719, in generate
    prompt_input = await self._get_prompt_input(prompt,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 607, in _get_prompt_input
    prompt = [
             ^
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 608, in <listcomp>
    msg if isinstance(msg['content'], str) else dict(role=msg['role'], content=msg['content'][0]['text'])
                      ~~~^^^^^^^^^^^
KeyError: 'content'
INFO:     172.16.1.21:50904 - "POST /v1/chat/completions HTTP/1.1" 200 OK
ERROR:    Exception in ASGI application
  + Exception Group Traceback (most recent call last):
  |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_utils.py", line 76, in collapse_excgroups
  |     yield
  |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 263, in __call__
  |     async with anyio.create_task_group() as task_group:
  |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 772, in __aexit__
  |     raise BaseExceptionGroup(
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi
    |     result = await app(  # type: ignore[func-returns-value]
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    |     return await self.app(scope, receive, send)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    |     await super().__call__(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/applications.py", line 112, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 187, in __call__
    |     raise exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in __call__
    |     await self.app(scope, receive, _send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/base.py", line 183, in __call__
    |     raise app_exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro
    |     await self.app(scope, receive_or_disconnect, send_no_error)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
    |     await self.app(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    |     raise exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 714, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 734, in app
    |     await route.handle(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle
    |     await self.app(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 76, in app
    |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    |     raise exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 74, in app
    |     await response(scope, receive, send)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 262, in __call__
    |     with collapse_excgroups():
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/contextlib.py", line 158, in __exit__
    |     self.gen.throw(typ, value, traceback)
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    |     raise exc
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 266, in wrap
    |     await func()
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 246, in stream_response
    |     async for chunk in self.body_iterator:
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/openai/api_server.py", line 475, in completion_stream_generator
    |     async for res in result_generator:
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 719, in generate
    |     prompt_input = await self._get_prompt_input(prompt,
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 607, in _get_prompt_input
    |     prompt = [
    |              ^
    |   File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 608, in <listcomp>
    |     msg if isinstance(msg['content'], str) else dict(role=msg['role'], content=msg['content'][0]['text'])
    |                       ~~~^^^^^^^^^^^
    | KeyError: 'content'
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/base.py", line 183, in __call__
    raise app_exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
    await self.app(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 714, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 734, in app
    await route.handle(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/routing.py", line 74, in app
    await response(scope, receive, send)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 262, in __call__
    with collapse_excgroups():
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    raise exc
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 266, in wrap
    await func()
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/starlette/responses.py", line 246, in stream_response
    async for chunk in self.body_iterator:
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/openai/api_server.py", line 475, in completion_stream_generator
    async for res in result_generator:
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 719, in generate
    prompt_input = await self._get_prompt_input(prompt,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 607, in _get_prompt_input
    prompt = [
             ^
  File "/home/kevin/miniconda3/envs/lmdeploy_0.10/lib/python3.11/site-packages/lmdeploy/serve/async_engine.py", line 608, in <listcomp>
    msg if isinstance(msg['content'], str) else dict(role=msg['role'], content=msg['content'][0]['text'])
                      ~~~^^^^^^^^^^^
KeyError: 'content'

KevinLiuMY avatar Sep 12 '25 16:09 KevinLiuMY

@KevinLiuMY hi, could you provide your messages data to api server? It seems content is missing. You can refer to this example as well: https://lmdeploy.readthedocs.io/en/latest/llm/api_server_tools.html#qwen2-5

...
    messages.append({
        'role': 'tool',
        'name': tool_call.function.name,
        'content': tool_call_result,
        'tool_call_id': tool_call.id
    })

RunningLeon avatar Sep 16 '25 04:09 RunningLeon