Skip to content

[fix]pydantic to dict when build prompt #967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lightllm/server/api_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ async def chat_completions_impl(request: ChatCompletionRequest, raw_request: Req
"Unrecognized image input. Supports local path, http url, base64, and PIL.Image."
)

message.content = "\n".join(texts)

tools = None
if request.tools and request.tool_choice != "none":
# request.skip_special_tokens = False
Expand Down
3 changes: 2 additions & 1 deletion lightllm/server/build_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def init_tokenizer(args):

async def build_prompt(request, tools) -> str:
global tokenizer
messages = request.messages
# pydantic格式转成dict, 否则,当根据tokenizer_config.json拼template时,Jinja判断无法识别
messages = [m.model_dump(by_alias=True, exclude_none=True) for m in request.messages]
Comment on lines +13 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's good to see a comment explaining the reason for the conversion to a dictionary. However, consider adding a more specific comment indicating which part of the tokenizer_config.json is affected by this conversion. This will help future developers understand the context better.

Suggested change
# pydantic格式转成dict, 否则,当根据tokenizer_config.json拼template时,Jinja判断无法识别
messages = [m.model_dump(by_alias=True, exclude_none=True) for m in request.messages]
# pydantic格式转成dict, 否则,当根据tokenizer_config.json拼template时,Jinja判断无法识别, 尤其是tools参数

kwargs = {"conversation": messages}
if request.character_settings:
kwargs["character_settings"] = request.character_settings
Expand Down