Skip to content

Commit 4dd479b

Browse files
committed
add quick hack to render only some special tokens
1 parent 423b191 commit 4dd479b

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/llama-vocab.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,13 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
23302330
}
23312331
}
23322332

2333+
// @ngxson : quick hack for gpt-oss
2334+
for (const auto & t : token_to_id) {
2335+
if (t.first == "<|channel|>" || t.first == "<|message|>") {
2336+
id_to_token[t.second].attr = LLAMA_TOKEN_ATTR_NORMAL;
2337+
}
2338+
}
2339+
23332340
// sanity checks
23342341
if (special_eos_id != LLAMA_TOKEN_NULL && special_eog_ids.count(special_eos_id) == 0) {
23352342
special_eog_ids.insert(special_eos_id);

tools/server/public/index.html.gz

54 Bytes
Binary file not shown.

tools/server/webui/src/components/ChatMessage.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,22 @@ export default function ChatMessage({
6161
if (msg.content === null || msg.role !== 'assistant') {
6262
return { content: msg.content };
6363
}
64+
const REGEX_THINK_OPEN = /<think>|<\|channel\|>analysis<\|message\|>/;
65+
const REGEX_THINK_CLOSE = /<\/think>|<\|channel\|>final<\|message\|>/;
6466
let actualContent = '';
6567
let thought = '';
6668
let isThinking = false;
67-
let thinkSplit = msg.content.split('<think>', 2);
69+
let thinkSplit = msg.content.split(REGEX_THINK_OPEN, 2);
6870
actualContent += thinkSplit[0];
6971
while (thinkSplit[1] !== undefined) {
7072
// <think> tag found
71-
thinkSplit = thinkSplit[1].split('</think>', 2);
73+
thinkSplit = thinkSplit[1].split(REGEX_THINK_CLOSE, 2);
7274
thought += thinkSplit[0];
7375
isThinking = true;
7476
if (thinkSplit[1] !== undefined) {
7577
// </think> closing tag found
7678
isThinking = false;
77-
thinkSplit = thinkSplit[1].split('<think>', 2);
79+
thinkSplit = thinkSplit[1].split(REGEX_THINK_OPEN, 2);
7880
actualContent += thinkSplit[0];
7981
}
8082
}

0 commit comments

Comments
 (0)