The SendMessage method provides a simplified interface for
sending a single text prompt to the model and receiving the response
as a string. This method is intended for applications that do not
require structured input or detailed control over message formatting.
This method will not return until the request has completed, an
error has occurred, or the operation has timed out. Applications that
call this method from a user interface thread should provide visual
feedback while waiting for the response, or perform the request on
a background thread to maintain responsiveness.
Applications that accept user input should apply appropriate
validation, filtering, or normalization before sending requests to the
service provider. The ValidateText method verifies that
the prompt contains valid message text and the NormalizeText
method can be used to normalize text formatting. These functions do
not perform any semantic analysis of the prompt and do not provide
protection against malicious or intentionally misleading input.
This method does not validate or restrict the content of the input
message. It is the responsibility of the application to ensure that
user-provided input is appropriate for its intended use. This includes
considering scenarios where input may attempt to override instructions,
inject unintended prompts, or otherwise influence the behavior of the
model.
The response is written to the buffer specified by lpszResponse.
If the buffer is not large enough to contain the complete response,
the text will be truncated. The lpdwLength parameter will
always contain the number of characters actually copied to the buffer.
Line breaks in the response text are normalized before being stored
in the client history. Line feed and carriage return characters are
converted to the standard Windows CRLF end-of-line sequence, ensuring
consistent formatting across different providers and applications.
This also helps ensure compatibility with Windows common controls and
other user interface components.
Some models are capable of performing additional internal reasoning
before generating a response. The amount of reasoning performed and
whether it is exposed by the provider is model-specific. The library
returns the final response intended for the user and does not
currently expose model reasoning or intermediate processing steps.
This behavior ensures consistent results across providers, regardless
of how individual models implement or expose reasoning capabilities.
If the lpdwMessageId parameter is specified, it will receive
a unique identifier for the message within the current client session.
Message identifiers are assigned sequentially, but applications should
treat them as opaque values. They are only guaranteed to be unique
within a single session and should not be compared across different
client sessions.
This method automatically adds the message to the conversation
history for the session. Subsequent calls will include previous messages
as context, subject to any configured history or token limits. To clear
the conversation context, call ClearHistory or
ResetSession.
Applications that require more advanced features, such as structured
messages, role-based input, or access to detailed response metadata,
should use the SendMessageEx method instead.
#include "cstools12.h"
#include <stdio.h>
int _tmain(void)
{
CLlmClient llmClient;
// Establish a connection to OpenAI using the default endpoint
// and a lightweight model
BOOL bConnected = llmClient.Connect(
LLM_PROVIDER_OPENAI,
LLM_OPTION_DEFAULT,
LLM_TIMEOUT,
NULL, // Use default base URL
_T("gpt-6-luna"), // Model name
_T("%OPENAI_API_KEY%") // Provider API key
);
if (!bConnected)
{
dwError = llmClient.GetLastError();
_tprintf(_T("Unable to connect, error %lu\n"), dwError);
return 1;
}
TCHAR szResponse[4096] = {0};
DWORD dwResponseLength = _countof(szResponse); // number of TCHARs
DWORD dwMessageId = 0;
// Send a simple message to the model
if (llmClient.SendMessage(
_T("What is the capital city of Denmark?"),
szResponse,
&dwResponseLength,
&dwMessageId))
{
_tprintf(_T("Response:\n%s\n"), szResponse);
}
else
{
dwError = llmClient.GetLastError();
_tprintf(_T("Request failed, error %lu\n"), dwError);
}
// Close the connection explicitly
llmClient.Disconnect();
return 0;
}