mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-02 02:01:47 +00:00
fix(tui): format thinking paragraphs
This commit is contained in:
parent
64de685d3f
commit
6a3873942f
2 changed files with 26 additions and 7 deletions
|
|
@ -74,14 +74,21 @@ export const pasteTokenLabel = (text: string, lineCount: number) => {
|
|||
const THINKING_STATUS_RE = new RegExp(`^(?:${VERBS.join('|')})\\.{0,3}$`, 'i')
|
||||
const THINKING_STATUS_CHUNK_RE = new RegExp(`[^A-Za-z\n]+\\s*(?:${VERBS.join('|')})\\.{0,3}\\s*`, 'giu')
|
||||
|
||||
export const cleanThinkingText = (reasoning: string) =>
|
||||
reasoning
|
||||
.split('\n')
|
||||
.map(line => line.replace(THINKING_STATUS_CHUNK_RE, '').trim())
|
||||
.filter(line => line && !THINKING_STATUS_RE.test(line.replace(/\.\.\.$/, '').trim()))
|
||||
.join('\n')
|
||||
const normalizeThinkingParagraphs = (text: string) =>
|
||||
text
|
||||
.replace(/([^\n])(?=\*\*[^*\n][^\n]*?\*\*)/g, '$1\n\n')
|
||||
.replace(/\n{3,}/g, '\n\n')
|
||||
.trim()
|
||||
|
||||
export const cleanThinkingText = (reasoning: string) =>
|
||||
normalizeThinkingParagraphs(
|
||||
reasoning
|
||||
.split('\n')
|
||||
.map(line => line.replace(THINKING_STATUS_CHUNK_RE, '').trim())
|
||||
.filter(line => line && !THINKING_STATUS_RE.test(line.replace(/\.\.\.$/, '').trim()))
|
||||
.join('\n')
|
||||
)
|
||||
|
||||
export const thinkingPreview = (reasoning: string, mode: ThinkingMode, max: number = THINKING_COT_MAX) => {
|
||||
const raw = cleanThinkingText(reasoning)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue