Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
d7f4178d
Unverified
Commit
d7f4178d
authored
Jul 21, 2024
by
Cyrus Leung
Committed by
GitHub
Jul 21, 2024
Browse files
[Frontend] Move chat utils (#6602)
Co-authored-by:
Roger Wang
<
ywang@roblox.com
>
parent
082ecd80
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
49 deletions
+54
-49
tests/async_engine/test_chat_template.py
tests/async_engine/test_chat_template.py
+1
-1
vllm/entrypoints/chat_utils.py
vllm/entrypoints/chat_utils.py
+45
-6
vllm/entrypoints/openai/protocol.py
vllm/entrypoints/openai/protocol.py
+2
-36
vllm/entrypoints/openai/serving_chat.py
vllm/entrypoints/openai/serving_chat.py
+3
-3
vllm/entrypoints/openai/serving_tokenization.py
vllm/entrypoints/openai/serving_tokenization.py
+3
-3
No files found.
tests/async_engine/test_chat_template.py
View file @
d7f4178d
...
...
@@ -3,7 +3,7 @@ import pathlib
import
pytest
from
vllm.entrypoints.
openai.
chat_utils
import
load_chat_template
from
vllm.entrypoints.chat_utils
import
load_chat_template
from
vllm.entrypoints.openai.protocol
import
ChatCompletionRequest
from
vllm.transformers_utils.tokenizer
import
get_tokenizer
...
...
vllm/entrypoints/
openai/
chat_utils.py
→
vllm/entrypoints/chat_utils.py
View file @
d7f4178d
import
codecs
from
dataclasses
import
dataclass
,
field
from
functools
import
lru_cache
from
typing
import
Awaitable
,
Iterable
,
List
,
Optional
,
TypedDict
,
cast
,
final
from
openai.types.chat
import
(
ChatCompletionContentPartImageParam
,
ChatCompletionContentPartTextParam
)
from
typing
import
Awaitable
,
Iterable
,
List
,
Optional
,
Union
,
cast
,
final
# yapf conflicts with isort for this block
# yapf: disable
from
openai.types.chat
import
ChatCompletionContentPartImageParam
from
openai.types.chat
import
(
ChatCompletionContentPartParam
as
OpenAIChatCompletionContentPartParam
)
from
openai.types.chat
import
ChatCompletionContentPartTextParam
from
openai.types.chat
import
(
ChatCompletionMessageParam
as
OpenAIChatCompletionMessageParam
)
# yapf: enable
# pydantic needs the TypedDict from typing_extensions
from
pydantic
import
ConfigDict
from
transformers
import
PreTrainedTokenizer
from
typing_extensions
import
Required
,
TypedDict
from
vllm.config
import
ModelConfig
from
vllm.entrypoints.openai.protocol
import
(
ChatCompletionContentPartParam
,
ChatCompletionMessageParam
)
from
vllm.logger
import
init_logger
from
vllm.multimodal
import
MultiModalDataDict
from
vllm.multimodal.utils
import
async_get_and_parse_image
...
...
@@ -17,6 +25,37 @@ from vllm.multimodal.utils import async_get_and_parse_image
logger
=
init_logger
(
__name__
)
class
CustomChatCompletionContentPartParam
(
TypedDict
,
total
=
False
):
__pydantic_config__
=
ConfigDict
(
extra
=
"allow"
)
# type: ignore
type
:
Required
[
str
]
"""The type of the content part."""
ChatCompletionContentPartParam
=
Union
[
OpenAIChatCompletionContentPartParam
,
CustomChatCompletionContentPartParam
]
class
CustomChatCompletionMessageParam
(
TypedDict
,
total
=
False
):
"""Enables custom roles in the Chat Completion API."""
role
:
Required
[
str
]
"""The role of the message's author."""
content
:
Union
[
str
,
List
[
ChatCompletionContentPartParam
]]
"""The contents of the message."""
name
:
str
"""An optional name for the participant.
Provides the model information to differentiate between participants of the
same role.
"""
ChatCompletionMessageParam
=
Union
[
OpenAIChatCompletionMessageParam
,
CustomChatCompletionMessageParam
]
@
final
# So that it should be compatible with Dict[str, str]
class
ConversationMessage
(
TypedDict
):
role
:
str
...
...
vllm/entrypoints/openai/protocol.py
View file @
d7f4178d
...
...
@@ -3,50 +3,16 @@
import
time
from
typing
import
Any
,
Dict
,
List
,
Literal
,
Optional
,
Union
import
openai.types.chat
import
torch
from
pydantic
import
BaseModel
,
ConfigDict
,
Field
,
model_validator
# pydantic needs the TypedDict from typing_extensions
from
typing_extensions
import
Annotated
,
Required
,
TypedDict
from
typing_extensions
import
Annotated
from
vllm.entrypoints.chat_utils
import
ChatCompletionMessageParam
from
vllm.pooling_params
import
PoolingParams
from
vllm.sampling_params
import
SamplingParams
from
vllm.utils
import
random_uuid
class
CustomChatCompletionContentPartParam
(
TypedDict
,
total
=
False
):
__pydantic_config__
=
ConfigDict
(
extra
=
"allow"
)
# type: ignore
type
:
Required
[
str
]
"""The type of the content part."""
ChatCompletionContentPartParam
=
Union
[
openai
.
types
.
chat
.
ChatCompletionContentPartParam
,
CustomChatCompletionContentPartParam
]
class
CustomChatCompletionMessageParam
(
TypedDict
,
total
=
False
):
"""Enables custom roles in the Chat Completion API."""
role
:
Required
[
str
]
"""The role of the message's author."""
content
:
Union
[
str
,
List
[
ChatCompletionContentPartParam
]]
"""The contents of the message."""
name
:
str
"""An optional name for the participant.
Provides the model information to differentiate between participants of the
same role.
"""
ChatCompletionMessageParam
=
Union
[
openai
.
types
.
chat
.
ChatCompletionMessageParam
,
CustomChatCompletionMessageParam
]
class
OpenAIBaseModel
(
BaseModel
):
# OpenAI API does not allow extra fields
model_config
=
ConfigDict
(
extra
=
"forbid"
)
...
...
vllm/entrypoints/openai/serving_chat.py
View file @
d7f4178d
...
...
@@ -9,7 +9,7 @@ from transformers import PreTrainedTokenizer
from
vllm.config
import
ModelConfig
from
vllm.engine.async_llm_engine
import
AsyncLLMEngine
from
vllm.entrypoints.
openai.
chat_utils
import
(
ConversationMessage
,
from
vllm.entrypoints.chat_utils
import
(
ConversationMessage
,
load_chat_template
,
parse_chat_message_content
)
from
vllm.entrypoints.openai.protocol
import
(
...
...
vllm/entrypoints/openai/serving_tokenization.py
View file @
d7f4178d
...
...
@@ -2,7 +2,7 @@ from typing import List, Optional
from
vllm.config
import
ModelConfig
from
vllm.engine.async_llm_engine
import
AsyncLLMEngine
from
vllm.entrypoints.
openai.
chat_utils
import
(
ConversationMessage
,
from
vllm.entrypoints.chat_utils
import
(
ConversationMessage
,
load_chat_template
,
parse_chat_message_content
)
from
vllm.entrypoints.openai.protocol
import
(
DetokenizeRequest
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment