SendMessage Method  
 

The SendMessage method sends a prompt to the current model and returns the generated response.

Syntax

object.SendMessage( [Prompt], [Response], [MessageId] )

Parameters

Prompt
An optional String which specifes the message prompt which should be sent to the model. If the Prompt parameter is not specified, the method will use the current value of the Prompt property. A prompt cannot consist only of spaces and line break characters. If the prompt does not contain any text, the method will fail.
Response
An optional String passed by reference which will contain the model's response to the prompt when the method returns. If the Response parameter is not specified, the application can obtain the current response by getting the value of the Response property. If this parameter is specified and the method fails, an empty string will be returned.
MessageId
An optional Integer passed by reference which will contain the message ID assigned to the message. If this information is not required, this parameter can be omitted.

Return Value

A value of True is returned if the method succeeds. If the method fails, it will return False and the LastError property will contain the error code.

Remarks

The SendMessage method sends a text prompt to the model and processes the response. This method performs a blocking operation. It will not return until the request has completed, an error has occurred, or the operation has timed out. It is recommended that the user interface provide visual feedback to the user while waiting for the response.

An application which accepts prompts provided by a user 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.

The validation and normalization methods do not perform any semantic analysis of the prompt and do not provide protection against malicious or intentionally misleading input. 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.

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 control 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 MessageId 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. You can retrieve a specific message from the conversation history using the GetMessage method.

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 the ClearHistory method.

The value of the Prompt and Response properties will be updated when this method returns. See the Response property for additional information about text formatting and Unicode handling for model responses.

For simple request and response operations, applications can use the Ask method instead of explicitly calling the Connect, SendMessage and Disconnect methods.

Example

LlmClient1.ProviderName = "Local"
LlmClient1.BaseUrl = "http://127.0.0.1:1234/v1/"
LlmClient1.ModelName = "mistralai/mistral-7b-instruct-v0.3"

' Connect to a locally hosted model using LM Studio
If LlmClient1.Connect() Then
    Dim strPrompt As String
    Dim strResponse As String
    Dim nMessageId As Long

    strPrompt = "How do you calculate the volume of a sphere?"

    ' Send the prompt to the model and display the response
    If LlmClient1.SendMessage(strPrompt, strResponse, nMessageId) Then
        MsgBox strResponse, vbInformation, "Message " & nMessageId
    Else
        MsgBox LlmClient1.LastErrorString, vbExclamation, "Error"
    End If

    LlmClient1.Disconnect
Else
    ' Unable to connect to the local server
    MsgBox LlmClient1.LastErrorString, vbExclamation, "Error"
End If  

See Also

Prompt Property, Response Property, TotalTokens Property, Ask Method, ClearHistory Method, GetMessage Method