Skip to content

Commit 2cb477d

Browse files
lu-ohaipiyushg
authored andcommitted
Merge pull request from add_ads_dependency to main
2 parents b4921c8 + 8674b6d commit 2cb477d

File tree

7 files changed

+207
-326
lines changed

7 files changed

+207
-326
lines changed

THIRD_PARTY_LICENSES.txt

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Oracle Infrastructure Cloud LangChain Plugin for Python Third Party License File
55
- MIT License
66
- The Universal Permissive License (UPL), Version 1.0
77
- Apache License Version 2.0, January 2004
8-
- BSD License (Copyright (c) 2005-2024, NumPy Developers.)
98

109
======================== Third Party Components ========================
1110
langchain-core
@@ -14,18 +13,24 @@ langchain-core
1413
* Source code: https://github.com/langchain-ai/langchain/tree/master/libs/core
1514
* Project home: https://python.langchain.com/docs/introduction/
1615

16+
langchain-openai
17+
* Copyright (c) LangChain, Inc.
18+
* License: MIT License (MIT)
19+
* Source code: https://github.com/langchain-ai/langchain
20+
* Project home: https://python.langchain.com/docs/introduction/
21+
1722
oci
1823
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
1924
* License: The Universal Permissive License (UPL), Version 1.0
2025
Apache License Version 2.0, January 2004
2126
* Source code: https://github.com/oracle/oci-python-sdk
2227
* Project home: https://docs.oracle.com/en-us/iaas/tools/python/2.148.0/index.html
2328

24-
numpy
25-
* Copyright (c) 2005-2025, NumPy Developers. All rights reserved.
26-
* License: BSD License (Copyright (c) 2005-2024, NumPy Developers.)
27-
* Source code: https://github.com/numpy/numpy
28-
* Project home: https://numpy.org/
29+
oracle-ads
30+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
31+
* License: The Universal Permissive License (UPL), Version 1.0
32+
* Source code: https://github.com/oracle/accelerated-data-science
33+
* Project home: https://accelerated-data-science.readthedocs.io/en/latest/
2934

3035
pydantic
3136
* Copyright (c) 2017 to present Pydantic Services Inc. and individual contributors.
@@ -58,7 +63,30 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5863
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5964
SOFTWARE.
6065

66+
--------------------- langchain-openai ----------------------
67+
MIT License
68+
69+
Copyright (c) LangChain, Inc.
70+
71+
Permission is hereby granted, free of charge, to any person obtaining a copy
72+
of this software and associated documentation files (the "Software"), to deal
73+
in the Software without restriction, including without limitation the rights
74+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
75+
copies of the Software, and to permit persons to whom the Software is
76+
furnished to do so, subject to the following conditions:
77+
78+
The above copyright notice and this permission notice shall be included in all
79+
copies or substantial portions of the Software.
80+
81+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
82+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
83+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
84+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
85+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
86+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
87+
SOFTWARE.
6188

89+
--------------------- oci ----------------------
6290
The Universal Permissive License (UPL), Version 1.0
6391

6492
Subject to the condition set forth below, permission is hereby granted to any person obtaining a copy of this software, associated documentation and/or data (collectively the "Software"), free of charge and under any and all copyright rights in the Software, and any and all patent rights owned or freely licensable by each licensor hereunder covering either (i) the unmodified Software as contributed to or provided by such licensor, or (ii) the Larger Works (as defined below), to deal in both
@@ -75,8 +103,6 @@ The above copyright notice and either this complete permission notice or at a mi
75103
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
76104
____________________________
77105

78-
--------------------- oci ----------------------
79-
80106
The Apache Software License, Version 2.0
81107
Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
82108

@@ -140,38 +166,43 @@ END OF TERMS AND CONDITIONS
140166
See the License for the specific language governing permissions and
141167
limitations under the License.
142168

143-
--------------------- NumPy ----------------------
144-
145-
Copyright (c) 2005-2025, NumPy Developers.
146-
All rights reserved.
147-
148-
Redistribution and use in source and binary forms, with or without
149-
modification, are permitted provided that the following conditions are
150-
met:
151-
152-
* Redistributions of source code must retain the above copyright
153-
notice, this list of conditions and the following disclaimer.
154-
155-
* Redistributions in binary form must reproduce the above
156-
copyright notice, this list of conditions and the following
157-
disclaimer in the documentation and/or other materials provided
158-
with the distribution.
159-
160-
* Neither the name of the NumPy Developers nor the names of any
161-
contributors may be used to endorse or promote products derived
162-
from this software without specific prior written permission.
163-
164-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
165-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
166-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
167-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
168-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
169-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
170-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
171-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
172-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
173-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
174-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
169+
--------------------- oracle-ads ----------------------
170+
171+
Copyright (c) 2025 Oracle and/or its affiliates.
172+
173+
The Universal Permissive License (UPL), Version 1.0
174+
175+
Subject to the condition set forth below, permission is hereby granted to any
176+
person obtaining a copy of this software, associated documentation and/or data
177+
(collectively the "Software"), free of charge and under any and all copyright
178+
rights in the Software, and any and all patent rights owned or freely
179+
licensable by each licensor hereunder covering either (i) the unmodified
180+
Software as contributed to or provided by such licensor, or (ii) the Larger
181+
Works (as defined below), to deal in both
182+
183+
(a) the Software, and
184+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
185+
one is included with the Software (each a "Larger Work" to which the Software
186+
is contributed by such licensors),
187+
188+
without restriction, including without limitation the rights to copy, create
189+
derivative works of, display, perform, and distribute the Software and make,
190+
use, sell, offer for sale, import, export, have made, and have sold the
191+
Software and the Larger Work(s), and to sublicense the foregoing rights on
192+
either these or other terms.
193+
194+
This license is subject to the following condition:
195+
The above copyright notice and either this complete permission notice or at
196+
a minimum a reference to the UPL must be included in all copies or
197+
substantial portions of the Software.
198+
199+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
200+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
201+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
202+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
203+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
204+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
205+
SOFTWARE.
175206

176207
--------------------- pydantic ----------------------
177208

libs/oci/README.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ All integrations in this package assume that you have the credentials setup to c
1111

1212
## Chat Models
1313

14+
### OCI Generative AI
15+
1416
`ChatOCIGenAI` class exposes chat models from OCI Generative AI.
1517

1618
```python
@@ -20,8 +22,48 @@ llm = ChatOCIGenAI()
2022
llm.invoke("Sing a ballad of LangChain.")
2123
```
2224

25+
### OCI Data Science
26+
27+
You may also instantiate the OCI Data Science model with the generic `ChatOCIModelDeployment` or framework specific class like `ChatOCIModelDeploymentVLLM`.
28+
29+
```python
30+
from langchain_oci.chat_models import ChatOCIModelDeployment, ChatOCIModelDeploymentVLLM
31+
32+
# Create an instance of OCI Model Deployment Endpoint
33+
# Replace the endpoint uri with your own
34+
endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict"
35+
36+
messages = [
37+
(
38+
"system",
39+
"You are a helpful assistant that translates English to French. Translate the user sentence.",
40+
),
41+
("human", "I love programming."),
42+
]
43+
44+
chat = ChatOCIModelDeployment(
45+
endpoint=endpoint,
46+
streaming=True,
47+
max_retries=1,
48+
model_kwargs={
49+
"temperature": 0.2,
50+
"max_tokens": 512,
51+
}, # other model params...
52+
default_headers={
53+
"route": "/v1/chat/completions",
54+
# other request headers ...
55+
},
56+
)
57+
chat.invoke(messages)
58+
59+
chat_vllm = ChatOCIModelDeploymentVLLM(endpoint=endpoint)
60+
chat_vllm.invoke(messages)
61+
```
62+
2363
## Embeddings
2464

65+
### OCI Generative AI
66+
2567
`OCIGenAIEmbeddings` class exposes embeddings from OCI Generative AI.
2668

2769
```python
@@ -31,12 +73,60 @@ embeddings = OCIGenAIEmbeddings()
3173
embeddings.embed_query("What is the meaning of life?")
3274
```
3375

76+
### OCI Data Science
77+
78+
You may also instantiate the OCI Data Science model with the `OCIModelDeploymentEndpointEmbeddings`.
79+
80+
```python
81+
from langchain_oci.embeddings import OCIModelDeploymentEndpointEmbeddings
82+
83+
# Create an instance of OCI Model Deployment Endpoint
84+
# Replace the endpoint uri with your own
85+
endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict"
86+
87+
embeddings = OCIModelDeploymentEndpointEmbeddings(
88+
endpoint=endpoint,
89+
)
90+
91+
query = "Hello World!"
92+
embeddings.embed_query(query)
93+
94+
documents = ["This is a sample document", "and here is another one"]
95+
embeddings.embed_documents(documents)
96+
```
97+
3498
## LLMs
99+
100+
### OCI Generative AI
101+
35102
`OCIGenAI` class exposes LLMs from OCI Generative AI.
36103

37104
```python
38105
from langchain_oci import OCIGenAI
39106

40107
llm = OCIGenAI()
41108
llm.invoke("The meaning of life is")
42-
```
109+
```
110+
111+
### OCI Data Science
112+
113+
You may also instantiate the OCI Data Science model with `OCIModelDeploymentLLM` or `OCIModelDeploymentVLLM`.
114+
115+
```python
116+
from langchain_oci.llms import OCIModelDeploymentLLM, OCIModelDeploymentVLLM
117+
118+
# Create an instance of OCI Model Deployment Endpoint
119+
# Replace the endpoint uri and model name with your own
120+
endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict"
121+
122+
llm = OCIModelDeploymentLLM(
123+
endpoint=endpoint,
124+
model="odsc-llm",
125+
)
126+
llm.invoke("Who is the first president of United States?")
127+
128+
vllm = OCIModelDeploymentVLLM(
129+
endpoint=endpoint,
130+
)
131+
vllm.invoke("Who is the first president of United States?")
132+
```

libs/oci/langchain_oci/llms/oci_data_science_model_deployment_endpoint.py

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
"""LLM for OCI data science model deployment endpoint."""
55

6+
from contextlib import asynccontextmanager
67
import json
78
import logging
89
import traceback
910
from typing import (
1011
Any,
12+
AsyncGenerator,
1113
AsyncIterator,
1214
Callable,
1315
Dict,
@@ -30,8 +32,6 @@
3032
from langchain_core.utils import get_from_dict_or_env
3133
from pydantic import Field, model_validator
3234

33-
from langchain_oci.utilities.requests import Requests
34-
3535
logger = logging.getLogger(__name__)
3636
DEFAULT_INFERENCE_ENDPOINT = "/v1/completions"
3737

@@ -169,15 +169,18 @@ def _completion_with_retry(**kwargs: Any) -> Any:
169169
request_timeout = kwargs.pop("request_timeout", DEFAULT_TIME_OUT)
170170
data = kwargs.pop("data")
171171
stream = kwargs.pop("stream", self.streaming)
172+
headers = self._headers()
173+
auth = self.auth.get("signer")
174+
url = self.endpoint
172175

173-
request = Requests(
174-
headers=self._headers(), auth=self.auth.get("signer")
175-
)
176-
response = request.post(
177-
url=self.endpoint,
178-
data=data,
176+
response = requests.post(
177+
url=url,
178+
json=data,
179179
timeout=request_timeout,
180180
stream=stream,
181+
headers=headers,
182+
auth=auth,
183+
verify=True,
181184
**kwargs,
182185
)
183186
self._check_response(response)
@@ -211,20 +214,29 @@ async def _completion_with_retry(**kwargs: Any) -> Any:
211214
request_timeout = kwargs.pop("request_timeout", DEFAULT_TIME_OUT)
212215
data = kwargs.pop("data")
213216
stream = kwargs.pop("stream", self.streaming)
217+
headers = self._headers(is_async=True, body=data)
218+
auth = self.auth.get("signer")
219+
url = self.endpoint
220+
method = "POST"
214221

215-
request = Requests(headers=self._headers(is_async=True, body=data))
216222
if stream:
217-
response = request.apost(
218-
url=self.endpoint,
219-
data=data,
223+
response = self._arequest(
224+
method=method,
225+
url=url,
226+
json=data,
220227
timeout=request_timeout,
228+
headers=headers,
229+
auth=auth,
221230
)
222231
return self._aiter_sse(response)
223232
else:
224-
async with request.apost(
225-
url=self.endpoint,
226-
data=data,
233+
async with self._arequest(
234+
method=method,
235+
url=url,
236+
json=data,
227237
timeout=request_timeout,
238+
headers=headers,
239+
auth=auth,
228240
) as resp:
229241
self._check_response(resp)
230242
data = await resp.json()
@@ -244,6 +256,21 @@ async def _completion_with_retry(**kwargs: Any) -> Any:
244256

245257
return await _completion_with_retry(**kwargs)
246258

259+
@asynccontextmanager
260+
async def _arequest(
261+
self, method: str, url: str, headers: dict, auth: Any, **kwargs: Any
262+
) -> AsyncGenerator[aiohttp.ClientResponse, None]:
263+
"""Make an async request."""
264+
async with aiohttp.ClientSession() as session:
265+
async with session.request(
266+
method,
267+
url,
268+
headers=headers,
269+
auth=auth,
270+
**kwargs,
271+
) as response:
272+
yield response
273+
247274
def _check_response(self, response: Any) -> None:
248275
"""Handle server error by checking the response status.
249276

libs/oci/langchain_oci/utilities/__init__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)