Skip to content
Open
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- fix(server): show falsey defaults in CLI help by @cupkk in #2355

## [0.3.34]

- feat: update llama.cpp to ggml-org/llama.cpp@e3546c794
Expand Down
2 changes: 1 addition & 1 deletion llama_cpp/server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def add_args_from_model(parser: argparse.ArgumentParser, model: Type[BaseModel])

for name, field in model.model_fields.items():
description = field.description
if field.default and description and not field.is_required():
if description and not field.is_required() and field.default is not None:
description += f" (default: {field.default})"
base_type = (
_get_base_type(field.annotation) if field.annotation is not None else str
Expand Down
24 changes: 24 additions & 0 deletions tests/test_server_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import argparse

from pydantic import BaseModel, Field

from llama_cpp.server.cli import add_args_from_model


class ServerCliSettings(BaseModel):
enabled: bool = Field(default=False, description="Enable feature")
retries: int = Field(default=0, description="Retry count")
workers: int = Field(default=2, description="Worker count")
required_value: str = Field(description="Required value")


def test_add_args_from_model_includes_falsey_defaults_in_help():
parser = argparse.ArgumentParser()

add_args_from_model(parser, ServerCliSettings)

help_by_dest = {action.dest: action.help for action in parser._actions}
assert help_by_dest["enabled"] == "Enable feature (default: False)"
assert help_by_dest["retries"] == "Retry count (default: 0)"
assert help_by_dest["workers"] == "Worker count (default: 2)"
assert help_by_dest["required_value"] == "Required value"