Repository: sashabaranov/go-openai
Pull request #883 (2024-10-18 15:46:55)

fix: Updated Assistent struct with latest fields based on OpenAI docs
**Describe the change**
Added missing fields to Assistent struct.

**Provide OpenAI documentation link**
https://platform.openai.com/docs/api-reference/assistants/object

**Describe your solution**
Updated Assistent struct based on OpenAI docs. Also synced order based on docs.


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/sashabaranov/go-openai/pull/883?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alex+Baranov) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 98.85%. Comparing base [(`774fc9d`)](https://app.codecov.io/gh/sashabaranov/go-openai/commit/774fc9dd12ed60c10a9f9f03319ddb9cd5f8780c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alex+Baranov) to head [(`1037384`)](https://app.codecov.io/gh/sashabaranov/go-openai/commit/103738493417921bd0b914119904ebe3c9689a01?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alex+Baranov).
> Report is 64 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master     #883      +/-   ##
==========================================
+ Coverage   98.46%   98.85%   +0.39%     
==========================================
  Files          24       26       +2     
  Lines        1364     1749     +385     
==========================================
+ Hits         1343     1729     +386     
+ Misses         15       14       -1     
  Partials        6        6              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/sashabaranov/go-openai/pull/883?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alex+Baranov).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alex+Baranov).


Patch:
diff --git a/assistant.go b/assistant.go
index 4c89c1b..8aab5bc 100644
--- a/assistant.go
+++ b/assistant.go
@@ -14,17 +14,20 @@ const (
 )
 
 type Assistant struct {
-	ID            string                 `json:"id"`
-	Object        string                 `json:"object"`
-	CreatedAt     int64                  `json:"created_at"`
-	Name          *string                `json:"name,omitempty"`
-	Description   *string                `json:"description,omitempty"`
-	Model         string                 `json:"model"`
-	Instructions  *string                `json:"instructions,omitempty"`
-	Tools         []AssistantTool        `json:"tools"`
-	FileIDs       []string               `json:"file_ids,omitempty"`
-	Metadata      map[string]any         `json:"metadata,omitempty"`
-	ToolResources *AssistantToolResource `json:"tool_resources,omitempty"`
+	ID             string                 `json:"id"`
+	Object         string                 `json:"object"`
+	CreatedAt      int64                  `json:"created_at"`
+	Name           *string                `json:"name,omitempty"`
+	Description    *string                `json:"description,omitempty"`
+	Model          string                 `json:"model"`
+	Instructions   *string                `json:"instructions,omitempty"`
+	Tools          []AssistantTool        `json:"tools"`
+	ToolResources  *AssistantToolResource `json:"tool_resources,omitempty"`
+	FileIDs        []string               `json:"file_ids,omitempty"` // Deprecated in v2
+	Metadata       map[string]any         `json:"metadata,omitempty"`
+	Temperature    *float32               `json:"temperature,omitempty"`
+	TopP           *float32               `json:"top_p,omitempty"`
+	ResponseFormat any                    `json:"response_format,omitempty"`
 
 	httpHeader
 }
diff --git a/client.go b/client.go
index 1e228a0..ed8595e 100644
--- a/client.go
+++ b/client.go
@@ -289,9 +289,6 @@ func (c *Client) handleErrorResp(resp *http.Response) error {
 	if err != nil {
 		return fmt.Errorf("error, reading response body: %w", err)
 	}
-	if !strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
-		return fmt.Errorf("error, status code: %d, status: %s, body: %s", resp.StatusCode, resp.Status, body)
-	}
 	var errRes ErrorResponse
 	err = json.Unmarshal(body, &errRes)
 	if err != nil || errRes.Error == nil {
diff --git a/error.go b/error.go
index fc9e7cd..8a74bd5 100644
--- a/error.go
+++ b/error.go
@@ -104,7 +104,10 @@ func (e *APIError) UnmarshalJSON(data []byte) (err error) {
 }
 
 func (e *RequestError) Error() string {
-	return fmt.Sprintf("error, status code: %d, status: %s, message: %s", e.HTTPStatusCode, e.HTTPStatus, e.Err)
+	return fmt.Sprintf(
+		"error, status code: %d, status: %s, message: %s, body: %s",
+		e.HTTPStatusCode, e.HTTPStatus, e.Err, e.Body,
+	)
 }
 
 func (e *RequestError) Unwrap() error {


Test patch:
diff --git a/client_test.go b/client_test.go
index 18da787..354a6b3 100644
--- a/client_test.go
+++ b/client_test.go
@@ -194,26 +194,31 @@ func TestHandleErrorResp(t *testing.T) {
 				{
 					"error":{}
 				}`)),
-			expected: "error, status code: 503, status: , message: ",
+			expected: `error, status code: 503, status: , message: , body: 
+				{
+					"error":{}
+				}`,
 		},
 		{
 			name:        "413 Request Entity Too Large",
 			httpCode:    http.StatusRequestEntityTooLarge,
 			contentType: "text/html",
-			body: bytes.NewReader([]byte(`<html>
-<head><title>413 Request Entity Too Large</title></head>
-<body>
-<center><h1>413 Request Entity Too Large</h1></center>
-<hr><center>nginx</center>
-</body>
-</html>`)),
-			expected: `error, status code: 413, status: , body: <html>
-<head><title>413 Request Entity Too Large</title></head>
-<body>
-<center><h1>413 Request Entity Too Large</h1></center>
-<hr><center>nginx</center>
-</body>
-</html>`,
+			body: bytes.NewReader([]byte(`
+	<html>
+	<head><title>413 Request Entity Too Large</title></head>
+	<body>
+	<center><h1>413 Request Entity Too Large</h1></center>
+	<hr><center>nginx</center>
+	</body>
+	</html>`)),
+			expected: `error, status code: 413, status: , message: invalid character '<' looking for beginning of value, body: 
+	<html>
+	<head><title>413 Request Entity Too Large</title></head>
+	<body>
+	<center><h1>413 Request Entity Too Large</h1></center>
+	<hr><center>nginx</center>
+	</body>
+	</html>`,
 		},
 		{
 			name:        "errorReader",