Skip to content

Commit 634923c

Browse files
authored
4.x: Langchain4j integration (helidon-io#9733)
* Lanchain4j integration * OpenAI provider * CDI integration with Service Registry * Fix for naming in proxy factory (NPE). * Fixes for qualifiers added during annotation mapping. * Removed contract from Lookup when created from Dependency that uses java.lang.Object * Added preview feature status to langchain4j * Default embedding store factory for text segments * Added support for ChatMemoryWindow annotation to simplify configuration of AI Services * Oracle embedding store support * Fixed docs of configuration of OpenAI models * Create a single bean in CDI, use provided type as its type (less beans in CDI created) * Using injection with Langchain4j OpenAi provider to avoid runtime lookups. * Added support for array types when creating TypeName from Type. * Changed name of injected proxies and tokenizers to use `.` instead of `:` between the provider name and the model type.
1 parent dec95f3 commit 634923c

92 files changed

Lines changed: 7219 additions & 57 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

all/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,18 @@
783783
<groupId>io.helidon.integrations.vault</groupId>
784784
<artifactId>helidon-integrations-vault-cdi</artifactId>
785785
</dependency>
786+
<dependency>
787+
<groupId>io.helidon.integrations.langchain4j</groupId>
788+
<artifactId>helidon-integrations-langchain4j</artifactId>
789+
</dependency>
790+
<dependency>
791+
<groupId>io.helidon.integrations.langchain4j</groupId>
792+
<artifactId>helidon-integrations-langchain4j-codegen</artifactId>
793+
</dependency>
794+
<dependency>
795+
<groupId>io.helidon.integrations.langchain4j.providers</groupId>
796+
<artifactId>helidon-integrations-langchain4j-providers-open-ai</artifactId>
797+
</dependency>
786798
<dependency>
787799
<groupId>io.helidon.openapi</groupId>
788800
<artifactId>helidon-openapi</artifactId>
@@ -1116,6 +1128,10 @@
11161128
<groupId>io.helidon.metadata</groupId>
11171129
<artifactId>helidon-metadata-hson</artifactId>
11181130
</dependency>
1131+
<dependency>
1132+
<groupId>io.helidon.metadata</groupId>
1133+
<artifactId>helidon-metadata-reflection</artifactId>
1134+
</dependency>
11191135
<dependency>
11201136
<groupId>io.helidon.integrations.oci.sdk</groupId>
11211137
<artifactId>helidon-integrations-oci-sdk-codegen</artifactId>

bom/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,21 @@
10381038
<artifactId>helidon-integrations-vault-cdi</artifactId>
10391039
<version>${helidon.version}</version>
10401040
</dependency>
1041+
<dependency>
1042+
<groupId>io.helidon.integrations.langchain4j</groupId>
1043+
<artifactId>helidon-integrations-langchain4j</artifactId>
1044+
<version>${helidon.version}</version>
1045+
</dependency>
1046+
<dependency>
1047+
<groupId>io.helidon.integrations.langchain4j</groupId>
1048+
<artifactId>helidon-integrations-langchain4j-codegen</artifactId>
1049+
<version>${helidon.version}</version>
1050+
</dependency>
1051+
<dependency>
1052+
<groupId>io.helidon.integrations.langchain4j.providers</groupId>
1053+
<artifactId>helidon-integrations-langchain4j-providers-open-ai</artifactId>
1054+
<version>${helidon.version}</version>
1055+
</dependency>
10411056

10421057
<!-- OpenAPI support -->
10431058
<dependency>
@@ -1484,6 +1499,11 @@
14841499
<artifactId>helidon-metadata-hson</artifactId>
14851500
<version>${helidon.version}</version>
14861501
</dependency>
1502+
<dependency>
1503+
<groupId>io.helidon.metadata</groupId>
1504+
<artifactId>helidon-metadata-reflection</artifactId>
1505+
<version>${helidon.version}</version>
1506+
</dependency>
14871507

14881508
<!-- Injection Integrations related -->
14891509
<dependency>

common/types/src/main/java/io/helidon/common/types/TypeNameSupport.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,10 @@
1616

1717
package io.helidon.common.types;
1818

19+
import java.lang.reflect.GenericArrayType;
1920
import java.lang.reflect.ParameterizedType;
2021
import java.lang.reflect.Type;
22+
import java.lang.reflect.TypeVariable;
2123
import java.lang.reflect.WildcardType;
2224
import java.util.ArrayList;
2325
import java.util.LinkedList;
@@ -198,6 +200,22 @@ static void type(TypeName.BuilderBase<?, ?> builder, Type type) {
198200
builder.wildcard(true);
199201
return;
200202
}
203+
if (reflectGenericType instanceof TypeVariable<?> tv) {
204+
for (Type bound : tv.getBounds()) {
205+
builder.addUpperBound(TypeName.create(bound));
206+
}
207+
208+
builder.className(tv.getName())
209+
.generic(true);
210+
return;
211+
}
212+
if (reflectGenericType instanceof GenericArrayType ga) {
213+
TypeName componentType = TypeName.create(ga.getGenericComponentType());
214+
215+
builder.from(componentType)
216+
.array(true);
217+
return;
218+
}
201219

202220
throw new IllegalArgumentException("We can only create a type from a class, GenericType, or a ParameterizedType,"
203221
+ " but got: " + reflectGenericType.getClass().getName());

dependencies/pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
<version.lib.junit>5.9.3</version.lib.junit>
9898
<version.lib.junit-platform-testkit>1.11.3</version.lib.junit-platform-testkit>
9999
<version.lib.kafka>3.8.1</version.lib.kafka>
100+
<!-- Kotlin: dependency convergence requirement, we never use this directly -->
101+
<version.lib.kotlin>1.9.10</version.lib.kotlin>
102+
<version.lib.langchain4j>0.35.0</version.lib.langchain4j>
103+
<version.lib.langchain4j.oracle>0.1.0</version.lib.langchain4j.oracle>
100104
<version.lib.log4j>2.21.1</version.lib.log4j>
101105
<version.lib.mariadb-java-client>2.6.2</version.lib.mariadb-java-client>
102106
<version.lib.maven-wagon>2.10</version.lib.maven-wagon>
@@ -962,6 +966,53 @@
962966
<artifactId>kafka-clients</artifactId>
963967
<version>${version.lib.kafka}</version>
964968
</dependency>
969+
<!-- Langchain4j integration -->
970+
<dependency>
971+
<groupId>dev.langchain4j</groupId>
972+
<artifactId>langchain4j-cohere</artifactId>
973+
<version>${version.lib.langchain4j}</version>
974+
</dependency>
975+
<dependency>
976+
<groupId>dev.langchain4j</groupId>
977+
<artifactId>langchain4j-ollama</artifactId>
978+
<version>${version.lib.langchain4j}</version>
979+
</dependency>
980+
<dependency>
981+
<groupId>dev.langchain4j</groupId>
982+
<artifactId>langchain4j-open-ai</artifactId>
983+
<version>${version.lib.langchain4j}</version>
984+
</dependency>
985+
<dependency>
986+
<groupId>dev.langchain4j</groupId>
987+
<artifactId>langchain4j-oracle</artifactId>
988+
<version>${version.lib.langchain4j}</version>
989+
</dependency>
990+
<dependency>
991+
<groupId>dev.langchain4j</groupId>
992+
<artifactId>langchain4j</artifactId>
993+
<version>${version.lib.langchain4j}</version>
994+
</dependency>
995+
<dependency>
996+
<groupId>dev.langchain4j</groupId>
997+
<artifactId>langchain4j-core</artifactId>
998+
<version>${version.lib.langchain4j}</version>
999+
</dependency>
1000+
<dependency>
1001+
<groupId>org.jetbrains.kotlin</groupId>
1002+
<artifactId>kotlin-stdlib</artifactId>
1003+
<version>${version.lib.kotlin}</version>
1004+
</dependency>
1005+
<dependency>
1006+
<groupId>org.jetbrains.kotlin</groupId>
1007+
<artifactId>kotlin-stdlib-common</artifactId>
1008+
<version>${version.lib.kotlin}</version>
1009+
</dependency>
1010+
<dependency>
1011+
<groupId>org.jetbrains.kotlin</groupId>
1012+
<artifactId>kotlin-stdlib-jdk8</artifactId>
1013+
<version>${version.lib.kotlin}</version>
1014+
</dependency>
1015+
<!-- Jersey -->
9651016
<dependency>
9661017
<groupId>org.glassfish.jersey.media</groupId>
9671018
<artifactId>jersey-media-json-binding</artifactId>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2025 Oracle and/or its affiliates.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>io.helidon.integrations.langchain4j</groupId>
25+
<artifactId>helidon-integrations-langchain4j-project</artifactId>
26+
<version>4.2.0-SNAPSHOT</version>
27+
<relativePath>../pom.xml</relativePath>
28+
</parent>
29+
30+
<artifactId>helidon-integrations-langchain4j-codegen</artifactId>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>io.helidon.common</groupId>
35+
<artifactId>helidon-common</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>io.helidon.common</groupId>
39+
<artifactId>helidon-common-types</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.helidon.codegen</groupId>
43+
<artifactId>helidon-codegen</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.helidon.codegen</groupId>
47+
<artifactId>helidon-codegen-class-model</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.helidon.service</groupId>
51+
<artifactId>helidon-service-codegen</artifactId>
52+
</dependency>
53+
</dependencies>
54+
</project>

0 commit comments

Comments
 (0)