1.问题描述
在运行FastChat
api服务时遇到了如下报错:
2024-06-24 04:23:34 | ERROR | stderr | +-+---------------- 1 ----------------
2024-06-24 04:23:34 | ERROR | stderr | | Traceback (most recent call last):
2024-06-24 04:23:34 | ERROR | stderr | | File "/usr/local/lib/python3.9/site-packages/starlette/responses.py", line 261, in wrap
2024-06-24 04:23:34 | ERROR | stderr | | await func()
2024-06-24 04:23:34 | ERROR | stderr | | File "/usr/local/lib/python3.9/site-packages/starlette/responses.py", line 250, in stream_response
2024-06-24 04:23:34 | ERROR | stderr | | async for chunk in self.body_iterator:
2024-06-24 04:23:34 | ERROR | stderr | | File "/root/FastChat/fastchat/serve/openai_api_server.py", line 517, in chat_completion_stream_generator
2024-06-24 04:23:34 | ERROR | stderr | | yield f"data: {chunk.json(exclude_unset=True, ensure_ascii=False)}\n\n"
2024-06-24 04:23:34 | ERROR | stderr | | File "/usr/local/lib/python3.9/site-packages/pydantic/main.py", line 1102, in json
2024-06-24 04:23:34 | ERROR | stderr | | raise TypeError('`dumps_kwargs` keyword arguments are no longer supported.')
2024-06-24 04:23:34 | ERROR | stderr | | TypeError: `dumps_kwargs` keyword arguments are no longer supported.
2024-06-24 04:23:34 | ERROR | stderr | +-----------------------------------
2.问题分析及解决
Pydantic 库从版本 1.8.0 开始不再支持 dumps_kwargs 关键字参数。
解决方法1
将chunk.json(exclude_unset=True, ensure_ascii=False)
更改为以下内容:
json.dumps(chunk.dict(exclude_unset=True), ensure_ascii=False)
解决方法2
回滚到之前版本
pip install pydantic==1.10.13