[oci_generative_ai] Option to pass auth_file_location (#29481)

**PR title**: "community: Option to pass auth_file_location for
oci_generative_ai"

**Description:** Option to pass auth_file_location, to overwrite config
file default location "~/.oci/config" where profile name configs
present. This is not fixing any issues. Just added optional parameter
called "auth_file_location", which internally supported by any OCI
client including GenerativeAiInferenceClient.
This commit is contained in:
Ashutosh Kumar
2025-02-04 08:14:13 +05:30
committed by GitHub
parent aeb42dc900
commit 65b404a2d1
5 changed files with 36 additions and 12 deletions

View File

@@ -29,6 +29,9 @@ class OCIGenAIEmbeddings(BaseModel, Embeddings):
Make sure you have the required policies (profile/roles) to
access the OCI Generative AI service. If a specific config profile is used,
you must pass the name of the profile (~/.oci/config) through auth_profile.
If a specific config file location is used, you must pass
the file location where profile name configs present
through auth_file_location
To use, you must provide the compartment id
along with the endpoint url, and model id
@@ -66,6 +69,11 @@ class OCIGenAIEmbeddings(BaseModel, Embeddings):
If not specified , DEFAULT will be used
"""
auth_file_location: Optional[str] = "~/.oci/config"
"""Path to the config file.
If not specified, ~/.oci/config will be used
"""
model_id: Optional[str] = None
"""Id of the model to call, e.g., cohere.embed-english-light-v2.0"""
@@ -108,7 +116,8 @@ class OCIGenAIEmbeddings(BaseModel, Embeddings):
if values["auth_type"] == OCIAuthType(1).name:
client_kwargs["config"] = oci.config.from_file(
profile_name=values["auth_profile"]
file_location=values["auth_file_location"],
profile_name=values["auth_profile"],
)
client_kwargs.pop("signer", None)
elif values["auth_type"] == OCIAuthType(2).name:
@@ -124,7 +133,8 @@ class OCIGenAIEmbeddings(BaseModel, Embeddings):
return oci.auth.signers.SecurityTokenSigner(st_string, pk)
client_kwargs["config"] = oci.config.from_file(
profile_name=values["auth_profile"]
file_location=values["auth_file_location"],
profile_name=values["auth_profile"],
)
client_kwargs["signer"] = make_security_token_signer(
oci_config=client_kwargs["config"]
@@ -151,11 +161,11 @@ class OCIGenAIEmbeddings(BaseModel, Embeddings):
) from ex
except Exception as e:
raise ValueError(
"Could not authenticate with OCI client. "
"Please check if ~/.oci/config exists. "
"If INSTANCE_PRINCIPLE or RESOURCE_PRINCIPLE is used, "
"Please check the specified "
"auth_profile and auth_type are valid."
"""Could not authenticate with OCI client.
If INSTANCE_PRINCIPAL or RESOURCE_PRINCIPAL is used,
please check the specified
auth_profile, auth_file_location and auth_type are valid.""",
e,
) from e
return values