Compare commits
2 Commits
e051ca803c
...
14d13a7d76
Author | SHA1 | Date | |
---|---|---|---|
14d13a7d76 | |||
3ccc0dd265 |
27
build.gradle
27
build.gradle
@ -1,34 +1,13 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'io.freefair.lombok' version '8.10'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
group = 'be.seeseemelk'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'io.github.ollama4j:ollama4j:1.0.82'
|
||||
|
||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testImplementation 'org.hamcrest:hamcrest:3.0'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
allprojects {
|
||||
group = 'be.seeseemelk'
|
||||
version = '0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
library(MavenPublication) {
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
name = "Gitea"
|
||||
|
34
libllamascript/build.gradle
Normal file
34
libllamascript/build.gradle
Normal file
@ -0,0 +1,34 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'io.freefair.lombok' version '8.10'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'io.github.ollama4j:ollama4j:1.0.82'
|
||||
|
||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testImplementation 'org.hamcrest:hamcrest:3.0'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
libllamascript(MavenPublication) {
|
||||
from components.java
|
||||
artifactId 'libllamascript'
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +1,4 @@
|
||||
rootProject.name = 'libllamascript'
|
||||
rootProject.name = 'llamascript'
|
||||
|
||||
include('libllamascript')
|
||||
include('spring-llamascript-starter')
|
||||
|
38
spring-llamascript-starter/build.gradle
Normal file
38
spring-llamascript-starter/build.gradle
Normal file
@ -0,0 +1,38 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'io.freefair.lombok' version '8.10'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven{ url 'https://gitea.seeseepuff.be/api/packages/llamascript/maven' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot:3.3.2'
|
||||
implementation 'org.springframework.boot:spring-boot-autoconfigure:3.3.2'
|
||||
implementation 'org.springframework.boot:spring-boot-configuration-processor:3.3.2'
|
||||
api project(':libllamascript')
|
||||
|
||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testImplementation 'org.hamcrest:hamcrest:3.0'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
springLlamascriptStarter(MavenPublication) {
|
||||
from components.java
|
||||
artifactId 'spring-llamascript-starter'
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package be.seeseemelk.llamascript.autoconfigure;
|
||||
|
||||
import be.seeseemelk.llamascript.LLamaScriptFactory;
|
||||
import be.seeseemelk.llamascript.LlamaScript;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(LlamaScriptProperties.class)
|
||||
public class LlamaScriptAutoConfiguration {
|
||||
@Autowired
|
||||
private LlamaScriptProperties properties;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public LLamaScriptFactory lLamaScriptFactory() {
|
||||
var factory = new LLamaScriptFactory();
|
||||
factory.setHost(properties.getHost());
|
||||
factory.setModel(properties.getModel());
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public LlamaScript llamaScript(LLamaScriptFactory factory) {
|
||||
return factory.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package be.seeseemelk.llamascript.autoconfigure;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigurationProperties(prefix = "llamascript")
|
||||
public class LlamaScriptProperties {
|
||||
private String host = "http://localhost:11434";
|
||||
private String model = "llama3.1:8b";
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
be.seeseemelk.llamascript.autoconfigure.LlamaScriptAutoConfiguration
|
@ -0,0 +1,12 @@
|
||||
package be.seeseemelk.llamascript;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
public class AbstractLlamaTest {
|
||||
protected LlamaScript llama;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
llama = new LLamaScriptFactory().build();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package be.seeseemelk.llamascript;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class BooleanTests extends AbstractLlamaTest {
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1, 2, 3, 4, 5})
|
||||
void isEven(int number) {
|
||||
boolean isEven = llama.evalBool("Return true if the number is even", number);
|
||||
assertThat(isEven, equalTo(number % 2 == 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isABuilding() {
|
||||
boolean isBuilding = llama.evalBool("Return true if the argument is a building or skyscraper", "Dalai Lama");
|
||||
assertThat(isBuilding, equalTo(false));
|
||||
|
||||
isBuilding = llama.evalBool("Return true if the argument is a building or skyscraper", "Burj Khalifa");
|
||||
assertThat(isBuilding, equalTo(true));
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package be.seeseemelk.llamascript;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class IntegerTests extends AbstractLlamaTest {
|
||||
@Test
|
||||
void canIncrementNumber() {
|
||||
int value = llama.evalInt("Increment the number", 4);
|
||||
assertThat(value, equalTo(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void canMultiply() {
|
||||
int value = llama.evalInt("Multiply the numbers", 2, 3);
|
||||
assertThat(value, equalTo(2*3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void canMax() {
|
||||
int value = llama.evalInt("Select the largest number", -2, 8);
|
||||
assertThat(value, equalTo(8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void canDoWeirdStuff() {
|
||||
int value = llama.evalInt("Select the number with the most '5's in it.", 12, 5, 1023978, 158525);
|
||||
assertThat(value, equalTo(158525));
|
||||
}
|
||||
|
||||
@Test
|
||||
void givePositivity() {
|
||||
int value = llama.evalInt("If the string is something positive, return 1. Else, return 0.", "I like rainbows");
|
||||
assertThat(value, equalTo(1));
|
||||
|
||||
value = llama.evalInt("If the string is something positive, return 1. Else, return 0.", "Death to all");
|
||||
assertThat(value, equalTo(0));
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package be.seeseemelk.llamascript;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class StringTests extends AbstractLlamaTest {
|
||||
@Test
|
||||
void canUppercase() {
|
||||
String value = llama.evalString("Return the string in uppercase", "Cat");
|
||||
assertThat(value, equalTo("CAT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void canLowercase() {
|
||||
String value = llama.evalString("Return the string in lowercase", "Cat");
|
||||
assertThat(value, equalTo("cat"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void canInvert() {
|
||||
String value = llama.evalString("Return the string backwards", "Cat");
|
||||
assertThat(value, equalTo("taC"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void canSelectLongest() {
|
||||
String value = llama.evalString("Return the longest string", "Cat", "Dog", "Horse");
|
||||
assertThat(value, equalTo("Horse"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void canDoWeirdStuff() {
|
||||
String value = llama.evalString("Return the string that does not fit", "Cat", "Dog", "Horse", "Bicycle");
|
||||
assertThat(value, equalTo("Bicycle"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void canDoReallyWeirdStuff() {
|
||||
String value = llama.evalString("Sort the letters alphabetically", "horse");
|
||||
assertThat(value, equalTo("ehors"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user