OpenAICompatibleWebClient

OpenAICompatibleWebClient class

A built-in IAIWebClient implementation that connects to an OpenAI-compatible LLM provider at a specified base URL.

OpenAICompatibleWebClient

NameDescription
OpenAICompatibleWebClient(String, String, String)Creates an instance of the OpenAI-compatible web client.

Parameters:

NameTypeDescription
modelStringModel name supported by the LLM provider.
apiKeyStringAPI key (token).
baseUrlStringBase URL of the OpenAI-compatible LLM. OpenAICompatibleWebClient aiClient = new OpenAICompatibleWebClient(“model-name”, apiKey, “https://api.llm-provider.com/v1"); try { SlidesAIAgent aiAgent = new SlidesAIAgent(aiClient); Presentation presentation = new Presentation(“Presentation.pptx”); try { aiAgent.translate(presentation, “spanish”); presentation.save(“translated.pptx”, SaveFormat.Pptx); } finally { if (presentation != null) presentation.dispose(); } } finally { if (aiClient != null) aiClient.dispose(); }

Returns: OpenAICompatibleWebClient

Error

ErrorCondition
ArgumentExceptionBase URL value can’t be null or empty.

OpenAICompatibleWebClient

NameDescription
OpenAICompatibleWebClient(String, String, String, HttpURLConnection)Creates an instance of the OpenAI-compatible web client that uses an externally managed HttpURLConnection. The provided HttpURLConnection is not disposed by this instance and remains owned by the caller.

Parameters:

NameTypeDescription
modelStringModel name supported by the LLM provider.
apiKeyStringAPI key (token).
baseUrlStringBase URL of the OpenAI-compatible LLM.
httpClientHttpURLConnectionAn externally managed {@code HttpURLConnection} instance. URL url = new URL(url); HttpURLConnection httpClient = (HttpURLConnection) url.openConnection(); try { OpenAICompatibleWebClient aiClient = new OpenAICompatibleWebClient(“model-name”, apiKey, “https://api.llm-provider.com/v1", httpClient); SlidesAIAgent aiAgent = new SlidesAIAgent(aiClient); Presentation presentation = new Presentation(“Presentation.pptx”); try { aiAgent.translate(presentation, “spanish”); presentation.save(“translated.pptx”, SaveFormat.Pptx); } finally { if (presentation != null) presentation.dispose(); } } finally { if (httpClient != null) httpClient.disconnect(); }

Returns: OpenAICompatibleWebClient

Error

ErrorCondition
ArgumentNullExceptionHttpClient can’t be null.

callChat

NameDescription
callChat (String)Sends a chat instruction to the AI model using an externally managed HttpURLConnection instance and returns response message to the given instruction.

Parameters:

NameTypeDescription
instructionStringThe instruction or message to be processed by the AI model.

Returns: String

Error

ErrorCondition
com.aspose.ms.System.ArgumentExceptionAI chat instruction can’t be null or empty

createConversation

NameDescription
createConversation ()Creates a conversation instance. Unlike regular AI calls, conversations retain the entire context.

Returns: OpenAIConversation


dispose

NameDescription
dispose ()Releases resources used by this instance.