| |
| BOOL WINAPI LlmDeleteSession( |
| |
LPLLM_SESSION *lppSession |
|
| ); |
The LlmDeleteSession function releases an
LLM_SESSION structure allocated by LlmCreateSession
or LlmCreateSessionEx.
Parameters
- lppSession
- A pointer to a variable that contains a pointer to an
LLM_SESSION structure previously allocated by
LlmCreateSession or LlmCreateSessionEx. On successful return,
the pointer is set to NULL.
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 LlmDeleteSession function releases the memory allocated for
an LLM_SESSION structure created by LlmCreateSession
or LlmCreateSessionEx. This function should be used only with
session structures allocated by the library.
Do not call this function with an LLM_SESSION structure
allocated by the application, declared on the stack, or embedded in
another structure. Only the exact pointer returned by
LlmCreateSession or LlmCreateSessionEx should be passed to
this function. Passing any other pointer may cause the application to
fail.
After a session structure has been used with LlmConnectEx, it
may be deleted immediately. The library makes an internal copy of the
session configuration when the client session is created, so the
original structure does not need to remain allocated for the lifetime of
the client handle.
This function does not disconnect an active client session. To close a
connection created by LlmConnect or LlmConnectEx, call
LlmDisconnect.
Example
#include "cstools12.h"
#include <stdio.h>
int _tmain(void)
{
HCLIENT hClient = INVALID_CLIENT;
LPLLM_SESSION lpSession = NULL;
DWORD dwError = NO_ERROR;
// Initialize the SocketTools library
if (!LlmInitialize(CSTOOLS12_LICENSE_KEY, NULL))
{
_tprintf(_T("Initialization failed: %lu\n"), LlmGetLastError());
return 1;
}
// Create a session structure using helper function
if (!LlmCreateSession(LLM_PROVIDER_OPENAI,
NULL, // Default base URL
_T("gpt-5.4-nano"), // Model name
_T("%OPENAI_API_KEY%"), // Provider API key
NULL, // API version
&lpSession))
{
dwError = LlmGetLastError();
_tprintf(_T("Unable to create session, error %lu\n"), dwError);
LlmUninitialize();
return 1;
}
// Establish a connection using the session structure
hClient = LlmConnectEx(LLM_PROVIDER_OPENAI,
LLM_OPTION_DEFAULT,
lpSession);
if (hClient == INVALID_CLIENT)
{
dwError = LlmGetLastError();
_tprintf(_T("Unable to connect, error %lu\n"), dwError);
// Clean up session before exit
LlmDeleteSession(&lpSession);
LlmUninitialize();
return 1;
}
// The session structure is no longer needed after connecting
LlmDeleteSession(&lpSession);
TCHAR szResponse[4096] = {0};
DWORD dwResponseLength = _countof(szResponse);
DWORD dwMessageId = 0;
if (LlmSendMessage(hClient,
0,
_T("What is the capital city of Denmark?"),
szResponse,
&dwResponseLength,
&dwMessageId))
{
_tprintf(_T("Response:\n%s\n"), szResponse);
}
else
{
dwError = LlmGetLastError();
_tprintf(_T("Request failed, error %lu\n"), dwError);
}
LlmDisconnect(hClient);
LlmUninitialize();
return 0;
}
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
LlmCreateSession,
LlmCreateSessionEx,
LlmConnectEx,
LlmDisconnect,
LLM_SESSION
|
|