File size: 463 Bytes
3d3d712
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from typing import Dict, Literal, Optional

ChatMessageRoleType = Literal["system", "user", "assistant", "function"]
ChatMessageType = Dict[Literal["role", "name", "content"], str]


def format_chat_message(
    role: ChatMessageRoleType,
    message: str,
    name: Optional[str] = None,
) -> ChatMessageType:
    msg: ChatMessageType = {
        "role": role,
        "content": message,
    }
    if name is not None:
        msg["name"] = name
    return msg