gpt-oss: implement harmony parsing (#15181)

* model : add harmony parser for gpt-oss

* gpt-oss : fix grammar trigger from causing empty stack

* gpt-oss: tweak the grammar trigger again

* gpt-oss : add support for recipient in role header

* gpt-oss : fix ungrouped tool calls in grammar

* gpt-oss : loosen function name matching during parse

* gpt-oss : clean up workarounds

* gpt-oss : add template tests

* gpt-oss : simulate thinking and tool call tags

* gpt-oss : undo think tags when reasoning_format is none

* gpt-oss : set special tokens back to user defined

* gpt-oss : update openai-gpt-oss template

* server : filter out harmony thought messages

* gpt-oss : simplify parsing
This commit is contained in:
Aldehir Rojas
2025-08-14 09:23:11 -05:00
committed by GitHub
parent 646944cfa8
commit b204a5a234
7 changed files with 672 additions and 12 deletions

Binary file not shown.

View File

@@ -62,8 +62,7 @@ export default function ChatMessage({
return { content: msg.content };
}
const REGEX_THINK_OPEN = /<think>|<\|channel\|>analysis<\|message\|>/;
const REGEX_THINK_CLOSE =
/<\/think>|<\|start\|>assistant<\|channel\|>final<\|message\|>/;
const REGEX_THINK_CLOSE = /<\/think>|<\|end\|>/;
let actualContent = '';
let thought = '';
let isThinking = false;

View File

@@ -131,9 +131,7 @@ export function filterThoughtFromMsgs(messages: APIMessage[]) {
content:
msg.role === 'assistant'
? contentStr
.split(
/<\/think>|<\|start\|>assistant<\|channel\|>final<\|message\|>/
)
.split(/<\/think>|<\|end\|>/)
.at(-1)!
.trim()
: contentStr,