Skip to contents

A wrapper around get_reply() to retrieve the most recent assistant reply.

Usage

last_reply(.llm, .raw = FALSE)

Arguments

.llm

A LLMMessage object.

.raw

A logical value indicating whether to return the raw text even if the message is marked as JSON. Defaults to FALSE, meaning the function will attempt to parse the JSON.

Value

Returns the content of the assistant's reply at the specified index, based on the following conditions:

  • If there are no assistant replies, NULL is returned.

  • If the reply is marked as JSON and parsing is successful, a list containing:

    • parsed_content: The parsed JSON content.

    • raw_response: The original raw content.

    • json: A flag indicating successful JSON parsing (TRUE).

  • If JSON parsing fails, a list containing:

    • parsed_content: NULL.

    • raw_response: The original raw content.

    • json: FALSE.

  • If .raw is TRUE or the message is not marked as JSON, returns the raw text content directly.