forked from phoenix/litellm-mirror
[Feat Proxy] Allow using hypercorn for http v2 (#5950)
* use run_hypercorn * add docs on using hypercorn
This commit is contained in:
parent
7500855654
commit
0d0f46a826
2 changed files with 50 additions and 2 deletions
|
@ -684,7 +684,27 @@ docker run ghcr.io/berriai/litellm:main-latest \
|
||||||
|
|
||||||
Provide an ssl certificate when starting litellm proxy server
|
Provide an ssl certificate when starting litellm proxy server
|
||||||
|
|
||||||
### 3. Providing LiteLLM config.yaml file as a s3, GCS Bucket Object/url
|
### 3. Using Http/2 with Hypercorn
|
||||||
|
|
||||||
|
Use this if you want to run the proxy with hypercorn to support http/2
|
||||||
|
|
||||||
|
**Usage**
|
||||||
|
Pass the `--run_hypercorn` flag when starting the proxy
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker run \
|
||||||
|
-v $(pwd)/proxy_config.yaml:/app/config.yaml \
|
||||||
|
-p 4000:4000 \
|
||||||
|
-e LITELLM_LOG="DEBUG"\
|
||||||
|
-e SERVER_ROOT_PATH="/api/v1"\
|
||||||
|
-e DATABASE_URL=postgresql://<user>:<password>@<host>:<port>/<dbname> \
|
||||||
|
-e LITELLM_MASTER_KEY="sk-1234"\
|
||||||
|
ghcr.io/berriai/litellm:main-latest \
|
||||||
|
--config /app/config.yaml
|
||||||
|
--run_hypercorn
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Providing LiteLLM config.yaml file as a s3, GCS Bucket Object/url
|
||||||
|
|
||||||
Use this if you cannot mount a config file on your deployment service (example - AWS Fargate, Railway etc)
|
Use this if you cannot mount a config file on your deployment service (example - AWS Fargate, Railway etc)
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,12 @@ def is_port_in_use(port):
|
||||||
is_flag=True,
|
is_flag=True,
|
||||||
help="Starts proxy via gunicorn, instead of uvicorn (better for managing multiple workers)",
|
help="Starts proxy via gunicorn, instead of uvicorn (better for managing multiple workers)",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--run_hypercorn",
|
||||||
|
default=False,
|
||||||
|
is_flag=True,
|
||||||
|
help="Starts proxy via hypercorn, instead of uvicorn (supports HTTP/2)",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--ssl_keyfile_path",
|
"--ssl_keyfile_path",
|
||||||
default=None,
|
default=None,
|
||||||
|
@ -240,6 +246,7 @@ def run_server(
|
||||||
health,
|
health,
|
||||||
version,
|
version,
|
||||||
run_gunicorn,
|
run_gunicorn,
|
||||||
|
run_hypercorn,
|
||||||
ssl_keyfile_path,
|
ssl_keyfile_path,
|
||||||
ssl_certfile_path,
|
ssl_certfile_path,
|
||||||
):
|
):
|
||||||
|
@ -668,7 +675,7 @@ def run_server(
|
||||||
import litellm
|
import litellm
|
||||||
from litellm.proxy.proxy_server import app
|
from litellm.proxy.proxy_server import app
|
||||||
|
|
||||||
if run_gunicorn == False:
|
if run_gunicorn == False and run_hypercorn == False:
|
||||||
if ssl_certfile_path is not None and ssl_keyfile_path is not None:
|
if ssl_certfile_path is not None and ssl_keyfile_path is not None:
|
||||||
print( # noqa
|
print( # noqa
|
||||||
f"\033[1;32mLiteLLM Proxy: Using SSL with certfile: {ssl_certfile_path} and keyfile: {ssl_keyfile_path}\033[0m\n" # noqa
|
f"\033[1;32mLiteLLM Proxy: Using SSL with certfile: {ssl_certfile_path} and keyfile: {ssl_keyfile_path}\033[0m\n" # noqa
|
||||||
|
@ -771,6 +778,27 @@ def run_server(
|
||||||
StandaloneApplication(
|
StandaloneApplication(
|
||||||
app=app, options=gunicorn_options
|
app=app, options=gunicorn_options
|
||||||
).run() # Run gunicorn
|
).run() # Run gunicorn
|
||||||
|
elif run_hypercorn == True:
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from hypercorn.asyncio import serve
|
||||||
|
from hypercorn.config import Config
|
||||||
|
|
||||||
|
print( # noqa
|
||||||
|
f"\033[1;32mLiteLLM Proxy: Starting server on {host}:{port} using Hypercorn\033[0m\n" # noqa
|
||||||
|
) # noqa
|
||||||
|
config = Config()
|
||||||
|
config.bind = [f"{host}:{port}"]
|
||||||
|
|
||||||
|
if ssl_certfile_path is not None and ssl_keyfile_path is not None:
|
||||||
|
print( # noqa
|
||||||
|
f"\033[1;32mLiteLLM Proxy: Using SSL with certfile: {ssl_certfile_path} and keyfile: {ssl_keyfile_path}\033[0m\n" # noqa
|
||||||
|
)
|
||||||
|
config.certfile = ssl_certfile_path
|
||||||
|
config.keyfile = ssl_keyfile_path
|
||||||
|
|
||||||
|
# hypercorn serve raises a type warning when passing a fast api app - even though fast API is a valid type
|
||||||
|
asyncio.run(serve(app, config)) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue