handle <think> tag
This commit is contained in:
@@ -17,6 +17,7 @@ export type ParsedInfioBlock =
|
||||
endLine?: number
|
||||
action?: InfioBlockAction
|
||||
}
|
||||
| { type: 'think'; content: string }
|
||||
|
||||
function isInfioBlockAction(value: string): value is InfioBlockAction {
|
||||
return Object.values<string>(InfioBlockAction).includes(value)
|
||||
@@ -82,6 +83,39 @@ export function parseinfioBlocks(input: string): ParsedInfioBlock[] {
|
||||
})
|
||||
}
|
||||
lastEndOffset = endOffset
|
||||
} else if (node.nodeName === 'think') {
|
||||
if (!node.sourceCodeLocation) {
|
||||
throw new Error('sourceCodeLocation is undefined')
|
||||
}
|
||||
const startOffset = node.sourceCodeLocation.startOffset
|
||||
const endOffset = node.sourceCodeLocation.endOffset
|
||||
if (startOffset > lastEndOffset) {
|
||||
parsedResult.push({
|
||||
type: 'string',
|
||||
content: input.slice(lastEndOffset, startOffset),
|
||||
})
|
||||
}
|
||||
|
||||
const children = node.childNodes
|
||||
if (children.length === 0) {
|
||||
parsedResult.push({
|
||||
type: 'think',
|
||||
content: '',
|
||||
})
|
||||
} else {
|
||||
const innerContentStartOffset =
|
||||
children[0].sourceCodeLocation?.startOffset
|
||||
const innerContentEndOffset =
|
||||
children[children.length - 1].sourceCodeLocation?.endOffset
|
||||
if (!innerContentStartOffset || !innerContentEndOffset) {
|
||||
throw new Error('sourceCodeLocation is undefined')
|
||||
}
|
||||
parsedResult.push({
|
||||
type: 'think',
|
||||
content: input.slice(innerContentStartOffset, innerContentEndOffset),
|
||||
})
|
||||
}
|
||||
lastEndOffset = endOffset
|
||||
}
|
||||
}
|
||||
if (lastEndOffset < input.length) {
|
||||
|
||||
Reference in New Issue
Block a user