Skip to content

Commit 5ca7872

Browse files
Merge branch 'main' into patch-2
2 parents 078b3d2 + a7802a0 commit 5ca7872

File tree

7 files changed

+320
-10
lines changed

7 files changed

+320
-10
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2024 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# Integration of OCI Generative AI in Langflow
22

3-
This repository contains all the code for a prototype of the integration of OCI Generative AI in Langflow
3+
[![License: UPL](https://img.shields.io/badge/license-UPL-green)](https://img.shields.io/badge/license-UPL-green) [![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=oracle-devrel_test)](https://sonarcloud.io/dashboard?id=oracle-devrel_test)
44

5-
Reviewed: 23.01.2025
6-
7-
# **Link to code**
8-
[Code](https://github.com/luigisaetta/oci_langflow/tree/main)
5+
## Introduction
6+
This repository contains the code for a prototype of the integration of OCI Generative AI in Langflow
97

10-
# License
11-
8+
Reviewed: 25.06.2025
9+
10+
## Security
11+
Please consult the [security guide](./SECURITY.md) for our responsible security
12+
vulnerability disclosure process.
13+
14+
## License
1215
Copyright (c) 2024 Oracle and/or its affiliates.
13-
16+
1417
Licensed under the Universal Permissive License (UPL), Version 1.0.
15-
16-
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
18+
19+
See [LICENSE](LICENSE.txt) for more details.
20+
21+
ORACLE AND ITS AFFILIATES DO NOT PROVIDE ANY WARRANTY WHATSOEVER, EXPRESS OR IMPLIED, FOR ANY SOFTWARE, MATERIAL OR CONTENT OF ANY KIND CONTAINED OR PRODUCED WITHIN THIS REPOSITORY, AND IN PARTICULAR SPECIFICALLY DISCLAIM ANY AND ALL IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. FURTHERMORE, ORACLE AND ITS AFFILIATES DO NOT REPRESENT THAT ANY CUSTOMARY SECURITY REVIEW HAS BEEN PERFORMED WITH RESPECT TO ANY SOFTWARE, MATERIAL OR CONTENT CONTAINED OR PRODUCED WITHIN THIS REPOSITORY. IN ADDITION, AND WITHOUT LIMITING THE FOREGOING, THIRD PARTIES MAY HAVE POSTED SOFTWARE, MATERIAL OR CONTENT TO THIS REPOSITORY WITHOUT ANY REVIEW. USE AT YOUR OWN RISK.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""
2+
Custom integration with Langflow and OCI Embeddings Model
3+
4+
Author: L. Saetta (Oracle)
5+
6+
"""
7+
8+
from langchain_community.embeddings import OCIGenAIEmbeddings
9+
10+
from langflow.base.models.model import LCModelComponent
11+
from langflow.io import DropdownInput, StrInput, Output, SecretStrInput
12+
from langflow.field_typing import Embeddings
13+
14+
class OCIEmbeddingsComponent(LCModelComponent):
15+
"""
16+
This class integrates the OCI Embeddings Model with Langflow.
17+
18+
Notes:
19+
* Security: for now API_KEY, set your key-pair in $HOME/.oci
20+
21+
"""
22+
23+
display_name = "OCI Cohere Embeddings"
24+
description = "Generate Embeddings using OCI Cohere models."
25+
26+
inputs = [
27+
# example of dropdown
28+
DropdownInput(
29+
name="auth_type",
30+
display_name="auth_type",
31+
info="The type of auth_type to use for the chat model",
32+
advanced=True,
33+
options=[
34+
"API_KEY",
35+
"RESOURCE_PRINCIPAL",
36+
],
37+
value="API_KEY",
38+
),
39+
DropdownInput(
40+
name="model",
41+
display_name="Model",
42+
advanced=True,
43+
options=[
44+
"cohere.embed-english-v3.0",
45+
"cohere.embed-multilingual-v3.0",
46+
],
47+
value="cohere.embed-english-v3.0",
48+
),
49+
StrInput(
50+
name="service_endpoint",
51+
display_name="Service Endpoint",
52+
info="OCI Service Endpoint URL",
53+
required=True,
54+
),
55+
SecretStrInput(
56+
name="compartment_id",
57+
display_name="Compartment ID",
58+
info="OCI Compartment OCID",
59+
),
60+
]
61+
62+
outputs = [
63+
Output(display_name="Embeddings", name="embeddings", method="build_embeddings"),
64+
]
65+
66+
def build_model(self) -> Embeddings:
67+
"""
68+
build the embeddings model
69+
"""
70+
return self.build_embeddings()
71+
72+
def build_embeddings(self) -> Embeddings:
73+
"""
74+
build the embeddings model
75+
"""
76+
# default truncate strategy is END
77+
return OCIGenAIEmbeddings(
78+
auth_type=self.auth_type,
79+
model_id=self.model,
80+
service_endpoint=self.service_endpoint,
81+
compartment_id=self.compartment_id,
82+
)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
Custom integration with Langflow and OCI Chat Model
3+
4+
Author: L. Saetta (Oracle)
5+
6+
This is part of demo code, in a real project you need to customise to fit your needs:
7+
* temperature
8+
* max_tokens
9+
* models list
10+
"""
11+
12+
from langflow.base.models.model import LCModelComponent
13+
from langflow.inputs import StrInput, DropdownInput, SecretStrInput
14+
from langflow.field_typing import LanguageModel
15+
from langchain_community.chat_models.oci_generative_ai import ChatOCIGenAI
16+
17+
18+
class OCIChatComponent(LCModelComponent):
19+
"""
20+
This class integrates the OCI Chat Model with Langflow.
21+
22+
Notes:
23+
* Security: for now API_KEY, set your key-pair in $HOME/.oci
24+
25+
"""
26+
27+
display_name = "OCI Chat Model"
28+
description = "OCI's Generative AI Chat Model."
29+
30+
inputs = [
31+
*LCModelComponent._base_inputs,
32+
DropdownInput(
33+
name="auth_type",
34+
display_name="auth_type",
35+
info="The type of auth_type to use for the chat model",
36+
advanced=True,
37+
options=[
38+
"API_KEY",
39+
"RESOURCE_PRINCIPAL",
40+
],
41+
value="API_KEY",
42+
),
43+
DropdownInput(
44+
name="model_id",
45+
display_name="model_id",
46+
info="The model_id to use for the chat model",
47+
advanced=True,
48+
options=[
49+
"meta.llama-3.3-70b-instruct",
50+
"cohere.command-r-plus-08-2024",
51+
"meta.llama-3.1-405b-instruct",
52+
],
53+
value="meta.llama-3.1-70b-instruct",
54+
),
55+
StrInput(
56+
name="service_endpoint",
57+
display_name="Service Endpoint",
58+
info="OCI Service Endpoint URL",
59+
value="https://inference.generativeai.eu-frankfurt-1.oci.oraclecloud.com",
60+
),
61+
SecretStrInput(
62+
name="compartment_id",
63+
display_name="Compartment ID",
64+
info="OCI Compartment OCID",
65+
),
66+
]
67+
68+
def build_model(self) -> LanguageModel:
69+
chat_model = ChatOCIGenAI(
70+
auth_type=self.auth_type,
71+
model_id=self.model_id,
72+
service_endpoint=self.service_endpoint,
73+
compartment_id=self.compartment_id,
74+
model_kwargs={"temperature": 0.1, "max_tokens": 1024},
75+
)
76+
77+
return chat_model
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""
2+
Custom integration with Langflow and OCI Vector Store
3+
4+
Author: L. Saetta (Oracle)
5+
6+
"""
7+
8+
import oracledb
9+
from langchain_community.vectorstores.oraclevs import OracleVS
10+
from langchain_community.vectorstores.utils import DistanceStrategy
11+
12+
from langflow.base.vectorstores.model import (
13+
LCVectorStoreComponent,
14+
check_cached_vector_store,
15+
)
16+
from langflow.helpers.data import docs_to_data
17+
from langflow.io import (
18+
HandleInput,
19+
IntInput,
20+
StrInput,
21+
SecretStrInput,
22+
MessageTextInput,
23+
)
24+
from langflow.schema import Data
25+
26+
27+
class OCIVectorStoreComponent(LCVectorStoreComponent):
28+
"""
29+
Wrapper for the OCI Vector Store
30+
"""
31+
32+
display_name = "OCIVectorStore"
33+
description = "OCI Vector Store based on 23AI"
34+
name = "ocivector"
35+
36+
inputs = [
37+
SecretStrInput(name="db_user", required=True),
38+
SecretStrInput(name="db_pwd", required=True),
39+
SecretStrInput(name="dsn", required=True),
40+
SecretStrInput(name="wallet_dir", required=True),
41+
SecretStrInput(name="wallet_pwd", required=True),
42+
StrInput(name="collection_name", display_name="Table", required=True),
43+
# this way we can handle the input for the search and it can be connected
44+
# in the flow
45+
MessageTextInput(
46+
name="search_query",
47+
display_name="search_query",
48+
info="Enter the search query.",
49+
),
50+
*LCVectorStoreComponent.inputs,
51+
HandleInput(
52+
name="embedding", display_name="Embedding", input_types=["Embeddings"]
53+
),
54+
IntInput(
55+
name="number_of_results",
56+
display_name="Number of Results",
57+
info="Number of results to return.",
58+
value=4,
59+
advanced=True,
60+
),
61+
]
62+
63+
def handle_credentials(self) -> dict:
64+
"""
65+
this function organizes the parameters to connect
66+
to DB
67+
"""
68+
_connect_args_vector = {
69+
"user": self.db_user,
70+
"password": self.db_pwd,
71+
"dsn": self.dsn,
72+
"config_dir": self.wallet_dir,
73+
"wallet_location": self.wallet_dir,
74+
"wallet_password": self.wallet_pwd,
75+
}
76+
return _connect_args_vector
77+
78+
@check_cached_vector_store
79+
def build_vector_store(self) -> OracleVS:
80+
connect_args_vector = self.handle_credentials()
81+
82+
conn = oracledb.connect(**connect_args_vector)
83+
84+
v_store = OracleVS(
85+
client=conn,
86+
table_name=self.collection_name,
87+
distance_strategy=DistanceStrategy.COSINE,
88+
embedding_function=self.embedding,
89+
)
90+
return v_store
91+
92+
def search_documents(self) -> list[Data]:
93+
"""
94+
no changes needed here
95+
"""
96+
vector_store = self.build_vector_store()
97+
98+
if (
99+
self.search_query
100+
and isinstance(self.search_query, str)
101+
and self.search_query.strip()
102+
):
103+
docs = vector_store.similarity_search(
104+
query=self.search_query,
105+
k=self.number_of_results,
106+
)
107+
108+
data = docs_to_data(docs)
109+
self.status = data
110+
return data
111+
return []
Loading
Loading

0 commit comments

Comments
 (0)