Credential object securely stores API key from your AI provider for use by Oracle Database. The following table shows AI Provider and corresponding credential object format
AI Provider |
Credential format |
|---|---|
Anthropic |
{"username": "anthropic", "password": "sk-xxx"}
|
HuggingFace |
{"username": "hf", "password": "hf_xxx"}
|
OCI Gen AI |
{"user_ocid": "", "tenancy_ocid": "", "private_key": "", "fingerprint": ""}
|
OpenAI |
{"username": "openai", "password": "sk-xxx"}
|
1. Create credential¶
In this example, we create a credential object to authenticate to OCI Gen AI service provider:
1.1. Sync API¶
import os
import oci
import select_ai
user = os.getenv("SELECT_AI_USER")
password = os.getenv("SELECT_AI_PASSWORD")
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
select_ai.connect(user=user, password=password, dsn=dsn)
# Default config file and profile
default_config = oci.config.from_file()
oci.config.validate_config(default_config)
with open(default_config["key_file"]) as fp:
key_contents = fp.read()
credential = {
"credential_name": "my_oci_ai_profile_key",
"user_ocid": default_config["user"],
"tenancy_ocid": default_config["tenancy"],
"private_key": key_contents,
"fingerprint": default_config["fingerprint"],
}
select_ai.create_credential(credential=credential, replace=True)
print("Created credential: ", credential["credential_name"])
output:
Created credential: my_oci_ai_profile_key
1.2. Async API¶
import asyncio
import os
import oci
import select_ai
user = os.getenv("SELECT_AI_USER")
password = os.getenv("SELECT_AI_PASSWORD")
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
async def main():
await select_ai.async_connect(user=user, password=password, dsn=dsn)
default_config = oci.config.from_file()
oci.config.validate_config(default_config)
with open(default_config["key_file"]) as fp:
key_contents = fp.read()
credential = {
"credential_name": "my_oci_ai_profile_key",
"user_ocid": default_config["user"],
"tenancy_ocid": default_config["tenancy"],
"private_key": key_contents,
"fingerprint": default_config["fingerprint"],
}
await select_ai.async_create_credential(
credential=credential, replace=True
)
print("Created credential: ", credential["credential_name"])
asyncio.run(main())
output:
Created credential: my_oci_ai_profile_key