From: Mathieu Baudier Date: Thu, 15 Aug 2024 16:11:32 +0000 (+0200) Subject: Introduce de.kherud.llama X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=e004cff7e4d548b1335545f1fcdd50461b2ca239;p=gpl%2Fargeo-tp.git Introduce de.kherud.llama --- diff --git a/rebuild/org.argeo.tp.ml/Makefile b/rebuild/org.argeo.tp.ml/Makefile new file mode 100644 index 0000000..d1268db --- /dev/null +++ b/rebuild/org.argeo.tp.ml/Makefile @@ -0,0 +1,39 @@ +include ../../sdk.mk +.PHONY: clean all osgi + +export NO_SDK_LEGAL := true + +A2_CATEGORY = org.argeo.tp.ml + +## FIXME - DON'T FORGET TO UPDATE THE VERSION IN THE RELATED bnd.bnd FILE! +JLLAMA_BRANCH=3.3 +JLLAMA_VERSION=$(JLLAMA_BRANCH).0 + +all: retrieve-jllama osgi + mkdir -p $(SDK_BUILD_BASE)/a2/$(TARGET_ARCH_CATEGORY_PREFIX)/$(A2_CATEGORY) + mv $(SDK_BUILD_BASE)/a2/$(A2_CATEGORY)/de.kherud.llama.$(JLLAMA_BRANCH).jar $(SDK_BUILD_BASE)/a2/$(TARGET_ARCH_CATEGORY_PREFIX)/$(A2_CATEGORY) + +install: + mkdir -p $(A2_NATIVE_INSTALL_TARGET)/$(A2_CATEGORY) + $(INSTALL) $(A2_NATIVE_INSTALL_TARGET)/$(A2_CATEGORY) $(SDK_BUILD_BASE)/a2/$(TARGET_ARCH_CATEGORY_PREFIX)/$(A2_CATEGORY)/de.kherud.llama.$(JLLAMA_BRANCH).jar + +uninstall: osgi-uninstall + @if [ -d $(A2_NATIVE_INSTALL_TARGET) ]; then find $(A2_NATIVE_INSTALL_TARGET) -empty -type d -delete; fi + +retrieve-jllama: SRC_DIR=src/jllama +retrieve-jllama: + rm -rf $(SRC_DIR) + mkdir -p $(SRC_DIR) + git clone --branch v$(JLLAMA_VERSION) https://github.com/kherud/java-llama.cpp.git $(SRC_DIR) + rm -rf $(SRC_DIR)/.git + rsync -a --delete --exclude module-info.java $(SRC_DIR)/src/main/java/ de.kherud.llama/src + # diff -crB src/jllama/src/main/java de.kherud.llama/src > remove-jetbrain-annotations.patch + patch -p0 < remove-jetbrain-annotations.patch + +BUNDLES = \ +de.kherud.llama \ + +clean: + rm -rf $(BUILD_BASE) + +include $(SDK_SRC_BASE)/sdk/argeo-build/osgi.mk diff --git a/rebuild/org.argeo.tp.ml/de.kherud.llama/.classpath b/rebuild/org.argeo.tp.ml/de.kherud.llama/.classpath new file mode 100644 index 0000000..81fe078 --- /dev/null +++ b/rebuild/org.argeo.tp.ml/de.kherud.llama/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rebuild/org.argeo.tp.ml/de.kherud.llama/.gitignore b/rebuild/org.argeo.tp.ml/de.kherud.llama/.gitignore new file mode 100644 index 0000000..651109a --- /dev/null +++ b/rebuild/org.argeo.tp.ml/de.kherud.llama/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/src/ diff --git a/rebuild/org.argeo.tp.ml/de.kherud.llama/.project b/rebuild/org.argeo.tp.ml/de.kherud.llama/.project new file mode 100644 index 0000000..1bc8a5a --- /dev/null +++ b/rebuild/org.argeo.tp.ml/de.kherud.llama/.project @@ -0,0 +1,28 @@ + + + de.kherud.llama + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rebuild/org.argeo.tp.ml/de.kherud.llama/.settings/org.eclipse.jdt.core.prefs b/rebuild/org.argeo.tp.ml/de.kherud.llama/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..62ef348 --- /dev/null +++ b/rebuild/org.argeo.tp.ml/de.kherud.llama/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/rebuild/org.argeo.tp.ml/de.kherud.llama/.settings/org.eclipse.pde.core.prefs b/rebuild/org.argeo.tp.ml/de.kherud.llama/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000..f29e940 --- /dev/null +++ b/rebuild/org.argeo.tp.ml/de.kherud.llama/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/rebuild/org.argeo.tp.ml/de.kherud.llama/META-INF/.gitignore b/rebuild/org.argeo.tp.ml/de.kherud.llama/META-INF/.gitignore new file mode 100644 index 0000000..4854a41 --- /dev/null +++ b/rebuild/org.argeo.tp.ml/de.kherud.llama/META-INF/.gitignore @@ -0,0 +1 @@ +/MANIFEST.MF diff --git a/rebuild/org.argeo.tp.ml/de.kherud.llama/bnd.bnd b/rebuild/org.argeo.tp.ml/de.kherud.llama/bnd.bnd new file mode 100644 index 0000000..c9b5922 --- /dev/null +++ b/rebuild/org.argeo.tp.ml/de.kherud.llama/bnd.bnd @@ -0,0 +1,4 @@ + +major: 3 +minor: 3 +micro: 0 diff --git a/rebuild/org.argeo.tp.ml/de.kherud.llama/build.properties b/rebuild/org.argeo.tp.ml/de.kherud.llama/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/rebuild/org.argeo.tp.ml/de.kherud.llama/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/rebuild/org.argeo.tp.ml/remove-jetbrain-annotations.patch b/rebuild/org.argeo.tp.ml/remove-jetbrain-annotations.patch new file mode 100644 index 0000000..7a9d81b --- /dev/null +++ b/rebuild/org.argeo.tp.ml/remove-jetbrain-annotations.patch @@ -0,0 +1,124 @@ +diff -crB src/jllama/src/main/java/de/kherud/llama/LlamaIterable.java de.kherud.llama/src/de/kherud/llama/LlamaIterable.java +*** src/jllama/src/main/java/de/kherud/llama/LlamaIterable.java 2024-08-15 17:35:49.059197840 +0200 +--- de.kherud.llama/src/de/kherud/llama/LlamaIterable.java 2024-08-15 17:45:43.971905905 +0200 +*************** +*** 1,14 **** + 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 { + +- @NotNull + @Override + LlamaIterator iterator(); + +--- 1,11 ---- +diff -crB src/jllama/src/main/java/de/kherud/llama/LlamaLoader.java de.kherud.llama/src/de/kherud/llama/LlamaLoader.java +*** src/jllama/src/main/java/de/kherud/llama/LlamaLoader.java 2024-08-15 17:35:49.059197840 +0200 +--- de.kherud.llama/src/de/kherud/llama/LlamaLoader.java 2024-08-15 17:46:01.588281158 +0200 +*************** +*** 28,35 **** + 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). +--- 28,33 ---- +*************** +*** 182,188 **** + } + } + +- @Nullable + private static Path extractFile(String sourceDirectory, String fileName, String targetDirectory, boolean addUuid) { + String nativeLibraryFilePath = sourceDirectory + "/" + fileName; + +--- 180,185 ---- +diff -crB src/jllama/src/main/java/de/kherud/llama/LlamaModel.java de.kherud.llama/src/de/kherud/llama/LlamaModel.java +*** src/jllama/src/main/java/de/kherud/llama/LlamaModel.java 2024-08-15 17:35:49.059197840 +0200 +--- de.kherud.llama/src/de/kherud/llama/LlamaModel.java 2024-08-15 17:46:21.072696202 +0200 +*************** +*** 1,7 **** + 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; +--- 1,6 ---- +*************** +*** 108,114 **** + * @param format the log format to use + * @param callback a method to call for log messages + */ +! public static native void setLogger(LogFormat format, @Nullable BiConsumer callback); + + @Override + public void close() { +--- 107,113 ---- + * @param format the log format to use + * @param callback a method to call for log messages + */ +! public static native void setLogger(LogFormat format, BiConsumer callback); + + @Override + public void close() { +diff -crB src/jllama/src/main/java/de/kherud/llama/LlamaOutput.java de.kherud.llama/src/de/kherud/llama/LlamaOutput.java +*** src/jllama/src/main/java/de/kherud/llama/LlamaOutput.java 2024-08-15 17:35:49.059197840 +0200 +--- de.kherud.llama/src/de/kherud/llama/LlamaOutput.java 2024-08-15 17:46:42.069143454 +0200 +*************** +*** 1,7 **** + package de.kherud.llama; + +- import org.jetbrains.annotations.NotNull; +- + import java.nio.charset.StandardCharsets; + import java.util.Map; + +--- 1,5 ---- +*************** +*** 15,32 **** + * The last bit of generated text that is representable as text (i.e., cannot be individual utf-8 multibyte code + * points). + */ +- @NotNull + public final String text; + + /** + * Note, that you have to configure {@link InferenceParameters#setNProbs(int)} in order for probabilities to be returned. + */ +- @NotNull + public final Map probabilities; + + final boolean stop; + +! LlamaOutput(byte[] generated, @NotNull Map probabilities, boolean stop) { + this.text = new String(generated, StandardCharsets.UTF_8); + this.probabilities = probabilities; + this.stop = stop; +--- 13,28 ---- + * The last bit of generated text that is representable as text (i.e., cannot be individual utf-8 multibyte code + * points). + */ + public final String text; + + /** + * Note, that you have to configure {@link InferenceParameters#setNProbs(int)} in order for probabilities to be returned. + */ + public final Map probabilities; + + final boolean stop; + +! LlamaOutput(byte[] generated, Map probabilities, boolean stop) { + this.text = new String(generated, StandardCharsets.UTF_8); + this.probabilities = probabilities; + this.stop = stop; diff --git a/rebuild/org.argeo.tp.ml/src/.gitignore b/rebuild/org.argeo.tp.ml/src/.gitignore new file mode 100644 index 0000000..2149a7e --- /dev/null +++ b/rebuild/org.argeo.tp.ml/src/.gitignore @@ -0,0 +1 @@ +/jllama/