Comments (9)
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.
@mssfang could you please follow up?
from azure-sdk-for-java.
@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.
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.
@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.
from azure-sdk-for-java.
Request error, but the returned http code is still 200 OK, so there is no HttpResponseException to be throw.
from azure-sdk-for-java.
@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.
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.
Hi @XhstormR, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!
from azure-sdk-for-java.
Related Issues (20)
- Investigate canSendKnownLengthNoBufferAsyncFluxBinaryData time out issue
- [Test proxy] Refactor and re-record quantum jobs tests
- [Test Proxy] Refactor and re-record needed for storage tests
- [FEATURE REQ] Add support for managed identities in azure-storage-file-share HOT 3
- [BUG] Multiple createPathFile internal operations causing uploadFIle api to convert finite size file to zero bytes file in ADLS gen2 HOT 12
- [OpenAI][Assistants] Add custom code for `uploadFile` for server requirement for `filename`
- Legacy flag for the Java SDK HOT 2
- sdk/cosmos/azure-cosmos-spark_3-5_2-12 - "_corrupt_record" column isn't getting populated when reading from Cosmos DB HOT 5
- [BUG] Different embedding 3 vectors in Azure vs. OpenAI HOT 3
- User can't manage the lifecycle of THREAD_POOL in Azure Table Storage Java SDK HOT 2
- [BUG] Azure SQL ActiveDirectoryManagedIdentity authentication with sleuth HOT 3
- Is it missing partial update function for blob HOT 7
- [Text Translation] Use the latest test proxy
- [BUG] Unable to list Virtual Networks in an Subscription HOT 4
- [FEATURE REQ] [OpenAI Client] Feature parity with official Python client (and also fully support vLLM) HOT 1
- [QUERY] How can we update a deployment using createOrUpdateDeploymentWithResponse API? HOT 1
- mgmt, fix TypeSpec generation/sdk automation script
- [BUG] Javadoc for RequestRetryOptions may be incorrect or misleading HOT 2
- [FEATURE REQ] Add @ServiceConnection support for CosmosDB, EventHub and Azurite HOT 5
- [BUG] Embedding model input parameter support. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-sdk-for-java.