32
32
from langchain_ollama import ChatOllama
33
33
from langchain_openai import ChatOpenAI
34
34
35
+ from langchain_community .chat_models .oci_generative_ai import ChatOCIGenAI
36
+
37
+
35
38
from llama_index .core import Document
36
39
from llama_index .core .node_parser import SentenceSplitter
37
40
@@ -102,7 +105,8 @@ def get_ll_model(model, ll_models_config=None, giskarded=False):
102
105
"frequency_penalty" : lm_params ["frequency_penalty" ][0 ],
103
106
"presence_penalty" : lm_params ["presence_penalty" ][0 ],
104
107
}
105
-
108
+ logger .info ("LLM_API:" + llm_api )
109
+
106
110
## Start - Add Additional Model Authentication Here
107
111
client = None
108
112
if giskarded :
@@ -117,6 +121,17 @@ def get_ll_model(model, ll_models_config=None, giskarded=False):
117
121
client = ChatPerplexity (pplx_api_key = lm_params ["api_key" ], model_kwargs = common_params )
118
122
elif llm_api == "ChatOllama" :
119
123
client = ChatOllama (model = model ,base_url = lm_params ["url" ], model_kwargs = common_params )
124
+ elif llm_api == "CohereOCI" :
125
+ #state.oci_config["tenancy_ocid"]
126
+ client = ChatOCIGenAI (
127
+ model_id = model ,
128
+ service_endpoint = lm_params ["url" ],
129
+ compartment_id = os .environ .get ("OCI_COMPARTMENT_ID" , default = "" ),
130
+ auth_profile = lm_params ["api_key" ],
131
+ model_kwargs = {"temperature" : common_params ["temperature" ], "max_tokens" : common_params ["max_tokens" ],"top_p" : common_params ["top_p" ],
132
+ "frequency_penalty" : common_params ["frequency_penalty" ], "presence_penalty" : common_params ["presence_penalty" ]}
133
+ )
134
+
120
135
## End - Add Additional Model Authentication Here
121
136
api_accessible , err_msg = is_url_accessible (llm_url )
122
137
@@ -134,6 +149,7 @@ def get_embedding_model(model, embed_model_config=None, giskarded=False):
134
149
embed_key = embed_model_config [model ]["api_key" ]
135
150
136
151
logger .debug ("Matching Embedding API: %s" , embed_api )
152
+
137
153
if giskarded :
138
154
giskard_key = embed_key or "giskard"
139
155
_client = OpenAI (api_key = giskard_key , base_url = f"{ embed_url } /v1/" )
@@ -148,6 +164,9 @@ def get_embedding_model(model, embed_model_config=None, giskarded=False):
148
164
client = embed_api (model = model , base_url = embed_url )
149
165
elif embed_api .__name__ == "CohereEmbeddings" :
150
166
client = embed_api (model = model , cohere_api_key = embed_key )
167
+ elif embed_api .__name__ == "OCIGenAIEmbeddings" :
168
+ client = embed_api (model_id = model , service_endpoint = embed_url , compartment_id = os .environ .get ("OCI_COMPARTMENT_ID" , default = "" ), auth_profile = embed_key )
169
+
151
170
else :
152
171
client = embed_api (model = embed_url )
153
172
@@ -397,6 +416,10 @@ def json_to_doc(file: str):
397
416
398
417
execute_sql (db_conn , mergesql )
399
418
db_conn .commit ()
419
+ #NOTE: In this release, index is automatically created without user control. This part of code helps the future release
420
+ #to re-create an index or leave without an existing vectorstore.
421
+ #for this reason the index_exists is set to True to recreate in any case the index.
422
+ index_exists = True
400
423
401
424
if (index_exists ):
402
425
# Build the Index
@@ -498,6 +521,7 @@ def oci_initialize(
498
521
region = None ,
499
522
key_file = None ,
500
523
security_token_file = None ,
524
+ compartment_id = None ,
501
525
):
502
526
"""Initialize the configuration for OCI AuthN"""
503
527
config = {
@@ -510,10 +534,12 @@ def oci_initialize(
510
534
"additional_user_agent" : "" ,
511
535
"log_requests" : False ,
512
536
"pass_phrase" : None ,
537
+ "compartment_id" :compartment_id ,
513
538
}
514
539
515
540
config_file = os .environ .get ("OCI_CLI_CONFIG_FILE" , default = oci .config .DEFAULT_LOCATION )
516
541
config_profile = os .environ .get ("OCI_CLI_PROFILE" , default = oci .config .DEFAULT_PROFILE )
542
+ compartment_id = os .environ .get ("OCI_COMPARTMENT_ID" , default = "" )
517
543
518
544
# Ingest config file when parameter are missing
519
545
if not (fingerprint and tenancy and region and key_file and (user or security_token_file )):
@@ -529,6 +555,7 @@ def oci_initialize(
529
555
config ["tenancy" ] = os .environ .get ("OCI_CLI_TENANCY" , config .get ("tenancy" ))
530
556
config ["region" ] = os .environ .get ("OCI_CLI_REGION" , config .get ("region" ))
531
557
config ["key_file" ] = os .environ .get ("OCI_CLI_KEY_FILE" , config .get ("key_file" ))
558
+ config ["compartment_id" ] = os .environ .get ("OCI_COMPARTMENT_ID" , config .get ("compartment_id" ))
532
559
return config
533
560
534
561
0 commit comments