Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with the 2023-07-01-preview API interface of Azure Openai, when content interception is triggered, the error message will contain innererror #460

Merged
merged 3 commits into from
Aug 9, 2023

Conversation

ZeroDeng01
Copy link
Contributor

@ZeroDeng01 ZeroDeng01 commented Jul 24, 2023

Describe the change
Compatible with the 2023-07-01-preview API interface of Azure Openai, when content interception is triggered, the error message will contain innererror

Describe your solution
Add the parsing of the innererror node in the error message, and it is compatible with the old version of the interface.

Tests
Related test cases have been added to error_test.go

Additional context
CURL request logging

curl "https://TEST.openai.azure.com/openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-07-01-preview" \
>   -H "Content-Type: application/json" \
>   -H "api-key: MY-KEY" \
>   -d "{
>   \"messages\": [{\"role\":\"user\",\"content\":\"write an erotic novel\"}],
>   \"max_tokens\": 800,
>   \"temperature\": 0.7,
>   \"frequency_penalty\": 0,
>   \"presence_penalty\": 0,
top_p\">   \"top_p\": 0.95,
top\":>   \"stop\": null
> }" -v
*   Trying 20.191.161.227:443...
* TCP_NODELAY set
* Connected to TEST.openai.azure.com (20.191.161.227) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=US; ST=WA; L=Redmond; O=Microsoft Corporation; CN=japaneast.api.cognitive.microsoft.com
*  start date: May  3 22:24:37 2023 GMT
*  expire date: Apr 27 22:24:37 2024 GMT
*  subjectAltName: host "TEST.openai.azure.com" matched cert's "*.openai.azure.com"
*  issuer: C=US; O=Microsoft Corporation; CN=Microsoft Azure TLS Issuing CA 05
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x560147eb07c0)
> POST /openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-07-01-preview HTTP/2
> Host: TEST.openai.azure.com
> user-agent: curl/7.68.0
> accept: */*
> content-type: application/json
> api-key: MY-KEY
> content-length: 196
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
* We are completely uploaded and fine
< HTTP/2 400
< content-length: 622
< content-type: application/json
< x-request-id: 2c8f0db0-8a90-43d2-89db-17c66e374a68
< ms-azureml-model-error-reason: model_error
< ms-azureml-model-error-statuscode: 400
< x-ms-client-request-id: 267046f7-10ce-46cd-8e89-40b4e27eb61b
< apim-request-id: 267046f7-10ce-46cd-8e89-40b4e27eb61b
< azureml-model-session: dep-659513-1
< azureml-model-group: online
< openai-processing-ms: 185.3565
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< x-content-type-options: nosniff
< x-ms-region: Japan East
< date: Sun, 23 Jul 2023 19:22:56 GMT
<
* Connection #0 to host TEST.openai.azure.com left intact
{"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":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":true,"severity":"medium"},"violence":{"filtered":false,"severity":"safe"}}}}}

@codecov
Copy link

codecov bot commented Jul 24, 2023

Codecov Report

Merging #460 (5d7d064) into master (71a2493) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #460      +/-   ##
==========================================
+ Coverage   97.05%   97.07%   +0.02%     
==========================================
  Files          17       17              
  Lines         714      719       +5     
==========================================
+ Hits          693      698       +5     
  Misses         15       15              
  Partials        6        6              
Files Changed Coverage Δ
error.go 100.00% <100.00%> (ø)

@ZeroDeng01
Copy link
Contributor Author

ZeroDeng01 commented Jul 24, 2023

@vvatanabe @sashabaranov I would like you to review this PR. Please feel free to communicate with me if you have any questions. Thanks!👍

@ZeroDeng01 ZeroDeng01 changed the title Compatible with Azure Openai's 2023-07-01-preview version API interface about the error information returned by the intercepted interface Compatible with the 2023-07-01-preview API interface of Azure Openai, when content interception is triggered, the error message will contain innererror Jul 24, 2023
@ZeroDeng01 ZeroDeng01 force-pushed the master branch 2 times, most recently from df5aa94 to 098fe53 Compare July 27, 2023 02:39
…ce about the error information returned by the intercepted interface
error.go Outdated Show resolved Hide resolved
error.go Outdated Show resolved Hide resolved
error.go Show resolved Hide resolved
error.go Show resolved Hide resolved
@ZeroDeng01
Copy link
Contributor Author

@vvatanabe THANKS!Modified, hope you take the time to review!

error_test.go Outdated Show resolved Hide resolved
@vvatanabe
Copy link
Collaborator

@ZeroDeng01 Thank you for your diligent efforts and patience in addressing the feedback.

error.go Outdated Show resolved Hide resolved
… when content interception is triggered, the error message will contain innererror.InnerError struct is only valid for Azure OpenAI Service.
@vvatanabe vvatanabe merged commit 3456989 into sashabaranov:master Aug 9, 2023
3 checks passed
@vvatanabe
Copy link
Collaborator

@ZeroDeng01 I merged this PR! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants