LlmGetFirstMessage Function  
 
BOOL WINAPI LlmGetFirstMessage(
  HCLIENT hClient,  
  DWORD dwReserved,  
  LPLLM_MESSAGE lpMessage,  
  LPLLM_RESPONSE lpResponse  
);

The LlmGetFirstMessage function returns the first available message in the client history.

Parameters

hClient
A handle to the client session.
dwReserved
An integer value reserved for future use. This parameter should always be zero.
lpMessage
A pointer to an LLM_MESSAGE structure that receives information about the client request. This parameter may be NULL, in which case no message information is returned.
lpResponse
A pointer to an LLM_RESPONSE structure that receives information about the server response. This parameter may be NULL, in which case no response information is returned.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call LlmGetLastError. If there are no messages in the client history, the error code will be set to ST_ERROR_END_OF_MESSAGES.

Remarks

The LlmGetFirstMessage function retrieves the first message and associated response from the client session history. This function is typically used in conjunction with the LlmGetNextMessage function to enumerate all messages in the session.

If the lpMessage and/or lpResponse parameters are specified, their respective structures must be initialized with the dwSize member set to the size of the structure before calling this function. This enables the library to validate the structure version and maintain compatibility with future releases.

Messages are returned in chronological order, beginning with the oldest message in the client history. New messages are always appended to the end of the history, and if the history is trimmed, older messages are removed first. The order of messages is stable and reflects the sequence in which they were submitted.

If there are no messages in the client history, the function fails and sets the error code to ST_ERROR_END_OF_MESSAGES. Applications can use this condition to determine that no messages are available for enumeration.

Either the lpMessage or lpResponse parameter may be NULL if only one type of information is required. At least one of these parameters must be specified. If both parameters are NULL, the function fails and sets the error code to ST_ERROR_INVALID_PARAMETER.

Example

// Enumerate the message history and display message details
LLM_MESSAGE clientMessage = { sizeof(LLM_MESSAGE), 0 };
LLM_RESPONSE serverResponse = { sizeof(LLM_RESPONSE), 0 };

if (LlmGetFirstMessage(hClient, 0, &clientMessage, &serverResponse))
{
    do
    {
        _tprintf(_T("\nMessage %u\n"), clientMessage.dwMessageId);
        _tprintf(_T("  Input Tokens:    %u\n"), clientMessage.nInputTokens);
        _tprintf(_T("  Content Length:  %u\n"), clientMessage.nContentLength);
        _tprintf(_T("  Content:         \"%s\"\n"), clientMessage.lpszContent);

        _tprintf(_T("\nResponse %u\n"), serverResponse.dwMessageId);
        _tprintf(_T("  Elapsed:         %u ms\n"), serverResponse.dwElapsed);
        _tprintf(_T("  Output Tokens:   %u\n"), serverResponse.nOutputTokens);
        _tprintf(_T("  Content Length:  %u\n"), serverResponse.nContentLength);
        _tprintf(_T("  Content:         \"%s\"\n"), serverResponse.lpszContent);
        _tprintf(_T("  Response ID:     %s\n"), (serverResponse.lpszResponseId ? serverResponse.lpszResponseId : _T("None")));
        _tprintf(_T("  Model Name:      %s\n"), (serverResponse.lpszModelName ? serverResponse.lpszModelName : _T("None")));
        _tprintf(_T("  Status Text:     %s\n"), (serverResponse.lpszStatusText ? serverResponse.lpszStatusText : _T("None")));
    }
    while (LlmGetNextMessage(hClient, &clientMessage, &serverResponse));
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

LlmGetNextMessage, LlmGetHistorySize, LlmGetMessageById