mirror of
https://github.com/openai/openai-go.git
synced 2026-04-01 09:07:22 +09:00
chore(internal): update spec version (#95)
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
configured_endpoints: 68
|
||||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-f9320ebf347140052c7f8b0bc5c7db24f5e367c368c8cb34c3606af4e2b6591b.yml
|
||||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-b60d5559d5150ecd3b49136064e5e251d832899770ff385b711378389afba370.yml
|
||||
|
||||
2
api.md
2
api.md
@@ -90,6 +90,7 @@ Params Types:
|
||||
|
||||
Response Types:
|
||||
|
||||
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileContent">FileContent</a>
|
||||
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileDeleted">FileDeleted</a>
|
||||
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileObject">FileObject</a>
|
||||
|
||||
@@ -100,6 +101,7 @@ Methods:
|
||||
- <code title="get /files">client.Files.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileListParams">FileListParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination#Page">Page</a>[<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileObject">FileObject</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="delete /files/{file_id}">client.Files.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, fileID <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileDeleted">FileDeleted</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="get /files/{file_id}/content">client.Files.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileService.Content">Content</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</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>
|
||||
- <code title="get /files/{file_id}/content">client.Files.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileService.GetContent">GetContent</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, fileID <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FileContent">FileContent</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
|
||||
# Images
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ func (r AssistantToolChoiceFunctionParam) MarshalJSON() (data []byte, err error)
|
||||
// `{"type": "function", "function": {"name": "my_function"}}` forces the model to
|
||||
// call that tool.
|
||||
//
|
||||
// Union satisfied by [AssistantToolChoiceOptionString] or [AssistantToolChoice].
|
||||
// Union satisfied by [AssistantToolChoiceOptionBehavior] or [AssistantToolChoice].
|
||||
type AssistantToolChoiceOptionUnion interface {
|
||||
implementsAssistantToolChoiceOptionUnion()
|
||||
}
|
||||
@@ -229,7 +229,7 @@ func init() {
|
||||
"",
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.String,
|
||||
Type: reflect.TypeOf(AssistantToolChoiceOptionString("")),
|
||||
Type: reflect.TypeOf(AssistantToolChoiceOptionBehavior("")),
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.JSON,
|
||||
@@ -242,25 +242,25 @@ func init() {
|
||||
// `auto` means the model can pick between generating a message or calling one or
|
||||
// more tools. `required` means the model must call one or more tools before
|
||||
// responding to the user.
|
||||
type AssistantToolChoiceOptionString string
|
||||
type AssistantToolChoiceOptionBehavior string
|
||||
|
||||
const (
|
||||
AssistantToolChoiceOptionStringNone AssistantToolChoiceOptionString = "none"
|
||||
AssistantToolChoiceOptionStringAuto AssistantToolChoiceOptionString = "auto"
|
||||
AssistantToolChoiceOptionStringRequired AssistantToolChoiceOptionString = "required"
|
||||
AssistantToolChoiceOptionBehaviorNone AssistantToolChoiceOptionBehavior = "none"
|
||||
AssistantToolChoiceOptionBehaviorAuto AssistantToolChoiceOptionBehavior = "auto"
|
||||
AssistantToolChoiceOptionBehaviorRequired AssistantToolChoiceOptionBehavior = "required"
|
||||
)
|
||||
|
||||
func (r AssistantToolChoiceOptionString) IsKnown() bool {
|
||||
func (r AssistantToolChoiceOptionBehavior) IsKnown() bool {
|
||||
switch r {
|
||||
case AssistantToolChoiceOptionStringNone, AssistantToolChoiceOptionStringAuto, AssistantToolChoiceOptionStringRequired:
|
||||
case AssistantToolChoiceOptionBehaviorNone, AssistantToolChoiceOptionBehaviorAuto, AssistantToolChoiceOptionBehaviorRequired:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r AssistantToolChoiceOptionString) implementsAssistantToolChoiceOptionUnion() {}
|
||||
func (r AssistantToolChoiceOptionBehavior) implementsAssistantToolChoiceOptionUnion() {}
|
||||
|
||||
func (r AssistantToolChoiceOptionString) implementsAssistantToolChoiceOptionUnionParam() {}
|
||||
func (r AssistantToolChoiceOptionBehavior) implementsAssistantToolChoiceOptionUnionParam() {}
|
||||
|
||||
// Controls which (if any) tool is called by the model. `none` means the model will
|
||||
// not call any tools and instead generates a message. `auto` is the default value
|
||||
@@ -270,7 +270,7 @@ func (r AssistantToolChoiceOptionString) implementsAssistantToolChoiceOptionUnio
|
||||
// `{"type": "function", "function": {"name": "my_function"}}` forces the model to
|
||||
// call that tool.
|
||||
//
|
||||
// Satisfied by [AssistantToolChoiceOptionString], [AssistantToolChoiceParam].
|
||||
// Satisfied by [AssistantToolChoiceOptionBehavior], [AssistantToolChoiceParam].
|
||||
type AssistantToolChoiceOptionUnionParam interface {
|
||||
implementsAssistantToolChoiceOptionUnionParam()
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ func TestBetaThreadNewAndRunWithOptionalParams(t *testing.T) {
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
ToolChoice: openai.F[openai.AssistantToolChoiceOptionUnionParam](openai.AssistantToolChoiceOptionString(openai.AssistantToolChoiceOptionStringNone)),
|
||||
ToolChoice: openai.F[openai.AssistantToolChoiceOptionUnionParam](openai.AssistantToolChoiceOptionBehavior(openai.AssistantToolChoiceOptionBehaviorNone)),
|
||||
ToolResources: openai.F(openai.BetaThreadNewAndRunParamsToolResources{
|
||||
CodeInterpreter: openai.F(openai.BetaThreadNewAndRunParamsToolResourcesCodeInterpreter{
|
||||
FileIDs: openai.F([]string{"string", "string", "string"}),
|
||||
|
||||
@@ -136,7 +136,7 @@ func TestBetaThreadRunNewWithOptionalParams(t *testing.T) {
|
||||
Model: openai.F(openai.ChatModelGPT4o),
|
||||
ParallelToolCalls: openai.F(true),
|
||||
Temperature: openai.F(1.000000),
|
||||
ToolChoice: openai.F[openai.AssistantToolChoiceOptionUnionParam](openai.AssistantToolChoiceOptionString(openai.AssistantToolChoiceOptionStringNone)),
|
||||
ToolChoice: openai.F[openai.AssistantToolChoiceOptionUnionParam](openai.AssistantToolChoiceOptionBehavior(openai.AssistantToolChoiceOptionBehaviorNone)),
|
||||
Tools: openai.F([]openai.AssistantToolUnionParam{openai.CodeInterpreterToolParam{
|
||||
Type: openai.F(openai.CodeInterpreterToolTypeCodeInterpreter),
|
||||
}, openai.CodeInterpreterToolParam{
|
||||
|
||||
16
file.go
16
file.go
@@ -128,6 +128,22 @@ func (r *FileService) Content(ctx context.Context, fileID string, opts ...option
|
||||
return
|
||||
}
|
||||
|
||||
// Returns the contents of the specified file.
|
||||
//
|
||||
// Deprecated: The `.content()` method should be used instead
|
||||
func (r *FileService) GetContent(ctx context.Context, fileID string, opts ...option.RequestOption) (res *FileContent, err error) {
|
||||
opts = append(r.Options[:], opts...)
|
||||
if fileID == "" {
|
||||
err = errors.New("missing required file_id parameter")
|
||||
return
|
||||
}
|
||||
path := fmt.Sprintf("files/%s/content", fileID)
|
||||
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
|
||||
return
|
||||
}
|
||||
|
||||
type FileContent = string
|
||||
|
||||
type FileDeleted struct {
|
||||
ID string `json:"id,required"`
|
||||
Deleted bool `json:"deleted,required"`
|
||||
|
||||
22
file_test.go
22
file_test.go
@@ -143,3 +143,25 @@ func TestFileContent(t *testing.T) {
|
||||
t.Fatalf("return value not %s: %s", "abc", b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileGetContent(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
|
||||
}
|
||||
client := openai.NewClient(
|
||||
option.WithBaseURL(baseURL),
|
||||
option.WithAPIKey("My API Key"),
|
||||
)
|
||||
_, err := client.Files.GetContent(context.TODO(), "file_id")
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user