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

Structure representing a single chat message. More...

#include <LLM_agent.h>

Public Member Functions

 ChatMessage ()=default
 Default constructor.
 
 ChatMessage (const std::string &role_, const std::string &content_)
 Parameterized constructor.
 
json to_json () const
 Convert message to JSON representation.
 
bool operator== (const ChatMessage &other) const
 Equality comparison operator.
 

Static Public Member Functions

static ChatMessage from_json (const json &j)
 Create message from JSON representation.
 

Public Attributes

std::string role
 Message role (e.g., "user", "assistant", "system")
 
std::string content
 Message content text.
 

Detailed Description

Structure representing a single chat message.

Encapsulates a conversation message with role and content, providing JSON serialization and comparison functionality

Definition at line 15 of file LLM_agent.h.

Constructor & Destructor Documentation

◆ ChatMessage()

ChatMessage::ChatMessage ( const std::string & role_,
const std::string & content_ )
inline

Parameterized constructor.

Parameters
role_Message role identifier
content_Message content text

Definition at line 26 of file LLM_agent.h.

Member Function Documentation

◆ from_json()

static ChatMessage ChatMessage::from_json ( const json & j)
inlinestatic

Create message from JSON representation.

Parameters
jJSON object containing message data
Returns
ChatMessage instance created from JSON

Deserializes a message from JSON format

Exceptions
json::exceptionif required fields are missing

Definition at line 42 of file LLM_agent.h.

◆ operator==()

bool ChatMessage::operator== ( const ChatMessage & other) const
inline

Equality comparison operator.

Parameters
otherAnother ChatMessage to compare with
Returns
true if both role and content are identical, false otherwise

Definition at line 50 of file LLM_agent.h.

◆ to_json()

json ChatMessage::to_json ( ) const
inline

Convert message to JSON representation.

Returns
JSON object with role and content fields

Serializes the message for storage or transmission

Definition at line 32 of file LLM_agent.h.

Here is the caller graph for this function:

Member Data Documentation

◆ content

std::string ChatMessage::content

Message content text.

Definition at line 18 of file LLM_agent.h.

◆ role

std::string ChatMessage::role

Message role (e.g., "user", "assistant", "system")

Definition at line 17 of file LLM_agent.h.


The documentation for this struct was generated from the following file: