openai-java icon indicating copy to clipboard operation
openai-java copied to clipboard

Added `response_format` capabilities to chat completion request

Open PrimosK opened this issue 2 years ago • 9 comments

Added response_format capabilities including integration test.

PrimosK avatar Nov 14 '23 12:11 PrimosK

Would also love to see the support for 'seed' in the request (as the latest OpenAI adds support for adding a random generator seed)

n-saw avatar Nov 17 '23 16:11 n-saw

I wonder when this PR code will be released.

Be-poz avatar Nov 29 '23 09:11 Be-poz

I also need this PR merged, let me know if I can help with anything for the review.

LTMenezes avatar Nov 29 '23 12:11 LTMenezes

Also interested in this, are there any updates?

YanWittmann avatar Dec 03 '23 08:12 YanWittmann

We need this module very much, please merge this PR as soon as possible 😭

MrDalili avatar Dec 06 '23 03:12 MrDalili

Hey @TheoKanning , is there anything we can do to speed up this process?

gorkemblm avatar Dec 06 '23 03:12 gorkemblm

alternative way

public class JsonChatCompletionRequest {
    @JsonProperty("response_format")
    String responseFormat = "json_object";
}
OpenAiService getClient(String key, boolean jsonMode) {
        ObjectMapper mapper = defaultObjectMapper();
        if (jsonMode) {
            mapper.addMixIn(ChatCompletionRequest.class, JsonChatCompletionRequest.class);
        }
        OkHttpClient client = defaultClient(key, Duration.ofMillis(5 * 60 * 1000))
                .newBuilder()
                .build();
        Retrofit retrofit = defaultRetrofit(client, mapper);
        OpenAiApi api = retrofit.create(OpenAiApi.class);
        return new OpenAiService(api);
    }

KevinGu avatar Dec 08 '23 17:12 KevinGu

I just used this way

class ChatCompletionJsonRequest(target: ChatCompletionRequest) : ChatCompletionRequest(
    target.model, target.messages, target.temperature, target.topP, target.n, target.stream, target.stop,
    target.maxTokens, target.presencePenalty, target.frequencyPenalty, target.logitBias, target.user, target.functions, target.functionCall
) {
    @JsonProperty("response_format")
    val responseFormat: ResponseFormat = ResponseFormat("json_object")
}

data class ResponseFormat(val type: String)

Be-poz avatar Dec 22 '23 04:12 Be-poz

@TheoKanning please let us know how we can help to speed it up. Might be interesting to look into having some community admin that could approve those PR and merge them.

mbayou avatar Jan 12 '24 11:01 mbayou