OpenAICompatibleWebClient

Inheritance: java.lang.Object

All Implemented Interfaces: com.aspose.slides.IAIWebClient, com.aspose.ms.System.IDisposable

public final class OpenAICompatibleWebClient implements IAIWebClient, System.IDisposable

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

Constructors

ConstructorDescription
OpenAICompatibleWebClient(String model, String apiKey, String baseUrl)Creates an instance of the OpenAI-compatible web client.
OpenAICompatibleWebClient(String model, String apiKey, String baseUrl, HttpURLConnection httpClient)Creates an instance of the OpenAI-compatible web client that uses an externally managed HttpURLConnection .

Methods

MethodDescription
callChat(String instruction)Sends a chat instruction to the AI model using an externally managed HttpURLConnection instance and returns response message to the given instruction.
createConversation()Creates a conversation instance.
dispose()Releases resources used by this instance.

OpenAICompatibleWebClient(String model, String apiKey, String baseUrl)

public OpenAICompatibleWebClient(String model, String apiKey, String baseUrl)

Creates an instance of the OpenAI-compatible web client.

Parameters:

ParameterTypeDescription
modeljava.lang.StringModel name supported by the LLM provider.
apiKeyjava.lang.StringAPI key (token).
baseUrljava.lang.StringBase 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();
 }
``` |

### OpenAICompatibleWebClient(String model, String apiKey, String baseUrl, HttpURLConnection httpClient) {#OpenAICompatibleWebClient-java.lang.String-java.lang.String-java.lang.String-java.net.HttpURLConnection-}

public OpenAICompatibleWebClient(String model, String apiKey, String baseUrl, HttpURLConnection httpClient)



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:**
| Parameter | Type | Description |
| --- | --- | --- |
| model | java.lang.String | Model name supported by the LLM provider. |
| apiKey | java.lang.String | API key (token). |
| baseUrl | java.lang.String | Base URL of the OpenAI-compatible LLM. |
| httpClient | java.net.HttpURLConnection | An externally managed  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(); }


### callChat(String instruction) {#callChat-java.lang.String-}

public String callChat(String instruction)



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

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| instruction | java.lang.String | The instruction or message to be processed by the AI model. |

**Returns:**
java.lang.String - The message generated by the AI model in response to the given instruction.
### createConversation() {#createConversation--}

public final IAIConversation createConversation()



Creates a conversation instance. Unlike regular AI calls, conversations retain the entire context.

**Returns:**
[IAIConversation](../../com.aspose.slides/iaiconversation) - An [IAIConversation](../../com.aspose.slides/iaiconversation) instance.
### dispose() {#dispose--}

public final void dispose()



Releases resources used by this instance.