mirror of
https://github.com/hiyouga/LLaMA-Factory.git
synced 2025-08-22 13:42:51 +08:00
Merge pull request #3655 from Tendo33/main
1.Change the name of is_fastapi_available function 2. Added the log of printing requests when deploying using vllm Former-commit-id: f7c8eddbc584ab788579a53823ffe5b5808883b8
This commit is contained in:
commit
ed546236c0
@ -6,7 +6,7 @@ from typing_extensions import Annotated
|
|||||||
|
|
||||||
from ..chat import ChatModel
|
from ..chat import ChatModel
|
||||||
from ..extras.misc import torch_gc
|
from ..extras.misc import torch_gc
|
||||||
from ..extras.packages import is_fastapi_availble, is_starlette_available, is_uvicorn_available
|
from ..extras.packages import is_fastapi_available, is_starlette_available, is_uvicorn_available
|
||||||
from .chat import (
|
from .chat import (
|
||||||
create_chat_completion_response,
|
create_chat_completion_response,
|
||||||
create_score_evaluation_response,
|
create_score_evaluation_response,
|
||||||
@ -22,7 +22,7 @@ from .protocol import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if is_fastapi_availble():
|
if is_fastapi_available():
|
||||||
from fastapi import Depends, FastAPI, HTTPException, status
|
from fastapi import Depends, FastAPI, HTTPException, status
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBearer
|
from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBearer
|
||||||
|
@ -3,7 +3,8 @@ import uuid
|
|||||||
from typing import TYPE_CHECKING, AsyncGenerator, Dict, List, Optional, Tuple
|
from typing import TYPE_CHECKING, AsyncGenerator, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from ..data import Role as DataRole
|
from ..data import Role as DataRole
|
||||||
from ..extras.packages import is_fastapi_availble
|
from ..extras.logging import get_logger
|
||||||
|
from ..extras.packages import is_fastapi_available
|
||||||
from .common import dictify, jsonify
|
from .common import dictify, jsonify
|
||||||
from .protocol import (
|
from .protocol import (
|
||||||
ChatCompletionMessage,
|
ChatCompletionMessage,
|
||||||
@ -20,7 +21,9 @@ from .protocol import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if is_fastapi_availble():
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
if is_fastapi_available():
|
||||||
from fastapi import HTTPException, status
|
from fastapi import HTTPException, status
|
||||||
|
|
||||||
|
|
||||||
@ -39,6 +42,9 @@ ROLE_MAPPING = {
|
|||||||
|
|
||||||
|
|
||||||
def _process_request(request: "ChatCompletionRequest") -> Tuple[List[Dict[str, str]], str, str]:
|
def _process_request(request: "ChatCompletionRequest") -> Tuple[List[Dict[str, str]], str, str]:
|
||||||
|
params = dictify(request)
|
||||||
|
logger.info(f"==== request ====\n{params}")
|
||||||
|
|
||||||
if len(request.messages) == 0:
|
if len(request.messages) == 0:
|
||||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid length")
|
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid length")
|
||||||
|
|
||||||
|
@ -6,11 +6,11 @@ if TYPE_CHECKING:
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
def dictify(data: "BaseModel") -> Dict[str, Any]:
|
def dictify(data: "BaseModel", **kwargs) -> Dict[str, Any]:
|
||||||
try: # pydantic v2
|
try: # pydantic v2
|
||||||
return data.model_dump(exclude_unset=True)
|
return data.model_dump(**kwargs)
|
||||||
except AttributeError: # pydantic v1
|
except AttributeError: # pydantic v1
|
||||||
return data.dict(exclude_unset=True)
|
return data.dict(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def jsonify(data: "BaseModel") -> str:
|
def jsonify(data: "BaseModel") -> str:
|
||||||
|
@ -20,7 +20,7 @@ def _get_package_version(name: str) -> "Version":
|
|||||||
return version.parse("0.0.0")
|
return version.parse("0.0.0")
|
||||||
|
|
||||||
|
|
||||||
def is_fastapi_availble():
|
def is_fastapi_available():
|
||||||
return _is_package_available("fastapi")
|
return _is_package_available("fastapi")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user