Skip to content

Commit

Permalink
Java: Fix #6028 (#6912)
Browse files Browse the repository at this point in the history
### Description

Fixes: #6028

### Contribution Checklist

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄

Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
st4sik and st4sikR committed Jun 24, 2024
1 parent 9f409dc commit d93d290
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public Builder withTokenSelectionBiases(Map<Integer, Integer> tokenSelectionBias
*/
public Builder withResponseFormat(ResponseFormat responseFormat) {
if (responseFormat != null) {
settings.put(RESPONSE_FORMAT, responseFormat);
settings.put(RESPONSE_FORMAT, responseFormat.toString());
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.orchestration;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class PromptExecutionSettingsTest {

@Test
Expand Down Expand Up @@ -133,4 +132,60 @@ void testJsonDeserializeAndBuilder() throws Exception {

assertEquals(settingsFromBuilder, settingsFromJson);
}

@Test
void testJsonResponseFormat() {
PromptExecutionSettings settingsFromBuilder = PromptExecutionSettings.builder()
.withServiceId("custom-service")
.withMaxTokens(512)
.withTemperature(0.8)
.withTopP(0.5)
.withPresencePenalty(0.2)
.withFrequencyPenalty(0.3)
.withBestOf(3)
.withResultsPerPrompt(5)
.withResponseFormat(ResponseFormat.JSON_OBJECT)
.withModelId("custom-model")
.withUser("custom-user")
.build();

assertEquals(ResponseFormat.JSON_OBJECT, settingsFromBuilder.getResponseFormat());
}

@Test
void testTextResponseFormat() {
PromptExecutionSettings settingsFromBuilder = PromptExecutionSettings.builder()
.withServiceId("custom-service")
.withMaxTokens(512)
.withTemperature(0.8)
.withTopP(0.5)
.withPresencePenalty(0.2)
.withFrequencyPenalty(0.3)
.withBestOf(3)
.withResultsPerPrompt(5)
.withResponseFormat(ResponseFormat.TEXT)
.withModelId("custom-model")
.withUser("custom-user")
.build();

assertEquals(ResponseFormat.TEXT, settingsFromBuilder.getResponseFormat());
}

@Test
void testNullResponseFormat() {
PromptExecutionSettings settingsFromBuilder = PromptExecutionSettings.builder()
.withServiceId("custom-service")
.withMaxTokens(512)
.withTemperature(0.8)
.withTopP(0.5)
.withPresencePenalty(0.2)
.withFrequencyPenalty(0.3)
.withBestOf(3)
.withResultsPerPrompt(5)
.withModelId("custom-model")
.withUser("custom-user")
.build();

assertNull(settingsFromBuilder.getResponseFormat());
}
}

0 comments on commit d93d290

Please sign in to comment.