Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 1.8 support #73

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Java 11+](https://img.shields.io/badge/Java-11%2B-informational)
![Java 1.8+](https://img.shields.io/badge/Java-1.8%2B-informational)
![llama.cpp b3534](https://img.shields.io/badge/llama.cpp-%23b3534-informational)

# Java Bindings for [llama.cpp](https://github.com/ggerganov/llama.cpp)
Expand Down
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>de.kherud</groupId>
<artifactId>llama</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down Expand Up @@ -56,12 +56,6 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/de/kherud/llama/LlamaIterable.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package de.kherud.llama;

import org.jetbrains.annotations.NotNull;

/**
* An iterable used by {@link LlamaModel#generate(InferenceParameters)} that specifically returns a {@link LlamaIterator}.
*/
@FunctionalInterface
public interface LlamaIterable extends Iterable<LlamaOutput> {

@NotNull
@Override
LlamaIterator iterator();

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/de/kherud/llama/LlamaLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import java.util.List;
import java.util.stream.Stream;

import org.jetbrains.annotations.Nullable;

/**
* Set the system properties, de.kherud.llama.lib.path, de.kherud.llama.lib.name, appropriately so that the
* library can find *.dll, *.dylib and *.so files, according to the current OS (win, linux, mac).
Expand Down Expand Up @@ -182,7 +180,6 @@ private static boolean loadNativeLibrary(Path path) {
}
}

@Nullable
private static Path extractFile(String sourceDirectory, String fileName, String targetDirectory, boolean addUuid) {
String nativeLibraryFilePath = sourceDirectory + "/" + fileName;

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/de/kherud/llama/LlamaModel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.kherud.llama;

import de.kherud.llama.args.LogFormat;
import org.jetbrains.annotations.Nullable;

import java.lang.annotation.Native;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -106,9 +105,9 @@ public String decode(int[] tokens) {
* To disable logging, pass an empty callback, i.e., <code>(level, msg) -> {}</code>.
*
* @param format the log format to use
* @param callback a method to call for log messages
* @param callback a method to call for log messages (can be set to null)
*/
public static native void setLogger(LogFormat format, @Nullable BiConsumer<LogLevel, String> callback);
public static native void setLogger(LogFormat format, BiConsumer<LogLevel, String> callback);

@Override
public void close() {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/de/kherud/llama/LlamaOutput.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.kherud.llama;

import org.jetbrains.annotations.NotNull;

import java.nio.charset.StandardCharsets;
import java.util.Map;

Expand All @@ -13,20 +11,19 @@ public final class LlamaOutput {

/**
* The last bit of generated text that is representable as text (i.e., cannot be individual utf-8 multibyte code
* points).
* points). Not null.
*/
@NotNull
public final String text;

/**
* Note, that you have to configure {@link InferenceParameters#setNProbs(int)} in order for probabilities to be returned.
* Note, that you have to configure {@link InferenceParameters#setNProbs(int)} in order for probabilities to be
* returned. Not null.
*/
@NotNull
public final Map<String, Float> probabilities;

final boolean stop;

LlamaOutput(byte[] generated, @NotNull Map<String, Float> probabilities, boolean stop) {
LlamaOutput(byte[] generated, Map<String, Float> probabilities, boolean stop) {
this.text = new String(generated, StandardCharsets.UTF_8);
this.probabilities = probabilities;
this.stop = stop;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/de/kherud/llama/LlamaModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testGenerateGrammar() {
}
String output = sb.toString();

Assert.assertTrue(output.matches("[ab]+"));
Assert.assertTrue("'" + output + "' doesn't match [ab]+", output.matches("[ab]+"));
int generated = model.encode(output).length;
Assert.assertTrue(generated > 0 && generated <= nPredict + 1);
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testCompleteGrammar() {
.setGrammar("root ::= (\"a\" | \"b\")+")
.setNPredict(nPredict);
String output = model.complete(params);
Assert.assertTrue(output + " doesn't match [ab]+", output.matches("[ab]+"));
Assert.assertTrue("'" + output + "' doesn't match [ab]+", output.matches("[ab]+"));
int generated = model.encode(output).length;
Assert.assertTrue(generated > 0 && generated <= nPredict + 1);
}
Expand Down
Loading