Class OpenAiSetup
java.lang.Object
org.springframework.ai.openai.setup.OpenAiSetup
Helps configure the OpenAI Java SDK, depending on the platform used. This code is
inspired by LangChain4j's
`dev.langchain4j.model.openaiofficial.InternalOpenAiOfficialHelper` class, which is
coded by the same author (Julien Dubois, from Microsoft).
- Author:
- Julien Dubois
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenAiSetup.ModelProviderdetectModelProvider(boolean isMicrosoftFoundry, boolean isGitHubModels, @Nullable String baseUrl, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAIServiceVersion) static com.openai.client.OpenAIClientAsyncsetupAsyncClient(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAiServiceVersion, @Nullable String organizationId, boolean isAzure, boolean isGitHubModels, @Nullable String modelName, Duration timeout, int maxRetries, @Nullable Proxy proxy, @Nullable Map<String, String> customHeaders, io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry, @Nullable ExecutorService dispatcherExecutor) static com.openai.client.OpenAIClientsetupSyncClient(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAiServiceVersion, @Nullable String organizationId, boolean isAzure, boolean isGitHubModels, @Nullable String modelName, Duration timeout, int maxRetries, @Nullable Proxy proxy, @Nullable Map<String, String> customHeaders, io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry, @Nullable ExecutorService dispatcherExecutor) Sets up a synchronous OpenAI client.
-
Method Details
-
setupSyncClient
public static com.openai.client.OpenAIClient setupSyncClient(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAiServiceVersion, @Nullable String organizationId, boolean isAzure, boolean isGitHubModels, @Nullable String modelName, Duration timeout, int maxRetries, @Nullable Proxy proxy, @Nullable Map<String, String> customHeaders, io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry, @Nullable ExecutorService dispatcherExecutor) Sets up a synchronous OpenAI client.When
apiKeyis an empty string, the client is configured in no-auth mode: noAuthorizationheader is sent with any request. This is useful for connecting to custom OpenAI-compatible servers that use cookie-based or other non-bearer-token authentication. To enable this mode, setspring.ai.openai.api-key=(empty value) in your application properties, or pass aNoopApiKeyviaAbstractOpenAiOptions.AbstractBuilder.apiKey(org.springframework.ai.model.ApiKey). -
setupAsyncClient
public static com.openai.client.OpenAIClientAsync setupAsyncClient(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAiServiceVersion, @Nullable String organizationId, boolean isAzure, boolean isGitHubModels, @Nullable String modelName, Duration timeout, int maxRetries, @Nullable Proxy proxy, @Nullable Map<String, String> customHeaders, io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry, @Nullable ExecutorService dispatcherExecutor) -
detectModelProvider
public static OpenAiSetup.ModelProvider detectModelProvider(boolean isMicrosoftFoundry, boolean isGitHubModels, @Nullable String baseUrl, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAIServiceVersion)
-