Ask Method  
 

Sends a prompt to the current model and returns the response as a String value.

Syntax

object.Ask( [Prompt] )

Parameters

Prompt
A String value which specifes the message prompt which should be sent to the current 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.

Return Value

If the method succeeds, the return value is a String which contains the response generated by the current model. If the method fails, the return value will be an empty string. Extended error information can be obtained using the LastError property.

Remarks

This method provides a simplified way to send a single prompt to a model and return the generated response. Unlike the Connect, SendMessage and Disconnect methods, this method manages the connection automatically and is intended for simple request and response operations.

If there is no active connection to a service provider, the method will establish a temporary connection using the current values of the ProviderName, ModelName, BaseUrl and ApiKey properties. After the response has been returned, the temporary connection will be closed automatically.

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.

This method does not preserve conversation history between calls. Applications which require conversational context, persistent connections or advanced session management should use the Connect, SendMessage and Disconnect methods instead.

If the method succeeds but the model does not return any text, the return value will be an empty string and the LastError property will return zero.

Example

Dim strResponse As String

LlmClient1.ProviderName = "OpenAI"
LlmClient1.ModelName = "gpt-5.4-nano"
LlmClient1.ApiKey = "%OPENAI_API_KEY%"

strResponse = LlmClient1.Ask("How do you calculate the volume of a sphere?")

If Len(strResponse) > 0 Then
    MsgBox strResponse, vbInformation
Else
    If LlmClient1.LastError = 0 Then
        MsgBox "There was no response to this question", vbInformation
    Else
        MsgBox LlmClient1.LastErrorString, vbExclamation
    End If
End If  

See Also

ApiKey Property, BaseUrl Property, ModelName Property, Prompt Property, Provider Property, ProviderName Property, Response Property, TotalTokens Property, Connect Method, SendMessage Method