1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
use ;
/// Enumeration of special tokens used in the Tekken tokenizer.
///
/// Special tokens are used to mark different types of content and control sequences
/// in text and multimodal processing. Each variant corresponds to a specific
/// token string that has special meaning in the tokenization process.
///
/// # Token Categories
///
/// - **Control tokens**: UNK, BOS, EOS, PAD for general sequence control
/// - **Instruction tokens**: `BeginInst`, `EndInst` for instruction formatting
/// - **Tool tokens**: Various tokens for tool call formatting and results
/// - **Image tokens**: IMG, `ImgBreak`, `ImgEnd` for image content
/// - **Audio tokens**: Audio, `BeginAudio`, Transcribe for audio content
/// - **Code tokens**: Prefix, Middle, Suffix for code completion
/// - **System tokens**: `BeginSystem`, `EndSystem` for system prompts
/// Policy for handling special tokens during decoding.
///
/// This enum defines how special tokens should be treated when converting
/// token sequences back to text. Different policies allow for different
/// use cases and output formats.
///
/// # Variants
///
/// - `Ignore`: Skip special tokens completely in the output
/// - `Keep`: Include special tokens in their string form in the output
/// - `Raise`: Raise an error if special tokens are encountered during decoding
///
/// # Examples
///
/// ```rust,no_run
/// use tekken::special_tokens::SpecialTokenPolicy;
/// use tekken::tekkenizer::Tekkenizer;
///
/// let tokenizer = Tekkenizer::from_file("tekken.json")?;
/// let tokens = vec![1, 22177, 2]; // [BOS, "Hello", EOS]
///
/// // Keep special tokens: "<s>Hello</s>"
/// let with_special = tokenizer.decode(&tokens, SpecialTokenPolicy::Keep)?;
///
/// // Ignore special tokens: "Hello"
/// let without_special = tokenizer.decode(&tokens, SpecialTokenPolicy::Ignore)?;
///
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Information about a special token including its rank and properties.
///
/// This struct contains metadata about a special token, including its position
/// in the vocabulary (rank), string representation, and whether it's a control token.
///
/// # Fields
///
/// * `rank` - Position of the token in the vocabulary (token ID)
/// * `token_str` - String representation of the token
/// * `is_control` - Whether this is a control token (affects processing behavior)
///
/// # Examples
///
/// ```rust
/// use tekken::special_tokens::SpecialTokenInfo;
///
/// let bos_token = SpecialTokenInfo {
/// rank: 1,
/// token_str: "<s>".to_string(),
/// is_control: true,
/// };
/// ```