Class FromJson

  • All Implemented Interfaces:
    SdkAuth

    public class FromJson
    extends Object
    implements SdkAuth
    When instantiated and credentials() is called, already configured json file is scanned for credentials. The default expected file name is openai-credentials.json
    and read as a resource (so it should reside in resources folder). The file name and the path type can be modified by calling some of the factory functions below.
    • Field Detail

      • AUTH

        public static final FromJson AUTH
    • Method Detail

      • resource

        public static FromJson resource​(String resourceFileName)
        Factory method denoting a JSON resource file with relative path
        Parameters:
        resourceFileName - the relative path of the JSON resource
        Returns:
        new instance of the current class with configured credentials field
      • file

        public static FromJson file​(String fullPathFileName)
        Factory method denoting a JSON file with absolute path
        Parameters:
        fullPathFileName - the absolute path of the JSON file
        Returns:
        new instance of the current class with configured credentials field
      • credentials

        public bg.codexio.ai.openai.api.payload.credentials.ApiCredentials credentials()
        In this implementation we first look for the apiKey in the provided JSON file
        If this variable is missing, a NotValidAuthenticationMethod error is thrown, as the authentication can never proceed without an api key.
        If orgId or organizationId is configured, it is applied, otherwise the default empty value is used
        Check FromJson.AvailableKeys for the correct naming.
        Specified by:
        credentials in interface SdkAuth
        Returns:
        ready for usage instance of ApiCredentials