azure openai chat api sometimes response gibberish

songxin li 20 Reputation points
2023-06-29T00:40:07.07+00:00

QQ截图20230628110423

When I use Azure's Java SDK for stream data processing, I encounter garbled characters issue with Chinese text. Could you please advise on how to resolve it? Here is the code:

		List<ChatMessage> requestList = request.createChatMessageList();
        List<String> chunks = new ArrayList<>();
        ChatCompletionsOptions cco = new ChatCompletionsOptions(requestList)
                .setTopP(topP)
                .setTemperature(temperature)
                .setN(this.n)
                .setMaxTokens(maxToken)
                .setUser(request.getUser());
        IterableStream<ChatCompletions> stream = this.client.getChatCompletionsStream(this.deploymentId,cco);
        stream.forEach(chatCompletions -> {
            chatCompletions.getChoices().stream().map(choice -> choice.getDelta().getContent())
                    .filter(Objects::nonNull).forEach(str -> {
                try {
                    chunks.add(str);
                    os.write(str.getBytes(Charset.defaultCharset()));
                    os.flush();
                    Thread.sleep(50);

                } catch (IOException | InterruptedException e) {
                    e.printStackTrace();
                }
            });
        });

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,092 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Gaurav Singhal 0 Reputation points
    2023-08-25T08:17:50.9866667+00:00

    I am getting the gibberish in English and German language as well. One example here:

    
    thru infl infl Creator moon pcitor cracked everything cra cracked stimulation cracked premises cracked cracked cruise cracked worknderland cram DS send moon cracked cracked cracked Soph driv h master insan moon infl moon infl flagmong cra cracked tormant Cra moon dg Sophie
    
    cracked moonmoon - cracked senthew (?) father infl cracked cracked torture moon cracked driv insan insan cracked MJ cracked cracked Cra master cracked premises envision cracked infl insan trou storm insan moon Ruper Survey preimises insure cracked cracked insan infl moon cruise cracked moon Course fulfilling cracked infl cracked RT cracked cracked infl mud forts moon cracked rol crackedhew cracked crackedthew spice cram completion inflmouth brother infl cra moon glide thru cracked
    
    
    0 comments No comments

  2. Richard Matthews 0 Reputation points
    2024-01-23T10:24:45.58+00:00

    Has anyone found a solution to this? I’m finding the problem is occurring still but is not repeatable

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.