LlamaLib  v2.0.2
Cross-platform library for local LLMs
Loading...
Searching...
No Matches
ResponseConcatenator Class Reference

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.
 

Detailed Description

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.

Member Function Documentation

◆ build_concatenated_json()

json ResponseConcatenator::build_concatenated_json ( ) const

Build the final concatenated JSON result.

Definition at line 76 of file completion_processor.cpp.

Here is the caller graph for this function:

◆ chunk_count()

size_t ResponseConcatenator::chunk_count ( ) const
inline

Get the number of chunks processed.

Definition at line 62 of file completion_processor.h.

◆ get_content()

const std::string & ResponseConcatenator::get_content ( ) const
inline

Get the concatenated content string.

Definition at line 32 of file completion_processor.h.

◆ get_error()

const json & ResponseConcatenator::get_error ( ) const
inline

Get the error JSON if any.

Definition at line 52 of file completion_processor.h.

◆ get_result_json()

std::string ResponseConcatenator::get_result_json ( ) const

Get the complete result as JSON string.

Definition at line 83 of file completion_processor.cpp.

◆ get_tokens()

const std::vector< int > & ResponseConcatenator::get_tokens ( ) const
inline

Get the concatenated tokens.

Definition at line 37 of file completion_processor.h.

◆ has_error()

bool ResponseConcatenator::has_error ( ) const
inline

Check if processing encountered an error.

Definition at line 47 of file completion_processor.h.

◆ is_complete()

bool ResponseConcatenator::is_complete ( ) const
inline

Check if response is complete.

Definition at line 57 of file completion_processor.h.

◆ process_chunk()

bool ResponseConcatenator::process_chunk ( const std::string & chunk_data)

Process a single chunk and accumulate its content/tokens.

Parameters
chunk_dataThe JSON chunk data (can be SSE format "data: {...}" or plain JSON)
Returns
true if processing should continue, false if done or error

Definition at line 3 of file completion_processor.cpp.

◆ reset()

void ResponseConcatenator::reset ( )

Reset the concatenator state.

Definition at line 90 of file completion_processor.cpp.

◆ set_callback()

void ResponseConcatenator::set_callback ( CharArrayFn callback,
bool callWithJSON = false )
inline

Set a callback to be invoked after each chunk is processed.

Definition at line 67 of file completion_processor.h.


The documentation for this class was generated from the following files: