Skip to content

Commit 3bb9e6c

Browse files
committed
added examples project
1 parent fd2609e commit 3bb9e6c

File tree

7 files changed

+99
-1
lines changed

7 files changed

+99
-1
lines changed

llm4j-examples/pom.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.llm4j</groupId>
9+
<artifactId>llm4j-parent</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<relativePath>../parent-pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>llm4j-examples</artifactId>
15+
16+
<packaging>jar</packaging>
17+
<name>LLM4J Examples Module</name>
18+
<description>Examples showcasing how to LLM4J to query LLMs</description>
19+
20+
<url>http://github.com/dzlab</url>
21+
22+
<properties>
23+
<module-name>org.llm4j.examples</module-name>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.llm4j</groupId>
29+
<artifactId>llm4j-api</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.llm4j</groupId>
33+
<artifactId>llm4j-huggingface</artifactId>
34+
</dependency>
35+
36+
</dependencies>
37+
38+
39+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.llm4j.examples;
2+
3+
import org.apache.commons.configuration2.Configuration;
4+
import org.apache.commons.configuration2.builder.fluent.Configurations;
5+
import org.apache.commons.configuration2.ex.ConfigurationException;
6+
import org.llm4j.api.LLM4J;
7+
import org.llm4j.huggingface.HFLanguageModel;
8+
9+
public class HFApp {
10+
11+
public static void main(String[] args) throws ConfigurationException {
12+
Configuration config = new Configurations().properties("llm4j.properties");
13+
14+
HFLanguageModel.Builder factory = new HFLanguageModel.Builder();
15+
HFLanguageModel llm = (HFLanguageModel) LLM4J.getLanguageModel(config, factory);
16+
17+
String answer = llm.process("In what country is Andalossia?");
18+
System.out.println(answer);
19+
}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.llm4j.examples;
2+
3+
import org.apache.commons.configuration2.Configuration;
4+
import org.apache.commons.configuration2.builder.fluent.Configurations;
5+
import org.apache.commons.configuration2.ex.ConfigurationException;
6+
import org.llm4j.api.LLM4J;
7+
import org.llm4j.api.LanguageModel;
8+
9+
public class LLMApp {
10+
11+
public static void main(String[] args) throws ConfigurationException {
12+
Configuration config = new Configurations().properties("llm4j.properties");
13+
14+
LanguageModel llm = LLM4J.getLanguageModel(config);
15+
16+
String answer = llm.process("In what country is Andalossia?");
17+
System.out.println(answer);
18+
}
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.llm4j.huggingface.HFServiceProvider
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
hf.waitForModel=false
2+
hf.useCache=true
3+
4+
# Set API key using env variable or use actual value
5+
hf.apiKey=${env:HF_API_KEY}
6+
7+
modelId=tiiuae/falcon-7b-instruct
8+
# timeout in milliseconds
9+
timeout=10000
10+
11+
topK=3
12+
topP=0.4
13+
temperature=0.7
14+
repetitionPenalty=0.9
15+
maxNewTokens=256
16+
maxTime=11
17+
returnFullText=false
18+
numReturnSequences=2
19+
doSample=false

llm4j-huggingface/src/test/java/org/llm4j/huggingface/HFLanguageModelTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class HFLanguageModelTest {
1717
public void should_send_messages_and_receive_response() throws ConfigurationException {
1818

1919
Configuration config = new Configurations().properties("llm4j.properties");
20-
Configuration envConfig = new EnvironmentConfiguration();
2120

2221
LanguageModel llm = new HFLanguageModel.Builder()
2322
.getLanguageModel(config);

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<modules>
1616
<module>parent-pom.xml</module>
1717
<module>llm4j-api</module>
18+
<module>llm4j-examples</module>
1819
<module>llm4j-huggingface</module>
1920
</modules>
2021

0 commit comments

Comments
 (0)