From f8c8de18b720b224267d54da53d7d919ed0fdff3 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Thu, 29 May 2025 01:53:50 +0000
Subject: [PATCH] fix(client): return binary content from `get
/containers/{container_id}/files/{file_id}/content`
---
.stats.yml | 2 +-
api.md | 2 +-
containerfilecontent.go | 6 +++---
containerfilecontent_test.go | 34 ++++++++++++++++++++++++----------
4 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/.stats.yml b/.stats.yml
index e7ff873..c6d6f63 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,4 +1,4 @@
configured_endpoints: 97
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-d4bcffecf0cdadf746faa6708ed1ec81fac451f9b857deabbab26f0a343b9314.yml
openapi_spec_hash: 7c54a18b4381248bda7cc34c52142615
-config_hash: 2102e4b25bbcab5d32d5ffa5d34daa0c
+config_hash: d23f847b9ebb3f427d0f198035bd3e9f
diff --git a/api.md b/api.md
index 01ad798..d8851a0 100644
--- a/api.md
+++ b/api.md
@@ -747,4 +747,4 @@ Methods:
Methods:
-- client.Containers.Files.Content.Get(ctx context.Context, containerID string, fileID string) error
+- client.Containers.Files.Content.Get(ctx context.Context, containerID string, fileID string) (http.Response, error)
diff --git a/containerfilecontent.go b/containerfilecontent.go
index 1580538..0fb0fa9 100644
--- a/containerfilecontent.go
+++ b/containerfilecontent.go
@@ -32,9 +32,9 @@ func NewContainerFileContentService(opts ...option.RequestOption) (r ContainerFi
}
// Retrieve Container File Content
-func (r *ContainerFileContentService) Get(ctx context.Context, containerID string, fileID string, opts ...option.RequestOption) (err error) {
+func (r *ContainerFileContentService) Get(ctx context.Context, containerID string, fileID string, opts ...option.RequestOption) (res *http.Response, err error) {
opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
+ opts = append([]option.RequestOption{option.WithHeader("Accept", "application/binary")}, opts...)
if containerID == "" {
err = errors.New("missing required container_id parameter")
return
@@ -44,6 +44,6 @@ func (r *ContainerFileContentService) Get(ctx context.Context, containerID strin
return
}
path := fmt.Sprintf("containers/%s/files/%s/content", containerID, fileID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, nil, opts...)
+ err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
diff --git a/containerfilecontent_test.go b/containerfilecontent_test.go
index 3f43bce..10a7bc6 100644
--- a/containerfilecontent_test.go
+++ b/containerfilecontent_test.go
@@ -3,29 +3,30 @@
package openai_test
import (
+ "bytes"
"context"
"errors"
- "os"
+ "io"
+ "net/http"
+ "net/http/httptest"
"testing"
"github.com/openai/openai-go"
- "github.com/openai/openai-go/internal/testutil"
"github.com/openai/openai-go/option"
)
func TestContainerFileContentGet(t *testing.T) {
- baseURL := "http://localhost:4010"
- if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
- baseURL = envURL
- }
- if !testutil.CheckTestServer(t, baseURL) {
- return
- }
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(200)
+ w.Write([]byte("abc"))
+ }))
+ defer server.Close()
+ baseURL := server.URL
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
- err := client.Containers.Files.Content.Get(
+ resp, err := client.Containers.Files.Content.Get(
context.TODO(),
"container_id",
"file_id",
@@ -37,4 +38,17 @@ func TestContainerFileContentGet(t *testing.T) {
}
t.Fatalf("err should be nil: %s", err.Error())
}
+ defer resp.Body.Close()
+
+ b, err := io.ReadAll(resp.Body)
+ if err != nil {
+ var apierr *openai.Error
+ if errors.As(err, &apierr) {
+ t.Log(string(apierr.DumpRequest(true)))
+ }
+ t.Fatalf("err should be nil: %s", err.Error())
+ }
+ if !bytes.Equal(b, []byte("abc")) {
+ t.Fatalf("return value not %s: %s", "abc", b)
+ }
}