Class FromJson
- java.lang.Object
-
- bg.codexio.ai.openai.api.sdk.auth.FromJson
-
- All Implemented Interfaces:
SdkAuth
public class FromJson extends Object implements SdkAuth
When instantiated andcredentials()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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFromJson.AvailableKeys
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected InputStreamasInputStream()bg.codexio.ai.openai.api.payload.credentials.ApiCredentialscredentials()In this implementation we first look for the apiKey in the provided JSON file
If this variable is missing, aNotValidAuthenticationMethoderror 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
CheckFromJson.AvailableKeysfor the correct naming.static FromJsonfile(String fullPathFileName)Factory method denoting a JSON file with absolute pathstatic FromJsonresource(String resourceFileName)Factory method denoting a JSON resource file with relative path
-
-
-
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, aNotValidAuthenticationMethoderror 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
CheckFromJson.AvailableKeysfor the correct naming.- Specified by:
credentialsin interfaceSdkAuth- Returns:
- ready for usage instance of
ApiCredentials
-
asInputStream
protected InputStream asInputStream() throws IOException
- Throws:
IOException
-
-