Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa92cce

Browse filesBrowse files
committed
Add uvicorn.run arguments to argparse parser
1 parent dbca136 commit aa92cce
Copy full SHA for aa92cce

File tree

Expand file treeCollapse file tree

1 file changed

+29
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-4
lines changed

‎llama_cpp/server/__main__.py

Copy file name to clipboardExpand all lines: llama_cpp/server/__main__.py
+29-4Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"""
2424
import os
2525
import argparse
26+
import inspect
2627
from typing import List, Literal, Union
2728

2829
import uvicorn
@@ -91,10 +92,34 @@ def parse_bool_arg(arg):
9192
help=f"{description}",
9293
)
9394

95+
# Extract uvicorn.run function arguments to dynamically add them to argparse
96+
uvicorn_run_signature = inspect.signature(uvicorn.run)
97+
for param_name, param in uvicorn_run_signature.parameters.items():
98+
# Skip the "app" argument since it will be provided internally
99+
if param_name == "app":
100+
continue
101+
102+
# Handle special types and defaults
103+
param_type = param.annotation if param.annotation != inspect.Parameter.empty else str
104+
param_default = param.default if param.default != inspect.Parameter.empty else None
105+
106+
# Add argument to argparse
107+
parser.add_argument(
108+
f"--uvicorn-{param_name}",
109+
type=param_type,
110+
default=param_default,
111+
help=f"Uvicorn setting for {param_name} (default: {repr(param_default).replace('%', '%%')})"
112+
)
113+
94114
args = parser.parse_args()
95-
settings = Settings(**{k: v for k, v in vars(args).items() if v is not None})
115+
settings = Settings(**{k: v for k, v in vars(args).items() if v is not None and not k.startswith("uvicorn_")})
96116
app = create_app(settings=settings)
97117

98-
uvicorn.run(
99-
app, host=os.getenv("HOST", settings.host), port=int(os.getenv("PORT", settings.port))
100-
)
118+
# Separate out uvicorn arguments
119+
uvicorn_args = {k[8:]: v for k, v in vars(args).items() if k.startswith("uvicorn_") and v is not None}
120+
121+
# Merge with other environment-based settings if needed
122+
uvicorn_args['host'] = os.getenv("HOST", uvicorn_args.get('host', "127.0.0.1"))
123+
uvicorn_args['port'] = int(os.getenv("PORT", uvicorn_args.get('port', 8000)))
124+
125+
uvicorn.run(app, **uvicorn_args)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.