MCPcopy Create free account
hub / github.com/evilsocket/cake / extract_open_think

Function extract_open_think

cake-cli/src/chat.rs:277–296  ·  view source on GitHub ↗

Extract the text inside an open (unclosed) ` ` block, if any. Returns empty string if there's no open think block.

(content: &str)

Source from the content-addressed store, hash-verified

275/// Extract the text inside an open (unclosed) `<think>` block, if any.
276/// Returns empty string if there's no open think block.
277fn extract_open_think(content: &str) -> String {
278 let mut rest = content;
279 loop {
280 match rest.find("<think>") {
281 Some(pos) => {
282 rest = &rest[pos + 7..];
283 match rest.find("</think>") {
284 Some(end) => {
285 rest = &rest[end + 8..];
286 }
287 None => {
288 // This is the open block
289 return rest.trim().to_string();
290 }
291 }
292 }
293 None => return String::new(),
294 }
295 }
296}
297
298/// Remove all `<think>...</think>` blocks (closed) and any trailing open
299/// `<think>...` (still thinking) from the displayed content.

Callers 1

build_message_linesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected