diff --git a/src/main/java/io/github/ollama4j/utils/OptionsBuilder.java b/src/main/java/io/github/ollama4j/utils/OptionsBuilder.java index c71818a..4148170 100644 --- a/src/main/java/io/github/ollama4j/utils/OptionsBuilder.java +++ b/src/main/java/io/github/ollama4j/utils/OptionsBuilder.java @@ -1,5 +1,6 @@ package io.github.ollama4j.utils; +import java.io.IOException; import java.util.HashMap; /** Builder class for creating options for Ollama model. */ @@ -207,6 +208,34 @@ public class OptionsBuilder { return this; } + /** + * Alternative to the top_p, and aims to ensure a balance of qualityand variety. The parameter p + * represents the minimum probability for a token to be considered, relative to the probability + * of the most likely token. For example, with p=0.05 and the most likely token having a + * probability of 0.9, logits with a value less than 0.045 are filtered out. (Default: 0.0) + */ + public OptionsBuilder setMinP(float value) { + options.getOptionsMap().put("min_p", value); + return this; + } + + /** + * Allows passing an option not formally supported by the library + * @param name The option name for the parameter. + * @param value The value for the "{name}" parameter. + * @return The updated OptionsBuilder. + * @throws IllegalArgumentException if parameter has an unsupported type + */ + public OptionsBuilder setCustomOption(String name, Object value) throws IllegalArgumentException { + if (!(value instanceof Integer || value instanceof Float || value instanceof String)) { + throw new IllegalArgumentException("Invalid type for parameter. Allowed types are: Integer, Float, or String."); + } + options.getOptionsMap().put(name, value); + return this; + } + + + /** * Builds the options map. * @@ -215,4 +244,6 @@ public class OptionsBuilder { public Options build() { return options; } + + } diff --git a/src/test/java/io/github/ollama4j/unittests/jackson/TestChatRequestSerialization.java b/src/test/java/io/github/ollama4j/unittests/jackson/TestChatRequestSerialization.java index 2391a94..2ce210c 100644 --- a/src/test/java/io/github/ollama4j/unittests/jackson/TestChatRequestSerialization.java +++ b/src/test/java/io/github/ollama4j/unittests/jackson/TestChatRequestSerialization.java @@ -1,6 +1,7 @@ package io.github.ollama4j.unittests.jackson; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrowsExactly; import java.io.File; import java.util.List; @@ -59,6 +60,10 @@ public class TestChatRequestSerialization extends AbstractSerializationTest { + OllamaChatRequest req = builder.withMessage(OllamaChatMessageRole.USER, "Some prompt") + .withOptions(b.setCustomOption("cust_obj", new Object()).build()) + .build(); + }); } @Test