mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-04-26 01:08:52 +00:00
feat: list support in message.content (#122)
This commit is contained in:
@@ -41,7 +41,8 @@ class ChatCompletionStreamChoice(BaseModel):
|
|||||||
class ChatCompletionRequest(CommonCompletionRequest):
|
class ChatCompletionRequest(CommonCompletionRequest):
|
||||||
# Messages
|
# Messages
|
||||||
# Take in a string as well even though it's not part of the OAI spec
|
# Take in a string as well even though it's not part of the OAI spec
|
||||||
messages: Union[str, List[Dict[str, str]]]
|
# support messages.content as a list of dict
|
||||||
|
messages: Union[str, List[Dict[str, Union[str, List[Dict[str, str]]]]]]
|
||||||
prompt_template: Optional[str] = None
|
prompt_template: Optional[str] = None
|
||||||
add_generation_prompt: Optional[bool] = True
|
add_generation_prompt: Optional[bool] = True
|
||||||
template_vars: Optional[dict] = {}
|
template_vars: Optional[dict] = {}
|
||||||
|
|||||||
@@ -151,6 +151,19 @@ def format_prompt_with_template(data: ChatCompletionRequest):
|
|||||||
unwrap(data.ban_eos_token, False),
|
unwrap(data.ban_eos_token, False),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Deal with list in messages.content
|
||||||
|
# Just replace the content list with the very first text message
|
||||||
|
for message in data.messages:
|
||||||
|
if message["role"] == "user" and isinstance(message["content"], list):
|
||||||
|
message["content"] = next(
|
||||||
|
(
|
||||||
|
content["text"]
|
||||||
|
for content in message["content"]
|
||||||
|
if content["type"] == "text"
|
||||||
|
),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
|
||||||
# Overwrite any protected vars with their values
|
# Overwrite any protected vars with their values
|
||||||
data.template_vars.update(
|
data.template_vars.update(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user