Skip to content

Commit 89ea554

Browse files
authored
Merge pull request #1008 from quarkiverse/llama3-java
Introduce llama3-java module
2 parents 6369d00 + f159c78 commit 89ea554

Some content is hidden

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

45 files changed

+4217
-2
lines changed

.github/workflows/build-against-langchain4j.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
os: [ubuntu-latest]
21-
java: [17, 21]
21+
java: [21]
2222
runs-on: ${{ matrix.os }}
2323
steps:
2424
- name: Prepare git

.github/workflows/build-pull-request.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ jobs:
6666
| jq -R -s -c 'split("\n")[:-1]')
6767
6868
# Integration tests (without the in-process embedding models)
69-
# Remove JLama from the list
69+
# Remove JLama and Llama3 from the list
7070
cd integration-tests
7171
IT_MODULES=$( \
7272
find . -mindepth 2 -maxdepth 2 -type f -name 'pom.xml' -exec dirname {} \; \
7373
| sed 's|^\./||' \
7474
| sort -u \
7575
| grep -v jlama \
76+
| grep -v llama3-java \
7677
| grep -v in-process-embedding-models \
7778
| jq -R -s -c 'split("\n")[:-1]')
7879

.github/workflows/release-perform.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ jobs:
2626
secrets: inherit
2727
with:
2828
version: ${{github.event.inputs.tag || github.ref_name}}
29+
java_version: 23

.github/workflows/release-prepare.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ jobs:
1515
name: Prepare Release
1616
if: ${{ github.event.pull_request.merged == true}}
1717
uses: quarkiverse/.github/.github/workflows/prepare-release.yml@main
18+
with:
19+
java_version: 23 # use 23 so we can support running the Llama3 module on anything 21+
1820
secrets: inherit
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>io.quarkiverse.langchain4j</groupId>
6+
<artifactId>quarkus-langchain4j-integration-tests-parent</artifactId>
7+
<version>999-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>quarkus-langchain4j-integration-test-jlama</artifactId>
10+
<name>Quarkus LangChain4j - Integration Tests - Jlama</name>
11+
<properties>
12+
<skipITs>true</skipITs>
13+
<maven.compiler.release>21</maven.compiler.release>
14+
</properties>
15+
<dependencies>
16+
<dependency>
17+
<groupId>io.quarkus</groupId>
18+
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>io.quarkiverse.langchain4j</groupId>
22+
<artifactId>quarkus-langchain4j-llama3-java</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>io.quarkus</groupId>
27+
<artifactId>quarkus-junit5</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>io.rest-assured</groupId>
32+
<artifactId>rest-assured</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.assertj</groupId>
37+
<artifactId>assertj-core</artifactId>
38+
<version>${assertj.version}</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.quarkus</groupId>
43+
<artifactId>quarkus-devtools-testing</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
47+
<!-- Make sure the deployment artifact is built before executing this module -->
48+
<dependency>
49+
<groupId>io.quarkiverse.langchain4j</groupId>
50+
<artifactId>quarkus-langchain4j-llama3-java-deployment</artifactId>
51+
<version>${project.version}</version>
52+
<type>pom</type>
53+
<scope>test</scope>
54+
<exclusions>
55+
<exclusion>
56+
<groupId>*</groupId>
57+
<artifactId>*</artifactId>
58+
</exclusion>
59+
</exclusions>
60+
</dependency>
61+
</dependencies>
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<groupId>io.quarkus</groupId>
66+
<artifactId>quarkus-maven-plugin</artifactId>
67+
<executions>
68+
<execution>
69+
<goals>
70+
<goal>build</goal>
71+
</goals>
72+
</execution>
73+
</executions>
74+
<configuration>
75+
<jvmArgs>--enable-preview --enable-native-access=ALL-UNNAMED</jvmArgs>
76+
<modules>
77+
<module>jdk.incubator.vector</module>
78+
</modules>
79+
</configuration>
80+
</plugin>
81+
<plugin>
82+
<artifactId>maven-failsafe-plugin</artifactId>
83+
<executions>
84+
<execution>
85+
<goals>
86+
<goal>integration-test</goal>
87+
<goal>verify</goal>
88+
</goals>
89+
<configuration>
90+
<systemPropertyVariables>
91+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
92+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
93+
<maven.home>${maven.home}</maven.home>
94+
</systemPropertyVariables>
95+
</configuration>
96+
</execution>
97+
</executions>
98+
</plugin>
99+
</plugins>
100+
</build>
101+
<profiles>
102+
<profile>
103+
<id>native-image</id>
104+
<activation>
105+
<property>
106+
<name>native</name>
107+
</property>
108+
</activation>
109+
<build>
110+
<plugins>
111+
<plugin>
112+
<artifactId>maven-surefire-plugin</artifactId>
113+
<configuration>
114+
<skipTests>${native.surefire.skip}</skipTests>
115+
</configuration>
116+
</plugin>
117+
</plugins>
118+
</build>
119+
<properties>
120+
<skipITs>false</skipITs>
121+
<quarkus.package.type>native</quarkus.package.type>
122+
</properties>
123+
</profile>
124+
</profiles>
125+
</project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.acme.example.jlama.chat;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
import jakarta.ws.rs.core.MediaType;
6+
7+
import org.jboss.resteasy.reactive.RestStreamElementType;
8+
9+
import dev.langchain4j.data.message.AiMessage;
10+
import dev.langchain4j.model.StreamingResponseHandler;
11+
import dev.langchain4j.model.chat.ChatLanguageModel;
12+
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
13+
import dev.langchain4j.model.output.Response;
14+
import io.smallrye.common.annotation.Blocking;
15+
import io.smallrye.mutiny.Multi;
16+
17+
@Path("chat")
18+
public class ChatLanguageModelResource {
19+
20+
private final ChatLanguageModel chatModel;
21+
private final StreamingChatLanguageModel streamingChatModel;
22+
23+
public ChatLanguageModelResource(ChatLanguageModel chatModel, StreamingChatLanguageModel streamingChatModel) {
24+
this.chatModel = chatModel;
25+
this.streamingChatModel = streamingChatModel;
26+
}
27+
28+
@GET
29+
@Path("blocking")
30+
public String blocking() {
31+
return chatModel.generate("When was the nobel prize for economics first awarded?");
32+
}
33+
34+
@GET
35+
@Path("streaming")
36+
@RestStreamElementType(MediaType.TEXT_PLAIN)
37+
@Blocking
38+
public Multi<String> streaming() {
39+
return Multi.createFrom().emitter(emitter -> {
40+
streamingChatModel.generate("When was the nobel prize for economics first awarded?",
41+
new StreamingResponseHandler<>() {
42+
@Override
43+
public void onNext(String token) {
44+
emitter.emit(token);
45+
}
46+
47+
@Override
48+
public void onError(Throwable error) {
49+
emitter.fail(error);
50+
}
51+
52+
@Override
53+
public void onComplete(Response<AiMessage> response) {
54+
emitter.complete();
55+
}
56+
});
57+
});
58+
59+
}
60+
}

integration-tests/llama3-java/src/main/resources/application.properties

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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>io.quarkiverse.langchain4j</groupId>
6+
<artifactId>quarkus-langchain4j-llama3-java-parent</artifactId>
7+
<version>999-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>quarkus-langchain4j-llama3-java-deployment</artifactId>
10+
<name>Quarkus LangChain4j - Llama3 - Java - Deployment</name>
11+
<dependencies>
12+
<dependency>
13+
<groupId>io.quarkiverse.langchain4j</groupId>
14+
<artifactId>quarkus-langchain4j-llama3-java</artifactId>
15+
<version>${project.version}</version>
16+
</dependency>
17+
<dependency>
18+
<groupId>io.quarkiverse.langchain4j</groupId>
19+
<artifactId>quarkus-langchain4j-core-deployment</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>io.quarkus</groupId>
24+
<artifactId>quarkus-junit5-internal</artifactId>
25+
<scope>test</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.assertj</groupId>
29+
<artifactId>assertj-core</artifactId>
30+
<version>${assertj.version}</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>io.quarkiverse.langchain4j</groupId>
35+
<artifactId>quarkus-langchain4j-testing-internal</artifactId>
36+
<version>${project.version}</version>
37+
<scope>test</scope>
38+
</dependency>
39+
</dependencies>
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<artifactId>maven-compiler-plugin</artifactId>
44+
<configuration>
45+
<annotationProcessorPaths>
46+
<path>
47+
<groupId>io.quarkus</groupId>
48+
<artifactId>quarkus-extension-processor</artifactId>
49+
<version>${quarkus.version}</version>
50+
</path>
51+
</annotationProcessorPaths>
52+
</configuration>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.quarkiverse.langchain4j.llama3.deployment;
2+
3+
import java.util.Optional;
4+
5+
import io.quarkus.runtime.annotations.ConfigDocDefault;
6+
import io.quarkus.runtime.annotations.ConfigGroup;
7+
8+
@ConfigGroup
9+
public interface ChatModelBuildConfig {
10+
11+
/**
12+
* Whether the model should be enabled
13+
*/
14+
@ConfigDocDefault("true")
15+
Optional<Boolean> enabled();
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.quarkiverse.langchain4j.llama3.deployment;
2+
3+
import static io.quarkus.runtime.annotations.ConfigPhase.BUILD_TIME;
4+
5+
import io.quarkus.runtime.annotations.ConfigRoot;
6+
import io.smallrye.config.ConfigMapping;
7+
import io.smallrye.config.WithDefault;
8+
9+
@ConfigRoot(phase = BUILD_TIME)
10+
@ConfigMapping(prefix = "quarkus.langchain4j.llama3")
11+
public interface LangChain4jLlama3BuildTimeConfig {
12+
13+
/**
14+
* Determines whether the necessary Jlama models are downloaded and included in the jar at build time.
15+
* Currently, this option is only valid for {@code fast-jar} deployments.
16+
*/
17+
@WithDefault("true")
18+
boolean includeModelsInArtifact();
19+
20+
/**
21+
* Chat model related settings
22+
*/
23+
ChatModelBuildConfig chatModel();
24+
25+
}

0 commit comments

Comments
 (0)