Use Double instead of Float for portable ChatOptions
This change updates the type of portable chat options from Float to Double. Affected options include: - frequencyPenalty - presencePenalty - temperature - topP The motivation for this change is to simplify coding. In Java, Float values require an "f" suffix (e.g., 0.5f), while Double values don't need any suffix. This makes Double easier to type and reduces potential errors from forgetting the "f" suffix. APIs, tests, and documentation have been updated to reflect this change. Fixes gh-712 Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
This commit is contained in:
committed by
Mark Pollack
parent
40714c984d
commit
4b123a7516
@@ -29,25 +29,25 @@ public interface ChatOptions extends ModelOptions {
|
||||
String getModel();
|
||||
|
||||
@Nullable
|
||||
Float getFrequencyPenalty();
|
||||
Double getFrequencyPenalty();
|
||||
|
||||
@Nullable
|
||||
Integer getMaxTokens();
|
||||
|
||||
@Nullable
|
||||
Float getPresencePenalty();
|
||||
Double getPresencePenalty();
|
||||
|
||||
@Nullable
|
||||
List<String> getStopSequences();
|
||||
|
||||
@Nullable
|
||||
Float getTemperature();
|
||||
Double getTemperature();
|
||||
|
||||
@Nullable
|
||||
Integer getTopK();
|
||||
|
||||
@Nullable
|
||||
Float getTopP();
|
||||
Double getTopP();
|
||||
|
||||
ChatOptions copy();
|
||||
|
||||
|
||||
@@ -23,19 +23,19 @@ public class ChatOptionsBuilder {
|
||||
|
||||
private String model;
|
||||
|
||||
private Float frequencyPenalty;
|
||||
private Double frequencyPenalty;
|
||||
|
||||
private Integer maxTokens;
|
||||
|
||||
private Float presencePenalty;
|
||||
private Double presencePenalty;
|
||||
|
||||
private List<String> stopSequences;
|
||||
|
||||
private Float temperature;
|
||||
private Double temperature;
|
||||
|
||||
private Integer topK;
|
||||
|
||||
private Float topP;
|
||||
private Double topP;
|
||||
|
||||
@Override
|
||||
public String getModel() {
|
||||
@@ -47,11 +47,11 @@ public class ChatOptionsBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getFrequencyPenalty() {
|
||||
public Double getFrequencyPenalty() {
|
||||
return frequencyPenalty;
|
||||
}
|
||||
|
||||
public void setFrequencyPenalty(Float frequencyPenalty) {
|
||||
public void setFrequencyPenalty(Double frequencyPenalty) {
|
||||
this.frequencyPenalty = frequencyPenalty;
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ public class ChatOptionsBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getPresencePenalty() {
|
||||
public Double getPresencePenalty() {
|
||||
return presencePenalty;
|
||||
}
|
||||
|
||||
public void setPresencePenalty(Float presencePenalty) {
|
||||
public void setPresencePenalty(Double presencePenalty) {
|
||||
this.presencePenalty = presencePenalty;
|
||||
}
|
||||
|
||||
@@ -83,11 +83,11 @@ public class ChatOptionsBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTemperature() {
|
||||
public Double getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(Float temperature) {
|
||||
public void setTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
@@ -101,11 +101,11 @@ public class ChatOptionsBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTopP() {
|
||||
public Double getTopP() {
|
||||
return topP;
|
||||
}
|
||||
|
||||
public void setTopP(Float topP) {
|
||||
public void setTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class ChatOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatOptionsBuilder withFrequencyPenalty(Float frequencyPenalty) {
|
||||
public ChatOptionsBuilder withFrequencyPenalty(Double frequencyPenalty) {
|
||||
options.setFrequencyPenalty(frequencyPenalty);
|
||||
return this;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class ChatOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatOptionsBuilder withPresencePenalty(Float presencePenalty) {
|
||||
public ChatOptionsBuilder withPresencePenalty(Double presencePenalty) {
|
||||
options.setPresencePenalty(presencePenalty);
|
||||
return this;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public class ChatOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatOptionsBuilder withTemperature(Float temperature) {
|
||||
public ChatOptionsBuilder withTemperature(Double temperature) {
|
||||
options.setTemperature(temperature);
|
||||
return this;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public class ChatOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatOptionsBuilder withTopP(Float topP) {
|
||||
public ChatOptionsBuilder withTopP(Double topP) {
|
||||
options.setTopP(topP);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.util.Assert;
|
||||
* function-calling.
|
||||
*
|
||||
* @author Christian Tzolov
|
||||
* @author Thomas Vitale
|
||||
* @since 0.8.1
|
||||
*/
|
||||
public class FunctionCallingOptionsBuilder {
|
||||
@@ -66,7 +67,7 @@ public class FunctionCallingOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FunctionCallingOptionsBuilder withFrequencyPenalty(Float frequencyPenalty) {
|
||||
public FunctionCallingOptionsBuilder withFrequencyPenalty(Double frequencyPenalty) {
|
||||
this.options.setFrequencyPenalty(frequencyPenalty);
|
||||
return this;
|
||||
}
|
||||
@@ -76,7 +77,7 @@ public class FunctionCallingOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FunctionCallingOptionsBuilder withPresencePenalty(Float presencePenalty) {
|
||||
public FunctionCallingOptionsBuilder withPresencePenalty(Double presencePenalty) {
|
||||
this.options.setPresencePenalty(presencePenalty);
|
||||
return this;
|
||||
}
|
||||
@@ -86,7 +87,7 @@ public class FunctionCallingOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FunctionCallingOptionsBuilder withTemperature(Float temperature) {
|
||||
public FunctionCallingOptionsBuilder withTemperature(Double temperature) {
|
||||
this.options.setTemperature(temperature);
|
||||
return this;
|
||||
}
|
||||
@@ -96,7 +97,7 @@ public class FunctionCallingOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FunctionCallingOptionsBuilder withTopP(Float topP) {
|
||||
public FunctionCallingOptionsBuilder withTopP(Double topP) {
|
||||
this.options.setTopP(topP);
|
||||
return this;
|
||||
}
|
||||
@@ -113,19 +114,19 @@ public class FunctionCallingOptionsBuilder {
|
||||
|
||||
private String model;
|
||||
|
||||
private Float frequencyPenalty;
|
||||
private Double frequencyPenalty;
|
||||
|
||||
private Integer maxTokens;
|
||||
|
||||
private Float presencePenalty;
|
||||
private Double presencePenalty;
|
||||
|
||||
private List<String> stopSequences;
|
||||
|
||||
private Float temperature;
|
||||
private Double temperature;
|
||||
|
||||
private Integer topK;
|
||||
|
||||
private Float topP;
|
||||
private Double topP;
|
||||
|
||||
@Override
|
||||
public List<FunctionCallback> getFunctionCallbacks() {
|
||||
@@ -157,11 +158,11 @@ public class FunctionCallingOptionsBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getFrequencyPenalty() {
|
||||
public Double getFrequencyPenalty() {
|
||||
return frequencyPenalty;
|
||||
}
|
||||
|
||||
public void setFrequencyPenalty(Float frequencyPenalty) {
|
||||
public void setFrequencyPenalty(Double frequencyPenalty) {
|
||||
this.frequencyPenalty = frequencyPenalty;
|
||||
}
|
||||
|
||||
@@ -175,11 +176,11 @@ public class FunctionCallingOptionsBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getPresencePenalty() {
|
||||
public Double getPresencePenalty() {
|
||||
return presencePenalty;
|
||||
}
|
||||
|
||||
public void setPresencePenalty(Float presencePenalty) {
|
||||
public void setPresencePenalty(Double presencePenalty) {
|
||||
this.presencePenalty = presencePenalty;
|
||||
}
|
||||
|
||||
@@ -193,11 +194,11 @@ public class FunctionCallingOptionsBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTemperature() {
|
||||
public Double getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(Float temperature) {
|
||||
public void setTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
@@ -211,11 +212,11 @@ public class FunctionCallingOptionsBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTopP() {
|
||||
public Double getTopP() {
|
||||
return topP;
|
||||
}
|
||||
|
||||
public void setTopP(Float topP) {
|
||||
public void setTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ public class ChatBuilderTests {
|
||||
|
||||
@Test
|
||||
void createNewChatOptionsTest() {
|
||||
Float temperature = 1.1f;
|
||||
Float topP = 2.2f;
|
||||
Double temperature = 1.1;
|
||||
Double topP = 2.2;
|
||||
Integer topK = 111;
|
||||
|
||||
ChatOptions options = ChatOptionsBuilder.builder()
|
||||
@@ -57,8 +57,8 @@ public class ChatBuilderTests {
|
||||
|
||||
@Test
|
||||
void duplicateChatOptionsTest() {
|
||||
Float initTemperature = 1.1f;
|
||||
Float initTopP = 2.2f;
|
||||
Double initTemperature = 1.1;
|
||||
Double initTopP = 2.2;
|
||||
Integer initTopK = 111;
|
||||
|
||||
ChatOptions options = ChatOptionsBuilder.builder()
|
||||
@@ -71,8 +71,8 @@ public class ChatBuilderTests {
|
||||
|
||||
@Test
|
||||
void createFunctionCallingOptionTest() {
|
||||
Float temperature = 1.1f;
|
||||
Float topP = 2.2f;
|
||||
Double temperature = 1.1;
|
||||
Double topP = 2.2;
|
||||
Integer topK = 111;
|
||||
List<FunctionCallback> functionCallbacks = new ArrayList<>();
|
||||
Set<String> functions = new HashSet<>();
|
||||
|
||||
@@ -98,13 +98,13 @@ class DefaultChatModelObservationConventionTests {
|
||||
.provider("superprovider")
|
||||
.requestOptions(ChatOptionsBuilder.builder()
|
||||
.withModel("mistral")
|
||||
.withFrequencyPenalty(0.8f)
|
||||
.withFrequencyPenalty(0.8)
|
||||
.withMaxTokens(200)
|
||||
.withPresencePenalty(1.0f)
|
||||
.withPresencePenalty(1.0)
|
||||
.withStopSequences(List.of("addio", "bye"))
|
||||
.withTemperature(0.5f)
|
||||
.withTemperature(0.5)
|
||||
.withTopK(1)
|
||||
.withTopP(0.9f)
|
||||
.withTopP(0.9)
|
||||
.build())
|
||||
.build();
|
||||
observationContext.setResponse(new ChatResponse(
|
||||
|
||||
@@ -44,7 +44,7 @@ public class PromptTemplateTest {
|
||||
public void testCreateWithEmptyModelAndChatOptions() {
|
||||
String template = "This is a test prompt with no variables";
|
||||
PromptTemplate promptTemplate = new PromptTemplate(template);
|
||||
ChatOptions chatOptions = ChatOptionsBuilder.builder().withTemperature(0.7f).withTopK(3).build();
|
||||
ChatOptions chatOptions = ChatOptionsBuilder.builder().withTemperature(0.7).withTopK(3).build();
|
||||
|
||||
Prompt prompt = promptTemplate.create(chatOptions);
|
||||
|
||||
@@ -60,7 +60,7 @@ public class PromptTemplateTest {
|
||||
model.put("name", "Alice");
|
||||
model.put("age", 30);
|
||||
PromptTemplate promptTemplate = new PromptTemplate(template, model);
|
||||
ChatOptions chatOptions = ChatOptionsBuilder.builder().withTemperature(0.5f).withMaxTokens(100).build();
|
||||
ChatOptions chatOptions = ChatOptionsBuilder.builder().withTemperature(0.5).withMaxTokens(100).build();
|
||||
|
||||
Prompt prompt = promptTemplate.create(model, chatOptions);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class PromptTemplateTest {
|
||||
|
||||
Map<String, Object> overriddenModel = new HashMap<>();
|
||||
overriddenModel.put("color", "red");
|
||||
ChatOptions chatOptions = ChatOptionsBuilder.builder().withTemperature(0.8f).build();
|
||||
ChatOptions chatOptions = ChatOptionsBuilder.builder().withTemperature(0.8).build();
|
||||
|
||||
Prompt prompt = promptTemplate.create(overriddenModel, chatOptions);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user