Azure / autorest.java

Extension for AutoRest (https://github.com/Azure/autorest) that generates Java code
MIT License
33 stars 80 forks source link

client, do not automatically generate formatter:on/off comment #2693

Closed weidongxu-microsoft closed 2 months ago

weidongxu-microsoft commented 2 months ago

There be checkstyle error on https://github.com/Azure/azure-sdk-for-java/pull/39707/checks?check_run_id=23810678546

I guess we don't need to automatically add // @formatter:off to handwritten code. It is good enough that we support dev add if they need to.

Also it be simpler for dev to add on Javadoc and method code, e.g.

    /**
     * Gets chat completions for the provided chat messages in streaming mode. Chat completions support a wide variety
     * of tasks and generate text that continues from or "completes" provided prompt data.
     * <p>
     * <strong>Code Samples</strong>
     * </p>
     * <!-- @formatter:off -->
     * <!-- src_embed com.azure.ai.openai.OpenAIClient.getChatCompletionsStream#String-ChatCompletionsOptions -->
     * <pre>
     * openAIClient.getChatCompletionsStream&#40;deploymentOrModelId, new ChatCompletionsOptions&#40;chatMessages&#41;&#41;
     *     .forEach&#40;chatCompletions -&gt; &#123;
     *         if &#40;CoreUtils.isNullOrEmpty&#40;chatCompletions.getChoices&#40;&#41;&#41;&#41; &#123;
     *             return;
     *         &#125;
     *         ChatResponseMessage delta = chatCompletions.getChoices&#40;&#41;.get&#40;0&#41;.getDelta&#40;&#41;;
     *         if &#40;delta.getRole&#40;&#41; != null&#41; &#123;
     *             System.out.println&#40;&quot;Role = &quot; + delta.getRole&#40;&#41;&#41;;
     *         &#125;
     *         if &#40;delta.getContent&#40;&#41; != null&#41; &#123;
     *             String content = delta.getContent&#40;&#41;;
     *             System.out.print&#40;content&#41;;
     *         &#125;
     *     &#125;&#41;;
     * </pre>
     * <!-- end com.azure.ai.openai.OpenAIClient.getChatCompletionsStream#String-ChatCompletionsOptions -->
     * <!-- @formatter:on -->
     *
     * @param deploymentOrModelName Specifies either the model deployment name (when using Azure OpenAI) or model name
     * (when using non-Azure OpenAI) to use for this request.
     * @param chatCompletionsOptions The configuration information for a chat completions request. Completions support a
     * wide variety of tasks and generate text that continues from or "completes" provided prompt data.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return chat completions stream for the provided chat messages. Completions support a wide variety of tasks and
     * generate text that continues from or "completes" provided prompt data.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public IterableStream<ChatCompletions> getChatCompletionsStream(String deploymentOrModelName,
        ChatCompletionsOptions chatCompletionsOptions) {
        // @formatter:off
        chatCompletionsOptions.setStream(true);
        RequestOptions requestOptions = new RequestOptions();
        Flux<ByteBuffer> responseStream = getChatCompletionsWithResponse(deploymentOrModelName,
            BinaryData.fromObject(chatCompletionsOptions), requestOptions).getValue().toFluxByteBuffer();
        OpenAIServerSentEvents<ChatCompletions> chatCompletionsStream
            = new OpenAIServerSentEvents<>(responseStream, ChatCompletions.class);
        return new IterableStream<>(chatCompletionsStream.getEvents());
        // @formatter:on
    }

Instead of add to the code block.

This way, we may avoid logic on orphan comment.