Class OpenAIClientProvider


  • public class OpenAIClientProvider
    extends Object
    Builds an OpenAI client instance, see SettingsMap documentation for details on how the settings are loaded.

    If clientType is not set via OPENAI_CLIENT_TYPE setting, then this will attempt to first instantiate an OpenAI client, and if that fails, then it will attempt to instantiate an Azure OpenAI client.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static com.azure.ai.openai.OpenAIAsyncClient get​(List<File> propertyFileLocations)
      Get a client, overrides the default locations that are searched for settings
      static com.azure.ai.openai.OpenAIAsyncClient get​(List<File> propertyFileLocations, ClientType clientType)
      Get a client, overrides the default locations that are searched for settings
      com.azure.ai.openai.OpenAIAsyncClient getAsyncClient()
      Builds an OpenAI client instance, the settings for the client are loaded from the following sources in the order of precedence (lower number in this list overrides a higher number): 1.
      static com.azure.ai.openai.OpenAIAsyncClient getClient()
      Builds an OpenAI client instance, see SettingsMap documentation for details on how the settings are loaded.
      static com.azure.ai.openai.OpenAIAsyncClient getWithAdditional​(List<File> propertyFileLocations)
      Get a client, looks for settings in the default locations as defined by this class, PLUS the additional locations provided
      static com.azure.ai.openai.OpenAIAsyncClient getWithAdditional​(List<File> propertyFileLocations, ClientType clientType)
      Get a client, looks for settings in the default locations as defined by this class, PLUS the additional locations provided
    • Constructor Detail

      • OpenAIClientProvider

        public OpenAIClientProvider​(Map<String,​String> configuredSettings,
                                    @Nullable
                                    ClientType clientType)
        Create a new OpenAI client provider
        Parameters:
        configuredSettings - settings to use to configure the client
        clientType - client type
    • Method Detail

      • get

        public static com.azure.ai.openai.OpenAIAsyncClient get​(List<File> propertyFileLocations,
                                                                @Nullable
                                                                ClientType clientType)
                                                         throws ConfigurationException
        Get a client, overrides the default locations that are searched for settings
        Parameters:
        propertyFileLocations - locations to look for settings in
        clientType - client type
        Returns:
        A client instance
        Throws:
        ConfigurationException - if the settings are not found
      • get

        public static com.azure.ai.openai.OpenAIAsyncClient get​(List<File> propertyFileLocations)
                                                         throws ConfigurationException
        Get a client, overrides the default locations that are searched for settings
        Parameters:
        propertyFileLocations - locations to look for settings in
        Returns:
        A client instance
        Throws:
        ConfigurationException - if the settings are not found
      • getWithAdditional

        public static com.azure.ai.openai.OpenAIAsyncClient getWithAdditional​(List<File> propertyFileLocations,
                                                                              @Nullable
                                                                              ClientType clientType)
                                                                       throws ConfigurationException
        Get a client, looks for settings in the default locations as defined by this class, PLUS the additional locations provided
        Parameters:
        propertyFileLocations - additional locations to look for settings
        clientType - client type
        Returns:
        A client instance
        Throws:
        ConfigurationException
      • getWithAdditional

        public static com.azure.ai.openai.OpenAIAsyncClient getWithAdditional​(List<File> propertyFileLocations)
                                                                       throws ConfigurationException
        Get a client, looks for settings in the default locations as defined by this class, PLUS the additional locations provided
        Parameters:
        propertyFileLocations - additional locations to look for settings
        Returns:
        A client instance
        Throws:
        ConfigurationException
      • getClient

        public static com.azure.ai.openai.OpenAIAsyncClient getClient()
                                                               throws ConfigurationException
        Builds an OpenAI client instance, see SettingsMap documentation for details on how the settings are loaded.
        Returns:
        A client instance
        Throws:
        ConfigurationException - If the settings are not found
      • getAsyncClient

        public com.azure.ai.openai.OpenAIAsyncClient getAsyncClient()
                                                             throws ConfigurationException
        Builds an OpenAI client instance, the settings for the client are loaded from the following sources in the order of precedence (lower number in this list overrides a higher number):
        • 1. Environment variables.
        • 2. System properties.
        • 3. Properties file set via CONF_PROPERTIES environment variable.
        • 4. Properties file: ./conf.properties (Not used if CONF_PROPERTIES was set).
        • 5. Properties file: ~/.sk/conf.properties (Not used if CONF_PROPERTIES was set).

        If clientType is not set via OPENAI_CLIENT_TYPE setting, then this will attempt to first instantiate an OpenAI client, and if that fails, then it will attempt to instantiate an Azure OpenAI client.

        Returns:
        A client instance
        Throws:
        ConfigurationException - If the settings are not found