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.
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