mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
(fix) use gunicorn to start proxt
This commit is contained in:
parent
c7fe33202d
commit
5136d5980f
2 changed files with 17 additions and 15 deletions
|
@ -366,37 +366,46 @@ def run_server(
|
||||||
use_queue=use_queue,
|
use_queue=use_queue,
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
import gunicorn
|
import uvicorn
|
||||||
except:
|
except:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Uvicorn needs to be imported. Run - `pip install uvicorn`"
|
"Uvicorn needs to be imported. Run - `pip install uvicorn`"
|
||||||
)
|
)
|
||||||
if port == 8000 and is_port_in_use(port):
|
if port == 8000 and is_port_in_use(port):
|
||||||
port = random.randint(1024, 49152)
|
port = random.randint(1024, 49152)
|
||||||
|
# uvicorn.run(
|
||||||
|
# "litellm.proxy.proxy_server:app", host=host, port=port, workers=num_workers
|
||||||
|
# )
|
||||||
|
|
||||||
from gunicorn.app.base import BaseApplication
|
import gunicorn.app.base
|
||||||
|
|
||||||
class StandaloneApplication(BaseApplication):
|
class StandaloneApplication(gunicorn.app.base.BaseApplication):
|
||||||
def __init__(self, app, options=None):
|
def __init__(self, app, options=None):
|
||||||
self.options = options or {}
|
self.options = options or {}
|
||||||
self.application = app
|
self.application = app
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def load_config(self):
|
def load_config(self):
|
||||||
for key, value in self.options.items():
|
config = {
|
||||||
self.cfg.set(key, value)
|
key: value
|
||||||
|
for key, value in self.options.items()
|
||||||
|
if key in self.cfg.settings and value is not None
|
||||||
|
}
|
||||||
|
for key, value in config.items():
|
||||||
|
self.cfg.set(key.lower(), value)
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
return self.application
|
return self.application
|
||||||
|
|
||||||
num_workers = 4 # Set the desired number of Gunicorn workers
|
|
||||||
host = "0.0.0.0"
|
|
||||||
gunicorn_options = {
|
gunicorn_options = {
|
||||||
"bind": f"{host}:{port}",
|
"bind": f"{host}:{port}",
|
||||||
"workers": num_workers,
|
"workers": num_workers,
|
||||||
|
"worker_class": "uvicorn.workers.UvicornWorker",
|
||||||
|
"preload": True, # Add the preload flag
|
||||||
}
|
}
|
||||||
|
from litellm.proxy.proxy_server import app
|
||||||
|
|
||||||
StandaloneApplication(app, gunicorn_options).run()
|
StandaloneApplication(app=app, options=gunicorn_options).run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -41,13 +41,6 @@ model_list:
|
||||||
api_key: os.environ/OPENAI_API_KEY
|
api_key: os.environ/OPENAI_API_KEY
|
||||||
model_info:
|
model_info:
|
||||||
mode: embedding
|
mode: embedding
|
||||||
- model_name: text-davinci-003
|
|
||||||
litellm_params:
|
|
||||||
model: text-davinci-003
|
|
||||||
api_key: os.environ/OPENAI_API_KEY
|
|
||||||
model_info:
|
|
||||||
mode: completion
|
|
||||||
|
|
||||||
litellm_settings:
|
litellm_settings:
|
||||||
fallbacks: [{"openai-gpt-3.5": ["azure-gpt-3.5"]}]
|
fallbacks: [{"openai-gpt-3.5": ["azure-gpt-3.5"]}]
|
||||||
# cache: True
|
# cache: True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue