Skip to content

Commit 1869fe0

Browse files
authored
Merge pull request #2 from oracle/readme_update
Enhance README with Structured OCI GenAI and AI Platform Integration Examples
2 parents eade5c2 + 18f5770 commit 1869fe0

File tree

2 files changed

+198
-59
lines changed

2 files changed

+198
-59
lines changed

README.md

Lines changed: 141 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,154 @@
1-
# 🦜️🔗 LangChain 🤝 Oracle Cloud Infrastructure (OCI)
1+
# 🦜️🔗 LangChain 🤝 Oracle
22

3-
This repository provides LangChain components for various OCI services. It aims to replace and expand upon the existing LangChain OCI components found in the `langchain-community` package in the LangChain repository.
3+
Welcome to the official repository for LangChain integration with [Oracle Cloud Infrastructure (OCI)](https://cloud.oracle.com/). This library provides native LangChain components for interacting with Oracle's AI services—combining support for **OCI Generative AI** and **OCI Data Science**.
44

55
## Features
66

77
- **LLMs**: Includes LLM classes for OCI services like [Generative AI](https://cloud.oracle.com/ai-services/generative-ai) and [ModelDeployment Endpoints](https://cloud.oracle.com/ai-services/model-deployment), allowing you to leverage their language models within LangChain.
88
- **Agents**: Includes Runnables to support [Oracle Generative AI Agents](https://www.oracle.com/artificial-intelligence/generative-ai/agents/), allowing you to leverage Generative AI Agents within LangChain and LangGraph.
99
- **More to come**: This repository will continue to expand and offer additional components for various OCI services as development progresses.
1010

11-
**Note**: This repository will replace all OCI integrations currently present in the `langchain-community` package. Users are encouraged to migrate to this repository as soon as possible.
11+
> This project merges and replaces earlier OCI integrations from the `langchain-community` repository and unifies contributions from Oracle's GenAI and Data Science teams.
12+
> All integrations in this package assume that you have the credentials setup to connect with oci services.
13+
14+
---
1215

1316
## Installation
1417

15-
You can install the `langchain-oracle` package from PyPI.
18+
19+
```bash
20+
pip install -U langchain-oci
21+
```
22+
23+
---
24+
25+
## Quick Start
26+
27+
This repository includes two main integration categories:
28+
29+
- [OCI Generative AI](#oci-generative-ai-examples)
30+
- [OCI Data Science (Model Deployment)](#oci-data-science-model-deployment-examples)
31+
32+
33+
---
34+
35+
## OCI Generative AI Examples
36+
37+
### 1. Use a Chat Model
38+
39+
`ChatOCIGenAI` class exposes chat models from OCI Generative AI.
40+
41+
```python
42+
from langchain_oci import ChatOCIGenAI
43+
44+
llm = ChatOCIGenAI()
45+
llm.invoke("Sing a ballad of LangChain.")
46+
```
47+
48+
### 2. Use a Completion Model
49+
`OCIGenAI` class exposes LLMs from OCI Generative AI.
50+
51+
```python
52+
from langchain_oci import OCIGenAI
53+
54+
llm = OCIGenAI()
55+
llm.invoke("The meaning of life is")
56+
```
57+
58+
### 3. Use an Embedding Model
59+
`OCIGenAIEmbeddings` class exposes embeddings from OCI Generative AI.
60+
61+
```python
62+
from langchain_oci import OCIGenAIEmbeddings
63+
64+
embeddings = OCIGenAIEmbeddings()
65+
embeddings.embed_query("What is the meaning of life?")
66+
```
67+
68+
69+
## OCI Data Science Model Deployment Examples
70+
71+
### 1. Use a Chat Model
72+
73+
You may instantiate the OCI Data Science model with the generic `ChatOCIModelDeployment` or framework specific class like `ChatOCIModelDeploymentVLLM`.
74+
75+
```python
76+
from langchain_oci.chat_models import ChatOCIModelDeployment, ChatOCIModelDeploymentVLLM
77+
78+
# Create an instance of OCI Model Deployment Endpoint
79+
# Replace the endpoint uri with your own
80+
endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict"
81+
82+
messages = [
83+
(
84+
"system",
85+
"You are a helpful assistant that translates English to French. Translate the user sentence.",
86+
),
87+
("human", "I love programming."),
88+
]
89+
90+
chat = ChatOCIModelDeployment(
91+
endpoint=endpoint,
92+
streaming=True,
93+
max_retries=1,
94+
model_kwargs={
95+
"temperature": 0.2,
96+
"max_tokens": 512,
97+
}, # other model params...
98+
default_headers={
99+
"route": "/v1/chat/completions",
100+
# other request headers ...
101+
},
102+
)
103+
chat.invoke(messages)
104+
105+
chat_vllm = ChatOCIModelDeploymentVLLM(endpoint=endpoint)
106+
chat_vllm.invoke(messages)
107+
```
108+
109+
### 2. Use a Completion Model
110+
You may instantiate the OCI Data Science model with `OCIModelDeploymentLLM` or `OCIModelDeploymentVLLM`.
111+
112+
```python
113+
from langchain_oci.llms import OCIModelDeploymentLLM, OCIModelDeploymentVLLM
114+
115+
# Create an instance of OCI Model Deployment Endpoint
116+
# Replace the endpoint uri and model name with your own
117+
endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict"
118+
119+
llm = OCIModelDeploymentLLM(
120+
endpoint=endpoint,
121+
model="odsc-llm",
122+
)
123+
llm.invoke("Who is the first president of United States?")
124+
125+
vllm = OCIModelDeploymentVLLM(
126+
endpoint=endpoint,
127+
)
128+
vllm.invoke("Who is the first president of United States?")
129+
```
130+
131+
### 3. Use an Embedding Model
132+
You may instantiate the OCI Data Science model with the `OCIModelDeploymentEndpointEmbeddings`.
133+
134+
```python
135+
from langchain_oci.embeddings import OCIModelDeploymentEndpointEmbeddings
136+
137+
# Create an instance of OCI Model Deployment Endpoint
138+
# Replace the endpoint uri with your own
139+
endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict"
140+
141+
embeddings = OCIModelDeploymentEndpointEmbeddings(
142+
endpoint=endpoint,
143+
)
144+
145+
query = "Hello World!"
146+
embeddings.embed_query(query)
147+
148+
documents = ["This is a sample document", "and here is another one"]
149+
embeddings.embed_documents(documents)
150+
```
151+
16152

17153
## Contributing
18154

@@ -27,8 +163,4 @@ Please consult the [security guide](./SECURITY.md) for our responsible security
27163
Copyright (c) 2025 Oracle and/or its affiliates.
28164

29165
Released under the Universal Permissive License v1.0 as shown at
30-
<https://oss.oracle.com/licenses/upl/>.
31-
32-
release:
33-
/github subscribe langchain-ai/langchain-oci releases workflows:{name:"release"}
34-
/github unsubscribe langchain-ai/langchain-oci issues pulls commits deployments
166+
<https://oss.oracle.com/licenses/upl/>

libs/oci/README.md

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,21 @@ pip install -U langchain-oci
99
```
1010
All integrations in this package assume that you have the credentials setup to connect with oci services.
1111

12-
## Chat Models
12+
---
1313

14-
### OCI Generative AI
14+
## Quick Start
15+
16+
This repository includes two main integration categories:
17+
18+
- [OCI Generative AI](#oci-generative-ai-examples)
19+
- [OCI Data Science (Model Deployment)](#oci-data-science-model-deployment-examples)
20+
21+
22+
---
23+
24+
## OCI Generative AI Examples
25+
26+
### 1. Use a Chat Model
1527

1628
`ChatOCIGenAI` class exposes chat models from OCI Generative AI.
1729

@@ -22,9 +34,32 @@ llm = ChatOCIGenAI()
2234
llm.invoke("Sing a ballad of LangChain.")
2335
```
2436

25-
### OCI Data Science
37+
### 2. Use a Completion Model
38+
`OCIGenAI` class exposes LLMs from OCI Generative AI.
39+
40+
```python
41+
from langchain_oci import OCIGenAI
42+
43+
llm = OCIGenAI()
44+
llm.invoke("The meaning of life is")
45+
```
2646

27-
You may also instantiate the OCI Data Science model with the generic `ChatOCIModelDeployment` or framework specific class like `ChatOCIModelDeploymentVLLM`.
47+
### 3. Use an Embedding Model
48+
`OCIGenAIEmbeddings` class exposes embeddings from OCI Generative AI.
49+
50+
```python
51+
from langchain_oci import OCIGenAIEmbeddings
52+
53+
embeddings = OCIGenAIEmbeddings()
54+
embeddings.embed_query("What is the meaning of life?")
55+
```
56+
57+
58+
## OCI Data Science Model Deployment Examples
59+
60+
### 1. Use a Chat Model
61+
62+
You may instantiate the OCI Data Science model with the generic `ChatOCIModelDeployment` or framework specific class like `ChatOCIModelDeploymentVLLM`.
2863

2964
```python
3065
from langchain_oci.chat_models import ChatOCIModelDeployment, ChatOCIModelDeploymentVLLM
@@ -60,22 +95,30 @@ chat_vllm = ChatOCIModelDeploymentVLLM(endpoint=endpoint)
6095
chat_vllm.invoke(messages)
6196
```
6297

63-
## Embeddings
98+
### 2. Use a Completion Model
99+
You may instantiate the OCI Data Science model with `OCIModelDeploymentLLM` or `OCIModelDeploymentVLLM`.
64100

65-
### OCI Generative AI
101+
```python
102+
from langchain_oci.llms import OCIModelDeploymentLLM, OCIModelDeploymentVLLM
66103

67-
`OCIGenAIEmbeddings` class exposes embeddings from OCI Generative AI.
104+
# Create an instance of OCI Model Deployment Endpoint
105+
# Replace the endpoint uri and model name with your own
106+
endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict"
68107

69-
```python
70-
from langchain_oci import OCIGenAIEmbeddings
108+
llm = OCIModelDeploymentLLM(
109+
endpoint=endpoint,
110+
model="odsc-llm",
111+
)
112+
llm.invoke("Who is the first president of United States?")
71113

72-
embeddings = OCIGenAIEmbeddings()
73-
embeddings.embed_query("What is the meaning of life?")
114+
vllm = OCIModelDeploymentVLLM(
115+
endpoint=endpoint,
116+
)
117+
vllm.invoke("Who is the first president of United States?")
74118
```
75119

76-
### OCI Data Science
77-
78-
You may also instantiate the OCI Data Science model with the `OCIModelDeploymentEndpointEmbeddings`.
120+
### 3. Use an Embedding Model
121+
You may instantiate the OCI Data Science model with the `OCIModelDeploymentEndpointEmbeddings`.
79122

80123
```python
81124
from langchain_oci.embeddings import OCIModelDeploymentEndpointEmbeddings
@@ -94,39 +137,3 @@ embeddings.embed_query(query)
94137
documents = ["This is a sample document", "and here is another one"]
95138
embeddings.embed_documents(documents)
96139
```
97-
98-
## LLMs
99-
100-
### OCI Generative AI
101-
102-
`OCIGenAI` class exposes LLMs from OCI Generative AI.
103-
104-
```python
105-
from langchain_oci import OCIGenAI
106-
107-
llm = OCIGenAI()
108-
llm.invoke("The meaning of life is")
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-
```

0 commit comments

Comments
 (0)