| |
| BOOL WINAPI LlmConvertTimestamp( |
| |
TIME_T tTimestamp, |
|
| |
LPSYSTEMTIME lpSystemTime |
|
| |
BOOL bLocalTime |
|
| ); |
The LlmConvertTimestamp function converts a message or
response timestamp to a SYSTEMTIME structure.
Parameters
- tTimestamp
- A 64-bit timestamp value associated with a message or response.
This value represents the number of seconds that have elapsed since
January 1, 1970 UTC.
- lpSystemTime
- A pointer to a
SYSTEMTIME structure that receives the
converted date and time value.
- bLocalTime
- If this parameter is non-zero, the timestamp is converted to the
local system time. If this parameter is zero, the timestamp is converted
to Coordinated Universal Time (UTC).
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.
Remarks
The LlmConvertTimestamp function converts an internal
timestamp value used by the library into a standard
SYSTEMTIME structure. This allows applications to display
message and response times in a human-readable format. These
timestamps are used in the client history of requests sent to the
model and the responses it returned.
The tTimestamp parameter is a standard 64-bit Unix time
value and can be used interchangeably with functions in the C standard
library such as gmtime or localtime. Because
it is a 64-bit integer, it is not impacted by the Year 2038 problem.
Timestamps are returned by functions such as LlmSendMessage and
can be converted into a local date and time using the LlmConvertTimestamp
function.
The converted time can be returned as either local time or UTC by
specifying the bLocalTime parameter. Applications should use
local time for display purposes and UTC when storing or comparing
timestamps across systems. The SYSTEMTIME value can be formatted using
standard Windows functions such as GetDateFormatEx and
GetTimeFormatEx to display locale-specific date and time values.
If you wish to convert the message timestamp to a standardized ISO
8601 string value, use the LlmFormatTimestamp function.
Example
LLM_MESSAGE clientMessage = { sizeof(LLM_MESSAGE), 0 };
LLM_RESPONSE serverResponse = { sizeof(LLM_RESPONSE), 0 };
if (LlmGetFirstMessage(hClient, 0, &clientMessage, &serverResponse))
{
do
{
SYSTEMTIME stMessage = {0};
TCHAR szDate[64] = {0};
TCHAR szTime[64] = {0};
LlmConvertTimestamp(clientMessage.tTimestamp, &stMessage, TRUE);
GetDateFormat(LOCALE_USER_DEFAULT, 0,
&stMessage, NULL,
szDate, _countof(szDate));
GetTimeFormat(LOCALE_USER_DEFAULT, 0,
&stMessage, NULL,
szTime, _countof(szTime));
_tprintf(_T("\nMessage %u\n"), clientMessage.dwMessageId);
_tprintf(_T(" Timestamp: %s %s\n"), szDate, szTime);
_tprintf(_T(" Input Tokens: %u\n"), clientMessage.nInputTokens);
_tprintf(_T(" Content Length: %u\n"), clientMessage.nContentLength);
_tprintf(_T(" Content: \"%s\"\n"), clientMessage.lpszContent);
SYSTEMTIME stResponse = {0};
LlmConvertTimestamp(serverResponse.tTimestamp, &stResponse, TRUE);
GetDateFormat(LOCALE_USER_DEFAULT, 0,
&stResponse, NULL,
szDate, _countof(szDate));
GetTimeFormat(LOCALE_USER_DEFAULT, 0,
&stResponse, NULL,
szTime, _countof(szTime));
_tprintf(_T("\nResponse %u\n"), serverResponse.dwMessageId);
_tprintf(_T(" Timestamp: %s %s\n"), szDate, szTime);
_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));
}
This example uses the GetDateFormat and GetTimeFormat
functions for simplicity and compatibility with both ANSI and Unicode
builds. On current Windows platforms, applications should prefer using
GetDateFormatEx and GetTimeFormatEx, which provide improved
locale support and are recommended for new development. Note that these newer
functions are implemented as Unicode-only APIs.
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
See Also
LlmGetFirstMessage,
LlmFormatTimestamp,
LlmGetNextMessage,
LlmSendMessageEx,
LLM_MESSAGE,
LLM_RESPONSE
|
|