32 const std::string&
get_content()
const {
return concatenated_content_; }
37 const std::vector<int>&
get_tokens()
const {
return concatenated_tokens_; }
68 callback_ = std::move(callback);
69 callWithJSON_ = callWithJSON;
78 void accumulate_result(
const json& item);
80 std::string concatenated_content_;
81 std::vector<int> concatenated_tokens_;
82 json last_chunk_ = json::object();
83 json error_ = json::object();
84 bool has_error_ =
false;
85 bool is_complete_ =
false;
86 size_t chunk_count_ = 0;
87 CharArrayFn callback_;
88 bool callWithJSON_ =
false;
Handles concatenation of LLM response chunks (both streaming and non-streaming) Accumulates content a...
bool has_error() const
Check if processing encountered an error.
bool process_chunk(const std::string &chunk_data)
Process a single chunk and accumulate its content/tokens.
void reset()
Reset the concatenator state.
size_t chunk_count() const
Get the number of chunks processed.
const std::vector< int > & get_tokens() const
Get the concatenated tokens.
bool is_complete() const
Check if response is complete.
json build_concatenated_json() const
Build the final concatenated JSON result.
const json & get_error() const
Get the error JSON if any.
std::string get_result_json() const
Get the complete result as JSON string.
const std::string & get_content() const
Get the concatenated content string.
void set_callback(CharArrayFn callback, bool callWithJSON=false)
Set a callback to be invoked after each chunk is processed.
File with basic definitions.