EN 中文
Back to Overview

LiteRtLm_AppendMessageJson

Appends multimodal or complex JSON messages. Supports sending images, specifying Roles (e.g., tool/user/assistant), and injecting tool execution results.

01. Complex Content Injection Flow

graph TD JSON[JSON String] -->|Parse| Internal[Internal History Buffer] subgraph Content_Types [Content Types] Text[Plain Text] Image[Base64 Encoded Image] Tool[Tool Call Result: Tool Outputs] end JSON -.-> Content_Types
Core Purpose: Use this interface when you need the AI to "describe images" or to feed back execution results from the host environment to the AI after it triggers tool_calls.

02. Parameter Definitions

void LiteRtLm_AppendMessageJson(void* conv_ptr, const char* json_msg);
ParameterResponsibility
conv_ptr Valid Session handle.
json_msg JSON message string compliant with OpenAI format.
Example: {"role": "user", "content": [...]}

03. Vision Injection Code Example (Base64)

const char* ImageJson = 
    "{"
    "  \"role\": \"user\","
    "  \"content\": ["
    "    {\"type\": \"text\", \"text\": \"Analyze the objects in this image\"},"
    "    {\"type\": \"image_url\", \"image_url\": {\"url\": \"data:image/jpeg;base64,...\"}}"
    "  ]"
    "}";

LiteRtLm_AppendMessageJson(MyConv, ImageJson);