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

I occurs HTTP 400 when I use gpt-3.5-turbo

Open luoyashuo opened this issue 2 years ago • 1 comments

HTTP 400 occurs in the second talk Code:

OpenAiService service=new OpenAiService(OpenAiSpeaker.openAiKey, Duration.ofSeconds(60));
        List<ChatMessage> chatMessages=new ArrayList<>();
        chatMessages.add(new ChatMessage(ChatMessageRole.SYSTEM.value(),
                "你现在是一个产品经理,需要帮助我获得用户的需求"
//        "You are a helpful assistant."
        ));
        ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
                .model("gpt-3.5-turbo")
                .messages(chatMessages)
                .frequencyPenalty(.5)
                .temperature(.7)
                .maxTokens(4000)
                .build();
        Scanner scan = new Scanner(System.in);
        String input;
        while (!(input=scan.nextLine()).equals("N")){
            chatMessages.add(new ChatMessage(ChatMessageRole.USER.value(), input));
//            chatCompletionRequest = ChatCompletionRequest.builder()
//                    .model("gpt-3.5-turbo")
//                    .messages(chatMessages)
//                    .frequencyPenalty(.5)
//                    .temperature(.7)
//                    .maxTokens(4000)
//                    .build();
            chatCompletionRequest.setMessages(chatMessages);
            ChatCompletionResult chatCompletionResult=service.createChatCompletion(chatCompletionRequest);
            chatMessages.add(chatCompletionResult.getChoices().get(0).getMessage());
            System.out.println(chatCompletionResult.getChoices().get(0).getMessage().getContent());

Console:

我需要一个住宿管理系统
好的,让我先问一些问题来了解用户的需求:

1. 你认为这个住宿管理系统应该具备哪些功能?
2. 你想要这个系统是基于网页还是手机应用?
3. 你希望这个系统能够管理哪种类型的住宿,例如酒店、公寓、民宿等?
4. 你觉得这个系统需要支持哪些语言和货币种类?
5. 你希望这个系统有哪些支付方式,例如信用卡、支付宝等?

通过回答以上问题,我们可以更好地了解用户的需求,从而开发出符合用户期望的住宿管理系统。
具备自动结算功能
Exception in thread "main" retrofit2.adapter.rxjava2.HttpException: HTTP 400 
	at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:57)
	at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:38)
	at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:48)
	at io.reactivex.Observable.subscribe(Observable.java:10151)
	at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35)
	at io.reactivex.Observable.subscribe(Observable.java:10151)
	at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
	at io.reactivex.Single.subscribe(Single.java:2517)
	at io.reactivex.Single.blockingGet(Single.java:2001)
	at com.theokanning.openai.OpenAiService.createChatCompletion(OpenAiService.java:126)
	at Chatgpt.chatgptSpeaker.main(chatgptSpeaker.java:49)

Process finished with exit code 1

luoyashuo avatar Mar 16 '23 14:03 luoyashuo

Take your full first and second calls for chatMessages and run it through the tokenizer. It's not showing the correct error, but I suspect you are running up against the max tokens for submission. Just checked, seems to be well below.

https://platform.openai.com/tokenizer

cryptoapebot avatar Mar 16 '23 17:03 cryptoapebot

好的,让我先问一些问题来了解用户的需求:

  1. 你认为这个住宿管理系统应该具备哪些功能?
  2. 你想要这个系统是基于网页还是手机应用?
  3. 你希望这个系统能够管理哪种类型的住宿,例如酒店、公寓、民宿等?
  4. 你觉得这个系统需要支持哪些语言和货币种类?
  5. 你希望这个系统有哪些支付方式,例如信用卡、支付宝等?

通过回答以上问题,我们可以更好地了解用户的需求,从而开发出符合用户期望的住宿管理系统。

Thanks! I change the maxToken to 100 and it works pretty well!

luoyashuo avatar Mar 17 '23 00:03 luoyashuo