| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | from vllm.entrypoints.chat_utils import ( |
| 5 | ChatCompletionMessageParam, |
| 6 | ConversationMessage, |
| 7 | parse_chat_messages, |
| 8 | parse_chat_messages_async, |
| 9 | ) |
| 10 | from vllm.logger import init_logger |
| 11 | |
| 12 | from .base import BaseRenderer |
| 13 | from .inputs import DictPrompt |
| 14 | from .inputs.preprocess import parse_dec_only_prompt |
| 15 | from .params import ChatParams |
| 16 | |
| 17 | logger = init_logger(__name__) |
| 18 | |
| 19 | |
| 20 | class TerratorchRenderer(BaseRenderer): |
| 21 | def render_messages( |
| 22 | self, |
| 23 | messages: list[ChatCompletionMessageParam], |
| 24 | params: ChatParams, |
| 25 | ) -> tuple[list[ConversationMessage], DictPrompt]: |
| 26 | model_config = self.model_config |
| 27 | |
| 28 | conversation, mm_data, mm_uuids = parse_chat_messages( |
| 29 | messages, |
| 30 | model_config, |
| 31 | content_format="string", |
| 32 | media_io_kwargs=params.media_io_kwargs, |
| 33 | mm_processor_kwargs=params.mm_processor_kwargs, |
| 34 | ) |
| 35 | |
| 36 | prompt = parse_dec_only_prompt([1]) # Dummy token IDs |
| 37 | if mm_data is not None: |
| 38 | prompt["multi_modal_data"] = mm_data |
| 39 | if mm_uuids is not None: |
| 40 | prompt["multi_modal_uuids"] = mm_uuids |
| 41 | |
| 42 | return conversation, prompt |
| 43 | |
| 44 | async def render_messages_async( |
| 45 | self, |
| 46 | messages: list[ChatCompletionMessageParam], |
| 47 | params: ChatParams, |
| 48 | ) -> tuple[list[ConversationMessage], DictPrompt]: |
| 49 | model_config = self.model_config |
| 50 | |
| 51 | conversation, mm_data, mm_uuids = await parse_chat_messages_async( |
| 52 | messages, |
| 53 | model_config, |
| 54 | content_format="string", |
| 55 | media_io_kwargs=params.media_io_kwargs, |
| 56 | mm_processor_kwargs=params.mm_processor_kwargs, |
| 57 | ) |
| 58 | |
| 59 | prompt = parse_dec_only_prompt([1]) # Dummy token IDs |
| 60 | if mm_data is not None: |
| 61 | prompt["multi_modal_data"] = mm_data |
| 62 | if mm_uuids is not None: |
| 63 | prompt["multi_modal_uuids"] = mm_uuids |
| 64 | |
| 65 | return conversation, prompt |