forked from Mirror/ollama4j
		
	Add minp option and ability to set custom options
This commit is contained in:
		@@ -207,6 +207,33 @@ public class OptionsBuilder {
 | 
				
			|||||||
    return this;
 | 
					    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.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  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.
 | 
					   * Builds the options map.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
@@ -215,4 +242,6 @@ public class OptionsBuilder {
 | 
				
			|||||||
  public Options build() {
 | 
					  public Options build() {
 | 
				
			||||||
    return options;
 | 
					    return options;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,10 +3,12 @@ package io.github.ollama4j.unittests.jackson;
 | 
				
			|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
 | 
					import static org.junit.jupiter.api.Assertions.assertEquals;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					import java.security.InvalidParameterException;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import io.github.ollama4j.models.chat.OllamaChatRequest;
 | 
					import io.github.ollama4j.models.chat.OllamaChatRequest;
 | 
				
			||||||
import org.json.JSONObject;
 | 
					import org.json.JSONObject;
 | 
				
			||||||
 | 
					import org.junit.jupiter.api.Assertions;
 | 
				
			||||||
import org.junit.jupiter.api.BeforeEach;
 | 
					import org.junit.jupiter.api.BeforeEach;
 | 
				
			||||||
import org.junit.jupiter.api.Test;
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -59,6 +61,10 @@ public class TestChatRequestSerialization extends AbstractSerializationTest<Olla
 | 
				
			|||||||
            .withOptions(b.setSeed(1).build())
 | 
					            .withOptions(b.setSeed(1).build())
 | 
				
			||||||
            .withOptions(b.setTopK(1).build())
 | 
					            .withOptions(b.setTopK(1).build())
 | 
				
			||||||
            .withOptions(b.setTopP(1).build())
 | 
					            .withOptions(b.setTopP(1).build())
 | 
				
			||||||
 | 
					            .withOptions(b.setMinP(1).build())
 | 
				
			||||||
 | 
					            .withOptions(b.setCustomOption("cust_float", 1.0f).build())
 | 
				
			||||||
 | 
					            .withOptions(b.setCustomOption("cust_int", 1).build())
 | 
				
			||||||
 | 
					            .withOptions(b.setCustomOption("cust_str", "custom").build())
 | 
				
			||||||
            .build();
 | 
					            .build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        String jsonRequest = serialize(req);
 | 
					        String jsonRequest = serialize(req);
 | 
				
			||||||
@@ -72,6 +78,20 @@ public class TestChatRequestSerialization extends AbstractSerializationTest<Olla
 | 
				
			|||||||
        assertEquals(1, deserializeRequest.getOptions().get("seed"));
 | 
					        assertEquals(1, deserializeRequest.getOptions().get("seed"));
 | 
				
			||||||
        assertEquals(1, deserializeRequest.getOptions().get("top_k"));
 | 
					        assertEquals(1, deserializeRequest.getOptions().get("top_k"));
 | 
				
			||||||
        assertEquals(1.0, deserializeRequest.getOptions().get("top_p"));
 | 
					        assertEquals(1.0, deserializeRequest.getOptions().get("top_p"));
 | 
				
			||||||
 | 
					        assertEquals(1.0, deserializeRequest.getOptions().get("min_p"));
 | 
				
			||||||
 | 
					        assertEquals(1.0, deserializeRequest.getOptions().get("cust_float"));
 | 
				
			||||||
 | 
					        assertEquals(1, deserializeRequest.getOptions().get("cust_int"));
 | 
				
			||||||
 | 
					        assertEquals("custom", deserializeRequest.getOptions().get("cust_str"));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    public void testRequestWithInvalidCustomOption() {
 | 
				
			||||||
 | 
					        OptionsBuilder b = new OptionsBuilder();
 | 
				
			||||||
 | 
					        Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> {
 | 
				
			||||||
 | 
					                OllamaChatRequest req = builder.withMessage(OllamaChatMessageRole.USER, "Some prompt")
 | 
				
			||||||
 | 
					                .withOptions(b.setCustomOption("cust_obj", new Object()).build())
 | 
				
			||||||
 | 
					                .build();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user