Skip to content

Commit e2e7d3b

Browse files
committed
Support response json format
1 parent 39febda commit e2e7d3b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

api/src/main/java/com/launchableinc/openai/completion/chat/ChatCompletionRequest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public class ChatCompletionRequest {
2727
*/
2828
List<ChatMessage> messages;
2929

30+
/**
31+
* An object specifying the format that the model must output. Compatible with GPT-4 Turbo and all
32+
* GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106.
33+
* https://platform.openai.com/docs/api-reference/chat/create#chat-create-response_format
34+
*/
35+
@JsonProperty("response_format")
36+
ChatResponseFormat responseFormat;
37+
3038
/**
3139
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output
3240
* more random, while lower values like 0.2 will make it more focused and deterministic.<br> We
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.launchableinc.openai.completion.chat;
2+
3+
import com.fasterxml.jackson.annotation.JsonValue;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
7+
/*
8+
* OpenAI API Document:https://platform.openai.com/docs/api-reference/chat/create#chat-create-response_format
9+
*/
10+
@Data
11+
@Builder
12+
public class ChatResponseFormat {
13+
14+
private ResponseFormat type;
15+
16+
public enum ResponseFormat {
17+
TEXT("text"), JSON("json_object");
18+
19+
private final String value;
20+
21+
ResponseFormat(String value) {
22+
this.value = value;
23+
}
24+
25+
@JsonValue
26+
public String getValue() {
27+
return value;
28+
}
29+
}
30+
31+
}

0 commit comments

Comments
 (0)