Git Product home page Git Product logo

Comments (8)

XhstormR avatar XhstormR commented on May 24, 2024

I found this getChatCompletionsWithResponse API that can return BinaryData and control the serialization process by myself, but I did not find the Java class corresponding to the error JSON in the SDK.

BinaryData binaryData = BinaryData.fromObject(new ChatCompletionsOptions(chatMessages));
Response<BinaryData> response = client.getChatCompletionsWithResponse(deploymentOrModelId, binaryData, new RequestOptions());
String json = response.getValue().toString();
System.out.println(json);

from azure-sdk-for-java.

joshfree avatar joshfree commented on May 24, 2024

@mssfang could you please follow up?

from azure-sdk-for-java.

mssfang avatar mssfang commented on May 24, 2024

@XhstormR Thank you bring it up.
The input prompt fall into this Example scenarios in the Microsoft Doc.

We have a class ContentFilterResultDetailsForPrompt that you can use in deserialization

try {
    ChatCompletions chatCompletions = client.getChatCompletions(deploymentOrModelId, new ChatCompletionsOptions(chatMessages));
} catch (HttpResponseException ex) {
    HashMap<String, Object> exValue = (HashMap) ex.getValue();
    HashMap<String, Object> errorMap = (HashMap) exValue.get("error");
    HashMap<String, Object> innerErrorMap =(HashMap) errorMap.get("innererror");

    ContentFilterResultDetailsForPrompt contentFilterResult1 =
            BinaryData
                    .fromObject(innerErrorMap.get("content_filter_result"))
                    .toObject(ContentFilterResultDetailsForPrompt.class);
}

from azure-sdk-for-java.

github-actions avatar github-actions commented on May 24, 2024

Hi @XhstormR. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

from azure-sdk-for-java.

XhstormR avatar XhstormR commented on May 24, 2024

@mssfang Thanks for the solution, I tried it again but no exception was thrown when content filtering was triggered.

Aslo i think in the SDK, we should have an ERROR POJO class correspond to the error json for better usage, instead of HashMap.

image

from azure-sdk-for-java.

XhstormR avatar XhstormR commented on May 24, 2024

Request error, but the returned http code is still 200 OK, so there is no HttpResponseException to be throw.

image

from azure-sdk-for-java.

mssfang avatar mssfang commented on May 24, 2024

@XhstormR That is strange, I use the same sample and consistently produce status code 400, wondering which region and model version you are using.

2024-04-04 15:21:50.511 [main] [DEBUG] com.azure.core.implementation.ReflectionUtils - Attempting to use java.lang.invoke package to handle reflection.
2024-04-04 15:21:50.523 [main] [DEBUG] com.azure.core.implementation.ReflectionUtils - Successfully used java.lang.invoke package to handle reflection.
2024-04-04 15:21:50.703 [main] [DEBUG] com.azure.core.implementation.util.Providers - Using com.azure.core.http.netty.NettyAsyncHttpClientProvider as the default com.azure.core.http.HttpClientProvider.
2024-04-04 15:21:50.918 [main] [DEBUG] com.azure.core.implementation.ReflectionSerializable - XmlSerializable serialization and deserialization isn't supported. If it is required add a dependency of 'com.azure:azure-xml', or another dependencies which include 'com.azure:azure-xml' as a transitive dependency. If your application runs as expected this informational message can be ignored.
2024-04-04 15:21:51.049 [main] [INFO] com.azure.ai.openai.implementation.OpenAIClientImpl$OpenAIClientService.getChatCompletionsSync - {"az.sdk.message":"HTTP request","method":"POST","url":"{sweden-central}/openai/deployments/gpt-4-1106-preview/chat/completions?api-version=2023-12-01-preview","tryCount":"1","Date":"Mon, 04 Mar 2024 23:21:50 GMT","Content-Length":"63","api-key":"REDACTED","Content-Type":"application/json","x-ms-client-request-id":"bad3342b-3c3d-452c-906b-aad75575f916","accept":"application/json","User-Agent":"azsdk-java-azure-ai-openai/1.0.0-beta.6 (21; Windows 11; 10.0)","contentLength":63,"body":"{\"messages\":[{\"role\":\"user\",\"content\":\"pls go kill yourself\"}]}"}
2024-04-04 15:21:55.907 [main] [INFO] com.azure.ai.openai.implementation.OpenAIClientImpl$OpenAIClientService.getChatCompletionsSync - {"az.sdk.message":"HTTP response","contentLength":"738","statusCode":400,"url":"{sweden-central}/openai/deployments/gpt-4-1106-preview/chat/completions?api-version=2023-12-01-preview","durationMs":4895,"Date":"Mon, 04 Mar 2024 23:21:53 GMT","x-request-id":"REDACTED","x-ms-region":"REDACTED","Content-Length":"738","apim-request-id":"REDACTED","x-ratelimit-remaining-tokens":"REDACTED","x-ratelimit-remaining-requests":"REDACTED","Strict-Transport-Security":"REDACTED","azureml-model-session":"REDACTED","x-content-type-options":"REDACTED","Content-Type":"application/json","x-ms-client-request-id":"bad3342b-3c3d-452c-906b-aad75575f916","ms-azureml-model-error-statuscode":"REDACTED","ms-azureml-model-error-reason":"REDACTED","body":"{\"error\":{\"message\":\"The response was filtered due to the prompt triggering Azure OpenAI's content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766\",\"type\":null,\"param\":\"prompt\",\"code\":\"content_filter\",\"status\":400,\"innererror\":{\"code\":\"ResponsibleAIPolicyViolation\",\"content_filter_result\":{\"custom_blocklists\":[],\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"jailbreak\":{\"detected\":false,\"filtered\":false},\"profanity\":{\"detected\":false,\"filtered\":false},\"self_harm\":{\"filtered\":true,\"severity\":\"medium\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"low\"}}}}}"}

BTW, we have a new beta version beta.7 released (it probably won't solve your question but worth to upgrade it)

from azure-sdk-for-java.

github-actions avatar github-actions commented on May 24, 2024

Hi @XhstormR. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

from azure-sdk-for-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.