Chat message prompt template.
| 366 | |
| 367 | |
| 368 | class ChatMessagePromptTemplate(BaseStringMessagePromptTemplate): |
| 369 | """Chat message prompt template.""" |
| 370 | |
| 371 | role: str |
| 372 | """Role of the message.""" |
| 373 | |
| 374 | @classmethod |
| 375 | def get_lc_namespace(cls) -> List[str]: |
| 376 | """Get the namespace of the langchain object.""" |
| 377 | return ["langchain", "prompts", "chat"] |
| 378 | |
| 379 | def format(self, **kwargs: Any) -> BaseMessage: |
| 380 | """Format the prompt template. |
| 381 | |
| 382 | Args: |
| 383 | **kwargs: Keyword arguments to use for formatting. |
| 384 | |
| 385 | Returns: |
| 386 | Formatted message. |
| 387 | """ |
| 388 | text = self.prompt.format(**kwargs) |
| 389 | return ChatMessage( |
| 390 | content=text, role=self.role, additional_kwargs=self.additional_kwargs |
| 391 | ) |
| 392 | |
| 393 | async def aformat(self, **kwargs: Any) -> BaseMessage: |
| 394 | text = await self.prompt.aformat(**kwargs) |
| 395 | return ChatMessage( |
| 396 | content=text, role=self.role, additional_kwargs=self.additional_kwargs |
| 397 | ) |
| 398 | |
| 399 | |
| 400 | _StringImageMessagePromptTemplateT = TypeVar( |
no outgoing calls