![]() |
LlamaLib
v2.0.2
Cross-platform library for local LLMs
|
Handles concatenation of LLM response chunks (both streaming and non-streaming) Accumulates content and tokens from multiple response chunks into a single result. More...
#include <completion_processor.h>
Public Member Functions | |
| bool | process_chunk (const std::string &chunk_data) |
| Process a single chunk and accumulate its content/tokens. | |
| json | build_concatenated_json () const |
| Build the final concatenated JSON result. | |
| const std::string & | get_content () const |
| Get the concatenated content string. | |
| const std::vector< int > & | get_tokens () const |
| Get the concatenated tokens. | |
| std::string | get_result_json () const |
| Get the complete result as JSON string. | |
| bool | has_error () const |
| Check if processing encountered an error. | |
| const json & | get_error () const |
| Get the error JSON if any. | |
| bool | is_complete () const |
| Check if response is complete. | |
| size_t | chunk_count () const |
| Get the number of chunks processed. | |
| void | set_callback (CharArrayFn callback, bool callWithJSON=false) |
| Set a callback to be invoked after each chunk is processed. | |
| void | reset () |
| Reset the concatenator state. | |
Handles concatenation of LLM response chunks (both streaming and non-streaming) Accumulates content and tokens from multiple response chunks into a single result.
Definition at line 13 of file completion_processor.h.
| json ResponseConcatenator::build_concatenated_json | ( | ) | const |
Build the final concatenated JSON result.
Definition at line 76 of file completion_processor.cpp.
|
inline |
Get the number of chunks processed.
Definition at line 62 of file completion_processor.h.
|
inline |
Get the concatenated content string.
Definition at line 32 of file completion_processor.h.
|
inline |
Get the error JSON if any.
Definition at line 52 of file completion_processor.h.
| std::string ResponseConcatenator::get_result_json | ( | ) | const |
Get the complete result as JSON string.
Definition at line 83 of file completion_processor.cpp.
|
inline |
Get the concatenated tokens.
Definition at line 37 of file completion_processor.h.
|
inline |
Check if processing encountered an error.
Definition at line 47 of file completion_processor.h.
|
inline |
Check if response is complete.
Definition at line 57 of file completion_processor.h.
| bool ResponseConcatenator::process_chunk | ( | const std::string & | chunk_data | ) |
Process a single chunk and accumulate its content/tokens.
| chunk_data | The JSON chunk data (can be SSE format "data: {...}" or plain JSON) |
Definition at line 3 of file completion_processor.cpp.
| void ResponseConcatenator::reset | ( | ) |
Reset the concatenator state.
Definition at line 90 of file completion_processor.cpp.
|
inline |
Set a callback to be invoked after each chunk is processed.
Definition at line 67 of file completion_processor.h.