Implementation:Deepseek ai Janus Conversation Template
| Knowledge Sources | |
|---|---|
| Domains | NLP, Prompt_Engineering |
| Last Updated | 2026-02-10 09:30 GMT |
Overview
Concrete tool for managing conversation templates and rendering multi-turn prompts provided by the Janus conversation module.
Description
The Conversation dataclass and get_conv_template function provide a template registry system for formatting multi-turn dialogues. The Conversation class stores template metadata (role names, separators, stop tokens) and conversation history, then renders the full prompt via get_prompt(). The "deepseek" template is registered by default with <|User|> / <|Assistant|> role markers.
Usage
Import get_conv_template when you need to manually construct prompts from conversation messages. In practice, the VLChatProcessor.apply_sft_template_for_multi_turn_prompts method wraps this functionality, so direct usage is less common.
Code Reference
Source Location
- Repository: Janus
- File: janus/utils/conversation.py
- Lines: L52-237 (Conversation class), L235-237 (get_conv_template)
Signature
@dataclasses.dataclass
class Conversation:
name: str
system_template: str = "{system_message}"
system_message: str = ""
roles: List[str] = (("USER", "ASSISTANT"),)
messages: List[List[str]] = ()
offset: int = 0
sep_style: SeparatorStyle = SeparatorStyle.ADD_COLON_SINGLE
sep: str = "\n"
sep2: str = None
stop_str: str = None
stop_token_ids: List[int] = None
def get_prompt(self) -> str: ...
def append_message(self, role: str, message: str): ...
def copy(self) -> "Conversation": ...
def get_conv_template(name: str) -> Conversation:
"""Get a conversation template by name (returns a copy)."""
Import
from janus.utils.conversation import Conversation, get_conv_template
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | Template name (e.g., "deepseek", "llama-2", "plain") |
Outputs
| Name | Type | Description |
|---|---|---|
| conversation | Conversation | Conversation object with template settings and empty message history |
| get_prompt() returns | str | Fully formatted prompt string with role markers and separators |
Usage Examples
Basic Prompt Construction
from janus.utils.conversation import get_conv_template
# Get the DeepSeek conversation template
conv = get_conv_template("deepseek")
# Add messages
conv.append_message(conv.roles[0], "What is in this image?")
conv.append_message(conv.roles[1], "") # Empty = model should generate
# Render the formatted prompt
prompt = conv.get_prompt()
# Output: "<|User|>: What is in this image?\n\n<|Assistant|>:"
With System Prompt
conv = get_conv_template("deepseek")
conv.set_system_message("You are a helpful visual assistant.")
conv.append_message(conv.roles[0], "Describe the scene.")
conv.append_message(conv.roles[1], "")
prompt = conv.get_prompt()
# Output: "You are a helpful visual assistant.\n\n<|User|>: Describe the scene.\n\n<|Assistant|>:"