Entropic 2.11.1
Local-first agentic inference engine
Loading...
Searching...
No Matches
stream_think_filter.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
14#pragma once
15
16#include <cstddef>
17#include <string>
18
19namespace entropic {
20
25using TokenCallback = void (*)(const char*, size_t, void*);
26
37public:
45 StreamThinkFilter(TokenCallback cb, void* ud);
46
69 std::string open_marker, std::string close_marker);
70
78 void set_raw_callback(TokenCallback cb, void* ud);
79
87 void on_token(const char* chunk, size_t len);
88
98 void flush();
99
100private:
101 TokenCallback cb_;
102 void* ud_;
103 TokenCallback raw_cb_ = nullptr;
104 void* raw_ud_ = nullptr;
113 bool match_tag(const std::string& buf, bool& is_open) const;
114
115 bool in_think_ = false;
116
117 std::string open_marker_ = "<think>";
118 std::string close_marker_ = "</think>";
121 std::size_t max_marker_len_ = 8;
122 std::string tag_buf_;
123 std::string utf8_buf_;
124
132 void emit_utf8_safe(const char* data, size_t len);
133
139 void process_byte(char c);
140};
141
142} // namespace entropic
Streaming filter that removes <think> blocks from output.
void set_raw_callback(TokenCallback cb, void *ud)
Set optional raw callback (receives ALL tokens unfiltered).
void on_token(const char *chunk, size_t len)
Process a chunk of tokens.
void flush()
Flush any buffered partial tag content.
Activate model on GPU (WARM → ACTIVE).
void(*)(const char *, size_t, void *) TokenCallback
Token callback type matching the C API signature.