Skip to content

Commit dcb1615

Browse files
authored
Oracle OCI GenAi Chat Models (#226)
* Oracle OCI GenAi Chat Models * Bump up to fresh OCI SDK * Compliance fix
1 parent 431a88c commit dcb1615

23 files changed

+2928
-0
lines changed

langchain4j-community-bom/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
<version>${project.version}</version>
3737
</dependency>
3838

39+
<dependency>
40+
<groupId>dev.langchain4j</groupId>
41+
<artifactId>langchain4j-community-oci-genai</artifactId>
42+
<version>${project.version}</version>
43+
</dependency>
44+
3945
<dependency>
4046
<groupId>dev.langchain4j</groupId>
4147
<artifactId>langchain4j-community-qianfan</artifactId>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Oracle Cloud Infrastructure GenAI
2+
This module implements `ChatModels` with [OCI GenAI](https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service)
3+
over official OCI SDK.
4+
5+
## Requirements
6+
Oracle OCI tenancy with GenAi models available.
7+
See AI model availability [here](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/Content/generative-ai/pretrained-models.htm).
8+
9+
## Installation
10+
```xml
11+
<dependency>
12+
<groupId>dev.langchain4j</groupId>
13+
<artifactId>langchain4j-community-oci-genai</artifactId>
14+
</dependency>
15+
```
16+
Additionally, you have to select HTTP client for OCI SDK, by default, use a Jersey 3 based version:
17+
```xml
18+
<dependency>
19+
<groupId>com.oracle.oci.sdk</groupId>
20+
<artifactId>oci-java-sdk-common-httpclient-jersey3</artifactId>
21+
<version>${oci-sdk.version}</version>
22+
</dependency>
23+
```
24+
25+
In case use are on **Java EE/Jakarta EE 8 or older** runtime, please use Jersey 2 based version:
26+
```xml
27+
<dependency>
28+
<groupId>com.oracle.oci.sdk</groupId>
29+
<artifactId>oci-java-sdk-common-httpclient-jersey</artifactId>
30+
<version>${oci-sdk.version}</version>
31+
</dependency>
32+
```
33+
34+
More information can be found in [OCI SDK documentation](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/javasdk3.htm#javasdk3__HTTP-client-libraries).
35+
36+
37+
38+
39+
## Usage
40+
Minimal required configuration:
41+
* chat model name or OCID - Find models available in your tenancy in your OCI Console in Generative AI section
42+
* compartment id - OCID of the [compartment](https://docs.oracle.com/en/cloud/foundation/cloud_architecture/governance/compartments.html) with GenAi model you want to use
43+
* authentication provider - authentication provider used by [OCI SDK](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/javasdk.htm), see [configuring credential section](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/Content/API/SDKDocs/javasdkgettingstarted.htm#Configur__ConfigCreds) of SDK docs.
44+
45+
```java
46+
ChatModel chatModel = OciGenAiChatModel.builder()
47+
.authProvider(new ConfigFileAuthenticationDetailsProvider("DEFAULT")) // OCI SDK Authentication provider
48+
.chatModelId("meta.llama-3.3-70b-instruct") // Model name or OCID
49+
.compartmentId("ocid1.tenancy.oc1..your.compartment.ocid") // Compartment OCID
50+
.region(Region.EU_FRANKFURT_1)
51+
.build();
52+
```
53+
54+
Available chat models APIs:
55+
* `OciGenAiChatModel` - for all OCI GenAi generic chat models(llama)
56+
* `OciGenAiStreamingChatModel` - streaming API for OCI GenAi generic chat models
57+
* `OciGenAiCohereChatModel` - for all OCI GenAi Cohere chat models
58+
* `OciGenAiCohereStreamingChatModel` - streaming API for OCI GenAi Cohere chat models
59+
60+
## Running tests
61+
Integration tests are disabled unless following environment variables are available:
62+
63+
* `OCI_GENAI_COMPARTMENT_ID` - OCI compartment ID(OCID) for compartment with available on-demand GenAi models available
64+
* `OCI_GENAI_GENERIC_MODEL_NAME` - Generic on-demand GenAi model(non-cohere) name or OCID available at provided compartment
65+
* `OCI_GENAI_COHERE_MODEL_NAME` - Cohere on-demand GenAi model name or OCID available at provided compartment
66+
67+
Image test is disabled unless additional environment property is set:
68+
* `OCI_GENAI_GENERIC_VISION_MODEL_NAME` - Generic on-demand GenAi vision model(non-cohere) name or OCID available at provided compartment
69+
70+
Optional variables:
71+
* `OCI_GENAI_CONFIG_PROFILE` - [OCI configuration file](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm) profile, `DEFAULT` is used if not set
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>dev.langchain4j</groupId>
6+
<artifactId>langchain4j-community</artifactId>
7+
<version>1.1.0-beta7-SNAPSHOT</version>
8+
<relativePath>../../pom.xml</relativePath>
9+
</parent>
10+
11+
<artifactId>langchain4j-community-oci-genai</artifactId>
12+
<name>LangChain4j :: Community :: Integration :: Oracle OCI Generative AI</name>
13+
<description>Oracle OCI Generative AI</description>
14+
<url>https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service</url>
15+
16+
<licenses>
17+
<license>
18+
<name>Apache-2.0</name>
19+
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
20+
<distribution>repo</distribution>
21+
<comments>A business-friendly OSS license</comments>
22+
</license>
23+
</licenses>
24+
25+
<properties>
26+
<skipOciGenAiITs>false</skipOciGenAiITs>
27+
<oci-sdk.version>3.67.0</oci-sdk.version>
28+
<!-- Stable module name until lc4j switches to JPMS -->
29+
<automatic-module-name>langchain4j.community.oci.genai</automatic-module-name>
30+
</properties>
31+
32+
<dependencies>
33+
34+
<dependency>
35+
<groupId>dev.langchain4j</groupId>
36+
<artifactId>langchain4j-core</artifactId>
37+
<version>${langchain4j.core.version}</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>com.oracle.oci.sdk</groupId>
42+
<artifactId>oci-java-sdk-generativeaiinference</artifactId>
43+
<version>${oci-sdk.version}</version>
44+
</dependency>
45+
46+
<!-- Tests extend the integration tests from the core module -->
47+
<dependency>
48+
<groupId>dev.langchain4j</groupId>
49+
<artifactId>langchain4j-core</artifactId>
50+
<version>${langchain4j.core.version}</version>
51+
<classifier>tests</classifier>
52+
<type>test-jar</type>
53+
<scope>test</scope>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>dev.langchain4j</groupId>
58+
<artifactId>langchain4j</artifactId>
59+
<version>${langchain4j.version}</version>
60+
<scope>test</scope>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>dev.langchain4j</groupId>
65+
<artifactId>langchain4j</artifactId>
66+
<version>${langchain4j.version}</version>
67+
<classifier>tests</classifier>
68+
<type>test-jar</type>
69+
<scope>test</scope>
70+
</dependency>
71+
72+
<dependency>
73+
<groupId>org.junit.jupiter</groupId>
74+
<artifactId>junit-jupiter-engine</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.slf4j</groupId>
79+
<artifactId>jcl-over-slf4j</artifactId>
80+
<scope>test</scope>
81+
</dependency>
82+
<dependency>
83+
<groupId>com.oracle.oci.sdk</groupId>
84+
<artifactId>oci-java-sdk-common-httpclient-jersey3</artifactId>
85+
<version>${oci-sdk.version}</version>
86+
<scope>test</scope>
87+
</dependency>
88+
</dependencies>
89+
90+
<build>
91+
<plugins>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-compiler-plugin</artifactId>
95+
<configuration>
96+
<useModulePath>false</useModulePath>
97+
</configuration>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-surefire-plugin</artifactId>
102+
<configuration>
103+
<useModulePath>false</useModulePath>
104+
</configuration>
105+
</plugin>
106+
<plugin>
107+
<groupId>org.apache.maven.plugins</groupId>
108+
<artifactId>maven-failsafe-plugin</artifactId>
109+
<configuration>
110+
<skipTests>${skipOciGenAiITs}</skipTests>
111+
<useModulePath>false</useModulePath>
112+
</configuration>
113+
</plugin>
114+
<plugin>
115+
<groupId>org.apache.maven.plugins</groupId>
116+
<artifactId>maven-jar-plugin</artifactId>
117+
<configuration>
118+
<archive>
119+
<manifestEntries>
120+
<Automatic-Module-Name>${automatic-module-name}</Automatic-Module-Name>
121+
</manifestEntries>
122+
</archive>
123+
</configuration>
124+
</plugin>
125+
<plugin>
126+
<groupId>org.honton.chas</groupId>
127+
<artifactId>license-maven-plugin</artifactId>
128+
<configuration>
129+
<!--
130+
OCI SDK libs are dual-licensed under the UPL 1.0 or Apache License 2.0,
131+
license files are custom generated to the artifacts, hence not passing the compliance test.
132+
-->
133+
<skipCompliance>true</skipCompliance>
134+
</configuration>
135+
</plugin>
136+
</plugins>
137+
</build>
138+
139+
</project>

0 commit comments

Comments
 (0)