-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
65 lines (53 loc) · 2.21 KB
/
Copy pathutils.py
File metadata and controls
65 lines (53 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import argparse
import os
import oci
def make_security_token_signer(oci_config):
pk = oci.signer.load_private_key_from_file(oci_config.get("key_file"), None)
with open(oci_config.get("security_token_file")) as f:
st_string = f.read()
return oci.auth.signers.SecurityTokenSigner(st_string, pk)
def get_generative_ai_dp_client(endpoint, profile, use_session_token):
config = oci.config.from_file('~/.oci/config', profile)
if use_session_token:
signer = make_security_token_signer(oci_config=config)
return oci.generative_ai_inference.GenerativeAiInferenceClient(config=config, signer=signer, service_endpoint=endpoint, timeout=(10,240))
else:
return oci.generative_ai_inference.GenerativeAiInferenceClient(config=config, service_endpoint=endpoint, timeout=(10,240))
def initArgs():
parser = argparse.ArgumentParser()
parser.add_argument("--st", action="store_true", help="use session token")
return parser.parse_args()
# regions:
# us-chicago
# eu-frankfurt-1
# ap-tokyo-1
# ap-osaka-1
# ca-montreal-1
def getEnvVariables():
region = "us-chicago-1"
profile = "DEFAULT"
compartment = "<compartment_ocid>"
stage = "prod"
if os.getenv("GENAI_REGION") != None:
region = os.getenv("GENAI_REGION")
if os.getenv("GENAI_STAGE") != None:
stage = os.getenv("GENAI_STAGE")
if os.getenv("GENAI_PROFILE") != None:
profile = os.getenv("GENAI_PROFILE")
if os.getenv("GENAI_COMPARTMENT") != None:
compartment = os.getenv("GENAI_COMPARTMENT")
return (region, stage, profile, compartment)
def getEndpoint(region, stage):
if stage == "prod":
return f"https://inference.generativeai.{region}.oci.oraclecloud.com"
elif stage == "dev":
return f"https://dev.inference.generativeai.{region}.oci.oraclecloud.com"
elif stage == "ppe":
return f"https://ppe.inference.generativeai.{region}.oci.oraclecloud.com"
else:
print("Provide stage via env variable GENAI_STAGE: dev/ppe/prod")
quit()
def checkCompartmentPresent(compartment_id):
if "<compartment_ocid>" in compartment_id:
print("ERROR:Please update your compartment id via env variable GENAI_COMPARMENT")
quit()