From 731a345cfc0ba503d05a95630dc86e6a01d35b70 Mon Sep 17 00:00:00 2001 From: DocShotgun <126566557+DocShotgun@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:40:00 -0800 Subject: [PATCH] OAI: Keep behavior consistent between chat completion and encode * When vision is not enabled, only the first text block is kept in message.content if it is a list --- endpoints/core/router.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/endpoints/core/router.py b/endpoints/core/router.py index 0a48a2e..d7837f8 100644 --- a/endpoints/core/router.py +++ b/endpoints/core/router.py @@ -379,6 +379,20 @@ async def encode_tokens(data: TokenEncodeRequest) -> TokenEncodeResponse: if model.container.use_vision: data.text, embeddings = await preprocess_vision_request(data.text) + # Keeping behavior consistent with format_prompt_with_template + # Deal with list in messages.content + # Just replace the content list with the very first text message + for message in data.text: + if isinstance(message["content"], list): + message["content"] = next( + ( + content["text"] + for content in message["content"] + if content["type"] == "text" + ), + "", + ) + special_tokens_dict = model.container.get_special_tokens( unwrap(data.add_bos_token, True) )