Skip to content

Commit e525da9

Browse files
markpollackleijendary
authored andcommitted
Revert back to previous OpenAiApi implementation and disable config prop tests
Signed-off-by: leijendary <[email protected]>
1 parent 06028a5 commit e525da9

File tree

3 files changed

+14
-102
lines changed

3 files changed

+14
-102
lines changed

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatOptions.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest.StreamOptions;
3939
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest.ToolChoiceBuilder;
4040
import org.springframework.util.Assert;
41-
import org.springframework.util.StringUtils;
4241

4342
/**
4443
* @author Christian Tzolov
@@ -314,14 +313,6 @@ public ResponseFormat getResponseFormat() {
314313
}
315314

316315
public void setResponseFormat(ResponseFormat responseFormat) {
317-
if (responseFormat != null) {
318-
ResponseFormat.JsonSchema jsonSchema = StringUtils.hasText(responseFormat.getSchema())
319-
? new ResponseFormat.JsonSchema(responseFormat.getName(), responseFormat.getSchema(),
320-
responseFormat.getStrict())
321-
: null;
322-
323-
responseFormat.setJsonSchema(jsonSchema);
324-
}
325316
this.responseFormat = responseFormat;
326317
}
327318

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java

Lines changed: 11 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.List;
2020
import java.util.Map;
21-
import java.util.Objects;
2221
import java.util.concurrent.atomic.AtomicBoolean;
2322
import java.util.function.Consumer;
2423
import java.util.function.Predicate;
@@ -868,62 +867,16 @@ public static Object FUNCTION(String functionName) {
868867
}
869868
}
870869

871-
@JsonInclude(JsonInclude.Include.NON_NULL)
872-
public static class ResponseFormat {
873-
874-
@JsonProperty("type")
875-
private Type type;
876-
877-
private String name;
878-
879-
private String schema;
880-
881-
private Boolean strict;
882-
883-
@JsonProperty("json_schema")
884-
private JsonSchema jsonSchema;
885-
886-
@JsonProperty("type")
887-
public Type getType() {
888-
return this.type;
889-
}
890-
891-
@JsonProperty("json_schema")
892-
public JsonSchema getJsonSchema() {
893-
return StringUtils.hasText(this.schema) ? new JsonSchema(this.name, this.schema, this.strict) : null;
894-
}
895-
896-
public String getName() {
897-
return this.name;
898-
}
899-
900-
public void setName(String name) {
901-
this.name = name;
902-
}
903-
904-
public String getSchema() {
905-
return this.schema;
906-
}
907-
908-
public void setSchema(String schema) {
909-
this.schema = schema;
910-
}
911-
912-
public Boolean getStrict() {
913-
return this.strict;
914-
}
915-
916-
public void setStrict(Boolean strict) {
917-
this.strict = strict;
918-
}
919-
920-
private ResponseFormat() {
921-
}
922-
923-
public ResponseFormat(Type type, JsonSchema jsonSchema) {
924-
this.type = type;
925-
this.jsonSchema = jsonSchema;
926-
}
870+
/**
871+
* An object specifying the format that the model must output.
872+
* @param type Must be one of 'text' or 'json_object'.
873+
* @param jsonSchema JSON schema object that describes the format of the JSON object.
874+
* Only applicable when type is 'json_schema'.
875+
*/
876+
@JsonInclude(Include.NON_NULL)
877+
public record ResponseFormat(
878+
@JsonProperty("type") Type type,
879+
@JsonProperty("json_schema") JsonSchema jsonSchema) {
927880

928881
public ResponseFormat(Type type) {
929882
this(type, (JsonSchema) null);
@@ -937,40 +890,6 @@ public ResponseFormat(Type type, String name, String schema, Boolean strict) {
937890
this(type, StringUtils.hasText(schema) ? new JsonSchema(name, schema, strict) : null);
938891
}
939892

940-
public void setType(Type type) {
941-
this.type = type;
942-
}
943-
944-
public void setJsonSchema(JsonSchema jsonSchema) {
945-
this.jsonSchema = jsonSchema;
946-
}
947-
948-
@Override
949-
public boolean equals(Object o) {
950-
if (this == o) {
951-
return true;
952-
}
953-
if (o == null || getClass() != o.getClass()) {
954-
return false;
955-
}
956-
ResponseFormat that = (ResponseFormat) o;
957-
return Objects.equals(this.type, that.type) &&
958-
Objects.equals(this.jsonSchema, that.jsonSchema);
959-
}
960-
961-
@Override
962-
public int hashCode() {
963-
return Objects.hash(this.type, this.jsonSchema);
964-
}
965-
966-
@Override
967-
public String toString() {
968-
return "ResponseFormat{" +
969-
"type=" + this.type +
970-
", jsonSchema=" + this.jsonSchema +
971-
'}';
972-
}
973-
974893
public enum Type {
975894
/**
976895
* Generates a text response. (default)
@@ -1000,7 +919,7 @@ public enum Type {
1000919
* @param schema The JSON schema object that describes the format of the JSON object.
1001920
* @param strict If true, the model will only generate outputs that match the schema.
1002921
*/
1003-
@JsonInclude(JsonInclude.Include.NON_NULL)
922+
@JsonInclude(Include.NON_NULL)
1004923
public record JsonSchema(
1005924
@JsonProperty("name") String name,
1006925
@JsonProperty("schema") Map<String, Object> schema,
@@ -1016,7 +935,6 @@ public JsonSchema(String name, String schema, Boolean strict) {
1016935
}
1017936

1018937
}
1019-
1020938
/**
1021939
* @param includeUsage If set, an additional chunk will be streamed
1022940
* before the data: [DONE] message. The usage field on this chunk

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OpenAiResponseFormatPropertiesTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.ai.autoconfigure.openai;
1818

19+
import org.junit.jupiter.api.Disabled;
1920
import org.junit.jupiter.api.Test;
2021

2122
import org.springframework.ai.openai.OpenAiAudioSpeechModel;
@@ -38,6 +39,7 @@
3839
public class OpenAiResponseFormatPropertiesTests {
3940

4041
@Test
42+
@Disabled("GH-1645")
4143
public void responseFormatJsonSchema() {
4244

4345
String responseFormatJsonSchema = """
@@ -76,6 +78,7 @@ public void responseFormatJsonSchema() {
7678
}
7779

7880
@Test
81+
@Disabled("GH-1645")
7982
public void responseFormatJsonObject() {
8083

8184
new ApplicationContextRunner()

0 commit comments

Comments
 (0)