Skip to content

Commit

Permalink
Fix exception handle for proxy server
Browse files Browse the repository at this point in the history
  • Loading branch information
AllentDan committed Dec 16, 2024
1 parent 96e82eb commit f23ca96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions lmdeploy/cli/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def add_parser_proxy():
help='the strategy to dispatch requests to nodes')
ArgumentHelper.api_keys(parser)
ArgumentHelper.ssl(parser)
ArgumentHelper.log_level(parser)

@staticmethod
def gradio(args):
Expand Down
8 changes: 6 additions & 2 deletions lmdeploy/serve/proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def handle_unavailable_model(self, model_name):
Args:
model_name (str): the model in the request.
"""
logger.info(f'no model name: {model_name}')
logger.warn(f'no model name: {model_name}')
ret = {
'error_code': ErrorCodes.MODEL_NOT_FOUND,
'text': err_msg[ErrorCodes.MODEL_NOT_FOUND],
Expand All @@ -260,11 +260,13 @@ def handle_unavailable_model(self, model_name):

def handle_api_timeout(self, node_url):
"""Handle the api time out."""
logger.info(f'api timeout: {node_url}')
logger.warn(f'api timeout: {node_url}')
ret = {
'error_code': ErrorCodes.API_TIMEOUT,
'text': err_msg[ErrorCodes.API_TIMEOUT],
}
# exception happened, reduce unfinished num
self.nodes[node_url].unfinished -= 1
return json.dumps(ret).encode() + b'\n'

def stream_generate(self, request: Dict, node_url: str, node_path: str):
Expand Down Expand Up @@ -517,6 +519,7 @@ def proxy(server_name: str = '0.0.0.0',
'min_observed_latency'] = 'min_expected_latency',
api_keys: Optional[Union[List[str], str]] = None,
ssl: bool = False,
log_level: str = 'INFO',
**kwargs):
"""To launch the proxy server.
Expand All @@ -540,6 +543,7 @@ def proxy(server_name: str = '0.0.0.0',
if ssl:
ssl_keyfile = os.environ['SSL_KEYFILE']
ssl_certfile = os.environ['SSL_CERTFILE']
logger.setLevel(log_level)
uvicorn.run(app=app,
host=server_name,
port=server_port,
Expand Down

0 comments on commit f23ca96

Please sign in to comment.