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

fix parsing error of api error response (#381) #384

Conversation

vvatanabe
Copy link
Collaborator

@vvatanabe vvatanabe commented Jun 16, 2023

Fix #381

Context:
Basically, it is a string. However, if the json schema of the parameters field is invalid, as shown below, it is likely to be an array.

$ curl https://api.openai.com/v1/chat/completions -u :$OPENAI_API_KEY -H 'Content-Type: application/json' -d '{
  "model": "gpt-3.5-turbo-0613",
  "messages": [
    {"role": "user", "content": "What is the weather like in Boston?"}
  ],
  "functions": [
    {
      "name": "get_current_weather",
      "parameters": {
        "type": "object"
      }
    }
  ]
}'

{
  "error":{
     "message":[
        "Invalid schema for function 'get_current_weather': In context=(), object schema missing properties"
     ],
     "type":"invalid_request_error",
     "param":null,
     "code":null
  }
}

@codecov
Copy link

codecov bot commented Jun 16, 2023

Codecov Report

Merging #384 (e904f30) into master (f0770cf) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #384      +/-   ##
==========================================
+ Coverage   95.22%   95.26%   +0.04%     
==========================================
  Files          17       17              
  Lines         670      676       +6     
==========================================
+ Hits          638      644       +6     
  Misses         22       22              
  Partials       10       10              
Impacted Files Coverage Δ
error.go 100.00% <100.00%> (ø)

@vvatanabe vvatanabe force-pushed the fix-parsing-APIError-message-field-381 branch from 3c69475 to e904f30 Compare June 16, 2023 21:27
@vvatanabe
Copy link
Collaborator Author

@sashabaranov Please check it.

err := json.Unmarshal([]byte(response), &apiErr)
checks.HasError(t, err, "Message should be a string")
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has been moved to the newly added table test.

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

@sashabaranov sashabaranov merged commit e49d771 into sashabaranov:master Jun 17, 2023
3 checks passed
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.

APIError message fields may be a array
2 participants