mirror of
https://github.com/openai/openai-go.git
synced 2026-04-01 00:57:11 +09:00
fix(client): return binary content from get /containers/{container_id}/files/{file_id}/content
This commit is contained in:
@@ -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
|
||||
|
||||
2
api.md
2
api.md
@@ -747,4 +747,4 @@ Methods:
|
||||
|
||||
Methods:
|
||||
|
||||
- <code title="get /containers/{container_id}/files/{file_id}/content">client.Containers.Files.Content.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileContentService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, containerID <a href="https://pkg.go.dev/builtin#string">string</a>, fileID <a href="https://pkg.go.dev/builtin#string">string</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>
|
||||
- <code title="get /containers/{container_id}/files/{file_id}/content">client.Containers.Files.Content.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileContentService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, containerID <a href="https://pkg.go.dev/builtin#string">string</a>, fileID <a href="https://pkg.go.dev/builtin#string">string</a>) (http.Response, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user