diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index 8716e476..fea34540 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.1.0-beta.11"
+ ".": "1.0.0"
}
\ No newline at end of file
diff --git a/.stats.yml b/.stats.yml
index 2b6b6f08..0a07e689 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,4 +1,4 @@
-configured_endpoints: 87
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-262e171d0a8150ea1192474d16ba3afdf9a054b399f1a49a9c9b697a3073c136.yml
+configured_endpoints: 64
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-d51538ac955164de98b0c94a0a4718d96623fe39bf31a1d168be06c93c94e645.yml
openapi_spec_hash: 33e00a48df8f94c94f46290c489f132b
-config_hash: d8d5fda350f6db77c784f35429741a2e
+config_hash: c42d37618b8628ce7e1c76437db5dd8f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e4ddf70..e2c4e801 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,38 @@
# Changelog
+## 1.0.0 (2025-05-19)
+
+Full Changelog: [v0.1.0-beta.11...v1.0.0](https://github.com/openai/openai-go/compare/v0.1.0-beta.11...v1.0.0)
+
+### ⚠ BREAKING CHANGES
+
+* **client:** rename file array param variant
+* **api:** improve naming and remove assistants
+* **accumulator:** update casing ([#401](https://github.com/openai/openai-go/issues/401))
+
+### Features
+
+* **api:** improve naming and remove assistants ([4c623b8](https://github.com/openai/openai-go/commit/4c623b88a9025db1961cc57985eb7374342f43e7))
+
+
+### Bug Fixes
+
+* **accumulator:** update casing ([#401](https://github.com/openai/openai-go/issues/401)) ([d59453c](https://github.com/openai/openai-go/commit/d59453c95b89fdd0b51305778dec0a39ce3a9d2a))
+* **client:** correctly set stream key for multipart ([0ec68f0](https://github.com/openai/openai-go/commit/0ec68f0d779e7726931b1115eca9ae81eab59ba8))
+* **client:** don't panic on marshal with extra null field ([9c15332](https://github.com/openai/openai-go/commit/9c153320272d212beaa516d4c70d54ae8053a958))
+* **client:** increase max stream buffer size ([9456455](https://github.com/openai/openai-go/commit/945645559c5d68d9e28cf445d9c3b83e5fc6bd35))
+* **client:** rename file array param variant ([4cfcf86](https://github.com/openai/openai-go/commit/4cfcf869280e7531fbbc8c00db0dd9271d07c423))
+* **client:** use scanner for streaming ([aa58806](https://github.com/openai/openai-go/commit/aa58806bffc3aed68425c480414ddbb4dac3fa78))
+
+
+### Chores
+
+* **docs:** typo fix ([#400](https://github.com/openai/openai-go/issues/400)) ([bececf2](https://github.com/openai/openai-go/commit/bececf24cd0324b7c991b7d7f1d3eff6bf71f996))
+* **examples:** migrate enum ([#447](https://github.com/openai/openai-go/issues/447)) ([814dd8b](https://github.com/openai/openai-go/commit/814dd8b6cfe4eeb535dc8ecd161a409ea2eb6698))
+* **examples:** migrate to latest version ([#444](https://github.com/openai/openai-go/issues/444)) ([1c8754f](https://github.com/openai/openai-go/commit/1c8754ff905ed023f6381c8493910d63039407de))
+* **examples:** remove beta assisstants examples ([#445](https://github.com/openai/openai-go/issues/445)) ([5891583](https://github.com/openai/openai-go/commit/589158372be9c0517b5508f9ccd872fdb1fe480b))
+* **example:** update fine-tuning ([#450](https://github.com/openai/openai-go/issues/450)) ([421e3c5](https://github.com/openai/openai-go/commit/421e3c5065ace2d5ddd3d13a036477fff9123e5f))
+
## 0.1.0-beta.11 (2025-05-16)
Full Changelog: [v0.1.0-beta.10...v0.1.0-beta.11](https://github.com/openai/openai-go/compare/v0.1.0-beta.10...v0.1.0-beta.11)
diff --git a/MIGRATION.md b/MIGRATION.md
deleted file mode 100644
index 54990b8a..00000000
--- a/MIGRATION.md
+++ /dev/null
@@ -1,284 +0,0 @@
-# OpenAI Go Migration Guide
-
-
-
-This SDK includes breaking changes to improve the ergonomics of constructing parameters and accessing responses.
-
-To reduce verbosity, the `openai.F(...)` and `param.Field[T]` have been removed.
-All calls to `openai.F(...)` can be deleted.
-
-The SDK now uses the \`json:"...,omitzero"\`
struct tag to omit fields. Nested structs, arrays and maps
-can be declared like normal.
-
-The old SDK used interfaces for unions in requests, which required
-a type assertion to access variants and fields. The new design uses
-structs with a field for each variant, wherein only one field can be set.
-These struct unions also expose 'Get' methods to access and mutate subfields
-which may be shared by multiple variants.
-
-# Request parameters
-
-## Required primitives parameters serialize their zero values (`string`, `int64`, etc.)
-
-> [!CAUTION]
->
-> **This change can cause new behavior in existing code, without compiler warnings.**
-
-While migrating, ensure that all required fields are explicitly set. A required primitive
-field `Age` will use the \`json:"age,required"\`
struct tag without `omitzero`.
-
-If a required primitive field is not set, the zero value will be serialized.
-This was not the case in with `param.Field[T]`.
-
-```diff
-type FooParams struct {
-- Age param.Field[int64] `json:"age,required"`
-- Name param.Field[string] `json:"name"`
-+ Age int64 `json:"age,required"` // <== Notice no omitzero
-+ Name param.Opt[string] `json:"name,omitzero"`
-}
-```
-
-
-
-Previous |
-New |
-
-
-
-
-```go
-_ = FooParams{
- Name: openai.String("Jerry")
-}
-`{"name": "Jerry"}` // (after serialization)
-```
-
- |
-
-
-```go
-_ = FooParams{
- Name: openai.String("Jerry")
-}
-`{"name": "Jerry", "age": 0}` // <== Notice the age field
-```
-
- |
-
-
-
-The required field `"age"` is now present as `0`. Fields without the \`json:"...,omitzero"\`
struct tag
-are always serialized, including their zero values.
-
-## Transition from `param.Field[T]` to `omitzero`
-
-The `openai.F(...)` function and `param.Field[T]` type are no longer present in the new SDK.
-
-To represent omitted fields, the SDK uses \`json:"...,omitzero"\`
semantics from Go 1.24+ for JSON encoding[^1]. `omitzero` always omits fields
-with zero values.
-
-In all cases other than optional primitives, `openai.F()` can simply be removed.
-For optional primitive types, such as `param.Opt[string]`, you can use `openai.String(string)` to construct the value.
-Similar functions exist for other primitive types like `openai.Int(int)`, `openai.Bool(bool)`, etc.
-
-`omitzero` is used for fields whose type is either a struct, slice, map, string enum,
-or wrapped optional primitive (e.g. `param.Opt[T]`). Required primitive fields don't use `omitzero`.
-
-**Example User Code: Constructing a request**
-
-```diff
-foo = FooParams{
-- RequiredString: openai.String("hello"),
-+ RequiredString: "hello",
-
-- OptionalString: openai.String("hi"),
-+ OptionalString: openai.String("hi"),
-
-- Array: openai.F([]BarParam{
-- BarParam{Prop: ... }
-- }),
-+ Array: []BarParam{
-+ BarParam{Prop: ... }
-+ },
-
-- RequiredObject: openai.F(BarParam{ ... }),
-+ RequiredObject: BarParam{ ... },
-
-- OptionalObject: openai.F(BarParam{ ... }),
-+ OptionalObject: BarParam{ ... },
-
-- StringEnum: openai.F[BazEnum]("baz-ok"),
-+ StringEnum: "baz-ok",
-}
-```
-
-**Internal SDK Code: Fields of a request struct:**
-
-```diff
-type FooParams struct {
-- RequiredString param.Field[string] `json:"required_string,required"`
-+ RequiredString string `json:"required_string,required"`
-
-- OptionalString param.Field[string] `json:"optional_string"`
-+ OptionalString param.Opt[string] `json:"optional_string,omitzero"`
-
-- Array param.Field[[]BarParam] `json"array"`
-+ Array []BarParam `json"array,omitzero"`
-
-- Map param.Field[map[string]BarParam] `json"map"`
-+ Map map[string]BarParam `json"map,omitzero"`
-
-- RequiredObject param.Field[BarParam] `json:"required_object,required"`
-+ RequiredObject BarParam `json:"required_object,omitzero,required"`
-
-- OptionalObject param.Field[BarParam] `json:"optional_object"`
-+ OptionalObject BarParam `json:"optional_object,omitzero"`
-
-- StringEnum param.Field[BazEnum] `json:"string_enum"`
-+ StringEnum BazEnum `json:"string_enum,omitzero"`
-}
-```
-
-## Request Unions: Removing interfaces and moving to structs
-
-For a type `AnimalUnionParam` which could be either a `CatParam | DogParam`.
-
-
-Previous | New |
-
-
-
-```go
-type AnimalParam interface {
- ImplAnimalParam()
-}
-
-func (Dog) ImplAnimalParam() {}
-func (Cat) ImplAnimalParam() {}
-```
-
- |
-
-
-```go
-type AnimalUnionParam struct {
- OfCat *Cat `json:",omitzero,inline`
- OfDog *Dog `json:",omitzero,inline`
-}
-```
-
- |
-
-
-
-
-
-```go
-var dog AnimalParam = DogParam{
- Name: "spot", ...
-}
-var cat AnimalParam = CatParam{
- Name: "whiskers", ...
-}
-```
-
- |
-
-
-```go
-dog := AnimalUnionParam{
- OfDog: &DogParam{Name: "spot", ... },
-}
-cat := AnimalUnionParam{
- OfCat: &CatParam{Name: "whiskers", ... },
-}
-```
-
- |
-
-
-
-
-
-```go
-var name string
-switch v := animal.(type) {
-case Dog:
- name = v.Name
-case Cat:
- name = v.Name
-}
-```
-
- |
-
-
-```go
-// Accessing fields
-var name *string = animal.GetName()
-```
-
- |
-
-
-
-## Sending explicit `null` values
-
-The old SDK had a function `param.Null[T]()` which could set `param.Field[T]` to `null`.
-
-The new SDK uses `param.Null[T]()` for to set a `param.Opt[T]` to `null`,
-but `param.NullStruct[T]()` to set a param struct `T` to `null`.
-
-```diff
-- var nullPrimitive param.Field[int64] = param.Null[int64]()
-+ var nullPrimitive param.Opt[int64] = param.Null[int64]()
-
-- var nullStruct param.Field[BarParam] = param.Null[BarParam]()
-+ var nullStruct BarParam = param.NullStruct[BarParam]()
-```
-
-## Sending custom values
-
-The `openai.Raw[T](any)` function has been removed. All request structs now support a
-`.WithExtraField(map[string]any)` method to customize the fields.
-
-```diff
-foo := FooParams{
- A: param.String("hello"),
-- B: param.Raw[string](12) // sending `12` instead of a string
-}
-+ foo.SetExtraFields(map[string]any{
-+ "B": 12,
-+ })
-```
-
-# Response Properties
-
-## Checking for presence of optional fields
-
-The `.IsNull()` method has been changed to `.Valid()` to better reflect its behavior.
-
-```diff
-- if !resp.Foo.JSON.Bar.IsNull() {
-+ if resp.Foo.JSON.Bar.Valid() {
- println("bar is present:", resp.Foo.Bar)
-}
-```
-
-| Previous | New | Returns true for values |
-| -------------- | ------------------------ | ----------------------- |
-| `.IsNull()` | `!.Valid()` | `null` or Omitted |
-| `.IsMissing()` | `.Raw() == resp.Omitted` | Omitted |
-| | `.Raw() == resp.Null` |
-
-## Checking Raw JSON of a response
-
-The `.RawJSON()` method has moved to the parent of the `.JSON` property.
-
-```diff
-- resp.Foo.JSON.RawJSON()
-+ resp.Foo.RawJSON()
-```
-
-[^1]: The SDK doesn't require Go 1.24, despite supporting the `omitzero` feature
diff --git a/README.md b/README.md
index f8d97964..c7cbab9c 100644
--- a/README.md
+++ b/README.md
@@ -5,10 +5,6 @@
The OpenAI Go library provides convenient access to the [OpenAI REST API](https://platform.openai.com/docs)
from applications written in Go.
-> [!WARNING]
-> The latest version of this package uses a new design with significant breaking changes.
-> Please refer to the [migration guide](./MIGRATION.md) for more information on how to update your code.
-
## Installation
@@ -26,7 +22,7 @@ Or to pin the version:
```sh
-go get -u 'github.com/openai/openai-go@v0.1.0-beta.11'
+go get -u 'github.com/openai/openai-go@v1.0.0'
```
diff --git a/aliases.go b/aliases.go
index aeaf0665..ad0f18df 100644
--- a/aliases.go
+++ b/aliases.go
@@ -256,12 +256,6 @@ const CompoundFilterTypeOr = shared.CompoundFilterTypeOr
// This is an alias to an internal type.
type CompoundFilterParam = shared.CompoundFilterParam
-// This is an alias to an internal type.
-type ErrorObject = shared.ErrorObject
-
-// This is an alias to an internal type.
-type FunctionDefinition = shared.FunctionDefinition
-
// This is an alias to an internal type.
type FunctionDefinitionParam = shared.FunctionDefinitionParam
@@ -369,18 +363,6 @@ type ResponseFormatJSONObject = shared.ResponseFormatJSONObject
// This is an alias to an internal type.
type ResponseFormatJSONObjectParam = shared.ResponseFormatJSONObjectParam
-// JSON Schema response format. Used to generate structured JSON responses. Learn
-// more about
-// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
-//
-// This is an alias to an internal type.
-type ResponseFormatJSONSchema = shared.ResponseFormatJSONSchema
-
-// Structured Outputs configuration options, including a JSON Schema.
-//
-// This is an alias to an internal type.
-type ResponseFormatJSONSchemaJSONSchema = shared.ResponseFormatJSONSchemaJSONSchema
-
// JSON Schema response format. Used to generate structured JSON responses. Learn
// more about
// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
diff --git a/api.md b/api.md
index a601b65d..e77c5e24 100644
--- a/api.md
+++ b/api.md
@@ -18,14 +18,10 @@
- shared.ChatModel
- shared.ComparisonFilter
- shared.CompoundFilter
-- shared.ErrorObject
-- shared.FunctionDefinition
-- shared.FunctionParameters
- shared.Metadata
- shared.Reasoning
- shared.ReasoningEffort
- shared.ResponseFormatJSONObject
-- shared.ResponseFormatJSONSchema
- shared.ResponseFormatText
- shared.ResponsesModel
@@ -284,7 +280,7 @@ Methods:
- client.FineTuning.Checkpoints.Permissions.New(ctx context.Context, fineTunedModelCheckpoint string, body openai.FineTuningCheckpointPermissionNewParams) (pagination.Page[openai.FineTuningCheckpointPermissionNewResponse], error)
- client.FineTuning.Checkpoints.Permissions.Get(ctx context.Context, fineTunedModelCheckpoint string, query openai.FineTuningCheckpointPermissionGetParams) (openai.FineTuningCheckpointPermissionGetResponse, error)
-- client.FineTuning.Checkpoints.Permissions.Delete(ctx context.Context, fineTunedModelCheckpoint string, permissionID string) (openai.FineTuningCheckpointPermissionDeleteResponse, error)
+- client.FineTuning.Checkpoints.Permissions.Delete(ctx context.Context, permissionID string, body openai.FineTuningCheckpointPermissionDeleteParams) (openai.FineTuningCheckpointPermissionDeleteResponse, error)
## Alpha
@@ -361,11 +357,11 @@ Response Types:
Methods:
- client.VectorStores.Files.New(ctx context.Context, vectorStoreID string, body openai.VectorStoreFileNewParams) (openai.VectorStoreFile, error)
-- client.VectorStores.Files.Get(ctx context.Context, vectorStoreID string, fileID string) (openai.VectorStoreFile, error)
-- client.VectorStores.Files.Update(ctx context.Context, vectorStoreID string, fileID string, body openai.VectorStoreFileUpdateParams) (openai.VectorStoreFile, error)
+- client.VectorStores.Files.Get(ctx context.Context, fileID string, query openai.VectorStoreFileGetParams) (openai.VectorStoreFile, error)
+- client.VectorStores.Files.Update(ctx context.Context, fileID string, params openai.VectorStoreFileUpdateParams) (openai.VectorStoreFile, error)
- client.VectorStores.Files.List(ctx context.Context, vectorStoreID string, query openai.VectorStoreFileListParams) (pagination.CursorPage[openai.VectorStoreFile], error)
-- client.VectorStores.Files.Delete(ctx context.Context, vectorStoreID string, fileID string) (openai.VectorStoreFileDeleted, error)
-- client.VectorStores.Files.Content(ctx context.Context, vectorStoreID string, fileID string) (pagination.Page[openai.VectorStoreFileContentResponse], error)
+- client.VectorStores.Files.Delete(ctx context.Context, fileID string, body openai.VectorStoreFileDeleteParams) (openai.VectorStoreFileDeleted, error)
+- client.VectorStores.Files.Content(ctx context.Context, fileID string, query openai.VectorStoreFileContentParams) (pagination.Page[openai.VectorStoreFileContentResponse], error)
## FileBatches
@@ -376,161 +372,12 @@ Response Types:
Methods:
- client.VectorStores.FileBatches.New(ctx context.Context, vectorStoreID string, body openai.VectorStoreFileBatchNewParams) (openai.VectorStoreFileBatch, error)
-- client.VectorStores.FileBatches.Get(ctx context.Context, vectorStoreID string, batchID string) (openai.VectorStoreFileBatch, error)
-- client.VectorStores.FileBatches.Cancel(ctx context.Context, vectorStoreID string, batchID string) (openai.VectorStoreFileBatch, error)
-- client.VectorStores.FileBatches.ListFiles(ctx context.Context, vectorStoreID string, batchID string, query openai.VectorStoreFileBatchListFilesParams) (pagination.CursorPage[openai.VectorStoreFile], error)
+- client.VectorStores.FileBatches.Get(ctx context.Context, batchID string, query openai.VectorStoreFileBatchGetParams) (openai.VectorStoreFileBatch, error)
+- client.VectorStores.FileBatches.Cancel(ctx context.Context, batchID string, body openai.VectorStoreFileBatchCancelParams) (openai.VectorStoreFileBatch, error)
+- client.VectorStores.FileBatches.ListFiles(ctx context.Context, batchID string, params openai.VectorStoreFileBatchListFilesParams) (pagination.CursorPage[openai.VectorStoreFile], error)
# Beta
-## Assistants
-
-Params Types:
-
-- openai.AssistantToolUnionParam
-- openai.CodeInterpreterToolParam
-- openai.FileSearchToolParam
-- openai.FunctionToolParam
-
-Response Types:
-
-- openai.Assistant
-- openai.AssistantDeleted
-- openai.AssistantStreamEventUnion
-- openai.AssistantToolUnion
-- openai.CodeInterpreterTool
-- openai.FileSearchTool
-- openai.FunctionTool
-
-Methods:
-
-- client.Beta.Assistants.New(ctx context.Context, body openai.BetaAssistantNewParams) (openai.Assistant, error)
-- client.Beta.Assistants.Get(ctx context.Context, assistantID string) (openai.Assistant, error)
-- client.Beta.Assistants.Update(ctx context.Context, assistantID string, body openai.BetaAssistantUpdateParams) (openai.Assistant, error)
-- client.Beta.Assistants.List(ctx context.Context, query openai.BetaAssistantListParams) (pagination.CursorPage[openai.Assistant], error)
-- client.Beta.Assistants.Delete(ctx context.Context, assistantID string) (openai.AssistantDeleted, error)
-
-## Threads
-
-Params Types:
-
-- openai.AssistantResponseFormatOptionUnionParam
-- openai.AssistantToolChoiceParam
-- openai.AssistantToolChoiceFunctionParam
-- openai.AssistantToolChoiceOptionUnionParam
-
-Response Types:
-
-- openai.AssistantResponseFormatOptionUnion
-- openai.AssistantToolChoice
-- openai.AssistantToolChoiceFunction
-- openai.AssistantToolChoiceOptionUnion
-- openai.Thread
-- openai.ThreadDeleted
-
-Methods:
-
-- client.Beta.Threads.New(ctx context.Context, body openai.BetaThreadNewParams) (openai.Thread, error)
-- client.Beta.Threads.Get(ctx context.Context, threadID string) (openai.Thread, error)
-- client.Beta.Threads.Update(ctx context.Context, threadID string, body openai.BetaThreadUpdateParams) (openai.Thread, error)
-- client.Beta.Threads.Delete(ctx context.Context, threadID string) (openai.ThreadDeleted, error)
-- client.Beta.Threads.NewAndRun(ctx context.Context, body openai.BetaThreadNewAndRunParams) (openai.Run, error)
-
-### Runs
-
-Response Types:
-
-- openai.RequiredActionFunctionToolCall
-- openai.Run
-- openai.RunStatus
-
-Methods:
-
-- client.Beta.Threads.Runs.New(ctx context.Context, threadID string, params openai.BetaThreadRunNewParams) (openai.Run, error)
-- client.Beta.Threads.Runs.Get(ctx context.Context, threadID string, runID string) (openai.Run, error)
-- client.Beta.Threads.Runs.Update(ctx context.Context, threadID string, runID string, body openai.BetaThreadRunUpdateParams) (openai.Run, error)
-- client.Beta.Threads.Runs.List(ctx context.Context, threadID string, query openai.BetaThreadRunListParams) (pagination.CursorPage[openai.Run], error)
-- client.Beta.Threads.Runs.Cancel(ctx context.Context, threadID string, runID string) (openai.Run, error)
-- client.Beta.Threads.Runs.SubmitToolOutputs(ctx context.Context, threadID string, runID string, body openai.BetaThreadRunSubmitToolOutputsParams) (openai.Run, error)
-
-#### Steps
-
-Params Types:
-
-- openai.RunStepInclude
-
-Response Types:
-
-- openai.CodeInterpreterLogs
-- openai.CodeInterpreterOutputImage
-- openai.CodeInterpreterToolCall
-- openai.CodeInterpreterToolCallDelta
-- openai.FileSearchToolCall
-- openai.FileSearchToolCallDelta
-- openai.FunctionToolCall
-- openai.FunctionToolCallDelta
-- openai.MessageCreationStepDetails
-- openai.RunStep
-- openai.RunStepDelta
-- openai.RunStepDeltaEvent
-- openai.RunStepDeltaMessageDelta
-- openai.ToolCallUnion
-- openai.ToolCallDeltaUnion
-- openai.ToolCallDeltaObject
-- openai.ToolCallsStepDetails
-
-Methods:
-
-- client.Beta.Threads.Runs.Steps.Get(ctx context.Context, threadID string, runID string, stepID string, query openai.BetaThreadRunStepGetParams) (openai.RunStep, error)
-- client.Beta.Threads.Runs.Steps.List(ctx context.Context, threadID string, runID string, query openai.BetaThreadRunStepListParams) (pagination.CursorPage[openai.RunStep], error)
-
-### Messages
-
-Params Types:
-
-- openai.ImageFileParam
-- openai.ImageFileContentBlockParam
-- openai.ImageURLParam
-- openai.ImageURLContentBlockParam
-- openai.MessageContentPartParamUnion
-- openai.TextContentBlockParam
-
-Response Types:
-
-- openai.AnnotationUnion
-- openai.AnnotationDeltaUnion
-- openai.FileCitationAnnotation
-- openai.FileCitationDeltaAnnotation
-- openai.FilePathAnnotation
-- openai.FilePathDeltaAnnotation
-- openai.ImageFile
-- openai.ImageFileContentBlock
-- openai.ImageFileDelta
-- openai.ImageFileDeltaBlock
-- openai.ImageURL
-- openai.ImageURLContentBlock
-- openai.ImageURLDelta
-- openai.ImageURLDeltaBlock
-- openai.Message
-- openai.MessageContentUnion
-- openai.MessageContentDeltaUnion
-- openai.MessageDeleted
-- openai.MessageDelta
-- openai.MessageDeltaEvent
-- openai.RefusalContentBlock
-- openai.RefusalDeltaBlock
-- openai.Text
-- openai.TextContentBlock
-- openai.TextDelta
-- openai.TextDeltaBlock
-
-Methods:
-
-- client.Beta.Threads.Messages.New(ctx context.Context, threadID string, body openai.BetaThreadMessageNewParams) (openai.Message, error)
-- client.Beta.Threads.Messages.Get(ctx context.Context, threadID string, messageID string) (openai.Message, error)
-- client.Beta.Threads.Messages.Update(ctx context.Context, threadID string, messageID string, body openai.BetaThreadMessageUpdateParams) (openai.Message, error)
-- client.Beta.Threads.Messages.List(ctx context.Context, threadID string, query openai.BetaThreadMessageListParams) (pagination.CursorPage[openai.Message], error)
-- client.Beta.Threads.Messages.Delete(ctx context.Context, threadID string, messageID string) (openai.MessageDeleted, error)
-
# Batches
Response Types:
diff --git a/audiotranscription.go b/audiotranscription.go
index 6a939380..e45006ca 100644
--- a/audiotranscription.go
+++ b/audiotranscription.go
@@ -54,7 +54,9 @@ func (r *AudioTranscriptionService) NewStreaming(ctx context.Context, body Audio
err error
)
opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...)
+ body.SetExtraFields(map[string]any{
+ "stream": "true",
+ })
path := "audio/transcriptions"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)
return ssestream.NewStream[TranscriptionStreamEventUnion](ssestream.NewDecoder(raw), err)
@@ -371,6 +373,9 @@ func (r AudioTranscriptionNewParams) MarshalMultipart() (data []byte, contentTyp
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
+ if err == nil {
+ err = apiform.WriteExtras(writer, r.ExtraFields())
+ }
if err != nil {
writer.Close()
return nil, "", err
diff --git a/audiotranslation.go b/audiotranslation.go
index c4a0162d..aa754e94 100644
--- a/audiotranslation.go
+++ b/audiotranslation.go
@@ -90,6 +90,9 @@ func (r AudioTranslationNewParams) MarshalMultipart() (data []byte, contentType
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
+ if err == nil {
+ err = apiform.WriteExtras(writer, r.ExtraFields())
+ }
if err != nil {
writer.Close()
return nil, "", err
diff --git a/beta.go b/beta.go
index c426f355..6ff9ff8b 100644
--- a/beta.go
+++ b/beta.go
@@ -13,9 +13,7 @@ import (
// automatically. You should not instantiate this service directly, and instead use
// the [NewBetaService] method instead.
type BetaService struct {
- Options []option.RequestOption
- Assistants BetaAssistantService
- Threads BetaThreadService
+ Options []option.RequestOption
}
// NewBetaService generates a new service that applies the given options to each
@@ -24,7 +22,5 @@ type BetaService struct {
func NewBetaService(opts ...option.RequestOption) (r BetaService) {
r = BetaService{}
r.Options = opts
- r.Assistants = NewBetaAssistantService(opts...)
- r.Threads = NewBetaThreadService(opts...)
return
}
diff --git a/betaassistant.go b/betaassistant.go
deleted file mode 100644
index 6adbfa90..00000000
--- a/betaassistant.go
+++ /dev/null
@@ -1,2246 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai
-
-import (
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "net/http"
- "net/url"
-
- "github.com/openai/openai-go/internal/apijson"
- "github.com/openai/openai-go/internal/apiquery"
- "github.com/openai/openai-go/internal/requestconfig"
- "github.com/openai/openai-go/option"
- "github.com/openai/openai-go/packages/pagination"
- "github.com/openai/openai-go/packages/param"
- "github.com/openai/openai-go/packages/respjson"
- "github.com/openai/openai-go/shared"
- "github.com/openai/openai-go/shared/constant"
-)
-
-// BetaAssistantService contains methods and other services that help with
-// interacting with the openai API.
-//
-// Note, unlike clients, this service does not read variables from the environment
-// automatically. You should not instantiate this service directly, and instead use
-// the [NewBetaAssistantService] method instead.
-type BetaAssistantService struct {
- Options []option.RequestOption
-}
-
-// NewBetaAssistantService generates a new service that applies the given options
-// to each request. These options are applied after the parent client's options (if
-// there is one), and before any request-specific options.
-func NewBetaAssistantService(opts ...option.RequestOption) (r BetaAssistantService) {
- r = BetaAssistantService{}
- r.Options = opts
- return
-}
-
-// Create an assistant with a model and instructions.
-func (r *BetaAssistantService) New(ctx context.Context, body BetaAssistantNewParams, opts ...option.RequestOption) (res *Assistant, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- path := "assistants"
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
-}
-
-// Retrieves an assistant.
-func (r *BetaAssistantService) Get(ctx context.Context, assistantID string, opts ...option.RequestOption) (res *Assistant, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if assistantID == "" {
- err = errors.New("missing required assistant_id parameter")
- return
- }
- path := fmt.Sprintf("assistants/%s", assistantID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
- return
-}
-
-// Modifies an assistant.
-func (r *BetaAssistantService) Update(ctx context.Context, assistantID string, body BetaAssistantUpdateParams, opts ...option.RequestOption) (res *Assistant, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if assistantID == "" {
- err = errors.New("missing required assistant_id parameter")
- return
- }
- path := fmt.Sprintf("assistants/%s", assistantID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
-}
-
-// Returns a list of assistants.
-func (r *BetaAssistantService) List(ctx context.Context, query BetaAssistantListParams, opts ...option.RequestOption) (res *pagination.CursorPage[Assistant], err error) {
- var raw *http.Response
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
- path := "assistants"
- cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
- if err != nil {
- return nil, err
- }
- err = cfg.Execute()
- if err != nil {
- return nil, err
- }
- res.SetPageConfig(cfg, raw)
- return res, nil
-}
-
-// Returns a list of assistants.
-func (r *BetaAssistantService) ListAutoPaging(ctx context.Context, query BetaAssistantListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[Assistant] {
- return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
-}
-
-// Delete an assistant.
-func (r *BetaAssistantService) Delete(ctx context.Context, assistantID string, opts ...option.RequestOption) (res *AssistantDeleted, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if assistantID == "" {
- err = errors.New("missing required assistant_id parameter")
- return
- }
- path := fmt.Sprintf("assistants/%s", assistantID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
- return
-}
-
-// Represents an `assistant` that can call the model and use tools.
-type Assistant struct {
- // The identifier, which can be referenced in API endpoints.
- ID string `json:"id,required"`
- // The Unix timestamp (in seconds) for when the assistant was created.
- CreatedAt int64 `json:"created_at,required"`
- // The description of the assistant. The maximum length is 512 characters.
- Description string `json:"description,required"`
- // The system instructions that the assistant uses. The maximum length is 256,000
- // characters.
- Instructions string `json:"instructions,required"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,required"`
- // ID of the model to use. You can use the
- // [List models](https://platform.openai.com/docs/api-reference/models/list) API to
- // see all of your available models, or see our
- // [Model overview](https://platform.openai.com/docs/models) for descriptions of
- // them.
- Model string `json:"model,required"`
- // The name of the assistant. The maximum length is 256 characters.
- Name string `json:"name,required"`
- // The object type, which is always `assistant`.
- Object constant.Assistant `json:"object,required"`
- // A list of tool enabled on the assistant. There can be a maximum of 128 tools per
- // assistant. Tools can be of types `code_interpreter`, `file_search`, or
- // `function`.
- Tools []AssistantToolUnion `json:"tools,required"`
- // Specifies the format that the model must output. Compatible with
- // [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
- // [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
- // and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
- //
- // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
- // Outputs which ensures the model will match your supplied JSON schema. Learn more
- // in the
- // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
- //
- // Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
- // message the model generates is valid JSON.
- //
- // **Important:** when using JSON mode, you **must** also instruct the model to
- // produce JSON yourself via a system or user message. Without this, the model may
- // generate an unending stream of whitespace until the generation reaches the token
- // limit, resulting in a long-running and seemingly "stuck" request. Also note that
- // the message content may be partially cut off if `finish_reason="length"`, which
- // indicates the generation exceeded `max_tokens` or the conversation exceeded the
- // max context length.
- ResponseFormat AssistantResponseFormatOptionUnion `json:"response_format,nullable"`
- // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
- // make the output more random, while lower values like 0.2 will make it more
- // focused and deterministic.
- Temperature float64 `json:"temperature,nullable"`
- // A set of resources that are used by the assistant's tools. The resources are
- // specific to the type of tool. For example, the `code_interpreter` tool requires
- // a list of file IDs, while the `file_search` tool requires a list of vector store
- // IDs.
- ToolResources AssistantToolResources `json:"tool_resources,nullable"`
- // An alternative to sampling with temperature, called nucleus sampling, where the
- // model considers the results of the tokens with top_p probability mass. So 0.1
- // means only the tokens comprising the top 10% probability mass are considered.
- //
- // We generally recommend altering this or temperature but not both.
- TopP float64 `json:"top_p,nullable"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- CreatedAt respjson.Field
- Description respjson.Field
- Instructions respjson.Field
- Metadata respjson.Field
- Model respjson.Field
- Name respjson.Field
- Object respjson.Field
- Tools respjson.Field
- ResponseFormat respjson.Field
- Temperature respjson.Field
- ToolResources respjson.Field
- TopP respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r Assistant) RawJSON() string { return r.JSON.raw }
-func (r *Assistant) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A set of resources that are used by the assistant's tools. The resources are
-// specific to the type of tool. For example, the `code_interpreter` tool requires
-// a list of file IDs, while the `file_search` tool requires a list of vector store
-// IDs.
-type AssistantToolResources struct {
- CodeInterpreter AssistantToolResourcesCodeInterpreter `json:"code_interpreter"`
- FileSearch AssistantToolResourcesFileSearch `json:"file_search"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- CodeInterpreter respjson.Field
- FileSearch respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantToolResources) RawJSON() string { return r.JSON.raw }
-func (r *AssistantToolResources) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type AssistantToolResourcesCodeInterpreter struct {
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
- // available to the `code_interpreter“ tool. There can be a maximum of 20 files
- // associated with the tool.
- FileIDs []string `json:"file_ids"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileIDs respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantToolResourcesCodeInterpreter) RawJSON() string { return r.JSON.raw }
-func (r *AssistantToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type AssistantToolResourcesFileSearch struct {
- // The ID of the
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // attached to this assistant. There can be a maximum of 1 vector store attached to
- // the assistant.
- VectorStoreIDs []string `json:"vector_store_ids"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- VectorStoreIDs respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantToolResourcesFileSearch) RawJSON() string { return r.JSON.raw }
-func (r *AssistantToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type AssistantDeleted struct {
- ID string `json:"id,required"`
- Deleted bool `json:"deleted,required"`
- Object constant.AssistantDeleted `json:"object,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- Deleted respjson.Field
- Object respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantDeleted) RawJSON() string { return r.JSON.raw }
-func (r *AssistantDeleted) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// AssistantStreamEventUnion contains all possible properties and values from
-// [AssistantStreamEventThreadCreated], [AssistantStreamEventThreadRunCreated],
-// [AssistantStreamEventThreadRunQueued],
-// [AssistantStreamEventThreadRunInProgress],
-// [AssistantStreamEventThreadRunRequiresAction],
-// [AssistantStreamEventThreadRunCompleted],
-// [AssistantStreamEventThreadRunIncomplete],
-// [AssistantStreamEventThreadRunFailed],
-// [AssistantStreamEventThreadRunCancelling],
-// [AssistantStreamEventThreadRunCancelled],
-// [AssistantStreamEventThreadRunExpired],
-// [AssistantStreamEventThreadRunStepCreated],
-// [AssistantStreamEventThreadRunStepInProgress],
-// [AssistantStreamEventThreadRunStepDelta],
-// [AssistantStreamEventThreadRunStepCompleted],
-// [AssistantStreamEventThreadRunStepFailed],
-// [AssistantStreamEventThreadRunStepCancelled],
-// [AssistantStreamEventThreadRunStepExpired],
-// [AssistantStreamEventThreadMessageCreated],
-// [AssistantStreamEventThreadMessageInProgress],
-// [AssistantStreamEventThreadMessageDelta],
-// [AssistantStreamEventThreadMessageCompleted],
-// [AssistantStreamEventThreadMessageIncomplete], [AssistantStreamEventErrorEvent].
-//
-// Use the [AssistantStreamEventUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type AssistantStreamEventUnion struct {
- // This field is a union of [Thread], [Run], [RunStep], [RunStepDeltaEvent],
- // [Message], [MessageDeltaEvent], [shared.ErrorObject]
- Data AssistantStreamEventUnionData `json:"data"`
- // Any of "thread.created", "thread.run.created", "thread.run.queued",
- // "thread.run.in_progress", "thread.run.requires_action", "thread.run.completed",
- // "thread.run.incomplete", "thread.run.failed", "thread.run.cancelling",
- // "thread.run.cancelled", "thread.run.expired", "thread.run.step.created",
- // "thread.run.step.in_progress", "thread.run.step.delta",
- // "thread.run.step.completed", "thread.run.step.failed",
- // "thread.run.step.cancelled", "thread.run.step.expired",
- // "thread.message.created", "thread.message.in_progress", "thread.message.delta",
- // "thread.message.completed", "thread.message.incomplete", "error".
- Event string `json:"event"`
- // This field is from variant [AssistantStreamEventThreadCreated].
- Enabled bool `json:"enabled"`
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- Enabled respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyAssistantStreamEvent is implemented by each variant of
-// [AssistantStreamEventUnion] to add type safety for the return type of
-// [AssistantStreamEventUnion.AsAny]
-type anyAssistantStreamEvent interface {
- implAssistantStreamEventUnion()
-}
-
-func (AssistantStreamEventThreadCreated) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunCreated) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunQueued) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunInProgress) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunRequiresAction) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunCompleted) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunIncomplete) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunFailed) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunCancelling) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunCancelled) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunExpired) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunStepCreated) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunStepInProgress) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunStepDelta) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunStepCompleted) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunStepFailed) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunStepCancelled) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadRunStepExpired) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadMessageCreated) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadMessageInProgress) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadMessageDelta) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadMessageCompleted) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventThreadMessageIncomplete) implAssistantStreamEventUnion() {}
-func (AssistantStreamEventErrorEvent) implAssistantStreamEventUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := AssistantStreamEventUnion.AsAny().(type) {
-// case openai.AssistantStreamEventThreadCreated:
-// case openai.AssistantStreamEventThreadRunCreated:
-// case openai.AssistantStreamEventThreadRunQueued:
-// case openai.AssistantStreamEventThreadRunInProgress:
-// case openai.AssistantStreamEventThreadRunRequiresAction:
-// case openai.AssistantStreamEventThreadRunCompleted:
-// case openai.AssistantStreamEventThreadRunIncomplete:
-// case openai.AssistantStreamEventThreadRunFailed:
-// case openai.AssistantStreamEventThreadRunCancelling:
-// case openai.AssistantStreamEventThreadRunCancelled:
-// case openai.AssistantStreamEventThreadRunExpired:
-// case openai.AssistantStreamEventThreadRunStepCreated:
-// case openai.AssistantStreamEventThreadRunStepInProgress:
-// case openai.AssistantStreamEventThreadRunStepDelta:
-// case openai.AssistantStreamEventThreadRunStepCompleted:
-// case openai.AssistantStreamEventThreadRunStepFailed:
-// case openai.AssistantStreamEventThreadRunStepCancelled:
-// case openai.AssistantStreamEventThreadRunStepExpired:
-// case openai.AssistantStreamEventThreadMessageCreated:
-// case openai.AssistantStreamEventThreadMessageInProgress:
-// case openai.AssistantStreamEventThreadMessageDelta:
-// case openai.AssistantStreamEventThreadMessageCompleted:
-// case openai.AssistantStreamEventThreadMessageIncomplete:
-// case openai.AssistantStreamEventErrorEvent:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u AssistantStreamEventUnion) AsAny() anyAssistantStreamEvent {
- switch u.Event {
- case "thread.created":
- return u.AsThreadCreated()
- case "thread.run.created":
- return u.AsThreadRunCreated()
- case "thread.run.queued":
- return u.AsThreadRunQueued()
- case "thread.run.in_progress":
- return u.AsThreadRunInProgress()
- case "thread.run.requires_action":
- return u.AsThreadRunRequiresAction()
- case "thread.run.completed":
- return u.AsThreadRunCompleted()
- case "thread.run.incomplete":
- return u.AsThreadRunIncomplete()
- case "thread.run.failed":
- return u.AsThreadRunFailed()
- case "thread.run.cancelling":
- return u.AsThreadRunCancelling()
- case "thread.run.cancelled":
- return u.AsThreadRunCancelled()
- case "thread.run.expired":
- return u.AsThreadRunExpired()
- case "thread.run.step.created":
- return u.AsThreadRunStepCreated()
- case "thread.run.step.in_progress":
- return u.AsThreadRunStepInProgress()
- case "thread.run.step.delta":
- return u.AsThreadRunStepDelta()
- case "thread.run.step.completed":
- return u.AsThreadRunStepCompleted()
- case "thread.run.step.failed":
- return u.AsThreadRunStepFailed()
- case "thread.run.step.cancelled":
- return u.AsThreadRunStepCancelled()
- case "thread.run.step.expired":
- return u.AsThreadRunStepExpired()
- case "thread.message.created":
- return u.AsThreadMessageCreated()
- case "thread.message.in_progress":
- return u.AsThreadMessageInProgress()
- case "thread.message.delta":
- return u.AsThreadMessageDelta()
- case "thread.message.completed":
- return u.AsThreadMessageCompleted()
- case "thread.message.incomplete":
- return u.AsThreadMessageIncomplete()
- case "error":
- return u.AsErrorEvent()
- }
- return nil
-}
-
-func (u AssistantStreamEventUnion) AsThreadCreated() (v AssistantStreamEventThreadCreated) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunCreated() (v AssistantStreamEventThreadRunCreated) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunQueued() (v AssistantStreamEventThreadRunQueued) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunInProgress() (v AssistantStreamEventThreadRunInProgress) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunRequiresAction() (v AssistantStreamEventThreadRunRequiresAction) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunCompleted() (v AssistantStreamEventThreadRunCompleted) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunIncomplete() (v AssistantStreamEventThreadRunIncomplete) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunFailed() (v AssistantStreamEventThreadRunFailed) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunCancelling() (v AssistantStreamEventThreadRunCancelling) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunCancelled() (v AssistantStreamEventThreadRunCancelled) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunExpired() (v AssistantStreamEventThreadRunExpired) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunStepCreated() (v AssistantStreamEventThreadRunStepCreated) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunStepInProgress() (v AssistantStreamEventThreadRunStepInProgress) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunStepDelta() (v AssistantStreamEventThreadRunStepDelta) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunStepCompleted() (v AssistantStreamEventThreadRunStepCompleted) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunStepFailed() (v AssistantStreamEventThreadRunStepFailed) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunStepCancelled() (v AssistantStreamEventThreadRunStepCancelled) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadRunStepExpired() (v AssistantStreamEventThreadRunStepExpired) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadMessageCreated() (v AssistantStreamEventThreadMessageCreated) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadMessageInProgress() (v AssistantStreamEventThreadMessageInProgress) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadMessageDelta() (v AssistantStreamEventThreadMessageDelta) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadMessageCompleted() (v AssistantStreamEventThreadMessageCompleted) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsThreadMessageIncomplete() (v AssistantStreamEventThreadMessageIncomplete) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantStreamEventUnion) AsErrorEvent() (v AssistantStreamEventErrorEvent) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u AssistantStreamEventUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *AssistantStreamEventUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// AssistantStreamEventUnionData is an implicit subunion of
-// [AssistantStreamEventUnion]. AssistantStreamEventUnionData provides convenient
-// access to the sub-properties of the union.
-//
-// For type safety it is recommended to directly use a variant of the
-// [AssistantStreamEventUnion].
-type AssistantStreamEventUnionData struct {
- ID string `json:"id"`
- CreatedAt int64 `json:"created_at"`
- // This field is from variant [Thread].
- Metadata shared.Metadata `json:"metadata"`
- Object string `json:"object"`
- // This field is from variant [Thread].
- ToolResources ThreadToolResources `json:"tool_resources"`
- AssistantID string `json:"assistant_id"`
- CancelledAt int64 `json:"cancelled_at"`
- CompletedAt int64 `json:"completed_at"`
- // This field is from variant [Run].
- ExpiresAt int64 `json:"expires_at"`
- FailedAt int64 `json:"failed_at"`
- // This field is a union of [RunIncompleteDetails], [MessageIncompleteDetails]
- IncompleteDetails AssistantStreamEventUnionDataIncompleteDetails `json:"incomplete_details"`
- // This field is from variant [Run].
- Instructions string `json:"instructions"`
- // This field is a union of [RunLastError], [RunStepLastError]
- LastError AssistantStreamEventUnionDataLastError `json:"last_error"`
- // This field is from variant [Run].
- MaxCompletionTokens int64 `json:"max_completion_tokens"`
- // This field is from variant [Run].
- MaxPromptTokens int64 `json:"max_prompt_tokens"`
- // This field is from variant [Run].
- Model string `json:"model"`
- // This field is from variant [Run].
- ParallelToolCalls bool `json:"parallel_tool_calls"`
- // This field is from variant [Run].
- RequiredAction RunRequiredAction `json:"required_action"`
- // This field is from variant [Run].
- ResponseFormat AssistantResponseFormatOptionUnion `json:"response_format"`
- // This field is from variant [Run].
- StartedAt int64 `json:"started_at"`
- Status string `json:"status"`
- ThreadID string `json:"thread_id"`
- // This field is from variant [Run].
- ToolChoice AssistantToolChoiceOptionUnion `json:"tool_choice"`
- // This field is from variant [Run].
- Tools []AssistantToolUnion `json:"tools"`
- // This field is from variant [Run].
- TruncationStrategy RunTruncationStrategy `json:"truncation_strategy"`
- // This field is a union of [RunUsage], [RunStepUsage]
- Usage AssistantStreamEventUnionDataUsage `json:"usage"`
- // This field is from variant [Run].
- Temperature float64 `json:"temperature"`
- // This field is from variant [Run].
- TopP float64 `json:"top_p"`
- // This field is from variant [RunStep].
- ExpiredAt int64 `json:"expired_at"`
- RunID string `json:"run_id"`
- // This field is from variant [RunStep].
- StepDetails RunStepStepDetailsUnion `json:"step_details"`
- Type string `json:"type"`
- // This field is a union of [RunStepDelta], [MessageDelta]
- Delta AssistantStreamEventUnionDataDelta `json:"delta"`
- // This field is from variant [Message].
- Attachments []MessageAttachment `json:"attachments"`
- // This field is from variant [Message].
- Content []MessageContentUnion `json:"content"`
- // This field is from variant [Message].
- IncompleteAt int64 `json:"incomplete_at"`
- // This field is from variant [Message].
- Role MessageRole `json:"role"`
- // This field is from variant [shared.ErrorObject].
- Code string `json:"code"`
- // This field is from variant [shared.ErrorObject].
- Message string `json:"message"`
- // This field is from variant [shared.ErrorObject].
- Param string `json:"param"`
- JSON struct {
- ID respjson.Field
- CreatedAt respjson.Field
- Metadata respjson.Field
- Object respjson.Field
- ToolResources respjson.Field
- AssistantID respjson.Field
- CancelledAt respjson.Field
- CompletedAt respjson.Field
- ExpiresAt respjson.Field
- FailedAt respjson.Field
- IncompleteDetails respjson.Field
- Instructions respjson.Field
- LastError respjson.Field
- MaxCompletionTokens respjson.Field
- MaxPromptTokens respjson.Field
- Model respjson.Field
- ParallelToolCalls respjson.Field
- RequiredAction respjson.Field
- ResponseFormat respjson.Field
- StartedAt respjson.Field
- Status respjson.Field
- ThreadID respjson.Field
- ToolChoice respjson.Field
- Tools respjson.Field
- TruncationStrategy respjson.Field
- Usage respjson.Field
- Temperature respjson.Field
- TopP respjson.Field
- ExpiredAt respjson.Field
- RunID respjson.Field
- StepDetails respjson.Field
- Type respjson.Field
- Delta respjson.Field
- Attachments respjson.Field
- Content respjson.Field
- IncompleteAt respjson.Field
- Role respjson.Field
- Code respjson.Field
- Message respjson.Field
- Param respjson.Field
- raw string
- } `json:"-"`
-}
-
-func (r *AssistantStreamEventUnionData) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// AssistantStreamEventUnionDataIncompleteDetails is an implicit subunion of
-// [AssistantStreamEventUnion]. AssistantStreamEventUnionDataIncompleteDetails
-// provides convenient access to the sub-properties of the union.
-//
-// For type safety it is recommended to directly use a variant of the
-// [AssistantStreamEventUnion].
-type AssistantStreamEventUnionDataIncompleteDetails struct {
- Reason string `json:"reason"`
- JSON struct {
- Reason respjson.Field
- raw string
- } `json:"-"`
-}
-
-func (r *AssistantStreamEventUnionDataIncompleteDetails) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// AssistantStreamEventUnionDataLastError is an implicit subunion of
-// [AssistantStreamEventUnion]. AssistantStreamEventUnionDataLastError provides
-// convenient access to the sub-properties of the union.
-//
-// For type safety it is recommended to directly use a variant of the
-// [AssistantStreamEventUnion].
-type AssistantStreamEventUnionDataLastError struct {
- Code string `json:"code"`
- Message string `json:"message"`
- JSON struct {
- Code respjson.Field
- Message respjson.Field
- raw string
- } `json:"-"`
-}
-
-func (r *AssistantStreamEventUnionDataLastError) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// AssistantStreamEventUnionDataUsage is an implicit subunion of
-// [AssistantStreamEventUnion]. AssistantStreamEventUnionDataUsage provides
-// convenient access to the sub-properties of the union.
-//
-// For type safety it is recommended to directly use a variant of the
-// [AssistantStreamEventUnion].
-type AssistantStreamEventUnionDataUsage struct {
- CompletionTokens int64 `json:"completion_tokens"`
- PromptTokens int64 `json:"prompt_tokens"`
- TotalTokens int64 `json:"total_tokens"`
- JSON struct {
- CompletionTokens respjson.Field
- PromptTokens respjson.Field
- TotalTokens respjson.Field
- raw string
- } `json:"-"`
-}
-
-func (r *AssistantStreamEventUnionDataUsage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// AssistantStreamEventUnionDataDelta is an implicit subunion of
-// [AssistantStreamEventUnion]. AssistantStreamEventUnionDataDelta provides
-// convenient access to the sub-properties of the union.
-//
-// For type safety it is recommended to directly use a variant of the
-// [AssistantStreamEventUnion].
-type AssistantStreamEventUnionDataDelta struct {
- // This field is from variant [RunStepDelta].
- StepDetails RunStepDeltaStepDetailsUnion `json:"step_details"`
- // This field is from variant [MessageDelta].
- Content []MessageContentDeltaUnion `json:"content"`
- // This field is from variant [MessageDelta].
- Role MessageDeltaRole `json:"role"`
- JSON struct {
- StepDetails respjson.Field
- Content respjson.Field
- Role respjson.Field
- raw string
- } `json:"-"`
-}
-
-func (r *AssistantStreamEventUnionDataDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a new
-// [thread](https://platform.openai.com/docs/api-reference/threads/object) is
-// created.
-type AssistantStreamEventThreadCreated struct {
- // Represents a thread that contains
- // [messages](https://platform.openai.com/docs/api-reference/messages).
- Data Thread `json:"data,required"`
- Event constant.ThreadCreated `json:"event,required"`
- // Whether to enable input audio transcription.
- Enabled bool `json:"enabled"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- Enabled respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadCreated) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadCreated) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a new
-// [run](https://platform.openai.com/docs/api-reference/runs/object) is created.
-type AssistantStreamEventThreadRunCreated struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunCreated `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunCreated) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunCreated) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
-// moves to a `queued` status.
-type AssistantStreamEventThreadRunQueued struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunQueued `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunQueued) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunQueued) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
-// moves to an `in_progress` status.
-type AssistantStreamEventThreadRunInProgress struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunInProgress `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunInProgress) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunInProgress) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
-// moves to a `requires_action` status.
-type AssistantStreamEventThreadRunRequiresAction struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunRequiresAction `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunRequiresAction) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunRequiresAction) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
-// is completed.
-type AssistantStreamEventThreadRunCompleted struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunCompleted `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunCompleted) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunCompleted) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
-// ends with status `incomplete`.
-type AssistantStreamEventThreadRunIncomplete struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunIncomplete `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunIncomplete) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunIncomplete) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
-// fails.
-type AssistantStreamEventThreadRunFailed struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunFailed `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunFailed) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunFailed) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
-// moves to a `cancelling` status.
-type AssistantStreamEventThreadRunCancelling struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunCancelling `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunCancelling) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunCancelling) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
-// is cancelled.
-type AssistantStreamEventThreadRunCancelled struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunCancelled `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunCancelled) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunCancelled) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
-// expires.
-type AssistantStreamEventThreadRunExpired struct {
- // Represents an execution run on a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Run `json:"data,required"`
- Event constant.ThreadRunExpired `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunExpired) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunExpired) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)
-// is created.
-type AssistantStreamEventThreadRunStepCreated struct {
- // Represents a step in execution of a run.
- Data RunStep `json:"data,required"`
- Event constant.ThreadRunStepCreated `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunStepCreated) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunStepCreated) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)
-// moves to an `in_progress` state.
-type AssistantStreamEventThreadRunStepInProgress struct {
- // Represents a step in execution of a run.
- Data RunStep `json:"data,required"`
- Event constant.ThreadRunStepInProgress `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunStepInProgress) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunStepInProgress) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when parts of a
-// [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)
-// are being streamed.
-type AssistantStreamEventThreadRunStepDelta struct {
- // Represents a run step delta i.e. any changed fields on a run step during
- // streaming.
- Data RunStepDeltaEvent `json:"data,required"`
- Event constant.ThreadRunStepDelta `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunStepDelta) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunStepDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)
-// is completed.
-type AssistantStreamEventThreadRunStepCompleted struct {
- // Represents a step in execution of a run.
- Data RunStep `json:"data,required"`
- Event constant.ThreadRunStepCompleted `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunStepCompleted) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunStepCompleted) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)
-// fails.
-type AssistantStreamEventThreadRunStepFailed struct {
- // Represents a step in execution of a run.
- Data RunStep `json:"data,required"`
- Event constant.ThreadRunStepFailed `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunStepFailed) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunStepFailed) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)
-// is cancelled.
-type AssistantStreamEventThreadRunStepCancelled struct {
- // Represents a step in execution of a run.
- Data RunStep `json:"data,required"`
- Event constant.ThreadRunStepCancelled `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunStepCancelled) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunStepCancelled) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)
-// expires.
-type AssistantStreamEventThreadRunStepExpired struct {
- // Represents a step in execution of a run.
- Data RunStep `json:"data,required"`
- Event constant.ThreadRunStepExpired `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadRunStepExpired) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadRunStepExpired) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [message](https://platform.openai.com/docs/api-reference/messages/object) is
-// created.
-type AssistantStreamEventThreadMessageCreated struct {
- // Represents a message within a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Message `json:"data,required"`
- Event constant.ThreadMessageCreated `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadMessageCreated) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadMessageCreated) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [message](https://platform.openai.com/docs/api-reference/messages/object) moves
-// to an `in_progress` state.
-type AssistantStreamEventThreadMessageInProgress struct {
- // Represents a message within a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Message `json:"data,required"`
- Event constant.ThreadMessageInProgress `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadMessageInProgress) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadMessageInProgress) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when parts of a
-// [Message](https://platform.openai.com/docs/api-reference/messages/object) are
-// being streamed.
-type AssistantStreamEventThreadMessageDelta struct {
- // Represents a message delta i.e. any changed fields on a message during
- // streaming.
- Data MessageDeltaEvent `json:"data,required"`
- Event constant.ThreadMessageDelta `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadMessageDelta) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadMessageDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [message](https://platform.openai.com/docs/api-reference/messages/object) is
-// completed.
-type AssistantStreamEventThreadMessageCompleted struct {
- // Represents a message within a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Message `json:"data,required"`
- Event constant.ThreadMessageCompleted `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadMessageCompleted) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadMessageCompleted) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when a
-// [message](https://platform.openai.com/docs/api-reference/messages/object) ends
-// before it is completed.
-type AssistantStreamEventThreadMessageIncomplete struct {
- // Represents a message within a
- // [thread](https://platform.openai.com/docs/api-reference/threads).
- Data Message `json:"data,required"`
- Event constant.ThreadMessageIncomplete `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventThreadMessageIncomplete) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventThreadMessageIncomplete) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Occurs when an
-// [error](https://platform.openai.com/docs/guides/error-codes#api-errors) occurs.
-// This can happen due to an internal server error or a timeout.
-type AssistantStreamEventErrorEvent struct {
- Data shared.ErrorObject `json:"data,required"`
- Event constant.Error `json:"event,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Data respjson.Field
- Event respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantStreamEventErrorEvent) RawJSON() string { return r.JSON.raw }
-func (r *AssistantStreamEventErrorEvent) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// AssistantToolUnion contains all possible properties and values from
-// [CodeInterpreterTool], [FileSearchTool], [FunctionTool].
-//
-// Use the [AssistantToolUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type AssistantToolUnion struct {
- // Any of "code_interpreter", "file_search", "function".
- Type string `json:"type"`
- // This field is from variant [FileSearchTool].
- FileSearch FileSearchToolFileSearch `json:"file_search"`
- // This field is from variant [FunctionTool].
- Function shared.FunctionDefinition `json:"function"`
- JSON struct {
- Type respjson.Field
- FileSearch respjson.Field
- Function respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyAssistantTool is implemented by each variant of [AssistantToolUnion] to add
-// type safety for the return type of [AssistantToolUnion.AsAny]
-type anyAssistantTool interface {
- implAssistantToolUnion()
-}
-
-func (CodeInterpreterTool) implAssistantToolUnion() {}
-func (FileSearchTool) implAssistantToolUnion() {}
-func (FunctionTool) implAssistantToolUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := AssistantToolUnion.AsAny().(type) {
-// case openai.CodeInterpreterTool:
-// case openai.FileSearchTool:
-// case openai.FunctionTool:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u AssistantToolUnion) AsAny() anyAssistantTool {
- switch u.Type {
- case "code_interpreter":
- return u.AsCodeInterpreter()
- case "file_search":
- return u.AsFileSearch()
- case "function":
- return u.AsFunction()
- }
- return nil
-}
-
-func (u AssistantToolUnion) AsCodeInterpreter() (v CodeInterpreterTool) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantToolUnion) AsFileSearch() (v FileSearchTool) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantToolUnion) AsFunction() (v FunctionTool) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u AssistantToolUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *AssistantToolUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this AssistantToolUnion to a AssistantToolUnionParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// AssistantToolUnionParam.Overrides()
-func (r AssistantToolUnion) ToParam() AssistantToolUnionParam {
- return param.Override[AssistantToolUnionParam](r.RawJSON())
-}
-
-func AssistantToolParamOfFunction(function shared.FunctionDefinitionParam) AssistantToolUnionParam {
- var variant FunctionToolParam
- variant.Function = function
- return AssistantToolUnionParam{OfFunction: &variant}
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type AssistantToolUnionParam struct {
- OfCodeInterpreter *CodeInterpreterToolParam `json:",omitzero,inline"`
- OfFileSearch *FileSearchToolParam `json:",omitzero,inline"`
- OfFunction *FunctionToolParam `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u AssistantToolUnionParam) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[AssistantToolUnionParam](u.OfCodeInterpreter, u.OfFileSearch, u.OfFunction)
-}
-func (u *AssistantToolUnionParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *AssistantToolUnionParam) asAny() any {
- if !param.IsOmitted(u.OfCodeInterpreter) {
- return u.OfCodeInterpreter
- } else if !param.IsOmitted(u.OfFileSearch) {
- return u.OfFileSearch
- } else if !param.IsOmitted(u.OfFunction) {
- return u.OfFunction
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u AssistantToolUnionParam) GetFileSearch() *FileSearchToolFileSearchParam {
- if vt := u.OfFileSearch; vt != nil {
- return &vt.FileSearch
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u AssistantToolUnionParam) GetFunction() *shared.FunctionDefinitionParam {
- if vt := u.OfFunction; vt != nil {
- return &vt.Function
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u AssistantToolUnionParam) GetType() *string {
- if vt := u.OfCodeInterpreter; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfFileSearch; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfFunction; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-func init() {
- apijson.RegisterUnion[AssistantToolUnionParam](
- "type",
- apijson.Discriminator[CodeInterpreterToolParam]("code_interpreter"),
- apijson.Discriminator[FileSearchToolParam]("file_search"),
- apijson.Discriminator[FunctionToolParam]("function"),
- )
-}
-
-type CodeInterpreterTool struct {
- // The type of tool being defined: `code_interpreter`
- Type constant.CodeInterpreter `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterTool) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterTool) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this CodeInterpreterTool to a CodeInterpreterToolParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// CodeInterpreterToolParam.Overrides()
-func (r CodeInterpreterTool) ToParam() CodeInterpreterToolParam {
- return param.Override[CodeInterpreterToolParam](r.RawJSON())
-}
-
-func NewCodeInterpreterToolParam() CodeInterpreterToolParam {
- return CodeInterpreterToolParam{
- Type: "code_interpreter",
- }
-}
-
-// This struct has a constant value, construct it with
-// [NewCodeInterpreterToolParam].
-type CodeInterpreterToolParam struct {
- // The type of tool being defined: `code_interpreter`
- Type constant.CodeInterpreter `json:"type,required"`
- paramObj
-}
-
-func (r CodeInterpreterToolParam) MarshalJSON() (data []byte, err error) {
- type shadow CodeInterpreterToolParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *CodeInterpreterToolParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FileSearchTool struct {
- // The type of tool being defined: `file_search`
- Type constant.FileSearch `json:"type,required"`
- // Overrides for the file search tool.
- FileSearch FileSearchToolFileSearch `json:"file_search"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Type respjson.Field
- FileSearch respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileSearchTool) RawJSON() string { return r.JSON.raw }
-func (r *FileSearchTool) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this FileSearchTool to a FileSearchToolParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// FileSearchToolParam.Overrides()
-func (r FileSearchTool) ToParam() FileSearchToolParam {
- return param.Override[FileSearchToolParam](r.RawJSON())
-}
-
-// Overrides for the file search tool.
-type FileSearchToolFileSearch struct {
- // The maximum number of results the file search tool should output. The default is
- // 20 for `gpt-4*` models and 5 for `gpt-3.5-turbo`. This number should be between
- // 1 and 50 inclusive.
- //
- // Note that the file search tool may output fewer than `max_num_results` results.
- // See the
- // [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
- // for more information.
- MaxNumResults int64 `json:"max_num_results"`
- // The ranking options for the file search. If not specified, the file search tool
- // will use the `auto` ranker and a score_threshold of 0.
- //
- // See the
- // [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
- // for more information.
- RankingOptions FileSearchToolFileSearchRankingOptions `json:"ranking_options"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- MaxNumResults respjson.Field
- RankingOptions respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileSearchToolFileSearch) RawJSON() string { return r.JSON.raw }
-func (r *FileSearchToolFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The ranking options for the file search. If not specified, the file search tool
-// will use the `auto` ranker and a score_threshold of 0.
-//
-// See the
-// [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
-// for more information.
-type FileSearchToolFileSearchRankingOptions struct {
- // The score threshold for the file search. All values must be a floating point
- // number between 0 and 1.
- ScoreThreshold float64 `json:"score_threshold,required"`
- // The ranker to use for the file search. If not specified will use the `auto`
- // ranker.
- //
- // Any of "auto", "default_2024_08_21".
- Ranker string `json:"ranker"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ScoreThreshold respjson.Field
- Ranker respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileSearchToolFileSearchRankingOptions) RawJSON() string { return r.JSON.raw }
-func (r *FileSearchToolFileSearchRankingOptions) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The property Type is required.
-type FileSearchToolParam struct {
- // Overrides for the file search tool.
- FileSearch FileSearchToolFileSearchParam `json:"file_search,omitzero"`
- // The type of tool being defined: `file_search`
- //
- // This field can be elided, and will marshal its zero value as "file_search".
- Type constant.FileSearch `json:"type,required"`
- paramObj
-}
-
-func (r FileSearchToolParam) MarshalJSON() (data []byte, err error) {
- type shadow FileSearchToolParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *FileSearchToolParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Overrides for the file search tool.
-type FileSearchToolFileSearchParam struct {
- // The maximum number of results the file search tool should output. The default is
- // 20 for `gpt-4*` models and 5 for `gpt-3.5-turbo`. This number should be between
- // 1 and 50 inclusive.
- //
- // Note that the file search tool may output fewer than `max_num_results` results.
- // See the
- // [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
- // for more information.
- MaxNumResults param.Opt[int64] `json:"max_num_results,omitzero"`
- // The ranking options for the file search. If not specified, the file search tool
- // will use the `auto` ranker and a score_threshold of 0.
- //
- // See the
- // [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
- // for more information.
- RankingOptions FileSearchToolFileSearchRankingOptionsParam `json:"ranking_options,omitzero"`
- paramObj
-}
-
-func (r FileSearchToolFileSearchParam) MarshalJSON() (data []byte, err error) {
- type shadow FileSearchToolFileSearchParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *FileSearchToolFileSearchParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The ranking options for the file search. If not specified, the file search tool
-// will use the `auto` ranker and a score_threshold of 0.
-//
-// See the
-// [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
-// for more information.
-//
-// The property ScoreThreshold is required.
-type FileSearchToolFileSearchRankingOptionsParam struct {
- // The score threshold for the file search. All values must be a floating point
- // number between 0 and 1.
- ScoreThreshold float64 `json:"score_threshold,required"`
- // The ranker to use for the file search. If not specified will use the `auto`
- // ranker.
- //
- // Any of "auto", "default_2024_08_21".
- Ranker string `json:"ranker,omitzero"`
- paramObj
-}
-
-func (r FileSearchToolFileSearchRankingOptionsParam) MarshalJSON() (data []byte, err error) {
- type shadow FileSearchToolFileSearchRankingOptionsParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *FileSearchToolFileSearchRankingOptionsParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-func init() {
- apijson.RegisterFieldValidator[FileSearchToolFileSearchRankingOptionsParam](
- "ranker", "auto", "default_2024_08_21",
- )
-}
-
-type FunctionTool struct {
- Function shared.FunctionDefinition `json:"function,required"`
- // The type of tool being defined: `function`
- Type constant.Function `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Function respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FunctionTool) RawJSON() string { return r.JSON.raw }
-func (r *FunctionTool) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this FunctionTool to a FunctionToolParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// FunctionToolParam.Overrides()
-func (r FunctionTool) ToParam() FunctionToolParam {
- return param.Override[FunctionToolParam](r.RawJSON())
-}
-
-// The properties Function, Type are required.
-type FunctionToolParam struct {
- Function shared.FunctionDefinitionParam `json:"function,omitzero,required"`
- // The type of tool being defined: `function`
- //
- // This field can be elided, and will marshal its zero value as "function".
- Type constant.Function `json:"type,required"`
- paramObj
-}
-
-func (r FunctionToolParam) MarshalJSON() (data []byte, err error) {
- type shadow FunctionToolParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *FunctionToolParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaAssistantNewParams struct {
- // ID of the model to use. You can use the
- // [List models](https://platform.openai.com/docs/api-reference/models/list) API to
- // see all of your available models, or see our
- // [Model overview](https://platform.openai.com/docs/models) for descriptions of
- // them.
- Model shared.ChatModel `json:"model,omitzero,required"`
- // The description of the assistant. The maximum length is 512 characters.
- Description param.Opt[string] `json:"description,omitzero"`
- // The system instructions that the assistant uses. The maximum length is 256,000
- // characters.
- Instructions param.Opt[string] `json:"instructions,omitzero"`
- // The name of the assistant. The maximum length is 256 characters.
- Name param.Opt[string] `json:"name,omitzero"`
- // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
- // make the output more random, while lower values like 0.2 will make it more
- // focused and deterministic.
- Temperature param.Opt[float64] `json:"temperature,omitzero"`
- // An alternative to sampling with temperature, called nucleus sampling, where the
- // model considers the results of the tokens with top_p probability mass. So 0.1
- // means only the tokens comprising the top 10% probability mass are considered.
- //
- // We generally recommend altering this or temperature but not both.
- TopP param.Opt[float64] `json:"top_p,omitzero"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // **o-series models only**
- //
- // Constrains effort on reasoning for
- // [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
- // supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
- // result in faster responses and fewer tokens used on reasoning in a response.
- //
- // Any of "low", "medium", "high".
- ReasoningEffort shared.ReasoningEffort `json:"reasoning_effort,omitzero"`
- // A set of resources that are used by the assistant's tools. The resources are
- // specific to the type of tool. For example, the `code_interpreter` tool requires
- // a list of file IDs, while the `file_search` tool requires a list of vector store
- // IDs.
- ToolResources BetaAssistantNewParamsToolResources `json:"tool_resources,omitzero"`
- // Specifies the format that the model must output. Compatible with
- // [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
- // [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
- // and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
- //
- // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
- // Outputs which ensures the model will match your supplied JSON schema. Learn more
- // in the
- // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
- //
- // Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
- // message the model generates is valid JSON.
- //
- // **Important:** when using JSON mode, you **must** also instruct the model to
- // produce JSON yourself via a system or user message. Without this, the model may
- // generate an unending stream of whitespace until the generation reaches the token
- // limit, resulting in a long-running and seemingly "stuck" request. Also note that
- // the message content may be partially cut off if `finish_reason="length"`, which
- // indicates the generation exceeded `max_tokens` or the conversation exceeded the
- // max context length.
- ResponseFormat AssistantResponseFormatOptionUnionParam `json:"response_format,omitzero"`
- // A list of tool enabled on the assistant. There can be a maximum of 128 tools per
- // assistant. Tools can be of types `code_interpreter`, `file_search`, or
- // `function`.
- Tools []AssistantToolUnionParam `json:"tools,omitzero"`
- paramObj
-}
-
-func (r BetaAssistantNewParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantNewParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantNewParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A set of resources that are used by the assistant's tools. The resources are
-// specific to the type of tool. For example, the `code_interpreter` tool requires
-// a list of file IDs, while the `file_search` tool requires a list of vector store
-// IDs.
-type BetaAssistantNewParamsToolResources struct {
- CodeInterpreter BetaAssistantNewParamsToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
- FileSearch BetaAssistantNewParamsToolResourcesFileSearch `json:"file_search,omitzero"`
- paramObj
-}
-
-func (r BetaAssistantNewParamsToolResources) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantNewParamsToolResources
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantNewParamsToolResources) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaAssistantNewParamsToolResourcesCodeInterpreter struct {
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
- // available to the `code_interpreter` tool. There can be a maximum of 20 files
- // associated with the tool.
- FileIDs []string `json:"file_ids,omitzero"`
- paramObj
-}
-
-func (r BetaAssistantNewParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantNewParamsToolResourcesCodeInterpreter
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantNewParamsToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaAssistantNewParamsToolResourcesFileSearch struct {
- // The
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // attached to this assistant. There can be a maximum of 1 vector store attached to
- // the assistant.
- VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
- // A helper to create a
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // with file_ids and attach it to this assistant. There can be a maximum of 1
- // vector store attached to the assistant.
- VectorStores []BetaAssistantNewParamsToolResourcesFileSearchVectorStore `json:"vector_stores,omitzero"`
- paramObj
-}
-
-func (r BetaAssistantNewParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantNewParamsToolResourcesFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantNewParamsToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaAssistantNewParamsToolResourcesFileSearchVectorStore struct {
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // The chunking strategy used to chunk the file(s). If not set, will use the `auto`
- // strategy.
- ChunkingStrategy BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion `json:"chunking_strategy,omitzero"`
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
- // add to the vector store. There can be a maximum of 10000 files in a vector
- // store.
- FileIDs []string `json:"file_ids,omitzero"`
- paramObj
-}
-
-func (r BetaAssistantNewParamsToolResourcesFileSearchVectorStore) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantNewParamsToolResourcesFileSearchVectorStore
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantNewParamsToolResourcesFileSearchVectorStore) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion struct {
- OfAuto *BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto `json:",omitzero,inline"`
- OfStatic *BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion](u.OfAuto, u.OfStatic)
-}
-func (u *BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) asAny() any {
- if !param.IsOmitted(u.OfAuto) {
- return u.OfAuto
- } else if !param.IsOmitted(u.OfStatic) {
- return u.OfStatic
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetStatic() *BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic {
- if vt := u.OfStatic; vt != nil {
- return &vt.Static
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetType() *string {
- if vt := u.OfAuto; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfStatic; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-func init() {
- apijson.RegisterUnion[BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion](
- "type",
- apijson.Discriminator[BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto]("auto"),
- apijson.Discriminator[BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic]("static"),
- )
-}
-
-func NewBetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto() BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto {
- return BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto{
- Type: "auto",
- }
-}
-
-// The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
-// `800` and `chunk_overlap_tokens` of `400`.
-//
-// This struct has a constant value, construct it with
-// [NewBetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto].
-type BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto struct {
- // Always `auto`.
- Type constant.Auto `json:"type,required"`
- paramObj
-}
-
-func (r BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The properties Static, Type are required.
-type BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic struct {
- Static BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic `json:"static,omitzero,required"`
- // Always `static`.
- //
- // This field can be elided, and will marshal its zero value as "static".
- Type constant.Static `json:"type,required"`
- paramObj
-}
-
-func (r BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The properties ChunkOverlapTokens, MaxChunkSizeTokens are required.
-type BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic struct {
- // The number of tokens that overlap between chunks. The default value is `400`.
- //
- // Note that the overlap must not exceed half of `max_chunk_size_tokens`.
- ChunkOverlapTokens int64 `json:"chunk_overlap_tokens,required"`
- // The maximum number of tokens in each chunk. The default value is `800`. The
- // minimum value is `100` and the maximum value is `4096`.
- MaxChunkSizeTokens int64 `json:"max_chunk_size_tokens,required"`
- paramObj
-}
-
-func (r BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaAssistantUpdateParams struct {
- // The description of the assistant. The maximum length is 512 characters.
- Description param.Opt[string] `json:"description,omitzero"`
- // The system instructions that the assistant uses. The maximum length is 256,000
- // characters.
- Instructions param.Opt[string] `json:"instructions,omitzero"`
- // The name of the assistant. The maximum length is 256 characters.
- Name param.Opt[string] `json:"name,omitzero"`
- // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
- // make the output more random, while lower values like 0.2 will make it more
- // focused and deterministic.
- Temperature param.Opt[float64] `json:"temperature,omitzero"`
- // An alternative to sampling with temperature, called nucleus sampling, where the
- // model considers the results of the tokens with top_p probability mass. So 0.1
- // means only the tokens comprising the top 10% probability mass are considered.
- //
- // We generally recommend altering this or temperature but not both.
- TopP param.Opt[float64] `json:"top_p,omitzero"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // **o-series models only**
- //
- // Constrains effort on reasoning for
- // [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
- // supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
- // result in faster responses and fewer tokens used on reasoning in a response.
- //
- // Any of "low", "medium", "high".
- ReasoningEffort shared.ReasoningEffort `json:"reasoning_effort,omitzero"`
- // A set of resources that are used by the assistant's tools. The resources are
- // specific to the type of tool. For example, the `code_interpreter` tool requires
- // a list of file IDs, while the `file_search` tool requires a list of vector store
- // IDs.
- ToolResources BetaAssistantUpdateParamsToolResources `json:"tool_resources,omitzero"`
- // ID of the model to use. You can use the
- // [List models](https://platform.openai.com/docs/api-reference/models/list) API to
- // see all of your available models, or see our
- // [Model overview](https://platform.openai.com/docs/models) for descriptions of
- // them.
- Model BetaAssistantUpdateParamsModel `json:"model,omitzero"`
- // Specifies the format that the model must output. Compatible with
- // [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
- // [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
- // and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
- //
- // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
- // Outputs which ensures the model will match your supplied JSON schema. Learn more
- // in the
- // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
- //
- // Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
- // message the model generates is valid JSON.
- //
- // **Important:** when using JSON mode, you **must** also instruct the model to
- // produce JSON yourself via a system or user message. Without this, the model may
- // generate an unending stream of whitespace until the generation reaches the token
- // limit, resulting in a long-running and seemingly "stuck" request. Also note that
- // the message content may be partially cut off if `finish_reason="length"`, which
- // indicates the generation exceeded `max_tokens` or the conversation exceeded the
- // max context length.
- ResponseFormat AssistantResponseFormatOptionUnionParam `json:"response_format,omitzero"`
- // A list of tool enabled on the assistant. There can be a maximum of 128 tools per
- // assistant. Tools can be of types `code_interpreter`, `file_search`, or
- // `function`.
- Tools []AssistantToolUnionParam `json:"tools,omitzero"`
- paramObj
-}
-
-func (r BetaAssistantUpdateParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantUpdateParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantUpdateParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ID of the model to use. You can use the
-// [List models](https://platform.openai.com/docs/api-reference/models/list) API to
-// see all of your available models, or see our
-// [Model overview](https://platform.openai.com/docs/models) for descriptions of
-// them.
-type BetaAssistantUpdateParamsModel string
-
-const (
- BetaAssistantUpdateParamsModelGPT4_1 BetaAssistantUpdateParamsModel = "gpt-4.1"
- BetaAssistantUpdateParamsModelGPT4_1Mini BetaAssistantUpdateParamsModel = "gpt-4.1-mini"
- BetaAssistantUpdateParamsModelGPT4_1Nano BetaAssistantUpdateParamsModel = "gpt-4.1-nano"
- BetaAssistantUpdateParamsModelGPT4_1_2025_04_14 BetaAssistantUpdateParamsModel = "gpt-4.1-2025-04-14"
- BetaAssistantUpdateParamsModelGPT4_1Mini2025_04_14 BetaAssistantUpdateParamsModel = "gpt-4.1-mini-2025-04-14"
- BetaAssistantUpdateParamsModelGPT4_1Nano2025_04_14 BetaAssistantUpdateParamsModel = "gpt-4.1-nano-2025-04-14"
- BetaAssistantUpdateParamsModelO3Mini BetaAssistantUpdateParamsModel = "o3-mini"
- BetaAssistantUpdateParamsModelO3Mini2025_01_31 BetaAssistantUpdateParamsModel = "o3-mini-2025-01-31"
- BetaAssistantUpdateParamsModelO1 BetaAssistantUpdateParamsModel = "o1"
- BetaAssistantUpdateParamsModelO1_2024_12_17 BetaAssistantUpdateParamsModel = "o1-2024-12-17"
- BetaAssistantUpdateParamsModelGPT4o BetaAssistantUpdateParamsModel = "gpt-4o"
- BetaAssistantUpdateParamsModelGPT4o2024_11_20 BetaAssistantUpdateParamsModel = "gpt-4o-2024-11-20"
- BetaAssistantUpdateParamsModelGPT4o2024_08_06 BetaAssistantUpdateParamsModel = "gpt-4o-2024-08-06"
- BetaAssistantUpdateParamsModelGPT4o2024_05_13 BetaAssistantUpdateParamsModel = "gpt-4o-2024-05-13"
- BetaAssistantUpdateParamsModelGPT4oMini BetaAssistantUpdateParamsModel = "gpt-4o-mini"
- BetaAssistantUpdateParamsModelGPT4oMini2024_07_18 BetaAssistantUpdateParamsModel = "gpt-4o-mini-2024-07-18"
- BetaAssistantUpdateParamsModelGPT4_5Preview BetaAssistantUpdateParamsModel = "gpt-4.5-preview"
- BetaAssistantUpdateParamsModelGPT4_5Preview2025_02_27 BetaAssistantUpdateParamsModel = "gpt-4.5-preview-2025-02-27"
- BetaAssistantUpdateParamsModelGPT4Turbo BetaAssistantUpdateParamsModel = "gpt-4-turbo"
- BetaAssistantUpdateParamsModelGPT4Turbo2024_04_09 BetaAssistantUpdateParamsModel = "gpt-4-turbo-2024-04-09"
- BetaAssistantUpdateParamsModelGPT4_0125Preview BetaAssistantUpdateParamsModel = "gpt-4-0125-preview"
- BetaAssistantUpdateParamsModelGPT4TurboPreview BetaAssistantUpdateParamsModel = "gpt-4-turbo-preview"
- BetaAssistantUpdateParamsModelGPT4_1106Preview BetaAssistantUpdateParamsModel = "gpt-4-1106-preview"
- BetaAssistantUpdateParamsModelGPT4VisionPreview BetaAssistantUpdateParamsModel = "gpt-4-vision-preview"
- BetaAssistantUpdateParamsModelGPT4 BetaAssistantUpdateParamsModel = "gpt-4"
- BetaAssistantUpdateParamsModelGPT4_0314 BetaAssistantUpdateParamsModel = "gpt-4-0314"
- BetaAssistantUpdateParamsModelGPT4_0613 BetaAssistantUpdateParamsModel = "gpt-4-0613"
- BetaAssistantUpdateParamsModelGPT4_32k BetaAssistantUpdateParamsModel = "gpt-4-32k"
- BetaAssistantUpdateParamsModelGPT4_32k0314 BetaAssistantUpdateParamsModel = "gpt-4-32k-0314"
- BetaAssistantUpdateParamsModelGPT4_32k0613 BetaAssistantUpdateParamsModel = "gpt-4-32k-0613"
- BetaAssistantUpdateParamsModelGPT3_5Turbo BetaAssistantUpdateParamsModel = "gpt-3.5-turbo"
- BetaAssistantUpdateParamsModelGPT3_5Turbo16k BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-16k"
- BetaAssistantUpdateParamsModelGPT3_5Turbo0613 BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-0613"
- BetaAssistantUpdateParamsModelGPT3_5Turbo1106 BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-1106"
- BetaAssistantUpdateParamsModelGPT3_5Turbo0125 BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-0125"
- BetaAssistantUpdateParamsModelGPT3_5Turbo16k0613 BetaAssistantUpdateParamsModel = "gpt-3.5-turbo-16k-0613"
-)
-
-// A set of resources that are used by the assistant's tools. The resources are
-// specific to the type of tool. For example, the `code_interpreter` tool requires
-// a list of file IDs, while the `file_search` tool requires a list of vector store
-// IDs.
-type BetaAssistantUpdateParamsToolResources struct {
- CodeInterpreter BetaAssistantUpdateParamsToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
- FileSearch BetaAssistantUpdateParamsToolResourcesFileSearch `json:"file_search,omitzero"`
- paramObj
-}
-
-func (r BetaAssistantUpdateParamsToolResources) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantUpdateParamsToolResources
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantUpdateParamsToolResources) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaAssistantUpdateParamsToolResourcesCodeInterpreter struct {
- // Overrides the list of
- // [file](https://platform.openai.com/docs/api-reference/files) IDs made available
- // to the `code_interpreter` tool. There can be a maximum of 20 files associated
- // with the tool.
- FileIDs []string `json:"file_ids,omitzero"`
- paramObj
-}
-
-func (r BetaAssistantUpdateParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantUpdateParamsToolResourcesCodeInterpreter
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantUpdateParamsToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaAssistantUpdateParamsToolResourcesFileSearch struct {
- // Overrides the
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // attached to this assistant. There can be a maximum of 1 vector store attached to
- // the assistant.
- VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
- paramObj
-}
-
-func (r BetaAssistantUpdateParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaAssistantUpdateParamsToolResourcesFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaAssistantUpdateParamsToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaAssistantListParams struct {
- // A cursor for use in pagination. `after` is an object ID that defines your place
- // in the list. For instance, if you make a list request and receive 100 objects,
- // ending with obj_foo, your subsequent call can include after=obj_foo in order to
- // fetch the next page of the list.
- After param.Opt[string] `query:"after,omitzero" json:"-"`
- // A cursor for use in pagination. `before` is an object ID that defines your place
- // in the list. For instance, if you make a list request and receive 100 objects,
- // starting with obj_foo, your subsequent call can include before=obj_foo in order
- // to fetch the previous page of the list.
- Before param.Opt[string] `query:"before,omitzero" json:"-"`
- // A limit on the number of objects to be returned. Limit can range between 1 and
- // 100, and the default is 20.
- Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
- // Sort order by the `created_at` timestamp of the objects. `asc` for ascending
- // order and `desc` for descending order.
- //
- // Any of "asc", "desc".
- Order BetaAssistantListParamsOrder `query:"order,omitzero" json:"-"`
- paramObj
-}
-
-// URLQuery serializes [BetaAssistantListParams]'s query parameters as
-// `url.Values`.
-func (r BetaAssistantListParams) URLQuery() (v url.Values, err error) {
- return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
- ArrayFormat: apiquery.ArrayQueryFormatBrackets,
- NestedFormat: apiquery.NestedQueryFormatBrackets,
- })
-}
-
-// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
-// order and `desc` for descending order.
-type BetaAssistantListParamsOrder string
-
-const (
- BetaAssistantListParamsOrderAsc BetaAssistantListParamsOrder = "asc"
- BetaAssistantListParamsOrderDesc BetaAssistantListParamsOrder = "desc"
-)
diff --git a/betaassistant_test.go b/betaassistant_test.go
deleted file mode 100644
index bf556618..00000000
--- a/betaassistant_test.go
+++ /dev/null
@@ -1,194 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai_test
-
-import (
- "context"
- "errors"
- "os"
- "testing"
-
- "github.com/openai/openai-go"
- "github.com/openai/openai-go/internal/testutil"
- "github.com/openai/openai-go/option"
- "github.com/openai/openai-go/shared"
- "github.com/openai/openai-go/shared/constant"
-)
-
-func TestBetaAssistantNewWithOptionalParams(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.Beta.Assistants.New(context.TODO(), openai.BetaAssistantNewParams{
- Model: shared.ChatModelGPT4_1,
- Description: openai.String("description"),
- Instructions: openai.String("instructions"),
- Metadata: shared.Metadata{
- "foo": "string",
- },
- Name: openai.String("name"),
- ReasoningEffort: shared.ReasoningEffortLow,
- ResponseFormat: openai.AssistantResponseFormatOptionUnionParam{
- OfAuto: constant.ValueOf[constant.Auto](),
- },
- Temperature: openai.Float(1),
- ToolResources: openai.BetaAssistantNewParamsToolResources{
- CodeInterpreter: openai.BetaAssistantNewParamsToolResourcesCodeInterpreter{
- FileIDs: []string{"string"},
- },
- FileSearch: openai.BetaAssistantNewParamsToolResourcesFileSearch{
- VectorStoreIDs: []string{"string"},
- VectorStores: []openai.BetaAssistantNewParamsToolResourcesFileSearchVectorStore{{
- ChunkingStrategy: openai.BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion{
- OfAuto: &openai.BetaAssistantNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto{},
- },
- FileIDs: []string{"string"},
- Metadata: shared.Metadata{
- "foo": "string",
- },
- }},
- },
- },
- Tools: []openai.AssistantToolUnionParam{{
- OfCodeInterpreter: &openai.CodeInterpreterToolParam{},
- }},
- TopP: openai.Float(1),
- })
- 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())
- }
-}
-
-func TestBetaAssistantGet(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.Beta.Assistants.Get(context.TODO(), "assistant_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())
- }
-}
-
-func TestBetaAssistantUpdateWithOptionalParams(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.Beta.Assistants.Update(
- context.TODO(),
- "assistant_id",
- openai.BetaAssistantUpdateParams{
- Description: openai.String("description"),
- Instructions: openai.String("instructions"),
- Metadata: shared.Metadata{
- "foo": "string",
- },
- Model: openai.BetaAssistantUpdateParamsModelGPT4_1,
- Name: openai.String("name"),
- ReasoningEffort: shared.ReasoningEffortLow,
- ResponseFormat: openai.AssistantResponseFormatOptionUnionParam{
- OfAuto: constant.ValueOf[constant.Auto](),
- },
- Temperature: openai.Float(1),
- ToolResources: openai.BetaAssistantUpdateParamsToolResources{
- CodeInterpreter: openai.BetaAssistantUpdateParamsToolResourcesCodeInterpreter{
- FileIDs: []string{"string"},
- },
- FileSearch: openai.BetaAssistantUpdateParamsToolResourcesFileSearch{
- VectorStoreIDs: []string{"string"},
- },
- },
- Tools: []openai.AssistantToolUnionParam{{
- OfCodeInterpreter: &openai.CodeInterpreterToolParam{},
- }},
- TopP: openai.Float(1),
- },
- )
- 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())
- }
-}
-
-func TestBetaAssistantListWithOptionalParams(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.Beta.Assistants.List(context.TODO(), openai.BetaAssistantListParams{
- After: openai.String("after"),
- Before: openai.String("before"),
- Limit: openai.Int(0),
- Order: openai.BetaAssistantListParamsOrderAsc,
- })
- 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())
- }
-}
-
-func TestBetaAssistantDelete(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.Beta.Assistants.Delete(context.TODO(), "assistant_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())
- }
-}
diff --git a/betathread.go b/betathread.go
deleted file mode 100644
index a3b15e7f..00000000
--- a/betathread.go
+++ /dev/null
@@ -1,1557 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai
-
-import (
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "net/http"
-
- "github.com/openai/openai-go/internal/apijson"
- "github.com/openai/openai-go/internal/requestconfig"
- "github.com/openai/openai-go/option"
- "github.com/openai/openai-go/packages/param"
- "github.com/openai/openai-go/packages/respjson"
- "github.com/openai/openai-go/packages/ssestream"
- "github.com/openai/openai-go/shared"
- "github.com/openai/openai-go/shared/constant"
-)
-
-// BetaThreadService contains methods and other services that help with interacting
-// with the openai API.
-//
-// Note, unlike clients, this service does not read variables from the environment
-// automatically. You should not instantiate this service directly, and instead use
-// the [NewBetaThreadService] method instead.
-type BetaThreadService struct {
- Options []option.RequestOption
- Runs BetaThreadRunService
- Messages BetaThreadMessageService
-}
-
-// NewBetaThreadService generates a new service that applies the given options to
-// each request. These options are applied after the parent client's options (if
-// there is one), and before any request-specific options.
-func NewBetaThreadService(opts ...option.RequestOption) (r BetaThreadService) {
- r = BetaThreadService{}
- r.Options = opts
- r.Runs = NewBetaThreadRunService(opts...)
- r.Messages = NewBetaThreadMessageService(opts...)
- return
-}
-
-// Create a thread.
-func (r *BetaThreadService) New(ctx context.Context, body BetaThreadNewParams, opts ...option.RequestOption) (res *Thread, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- path := "threads"
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
-}
-
-// Create a thread and run it in one request. Poll the API until the run is complete.
-func (r *BetaThreadService) NewAndRunPoll(ctx context.Context, body BetaThreadNewAndRunParams, pollIntervalMs int, opts ...option.RequestOption) (res *Run, err error) {
- run, err := r.NewAndRun(ctx, body, opts...)
- if err != nil {
- return nil, err
- }
- return r.Runs.PollStatus(ctx, run.ThreadID, run.ID, pollIntervalMs, opts...)
-}
-
-// Retrieves a thread.
-func (r *BetaThreadService) Get(ctx context.Context, threadID string, opts ...option.RequestOption) (res *Thread, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s", threadID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
- return
-}
-
-// Modifies a thread.
-func (r *BetaThreadService) Update(ctx context.Context, threadID string, body BetaThreadUpdateParams, opts ...option.RequestOption) (res *Thread, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s", threadID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
-}
-
-// Delete a thread.
-func (r *BetaThreadService) Delete(ctx context.Context, threadID string, opts ...option.RequestOption) (res *ThreadDeleted, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s", threadID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
- return
-}
-
-// Create a thread and run it in one request.
-func (r *BetaThreadService) NewAndRun(ctx context.Context, body BetaThreadNewAndRunParams, opts ...option.RequestOption) (res *Run, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- path := "threads/runs"
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
-}
-
-// Create a thread and run it in one request.
-func (r *BetaThreadService) NewAndRunStreaming(ctx context.Context, body BetaThreadNewAndRunParams, opts ...option.RequestOption) (stream *ssestream.Stream[AssistantStreamEventUnion]) {
- var (
- raw *http.Response
- err error
- )
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithJSONSet("stream", true)}, opts...)
- path := "threads/runs"
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)
- return ssestream.NewStream[AssistantStreamEventUnion](ssestream.NewDecoder(raw), err)
-}
-
-// AssistantResponseFormatOptionUnion contains all possible properties and values
-// from [constant.Auto], [shared.ResponseFormatText],
-// [shared.ResponseFormatJSONObject], [shared.ResponseFormatJSONSchema].
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-//
-// If the underlying value is not a json object, one of the following properties
-// will be valid: OfAuto]
-type AssistantResponseFormatOptionUnion struct {
- // This field will be present if the value is a [constant.Auto] instead of an
- // object.
- OfAuto constant.Auto `json:",inline"`
- Type string `json:"type"`
- // This field is from variant [shared.ResponseFormatJSONSchema].
- JSONSchema shared.ResponseFormatJSONSchemaJSONSchema `json:"json_schema"`
- JSON struct {
- OfAuto respjson.Field
- Type respjson.Field
- JSONSchema respjson.Field
- raw string
- } `json:"-"`
-}
-
-func (u AssistantResponseFormatOptionUnion) AsAuto() (v constant.Auto) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantResponseFormatOptionUnion) AsText() (v shared.ResponseFormatText) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantResponseFormatOptionUnion) AsJSONObject() (v shared.ResponseFormatJSONObject) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantResponseFormatOptionUnion) AsJSONSchema() (v shared.ResponseFormatJSONSchema) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u AssistantResponseFormatOptionUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *AssistantResponseFormatOptionUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this AssistantResponseFormatOptionUnion to a
-// AssistantResponseFormatOptionUnionParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// AssistantResponseFormatOptionUnionParam.Overrides()
-func (r AssistantResponseFormatOptionUnion) ToParam() AssistantResponseFormatOptionUnionParam {
- return param.Override[AssistantResponseFormatOptionUnionParam](r.RawJSON())
-}
-
-func AssistantResponseFormatOptionParamOfAuto() AssistantResponseFormatOptionUnionParam {
- return AssistantResponseFormatOptionUnionParam{OfAuto: constant.ValueOf[constant.Auto]()}
-}
-
-func AssistantResponseFormatOptionParamOfJSONSchema(jsonSchema shared.ResponseFormatJSONSchemaJSONSchemaParam) AssistantResponseFormatOptionUnionParam {
- var variant shared.ResponseFormatJSONSchemaParam
- variant.JSONSchema = jsonSchema
- return AssistantResponseFormatOptionUnionParam{OfJSONSchema: &variant}
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type AssistantResponseFormatOptionUnionParam struct {
- // Construct this variant with constant.ValueOf[constant.Auto]()
- OfAuto constant.Auto `json:",omitzero,inline"`
- OfText *shared.ResponseFormatTextParam `json:",omitzero,inline"`
- OfJSONObject *shared.ResponseFormatJSONObjectParam `json:",omitzero,inline"`
- OfJSONSchema *shared.ResponseFormatJSONSchemaParam `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u AssistantResponseFormatOptionUnionParam) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[AssistantResponseFormatOptionUnionParam](u.OfAuto, u.OfText, u.OfJSONObject, u.OfJSONSchema)
-}
-func (u *AssistantResponseFormatOptionUnionParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *AssistantResponseFormatOptionUnionParam) asAny() any {
- if !param.IsOmitted(u.OfAuto) {
- return &u.OfAuto
- } else if !param.IsOmitted(u.OfText) {
- return u.OfText
- } else if !param.IsOmitted(u.OfJSONObject) {
- return u.OfJSONObject
- } else if !param.IsOmitted(u.OfJSONSchema) {
- return u.OfJSONSchema
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u AssistantResponseFormatOptionUnionParam) GetJSONSchema() *shared.ResponseFormatJSONSchemaJSONSchemaParam {
- if vt := u.OfJSONSchema; vt != nil {
- return &vt.JSONSchema
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u AssistantResponseFormatOptionUnionParam) GetType() *string {
- if vt := u.OfText; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfJSONObject; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfJSONSchema; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-// Specifies a tool the model should use. Use to force the model to call a specific
-// tool.
-type AssistantToolChoice struct {
- // The type of the tool. If type is `function`, the function name must be set
- //
- // Any of "function", "code_interpreter", "file_search".
- Type AssistantToolChoiceType `json:"type,required"`
- Function AssistantToolChoiceFunction `json:"function"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Type respjson.Field
- Function respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantToolChoice) RawJSON() string { return r.JSON.raw }
-func (r *AssistantToolChoice) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this AssistantToolChoice to a AssistantToolChoiceParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// AssistantToolChoiceParam.Overrides()
-func (r AssistantToolChoice) ToParam() AssistantToolChoiceParam {
- return param.Override[AssistantToolChoiceParam](r.RawJSON())
-}
-
-// The type of the tool. If type is `function`, the function name must be set
-type AssistantToolChoiceType string
-
-const (
- AssistantToolChoiceTypeFunction AssistantToolChoiceType = "function"
- AssistantToolChoiceTypeCodeInterpreter AssistantToolChoiceType = "code_interpreter"
- AssistantToolChoiceTypeFileSearch AssistantToolChoiceType = "file_search"
-)
-
-// Specifies a tool the model should use. Use to force the model to call a specific
-// tool.
-//
-// The property Type is required.
-type AssistantToolChoiceParam struct {
- // The type of the tool. If type is `function`, the function name must be set
- //
- // Any of "function", "code_interpreter", "file_search".
- Type AssistantToolChoiceType `json:"type,omitzero,required"`
- Function AssistantToolChoiceFunctionParam `json:"function,omitzero"`
- paramObj
-}
-
-func (r AssistantToolChoiceParam) MarshalJSON() (data []byte, err error) {
- type shadow AssistantToolChoiceParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *AssistantToolChoiceParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type AssistantToolChoiceFunction struct {
- // The name of the function to call.
- Name string `json:"name,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Name respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r AssistantToolChoiceFunction) RawJSON() string { return r.JSON.raw }
-func (r *AssistantToolChoiceFunction) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this AssistantToolChoiceFunction to a
-// AssistantToolChoiceFunctionParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// AssistantToolChoiceFunctionParam.Overrides()
-func (r AssistantToolChoiceFunction) ToParam() AssistantToolChoiceFunctionParam {
- return param.Override[AssistantToolChoiceFunctionParam](r.RawJSON())
-}
-
-// The property Name is required.
-type AssistantToolChoiceFunctionParam struct {
- // The name of the function to call.
- Name string `json:"name,required"`
- paramObj
-}
-
-func (r AssistantToolChoiceFunctionParam) MarshalJSON() (data []byte, err error) {
- type shadow AssistantToolChoiceFunctionParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *AssistantToolChoiceFunctionParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// AssistantToolChoiceOptionUnion contains all possible properties and values from
-// [string], [AssistantToolChoice].
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-//
-// If the underlying value is not a json object, one of the following properties
-// will be valid: OfAuto]
-type AssistantToolChoiceOptionUnion struct {
- // This field will be present if the value is a [string] instead of an object.
- OfAuto string `json:",inline"`
- // This field is from variant [AssistantToolChoice].
- Type AssistantToolChoiceType `json:"type"`
- // This field is from variant [AssistantToolChoice].
- Function AssistantToolChoiceFunction `json:"function"`
- JSON struct {
- OfAuto respjson.Field
- Type respjson.Field
- Function respjson.Field
- raw string
- } `json:"-"`
-}
-
-func (u AssistantToolChoiceOptionUnion) AsAuto() (v string) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AssistantToolChoiceOptionUnion) AsAssistantToolChoice() (v AssistantToolChoice) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u AssistantToolChoiceOptionUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *AssistantToolChoiceOptionUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this AssistantToolChoiceOptionUnion to a
-// AssistantToolChoiceOptionUnionParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// AssistantToolChoiceOptionUnionParam.Overrides()
-func (r AssistantToolChoiceOptionUnion) ToParam() AssistantToolChoiceOptionUnionParam {
- return param.Override[AssistantToolChoiceOptionUnionParam](r.RawJSON())
-}
-
-// `none` means the model will not call any tools and instead generates a message.
-// `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 AssistantToolChoiceOptionAuto string
-
-const (
- AssistantToolChoiceOptionAutoNone AssistantToolChoiceOptionAuto = "none"
- AssistantToolChoiceOptionAutoAuto AssistantToolChoiceOptionAuto = "auto"
- AssistantToolChoiceOptionAutoRequired AssistantToolChoiceOptionAuto = "required"
-)
-
-func AssistantToolChoiceOptionParamOfAssistantToolChoice(type_ AssistantToolChoiceType) AssistantToolChoiceOptionUnionParam {
- var variant AssistantToolChoiceParam
- variant.Type = type_
- return AssistantToolChoiceOptionUnionParam{OfAssistantToolChoice: &variant}
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type AssistantToolChoiceOptionUnionParam struct {
- // Check if union is this variant with !param.IsOmitted(union.OfAuto)
- OfAuto param.Opt[string] `json:",omitzero,inline"`
- OfAssistantToolChoice *AssistantToolChoiceParam `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u AssistantToolChoiceOptionUnionParam) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[AssistantToolChoiceOptionUnionParam](u.OfAuto, u.OfAssistantToolChoice)
-}
-func (u *AssistantToolChoiceOptionUnionParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *AssistantToolChoiceOptionUnionParam) asAny() any {
- if !param.IsOmitted(u.OfAuto) {
- return &u.OfAuto
- } else if !param.IsOmitted(u.OfAssistantToolChoice) {
- return u.OfAssistantToolChoice
- }
- return nil
-}
-
-// Represents a thread that contains
-// [messages](https://platform.openai.com/docs/api-reference/messages).
-type Thread struct {
- // The identifier, which can be referenced in API endpoints.
- ID string `json:"id,required"`
- // The Unix timestamp (in seconds) for when the thread was created.
- CreatedAt int64 `json:"created_at,required"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,required"`
- // The object type, which is always `thread`.
- Object constant.Thread `json:"object,required"`
- // A set of resources that are made available to the assistant's tools in this
- // thread. The resources are specific to the type of tool. For example, the
- // `code_interpreter` tool requires a list of file IDs, while the `file_search`
- // tool requires a list of vector store IDs.
- ToolResources ThreadToolResources `json:"tool_resources,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- CreatedAt respjson.Field
- Metadata respjson.Field
- Object respjson.Field
- ToolResources respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r Thread) RawJSON() string { return r.JSON.raw }
-func (r *Thread) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A set of resources that are made available to the assistant's tools in this
-// thread. The resources are specific to the type of tool. For example, the
-// `code_interpreter` tool requires a list of file IDs, while the `file_search`
-// tool requires a list of vector store IDs.
-type ThreadToolResources struct {
- CodeInterpreter ThreadToolResourcesCodeInterpreter `json:"code_interpreter"`
- FileSearch ThreadToolResourcesFileSearch `json:"file_search"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- CodeInterpreter respjson.Field
- FileSearch respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ThreadToolResources) RawJSON() string { return r.JSON.raw }
-func (r *ThreadToolResources) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type ThreadToolResourcesCodeInterpreter struct {
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
- // available to the `code_interpreter` tool. There can be a maximum of 20 files
- // associated with the tool.
- FileIDs []string `json:"file_ids"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileIDs respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ThreadToolResourcesCodeInterpreter) RawJSON() string { return r.JSON.raw }
-func (r *ThreadToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type ThreadToolResourcesFileSearch struct {
- // The
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // attached to this thread. There can be a maximum of 1 vector store attached to
- // the thread.
- VectorStoreIDs []string `json:"vector_store_ids"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- VectorStoreIDs respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ThreadToolResourcesFileSearch) RawJSON() string { return r.JSON.raw }
-func (r *ThreadToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type ThreadDeleted struct {
- ID string `json:"id,required"`
- Deleted bool `json:"deleted,required"`
- Object constant.ThreadDeleted `json:"object,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- Deleted respjson.Field
- Object respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ThreadDeleted) RawJSON() string { return r.JSON.raw }
-func (r *ThreadDeleted) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewParams struct {
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // A set of resources that are made available to the assistant's tools in this
- // thread. The resources are specific to the type of tool. For example, the
- // `code_interpreter` tool requires a list of file IDs, while the `file_search`
- // tool requires a list of vector store IDs.
- ToolResources BetaThreadNewParamsToolResources `json:"tool_resources,omitzero"`
- // A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
- // start the thread with.
- Messages []BetaThreadNewParamsMessage `json:"messages,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The properties Content, Role are required.
-type BetaThreadNewParamsMessage struct {
- // The text contents of the message.
- Content BetaThreadNewParamsMessageContentUnion `json:"content,omitzero,required"`
- // The role of the entity that is creating the message. Allowed values include:
- //
- // - `user`: Indicates the message is sent by an actual user and should be used in
- // most cases to represent user-generated messages.
- // - `assistant`: Indicates the message is generated by the assistant. Use this
- // value to insert messages from the assistant into the conversation.
- //
- // Any of "user", "assistant".
- Role string `json:"role,omitzero,required"`
- // A list of files attached to the message, and the tools they should be added to.
- Attachments []BetaThreadNewParamsMessageAttachment `json:"attachments,omitzero"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewParamsMessage) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsMessage
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsMessage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-func init() {
- apijson.RegisterFieldValidator[BetaThreadNewParamsMessage](
- "role", "user", "assistant",
- )
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadNewParamsMessageContentUnion struct {
- OfString param.Opt[string] `json:",omitzero,inline"`
- OfArrayOfContentParts []MessageContentPartParamUnion `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadNewParamsMessageContentUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadNewParamsMessageContentUnion](u.OfString, u.OfArrayOfContentParts)
-}
-func (u *BetaThreadNewParamsMessageContentUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadNewParamsMessageContentUnion) asAny() any {
- if !param.IsOmitted(u.OfString) {
- return &u.OfString.Value
- } else if !param.IsOmitted(u.OfArrayOfContentParts) {
- return &u.OfArrayOfContentParts
- }
- return nil
-}
-
-type BetaThreadNewParamsMessageAttachment struct {
- // The ID of the file to attach to the message.
- FileID param.Opt[string] `json:"file_id,omitzero"`
- // The tools to add this file to.
- Tools []BetaThreadNewParamsMessageAttachmentToolUnion `json:"tools,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewParamsMessageAttachment) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsMessageAttachment
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsMessageAttachment) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadNewParamsMessageAttachmentToolUnion struct {
- OfCodeInterpreter *CodeInterpreterToolParam `json:",omitzero,inline"`
- OfFileSearch *BetaThreadNewParamsMessageAttachmentToolFileSearch `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadNewParamsMessageAttachmentToolUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadNewParamsMessageAttachmentToolUnion](u.OfCodeInterpreter, u.OfFileSearch)
-}
-func (u *BetaThreadNewParamsMessageAttachmentToolUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadNewParamsMessageAttachmentToolUnion) asAny() any {
- if !param.IsOmitted(u.OfCodeInterpreter) {
- return u.OfCodeInterpreter
- } else if !param.IsOmitted(u.OfFileSearch) {
- return u.OfFileSearch
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaThreadNewParamsMessageAttachmentToolUnion) GetType() *string {
- if vt := u.OfCodeInterpreter; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfFileSearch; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-func init() {
- apijson.RegisterUnion[BetaThreadNewParamsMessageAttachmentToolUnion](
- "type",
- apijson.Discriminator[CodeInterpreterToolParam]("code_interpreter"),
- apijson.Discriminator[BetaThreadNewParamsMessageAttachmentToolFileSearch]("file_search"),
- )
-}
-
-func NewBetaThreadNewParamsMessageAttachmentToolFileSearch() BetaThreadNewParamsMessageAttachmentToolFileSearch {
- return BetaThreadNewParamsMessageAttachmentToolFileSearch{
- Type: "file_search",
- }
-}
-
-// This struct has a constant value, construct it with
-// [NewBetaThreadNewParamsMessageAttachmentToolFileSearch].
-type BetaThreadNewParamsMessageAttachmentToolFileSearch struct {
- // The type of tool being defined: `file_search`
- Type constant.FileSearch `json:"type,required"`
- paramObj
-}
-
-func (r BetaThreadNewParamsMessageAttachmentToolFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsMessageAttachmentToolFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsMessageAttachmentToolFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A set of resources that are made available to the assistant's tools in this
-// thread. The resources are specific to the type of tool. For example, the
-// `code_interpreter` tool requires a list of file IDs, while the `file_search`
-// tool requires a list of vector store IDs.
-type BetaThreadNewParamsToolResources struct {
- CodeInterpreter BetaThreadNewParamsToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
- FileSearch BetaThreadNewParamsToolResourcesFileSearch `json:"file_search,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewParamsToolResources) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsToolResources
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsToolResources) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewParamsToolResourcesCodeInterpreter struct {
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
- // available to the `code_interpreter` tool. There can be a maximum of 20 files
- // associated with the tool.
- FileIDs []string `json:"file_ids,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsToolResourcesCodeInterpreter
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewParamsToolResourcesFileSearch struct {
- // The
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // attached to this thread. There can be a maximum of 1 vector store attached to
- // the thread.
- VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
- // A helper to create a
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // with file_ids and attach it to this thread. There can be a maximum of 1 vector
- // store attached to the thread.
- VectorStores []BetaThreadNewParamsToolResourcesFileSearchVectorStore `json:"vector_stores,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsToolResourcesFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewParamsToolResourcesFileSearchVectorStore struct {
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // The chunking strategy used to chunk the file(s). If not set, will use the `auto`
- // strategy.
- ChunkingStrategy BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion `json:"chunking_strategy,omitzero"`
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
- // add to the vector store. There can be a maximum of 10000 files in a vector
- // store.
- FileIDs []string `json:"file_ids,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewParamsToolResourcesFileSearchVectorStore) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStore
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsToolResourcesFileSearchVectorStore) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion struct {
- OfAuto *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto `json:",omitzero,inline"`
- OfStatic *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion](u.OfAuto, u.OfStatic)
-}
-func (u *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) asAny() any {
- if !param.IsOmitted(u.OfAuto) {
- return u.OfAuto
- } else if !param.IsOmitted(u.OfStatic) {
- return u.OfStatic
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetStatic() *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic {
- if vt := u.OfStatic; vt != nil {
- return &vt.Static
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetType() *string {
- if vt := u.OfAuto; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfStatic; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-func init() {
- apijson.RegisterUnion[BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion](
- "type",
- apijson.Discriminator[BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto]("auto"),
- apijson.Discriminator[BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic]("static"),
- )
-}
-
-func NewBetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto() BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto {
- return BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto{
- Type: "auto",
- }
-}
-
-// The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
-// `800` and `chunk_overlap_tokens` of `400`.
-//
-// This struct has a constant value, construct it with
-// [NewBetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto].
-type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto struct {
- // Always `auto`.
- Type constant.Auto `json:"type,required"`
- paramObj
-}
-
-func (r BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The properties Static, Type are required.
-type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic struct {
- Static BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic `json:"static,omitzero,required"`
- // Always `static`.
- //
- // This field can be elided, and will marshal its zero value as "static".
- Type constant.Static `json:"type,required"`
- paramObj
-}
-
-func (r BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The properties ChunkOverlapTokens, MaxChunkSizeTokens are required.
-type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic struct {
- // The number of tokens that overlap between chunks. The default value is `400`.
- //
- // Note that the overlap must not exceed half of `max_chunk_size_tokens`.
- ChunkOverlapTokens int64 `json:"chunk_overlap_tokens,required"`
- // The maximum number of tokens in each chunk. The default value is `800`. The
- // minimum value is `100` and the maximum value is `4096`.
- MaxChunkSizeTokens int64 `json:"max_chunk_size_tokens,required"`
- paramObj
-}
-
-func (r BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadUpdateParams struct {
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // A set of resources that are made available to the assistant's tools in this
- // thread. The resources are specific to the type of tool. For example, the
- // `code_interpreter` tool requires a list of file IDs, while the `file_search`
- // tool requires a list of vector store IDs.
- ToolResources BetaThreadUpdateParamsToolResources `json:"tool_resources,omitzero"`
- paramObj
-}
-
-func (r BetaThreadUpdateParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadUpdateParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadUpdateParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A set of resources that are made available to the assistant's tools in this
-// thread. The resources are specific to the type of tool. For example, the
-// `code_interpreter` tool requires a list of file IDs, while the `file_search`
-// tool requires a list of vector store IDs.
-type BetaThreadUpdateParamsToolResources struct {
- CodeInterpreter BetaThreadUpdateParamsToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
- FileSearch BetaThreadUpdateParamsToolResourcesFileSearch `json:"file_search,omitzero"`
- paramObj
-}
-
-func (r BetaThreadUpdateParamsToolResources) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadUpdateParamsToolResources
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadUpdateParamsToolResources) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadUpdateParamsToolResourcesCodeInterpreter struct {
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
- // available to the `code_interpreter` tool. There can be a maximum of 20 files
- // associated with the tool.
- FileIDs []string `json:"file_ids,omitzero"`
- paramObj
-}
-
-func (r BetaThreadUpdateParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadUpdateParamsToolResourcesCodeInterpreter
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadUpdateParamsToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadUpdateParamsToolResourcesFileSearch struct {
- // The
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // attached to this thread. There can be a maximum of 1 vector store attached to
- // the thread.
- VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
- paramObj
-}
-
-func (r BetaThreadUpdateParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadUpdateParamsToolResourcesFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadUpdateParamsToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewAndRunParams struct {
- // The ID of the
- // [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
- // execute this run.
- AssistantID string `json:"assistant_id,required"`
- // Override the default system message of the assistant. This is useful for
- // modifying the behavior on a per-run basis.
- Instructions param.Opt[string] `json:"instructions,omitzero"`
- // The maximum number of completion tokens that may be used over the course of the
- // run. The run will make a best effort to use only the number of completion tokens
- // specified, across multiple turns of the run. If the run exceeds the number of
- // completion tokens specified, the run will end with status `incomplete`. See
- // `incomplete_details` for more info.
- MaxCompletionTokens param.Opt[int64] `json:"max_completion_tokens,omitzero"`
- // The maximum number of prompt tokens that may be used over the course of the run.
- // The run will make a best effort to use only the number of prompt tokens
- // specified, across multiple turns of the run. If the run exceeds the number of
- // prompt tokens specified, the run will end with status `incomplete`. See
- // `incomplete_details` for more info.
- MaxPromptTokens param.Opt[int64] `json:"max_prompt_tokens,omitzero"`
- // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
- // make the output more random, while lower values like 0.2 will make it more
- // focused and deterministic.
- Temperature param.Opt[float64] `json:"temperature,omitzero"`
- // An alternative to sampling with temperature, called nucleus sampling, where the
- // model considers the results of the tokens with top_p probability mass. So 0.1
- // means only the tokens comprising the top 10% probability mass are considered.
- //
- // We generally recommend altering this or temperature but not both.
- TopP param.Opt[float64] `json:"top_p,omitzero"`
- // Whether to enable
- // [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
- // during tool use.
- ParallelToolCalls param.Opt[bool] `json:"parallel_tool_calls,omitzero"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
- // be used to execute this run. If a value is provided here, it will override the
- // model associated with the assistant. If not, the model associated with the
- // assistant will be used.
- Model shared.ChatModel `json:"model,omitzero"`
- // A set of resources that are used by the assistant's tools. The resources are
- // specific to the type of tool. For example, the `code_interpreter` tool requires
- // a list of file IDs, while the `file_search` tool requires a list of vector store
- // IDs.
- ToolResources BetaThreadNewAndRunParamsToolResources `json:"tool_resources,omitzero"`
- // Override the tools the assistant can use for this run. This is useful for
- // modifying the behavior on a per-run basis.
- Tools []AssistantToolUnionParam `json:"tools,omitzero"`
- // Controls for how a thread will be truncated prior to the run. Use this to
- // control the intial context window of the run.
- TruncationStrategy BetaThreadNewAndRunParamsTruncationStrategy `json:"truncation_strategy,omitzero"`
- // Specifies the format that the model must output. Compatible with
- // [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
- // [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
- // and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
- //
- // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
- // Outputs which ensures the model will match your supplied JSON schema. Learn more
- // in the
- // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
- //
- // Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
- // message the model generates is valid JSON.
- //
- // **Important:** when using JSON mode, you **must** also instruct the model to
- // produce JSON yourself via a system or user message. Without this, the model may
- // generate an unending stream of whitespace until the generation reaches the token
- // limit, resulting in a long-running and seemingly "stuck" request. Also note that
- // the message content may be partially cut off if `finish_reason="length"`, which
- // indicates the generation exceeded `max_tokens` or the conversation exceeded the
- // max context length.
- ResponseFormat AssistantResponseFormatOptionUnionParam `json:"response_format,omitzero"`
- // Options to create a new thread. If no thread is provided when running a request,
- // an empty thread will be created.
- Thread BetaThreadNewAndRunParamsThread `json:"thread,omitzero"`
- // 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
- // and 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. Specifying a particular tool like `{"type": "file_search"}` or
- // `{"type": "function", "function": {"name": "my_function"}}` forces the model to
- // call that tool.
- ToolChoice AssistantToolChoiceOptionUnionParam `json:"tool_choice,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Options to create a new thread. If no thread is provided when running a request,
-// an empty thread will be created.
-type BetaThreadNewAndRunParamsThread struct {
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // A set of resources that are made available to the assistant's tools in this
- // thread. The resources are specific to the type of tool. For example, the
- // `code_interpreter` tool requires a list of file IDs, while the `file_search`
- // tool requires a list of vector store IDs.
- ToolResources BetaThreadNewAndRunParamsThreadToolResources `json:"tool_resources,omitzero"`
- // A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
- // start the thread with.
- Messages []BetaThreadNewAndRunParamsThreadMessage `json:"messages,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThread) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThread
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThread) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The properties Content, Role are required.
-type BetaThreadNewAndRunParamsThreadMessage struct {
- // The text contents of the message.
- Content BetaThreadNewAndRunParamsThreadMessageContentUnion `json:"content,omitzero,required"`
- // The role of the entity that is creating the message. Allowed values include:
- //
- // - `user`: Indicates the message is sent by an actual user and should be used in
- // most cases to represent user-generated messages.
- // - `assistant`: Indicates the message is generated by the assistant. Use this
- // value to insert messages from the assistant into the conversation.
- //
- // Any of "user", "assistant".
- Role string `json:"role,omitzero,required"`
- // A list of files attached to the message, and the tools they should be added to.
- Attachments []BetaThreadNewAndRunParamsThreadMessageAttachment `json:"attachments,omitzero"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadMessage) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadMessage
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadMessage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-func init() {
- apijson.RegisterFieldValidator[BetaThreadNewAndRunParamsThreadMessage](
- "role", "user", "assistant",
- )
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadNewAndRunParamsThreadMessageContentUnion struct {
- OfString param.Opt[string] `json:",omitzero,inline"`
- OfArrayOfContentParts []MessageContentPartParamUnion `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadNewAndRunParamsThreadMessageContentUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadNewAndRunParamsThreadMessageContentUnion](u.OfString, u.OfArrayOfContentParts)
-}
-func (u *BetaThreadNewAndRunParamsThreadMessageContentUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadNewAndRunParamsThreadMessageContentUnion) asAny() any {
- if !param.IsOmitted(u.OfString) {
- return &u.OfString.Value
- } else if !param.IsOmitted(u.OfArrayOfContentParts) {
- return &u.OfArrayOfContentParts
- }
- return nil
-}
-
-type BetaThreadNewAndRunParamsThreadMessageAttachment struct {
- // The ID of the file to attach to the message.
- FileID param.Opt[string] `json:"file_id,omitzero"`
- // The tools to add this file to.
- Tools []BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion `json:"tools,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadMessageAttachment) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadMessageAttachment
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadMessageAttachment) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion struct {
- OfCodeInterpreter *CodeInterpreterToolParam `json:",omitzero,inline"`
- OfFileSearch *BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion](u.OfCodeInterpreter, u.OfFileSearch)
-}
-func (u *BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion) asAny() any {
- if !param.IsOmitted(u.OfCodeInterpreter) {
- return u.OfCodeInterpreter
- } else if !param.IsOmitted(u.OfFileSearch) {
- return u.OfFileSearch
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion) GetType() *string {
- if vt := u.OfCodeInterpreter; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfFileSearch; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-func init() {
- apijson.RegisterUnion[BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion](
- "type",
- apijson.Discriminator[CodeInterpreterToolParam]("code_interpreter"),
- apijson.Discriminator[BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch]("file_search"),
- )
-}
-
-func NewBetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch() BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch {
- return BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch{
- Type: "file_search",
- }
-}
-
-// This struct has a constant value, construct it with
-// [NewBetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch].
-type BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch struct {
- // The type of tool being defined: `file_search`
- Type constant.FileSearch `json:"type,required"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A set of resources that are made available to the assistant's tools in this
-// thread. The resources are specific to the type of tool. For example, the
-// `code_interpreter` tool requires a list of file IDs, while the `file_search`
-// tool requires a list of vector store IDs.
-type BetaThreadNewAndRunParamsThreadToolResources struct {
- CodeInterpreter BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
- FileSearch BetaThreadNewAndRunParamsThreadToolResourcesFileSearch `json:"file_search,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadToolResources) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadToolResources
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadToolResources) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter struct {
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
- // available to the `code_interpreter` tool. There can be a maximum of 20 files
- // associated with the tool.
- FileIDs []string `json:"file_ids,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewAndRunParamsThreadToolResourcesFileSearch struct {
- // The
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // attached to this thread. There can be a maximum of 1 vector store attached to
- // the thread.
- VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
- // A helper to create a
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // with file_ids and attach it to this thread. There can be a maximum of 1 vector
- // store attached to the thread.
- VectorStores []BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore `json:"vector_stores,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore struct {
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // The chunking strategy used to chunk the file(s). If not set, will use the `auto`
- // strategy.
- ChunkingStrategy BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion `json:"chunking_strategy,omitzero"`
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
- // add to the vector store. There can be a maximum of 10000 files in a vector
- // store.
- FileIDs []string `json:"file_ids,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion struct {
- OfAuto *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto `json:",omitzero,inline"`
- OfStatic *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion](u.OfAuto, u.OfStatic)
-}
-func (u *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) asAny() any {
- if !param.IsOmitted(u.OfAuto) {
- return u.OfAuto
- } else if !param.IsOmitted(u.OfStatic) {
- return u.OfStatic
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetStatic() *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic {
- if vt := u.OfStatic; vt != nil {
- return &vt.Static
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetType() *string {
- if vt := u.OfAuto; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfStatic; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-func init() {
- apijson.RegisterUnion[BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion](
- "type",
- apijson.Discriminator[BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto]("auto"),
- apijson.Discriminator[BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic]("static"),
- )
-}
-
-func NewBetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto() BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto {
- return BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto{
- Type: "auto",
- }
-}
-
-// The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
-// `800` and `chunk_overlap_tokens` of `400`.
-//
-// This struct has a constant value, construct it with
-// [NewBetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto].
-type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto struct {
- // Always `auto`.
- Type constant.Auto `json:"type,required"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The properties Static, Type are required.
-type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic struct {
- Static BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic `json:"static,omitzero,required"`
- // Always `static`.
- //
- // This field can be elided, and will marshal its zero value as "static".
- Type constant.Static `json:"type,required"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The properties ChunkOverlapTokens, MaxChunkSizeTokens are required.
-type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic struct {
- // The number of tokens that overlap between chunks. The default value is `400`.
- //
- // Note that the overlap must not exceed half of `max_chunk_size_tokens`.
- ChunkOverlapTokens int64 `json:"chunk_overlap_tokens,required"`
- // The maximum number of tokens in each chunk. The default value is `800`. The
- // minimum value is `100` and the maximum value is `4096`.
- MaxChunkSizeTokens int64 `json:"max_chunk_size_tokens,required"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A set of resources that are used by the assistant's tools. The resources are
-// specific to the type of tool. For example, the `code_interpreter` tool requires
-// a list of file IDs, while the `file_search` tool requires a list of vector store
-// IDs.
-type BetaThreadNewAndRunParamsToolResources struct {
- CodeInterpreter BetaThreadNewAndRunParamsToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
- FileSearch BetaThreadNewAndRunParamsToolResourcesFileSearch `json:"file_search,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsToolResources) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsToolResources
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsToolResources) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewAndRunParamsToolResourcesCodeInterpreter struct {
- // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
- // available to the `code_interpreter` tool. There can be a maximum of 20 files
- // associated with the tool.
- FileIDs []string `json:"file_ids,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsToolResourcesCodeInterpreter
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadNewAndRunParamsToolResourcesFileSearch struct {
- // The ID of the
- // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
- // attached to this assistant. There can be a maximum of 1 vector store attached to
- // the assistant.
- VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsToolResourcesFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Controls for how a thread will be truncated prior to the run. Use this to
-// control the intial context window of the run.
-//
-// The property Type is required.
-type BetaThreadNewAndRunParamsTruncationStrategy struct {
- // The truncation strategy to use for the thread. The default is `auto`. If set to
- // `last_messages`, the thread will be truncated to the n most recent messages in
- // the thread. When set to `auto`, messages in the middle of the thread will be
- // dropped to fit the context length of the model, `max_prompt_tokens`.
- //
- // Any of "auto", "last_messages".
- Type string `json:"type,omitzero,required"`
- // The number of most recent messages from the thread when constructing the context
- // for the run.
- LastMessages param.Opt[int64] `json:"last_messages,omitzero"`
- paramObj
-}
-
-func (r BetaThreadNewAndRunParamsTruncationStrategy) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadNewAndRunParamsTruncationStrategy
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadNewAndRunParamsTruncationStrategy) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-func init() {
- apijson.RegisterFieldValidator[BetaThreadNewAndRunParamsTruncationStrategy](
- "type", "auto", "last_messages",
- )
-}
diff --git a/betathread_test.go b/betathread_test.go
deleted file mode 100644
index 53768d06..00000000
--- a/betathread_test.go
+++ /dev/null
@@ -1,248 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai_test
-
-import (
- "context"
- "errors"
- "os"
- "testing"
-
- "github.com/openai/openai-go"
- "github.com/openai/openai-go/internal/testutil"
- "github.com/openai/openai-go/option"
- "github.com/openai/openai-go/shared"
- "github.com/openai/openai-go/shared/constant"
-)
-
-func TestBetaThreadNewWithOptionalParams(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.Beta.Threads.New(context.TODO(), openai.BetaThreadNewParams{
- Messages: []openai.BetaThreadNewParamsMessage{{
- Content: openai.BetaThreadNewParamsMessageContentUnion{
- OfString: openai.String("string"),
- },
- Role: "user",
- Attachments: []openai.BetaThreadNewParamsMessageAttachment{{
- FileID: openai.String("file_id"),
- Tools: []openai.BetaThreadNewParamsMessageAttachmentToolUnion{{
- OfCodeInterpreter: &openai.CodeInterpreterToolParam{},
- }},
- }},
- Metadata: shared.Metadata{
- "foo": "string",
- },
- }},
- Metadata: shared.Metadata{
- "foo": "string",
- },
- ToolResources: openai.BetaThreadNewParamsToolResources{
- CodeInterpreter: openai.BetaThreadNewParamsToolResourcesCodeInterpreter{
- FileIDs: []string{"string"},
- },
- FileSearch: openai.BetaThreadNewParamsToolResourcesFileSearch{
- VectorStoreIDs: []string{"string"},
- VectorStores: []openai.BetaThreadNewParamsToolResourcesFileSearchVectorStore{{
- ChunkingStrategy: openai.BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion{
- OfAuto: &openai.BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto{},
- },
- FileIDs: []string{"string"},
- Metadata: shared.Metadata{
- "foo": "string",
- },
- }},
- },
- },
- })
- 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())
- }
-}
-
-func TestBetaThreadGet(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.Beta.Threads.Get(context.TODO(), "thread_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())
- }
-}
-
-func TestBetaThreadUpdateWithOptionalParams(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.Beta.Threads.Update(
- context.TODO(),
- "thread_id",
- openai.BetaThreadUpdateParams{
- Metadata: shared.Metadata{
- "foo": "string",
- },
- ToolResources: openai.BetaThreadUpdateParamsToolResources{
- CodeInterpreter: openai.BetaThreadUpdateParamsToolResourcesCodeInterpreter{
- FileIDs: []string{"string"},
- },
- FileSearch: openai.BetaThreadUpdateParamsToolResourcesFileSearch{
- VectorStoreIDs: []string{"string"},
- },
- },
- },
- )
- 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())
- }
-}
-
-func TestBetaThreadDelete(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.Beta.Threads.Delete(context.TODO(), "thread_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())
- }
-}
-
-func TestBetaThreadNewAndRunWithOptionalParams(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.Beta.Threads.NewAndRun(context.TODO(), openai.BetaThreadNewAndRunParams{
- AssistantID: "assistant_id",
- Instructions: openai.String("instructions"),
- MaxCompletionTokens: openai.Int(256),
- MaxPromptTokens: openai.Int(256),
- Metadata: shared.Metadata{
- "foo": "string",
- },
- Model: shared.ChatModelGPT4_1,
- ParallelToolCalls: openai.Bool(true),
- ResponseFormat: openai.AssistantResponseFormatOptionUnionParam{
- OfAuto: constant.ValueOf[constant.Auto](),
- },
- Temperature: openai.Float(1),
- Thread: openai.BetaThreadNewAndRunParamsThread{
- Messages: []openai.BetaThreadNewAndRunParamsThreadMessage{{
- Content: openai.BetaThreadNewAndRunParamsThreadMessageContentUnion{
- OfString: openai.String("string"),
- },
- Role: "user",
- Attachments: []openai.BetaThreadNewAndRunParamsThreadMessageAttachment{{
- FileID: openai.String("file_id"),
- Tools: []openai.BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion{{
- OfCodeInterpreter: &openai.CodeInterpreterToolParam{},
- }},
- }},
- Metadata: shared.Metadata{
- "foo": "string",
- },
- }},
- Metadata: shared.Metadata{
- "foo": "string",
- },
- ToolResources: openai.BetaThreadNewAndRunParamsThreadToolResources{
- CodeInterpreter: openai.BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter{
- FileIDs: []string{"string"},
- },
- FileSearch: openai.BetaThreadNewAndRunParamsThreadToolResourcesFileSearch{
- VectorStoreIDs: []string{"string"},
- VectorStores: []openai.BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore{{
- ChunkingStrategy: openai.BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion{
- OfAuto: &openai.BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto{},
- },
- FileIDs: []string{"string"},
- Metadata: shared.Metadata{
- "foo": "string",
- },
- }},
- },
- },
- },
- ToolChoice: openai.AssistantToolChoiceOptionUnionParam{
- OfAuto: openai.String("none"),
- },
- ToolResources: openai.BetaThreadNewAndRunParamsToolResources{
- CodeInterpreter: openai.BetaThreadNewAndRunParamsToolResourcesCodeInterpreter{
- FileIDs: []string{"string"},
- },
- FileSearch: openai.BetaThreadNewAndRunParamsToolResourcesFileSearch{
- VectorStoreIDs: []string{"string"},
- },
- },
- Tools: []openai.AssistantToolUnionParam{{
- OfCodeInterpreter: &openai.CodeInterpreterToolParam{},
- }},
- TopP: openai.Float(1),
- TruncationStrategy: openai.BetaThreadNewAndRunParamsTruncationStrategy{
- Type: "auto",
- LastMessages: openai.Int(1),
- },
- })
- 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())
- }
-}
diff --git a/betathreadmessage.go b/betathreadmessage.go
deleted file mode 100644
index 69d2fe96..00000000
--- a/betathreadmessage.go
+++ /dev/null
@@ -1,1698 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai
-
-import (
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "net/http"
- "net/url"
-
- "github.com/openai/openai-go/internal/apijson"
- "github.com/openai/openai-go/internal/apiquery"
- "github.com/openai/openai-go/internal/requestconfig"
- "github.com/openai/openai-go/option"
- "github.com/openai/openai-go/packages/pagination"
- "github.com/openai/openai-go/packages/param"
- "github.com/openai/openai-go/packages/respjson"
- "github.com/openai/openai-go/shared"
- "github.com/openai/openai-go/shared/constant"
-)
-
-// BetaThreadMessageService contains methods and other services that help with
-// interacting with the openai API.
-//
-// Note, unlike clients, this service does not read variables from the environment
-// automatically. You should not instantiate this service directly, and instead use
-// the [NewBetaThreadMessageService] method instead.
-type BetaThreadMessageService struct {
- Options []option.RequestOption
-}
-
-// NewBetaThreadMessageService generates a new service that applies the given
-// options to each request. These options are applied after the parent client's
-// options (if there is one), and before any request-specific options.
-func NewBetaThreadMessageService(opts ...option.RequestOption) (r BetaThreadMessageService) {
- r = BetaThreadMessageService{}
- r.Options = opts
- return
-}
-
-// Create a message.
-func (r *BetaThreadMessageService) New(ctx context.Context, threadID string, body BetaThreadMessageNewParams, opts ...option.RequestOption) (res *Message, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/messages", threadID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
-}
-
-// Retrieve a message.
-func (r *BetaThreadMessageService) Get(ctx context.Context, threadID string, messageID string, opts ...option.RequestOption) (res *Message, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if messageID == "" {
- err = errors.New("missing required message_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
- return
-}
-
-// Modifies a message.
-func (r *BetaThreadMessageService) Update(ctx context.Context, threadID string, messageID string, body BetaThreadMessageUpdateParams, opts ...option.RequestOption) (res *Message, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if messageID == "" {
- err = errors.New("missing required message_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
-}
-
-// Returns a list of messages for a given thread.
-func (r *BetaThreadMessageService) List(ctx context.Context, threadID string, query BetaThreadMessageListParams, opts ...option.RequestOption) (res *pagination.CursorPage[Message], err error) {
- var raw *http.Response
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/messages", threadID)
- cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
- if err != nil {
- return nil, err
- }
- err = cfg.Execute()
- if err != nil {
- return nil, err
- }
- res.SetPageConfig(cfg, raw)
- return res, nil
-}
-
-// Returns a list of messages for a given thread.
-func (r *BetaThreadMessageService) ListAutoPaging(ctx context.Context, threadID string, query BetaThreadMessageListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[Message] {
- return pagination.NewCursorPageAutoPager(r.List(ctx, threadID, query, opts...))
-}
-
-// Deletes a message.
-func (r *BetaThreadMessageService) Delete(ctx context.Context, threadID string, messageID string, opts ...option.RequestOption) (res *MessageDeleted, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if messageID == "" {
- err = errors.New("missing required message_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
- return
-}
-
-// AnnotationUnion contains all possible properties and values from
-// [FileCitationAnnotation], [FilePathAnnotation].
-//
-// Use the [AnnotationUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type AnnotationUnion struct {
- EndIndex int64 `json:"end_index"`
- // This field is from variant [FileCitationAnnotation].
- FileCitation FileCitationAnnotationFileCitation `json:"file_citation"`
- StartIndex int64 `json:"start_index"`
- Text string `json:"text"`
- // Any of "file_citation", "file_path".
- Type string `json:"type"`
- // This field is from variant [FilePathAnnotation].
- FilePath FilePathAnnotationFilePath `json:"file_path"`
- JSON struct {
- EndIndex respjson.Field
- FileCitation respjson.Field
- StartIndex respjson.Field
- Text respjson.Field
- Type respjson.Field
- FilePath respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyAnnotation is implemented by each variant of [AnnotationUnion] to add type
-// safety for the return type of [AnnotationUnion.AsAny]
-type anyAnnotation interface {
- implAnnotationUnion()
-}
-
-func (FileCitationAnnotation) implAnnotationUnion() {}
-func (FilePathAnnotation) implAnnotationUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := AnnotationUnion.AsAny().(type) {
-// case openai.FileCitationAnnotation:
-// case openai.FilePathAnnotation:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u AnnotationUnion) AsAny() anyAnnotation {
- switch u.Type {
- case "file_citation":
- return u.AsFileCitation()
- case "file_path":
- return u.AsFilePath()
- }
- return nil
-}
-
-func (u AnnotationUnion) AsFileCitation() (v FileCitationAnnotation) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AnnotationUnion) AsFilePath() (v FilePathAnnotation) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u AnnotationUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *AnnotationUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// AnnotationDeltaUnion contains all possible properties and values from
-// [FileCitationDeltaAnnotation], [FilePathDeltaAnnotation].
-//
-// Use the [AnnotationDeltaUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type AnnotationDeltaUnion struct {
- Index int64 `json:"index"`
- // Any of "file_citation", "file_path".
- Type string `json:"type"`
- EndIndex int64 `json:"end_index"`
- // This field is from variant [FileCitationDeltaAnnotation].
- FileCitation FileCitationDeltaAnnotationFileCitation `json:"file_citation"`
- StartIndex int64 `json:"start_index"`
- Text string `json:"text"`
- // This field is from variant [FilePathDeltaAnnotation].
- FilePath FilePathDeltaAnnotationFilePath `json:"file_path"`
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- EndIndex respjson.Field
- FileCitation respjson.Field
- StartIndex respjson.Field
- Text respjson.Field
- FilePath respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyAnnotationDelta is implemented by each variant of [AnnotationDeltaUnion] to
-// add type safety for the return type of [AnnotationDeltaUnion.AsAny]
-type anyAnnotationDelta interface {
- implAnnotationDeltaUnion()
-}
-
-func (FileCitationDeltaAnnotation) implAnnotationDeltaUnion() {}
-func (FilePathDeltaAnnotation) implAnnotationDeltaUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := AnnotationDeltaUnion.AsAny().(type) {
-// case openai.FileCitationDeltaAnnotation:
-// case openai.FilePathDeltaAnnotation:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u AnnotationDeltaUnion) AsAny() anyAnnotationDelta {
- switch u.Type {
- case "file_citation":
- return u.AsFileCitation()
- case "file_path":
- return u.AsFilePath()
- }
- return nil
-}
-
-func (u AnnotationDeltaUnion) AsFileCitation() (v FileCitationDeltaAnnotation) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u AnnotationDeltaUnion) AsFilePath() (v FilePathDeltaAnnotation) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u AnnotationDeltaUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *AnnotationDeltaUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A citation within the message that points to a specific quote from a specific
-// File associated with the assistant or the message. Generated when the assistant
-// uses the "file_search" tool to search files.
-type FileCitationAnnotation struct {
- EndIndex int64 `json:"end_index,required"`
- FileCitation FileCitationAnnotationFileCitation `json:"file_citation,required"`
- StartIndex int64 `json:"start_index,required"`
- // The text in the message content that needs to be replaced.
- Text string `json:"text,required"`
- // Always `file_citation`.
- Type constant.FileCitation `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- EndIndex respjson.Field
- FileCitation respjson.Field
- StartIndex respjson.Field
- Text respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileCitationAnnotation) RawJSON() string { return r.JSON.raw }
-func (r *FileCitationAnnotation) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FileCitationAnnotationFileCitation struct {
- // The ID of the specific File the citation is from.
- FileID string `json:"file_id,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileCitationAnnotationFileCitation) RawJSON() string { return r.JSON.raw }
-func (r *FileCitationAnnotationFileCitation) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A citation within the message that points to a specific quote from a specific
-// File associated with the assistant or the message. Generated when the assistant
-// uses the "file_search" tool to search files.
-type FileCitationDeltaAnnotation struct {
- // The index of the annotation in the text content part.
- Index int64 `json:"index,required"`
- // Always `file_citation`.
- Type constant.FileCitation `json:"type,required"`
- EndIndex int64 `json:"end_index"`
- FileCitation FileCitationDeltaAnnotationFileCitation `json:"file_citation"`
- StartIndex int64 `json:"start_index"`
- // The text in the message content that needs to be replaced.
- Text string `json:"text"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- EndIndex respjson.Field
- FileCitation respjson.Field
- StartIndex respjson.Field
- Text respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileCitationDeltaAnnotation) RawJSON() string { return r.JSON.raw }
-func (r *FileCitationDeltaAnnotation) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FileCitationDeltaAnnotationFileCitation struct {
- // The ID of the specific File the citation is from.
- FileID string `json:"file_id"`
- // The specific quote in the file.
- Quote string `json:"quote"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileID respjson.Field
- Quote respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileCitationDeltaAnnotationFileCitation) RawJSON() string { return r.JSON.raw }
-func (r *FileCitationDeltaAnnotationFileCitation) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A URL for the file that's generated when the assistant used the
-// `code_interpreter` tool to generate a file.
-type FilePathAnnotation struct {
- EndIndex int64 `json:"end_index,required"`
- FilePath FilePathAnnotationFilePath `json:"file_path,required"`
- StartIndex int64 `json:"start_index,required"`
- // The text in the message content that needs to be replaced.
- Text string `json:"text,required"`
- // Always `file_path`.
- Type constant.FilePath `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- EndIndex respjson.Field
- FilePath respjson.Field
- StartIndex respjson.Field
- Text respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FilePathAnnotation) RawJSON() string { return r.JSON.raw }
-func (r *FilePathAnnotation) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FilePathAnnotationFilePath struct {
- // The ID of the file that was generated.
- FileID string `json:"file_id,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FilePathAnnotationFilePath) RawJSON() string { return r.JSON.raw }
-func (r *FilePathAnnotationFilePath) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A URL for the file that's generated when the assistant used the
-// `code_interpreter` tool to generate a file.
-type FilePathDeltaAnnotation struct {
- // The index of the annotation in the text content part.
- Index int64 `json:"index,required"`
- // Always `file_path`.
- Type constant.FilePath `json:"type,required"`
- EndIndex int64 `json:"end_index"`
- FilePath FilePathDeltaAnnotationFilePath `json:"file_path"`
- StartIndex int64 `json:"start_index"`
- // The text in the message content that needs to be replaced.
- Text string `json:"text"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- EndIndex respjson.Field
- FilePath respjson.Field
- StartIndex respjson.Field
- Text respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FilePathDeltaAnnotation) RawJSON() string { return r.JSON.raw }
-func (r *FilePathDeltaAnnotation) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FilePathDeltaAnnotationFilePath struct {
- // The ID of the file that was generated.
- FileID string `json:"file_id"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FilePathDeltaAnnotationFilePath) RawJSON() string { return r.JSON.raw }
-func (r *FilePathDeltaAnnotationFilePath) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type ImageFile struct {
- // The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
- // in the message content. Set `purpose="vision"` when uploading the File if you
- // need to later display the file content.
- FileID string `json:"file_id,required"`
- // Specifies the detail level of the image if specified by the user. `low` uses
- // fewer tokens, you can opt in to high resolution using `high`.
- //
- // Any of "auto", "low", "high".
- Detail ImageFileDetail `json:"detail"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileID respjson.Field
- Detail respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ImageFile) RawJSON() string { return r.JSON.raw }
-func (r *ImageFile) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this ImageFile to a ImageFileParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// ImageFileParam.Overrides()
-func (r ImageFile) ToParam() ImageFileParam {
- return param.Override[ImageFileParam](r.RawJSON())
-}
-
-// Specifies the detail level of the image if specified by the user. `low` uses
-// fewer tokens, you can opt in to high resolution using `high`.
-type ImageFileDetail string
-
-const (
- ImageFileDetailAuto ImageFileDetail = "auto"
- ImageFileDetailLow ImageFileDetail = "low"
- ImageFileDetailHigh ImageFileDetail = "high"
-)
-
-// The property FileID is required.
-type ImageFileParam struct {
- // The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
- // in the message content. Set `purpose="vision"` when uploading the File if you
- // need to later display the file content.
- FileID string `json:"file_id,required"`
- // Specifies the detail level of the image if specified by the user. `low` uses
- // fewer tokens, you can opt in to high resolution using `high`.
- //
- // Any of "auto", "low", "high".
- Detail ImageFileDetail `json:"detail,omitzero"`
- paramObj
-}
-
-func (r ImageFileParam) MarshalJSON() (data []byte, err error) {
- type shadow ImageFileParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *ImageFileParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// References an image [File](https://platform.openai.com/docs/api-reference/files)
-// in the content of a message.
-type ImageFileContentBlock struct {
- ImageFile ImageFile `json:"image_file,required"`
- // Always `image_file`.
- Type constant.ImageFile `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ImageFile respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ImageFileContentBlock) RawJSON() string { return r.JSON.raw }
-func (r *ImageFileContentBlock) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this ImageFileContentBlock to a ImageFileContentBlockParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// ImageFileContentBlockParam.Overrides()
-func (r ImageFileContentBlock) ToParam() ImageFileContentBlockParam {
- return param.Override[ImageFileContentBlockParam](r.RawJSON())
-}
-
-// References an image [File](https://platform.openai.com/docs/api-reference/files)
-// in the content of a message.
-//
-// The properties ImageFile, Type are required.
-type ImageFileContentBlockParam struct {
- ImageFile ImageFileParam `json:"image_file,omitzero,required"`
- // Always `image_file`.
- //
- // This field can be elided, and will marshal its zero value as "image_file".
- Type constant.ImageFile `json:"type,required"`
- paramObj
-}
-
-func (r ImageFileContentBlockParam) MarshalJSON() (data []byte, err error) {
- type shadow ImageFileContentBlockParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *ImageFileContentBlockParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type ImageFileDelta struct {
- // Specifies the detail level of the image if specified by the user. `low` uses
- // fewer tokens, you can opt in to high resolution using `high`.
- //
- // Any of "auto", "low", "high".
- Detail ImageFileDeltaDetail `json:"detail"`
- // The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
- // in the message content. Set `purpose="vision"` when uploading the File if you
- // need to later display the file content.
- FileID string `json:"file_id"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Detail respjson.Field
- FileID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ImageFileDelta) RawJSON() string { return r.JSON.raw }
-func (r *ImageFileDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Specifies the detail level of the image if specified by the user. `low` uses
-// fewer tokens, you can opt in to high resolution using `high`.
-type ImageFileDeltaDetail string
-
-const (
- ImageFileDeltaDetailAuto ImageFileDeltaDetail = "auto"
- ImageFileDeltaDetailLow ImageFileDeltaDetail = "low"
- ImageFileDeltaDetailHigh ImageFileDeltaDetail = "high"
-)
-
-// References an image [File](https://platform.openai.com/docs/api-reference/files)
-// in the content of a message.
-type ImageFileDeltaBlock struct {
- // The index of the content part in the message.
- Index int64 `json:"index,required"`
- // Always `image_file`.
- Type constant.ImageFile `json:"type,required"`
- ImageFile ImageFileDelta `json:"image_file"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- ImageFile respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ImageFileDeltaBlock) RawJSON() string { return r.JSON.raw }
-func (r *ImageFileDeltaBlock) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type ImageURL struct {
- // The external URL of the image, must be a supported image types: jpeg, jpg, png,
- // gif, webp.
- URL string `json:"url,required" format:"uri"`
- // Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
- // to high resolution using `high`. Default value is `auto`
- //
- // Any of "auto", "low", "high".
- Detail ImageURLDetail `json:"detail"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- URL respjson.Field
- Detail respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ImageURL) RawJSON() string { return r.JSON.raw }
-func (r *ImageURL) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this ImageURL to a ImageURLParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// ImageURLParam.Overrides()
-func (r ImageURL) ToParam() ImageURLParam {
- return param.Override[ImageURLParam](r.RawJSON())
-}
-
-// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
-// to high resolution using `high`. Default value is `auto`
-type ImageURLDetail string
-
-const (
- ImageURLDetailAuto ImageURLDetail = "auto"
- ImageURLDetailLow ImageURLDetail = "low"
- ImageURLDetailHigh ImageURLDetail = "high"
-)
-
-// The property URL is required.
-type ImageURLParam struct {
- // The external URL of the image, must be a supported image types: jpeg, jpg, png,
- // gif, webp.
- URL string `json:"url,required" format:"uri"`
- // Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
- // to high resolution using `high`. Default value is `auto`
- //
- // Any of "auto", "low", "high".
- Detail ImageURLDetail `json:"detail,omitzero"`
- paramObj
-}
-
-func (r ImageURLParam) MarshalJSON() (data []byte, err error) {
- type shadow ImageURLParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *ImageURLParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// References an image URL in the content of a message.
-type ImageURLContentBlock struct {
- ImageURL ImageURL `json:"image_url,required"`
- // The type of the content part.
- Type constant.ImageURL `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ImageURL respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ImageURLContentBlock) RawJSON() string { return r.JSON.raw }
-func (r *ImageURLContentBlock) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this ImageURLContentBlock to a ImageURLContentBlockParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// ImageURLContentBlockParam.Overrides()
-func (r ImageURLContentBlock) ToParam() ImageURLContentBlockParam {
- return param.Override[ImageURLContentBlockParam](r.RawJSON())
-}
-
-// References an image URL in the content of a message.
-//
-// The properties ImageURL, Type are required.
-type ImageURLContentBlockParam struct {
- ImageURL ImageURLParam `json:"image_url,omitzero,required"`
- // The type of the content part.
- //
- // This field can be elided, and will marshal its zero value as "image_url".
- Type constant.ImageURL `json:"type,required"`
- paramObj
-}
-
-func (r ImageURLContentBlockParam) MarshalJSON() (data []byte, err error) {
- type shadow ImageURLContentBlockParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *ImageURLContentBlockParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type ImageURLDelta struct {
- // Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
- // to high resolution using `high`.
- //
- // Any of "auto", "low", "high".
- Detail ImageURLDeltaDetail `json:"detail"`
- // The URL of the image, must be a supported image types: jpeg, jpg, png, gif,
- // webp.
- URL string `json:"url"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Detail respjson.Field
- URL respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ImageURLDelta) RawJSON() string { return r.JSON.raw }
-func (r *ImageURLDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
-// to high resolution using `high`.
-type ImageURLDeltaDetail string
-
-const (
- ImageURLDeltaDetailAuto ImageURLDeltaDetail = "auto"
- ImageURLDeltaDetailLow ImageURLDeltaDetail = "low"
- ImageURLDeltaDetailHigh ImageURLDeltaDetail = "high"
-)
-
-// References an image URL in the content of a message.
-type ImageURLDeltaBlock struct {
- // The index of the content part in the message.
- Index int64 `json:"index,required"`
- // Always `image_url`.
- Type constant.ImageURL `json:"type,required"`
- ImageURL ImageURLDelta `json:"image_url"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- ImageURL respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ImageURLDeltaBlock) RawJSON() string { return r.JSON.raw }
-func (r *ImageURLDeltaBlock) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Represents a message within a
-// [thread](https://platform.openai.com/docs/api-reference/threads).
-type Message struct {
- // The identifier, which can be referenced in API endpoints.
- ID string `json:"id,required"`
- // If applicable, the ID of the
- // [assistant](https://platform.openai.com/docs/api-reference/assistants) that
- // authored this message.
- AssistantID string `json:"assistant_id,required"`
- // A list of files attached to the message, and the tools they were added to.
- Attachments []MessageAttachment `json:"attachments,required"`
- // The Unix timestamp (in seconds) for when the message was completed.
- CompletedAt int64 `json:"completed_at,required"`
- // The content of the message in array of text and/or images.
- Content []MessageContentUnion `json:"content,required"`
- // The Unix timestamp (in seconds) for when the message was created.
- CreatedAt int64 `json:"created_at,required"`
- // The Unix timestamp (in seconds) for when the message was marked as incomplete.
- IncompleteAt int64 `json:"incomplete_at,required"`
- // On an incomplete message, details about why the message is incomplete.
- IncompleteDetails MessageIncompleteDetails `json:"incomplete_details,required"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,required"`
- // The object type, which is always `thread.message`.
- Object constant.ThreadMessage `json:"object,required"`
- // The entity that produced the message. One of `user` or `assistant`.
- //
- // Any of "user", "assistant".
- Role MessageRole `json:"role,required"`
- // The ID of the [run](https://platform.openai.com/docs/api-reference/runs)
- // associated with the creation of this message. Value is `null` when messages are
- // created manually using the create message or create thread endpoints.
- RunID string `json:"run_id,required"`
- // The status of the message, which can be either `in_progress`, `incomplete`, or
- // `completed`.
- //
- // Any of "in_progress", "incomplete", "completed".
- Status MessageStatus `json:"status,required"`
- // The [thread](https://platform.openai.com/docs/api-reference/threads) ID that
- // this message belongs to.
- ThreadID string `json:"thread_id,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- AssistantID respjson.Field
- Attachments respjson.Field
- CompletedAt respjson.Field
- Content respjson.Field
- CreatedAt respjson.Field
- IncompleteAt respjson.Field
- IncompleteDetails respjson.Field
- Metadata respjson.Field
- Object respjson.Field
- Role respjson.Field
- RunID respjson.Field
- Status respjson.Field
- ThreadID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r Message) RawJSON() string { return r.JSON.raw }
-func (r *Message) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type MessageAttachment struct {
- // The ID of the file to attach to the message.
- FileID string `json:"file_id"`
- // The tools to add this file to.
- Tools []MessageAttachmentToolUnion `json:"tools"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileID respjson.Field
- Tools respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r MessageAttachment) RawJSON() string { return r.JSON.raw }
-func (r *MessageAttachment) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// MessageAttachmentToolUnion contains all possible properties and values from
-// [CodeInterpreterTool], [MessageAttachmentToolFileSearchTool].
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type MessageAttachmentToolUnion struct {
- Type string `json:"type"`
- JSON struct {
- Type respjson.Field
- raw string
- } `json:"-"`
-}
-
-func (u MessageAttachmentToolUnion) AsCodeInterpreterTool() (v CodeInterpreterTool) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u MessageAttachmentToolUnion) AsFileSearchTool() (v MessageAttachmentToolFileSearchTool) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u MessageAttachmentToolUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *MessageAttachmentToolUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type MessageAttachmentToolFileSearchTool struct {
- // The type of tool being defined: `file_search`
- Type constant.FileSearch `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r MessageAttachmentToolFileSearchTool) RawJSON() string { return r.JSON.raw }
-func (r *MessageAttachmentToolFileSearchTool) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// On an incomplete message, details about why the message is incomplete.
-type MessageIncompleteDetails struct {
- // The reason the message is incomplete.
- //
- // Any of "content_filter", "max_tokens", "run_cancelled", "run_expired",
- // "run_failed".
- Reason string `json:"reason,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Reason respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r MessageIncompleteDetails) RawJSON() string { return r.JSON.raw }
-func (r *MessageIncompleteDetails) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The entity that produced the message. One of `user` or `assistant`.
-type MessageRole string
-
-const (
- MessageRoleUser MessageRole = "user"
- MessageRoleAssistant MessageRole = "assistant"
-)
-
-// The status of the message, which can be either `in_progress`, `incomplete`, or
-// `completed`.
-type MessageStatus string
-
-const (
- MessageStatusInProgress MessageStatus = "in_progress"
- MessageStatusIncomplete MessageStatus = "incomplete"
- MessageStatusCompleted MessageStatus = "completed"
-)
-
-// MessageContentUnion contains all possible properties and values from
-// [ImageFileContentBlock], [ImageURLContentBlock], [TextContentBlock],
-// [RefusalContentBlock].
-//
-// Use the [MessageContentUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type MessageContentUnion struct {
- // This field is from variant [ImageFileContentBlock].
- ImageFile ImageFile `json:"image_file"`
- // Any of "image_file", "image_url", "text", "refusal".
- Type string `json:"type"`
- // This field is from variant [ImageURLContentBlock].
- ImageURL ImageURL `json:"image_url"`
- // This field is from variant [TextContentBlock].
- Text Text `json:"text"`
- // This field is from variant [RefusalContentBlock].
- Refusal string `json:"refusal"`
- JSON struct {
- ImageFile respjson.Field
- Type respjson.Field
- ImageURL respjson.Field
- Text respjson.Field
- Refusal respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyMessageContent is implemented by each variant of [MessageContentUnion] to add
-// type safety for the return type of [MessageContentUnion.AsAny]
-type anyMessageContent interface {
- implMessageContentUnion()
-}
-
-func (ImageFileContentBlock) implMessageContentUnion() {}
-func (ImageURLContentBlock) implMessageContentUnion() {}
-func (TextContentBlock) implMessageContentUnion() {}
-func (RefusalContentBlock) implMessageContentUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := MessageContentUnion.AsAny().(type) {
-// case openai.ImageFileContentBlock:
-// case openai.ImageURLContentBlock:
-// case openai.TextContentBlock:
-// case openai.RefusalContentBlock:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u MessageContentUnion) AsAny() anyMessageContent {
- switch u.Type {
- case "image_file":
- return u.AsImageFile()
- case "image_url":
- return u.AsImageURL()
- case "text":
- return u.AsText()
- case "refusal":
- return u.AsRefusal()
- }
- return nil
-}
-
-func (u MessageContentUnion) AsImageFile() (v ImageFileContentBlock) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u MessageContentUnion) AsImageURL() (v ImageURLContentBlock) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u MessageContentUnion) AsText() (v TextContentBlock) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u MessageContentUnion) AsRefusal() (v RefusalContentBlock) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u MessageContentUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *MessageContentUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// MessageContentDeltaUnion contains all possible properties and values from
-// [ImageFileDeltaBlock], [TextDeltaBlock], [RefusalDeltaBlock],
-// [ImageURLDeltaBlock].
-//
-// Use the [MessageContentDeltaUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type MessageContentDeltaUnion struct {
- Index int64 `json:"index"`
- // Any of "image_file", "text", "refusal", "image_url".
- Type string `json:"type"`
- // This field is from variant [ImageFileDeltaBlock].
- ImageFile ImageFileDelta `json:"image_file"`
- // This field is from variant [TextDeltaBlock].
- Text TextDelta `json:"text"`
- // This field is from variant [RefusalDeltaBlock].
- Refusal string `json:"refusal"`
- // This field is from variant [ImageURLDeltaBlock].
- ImageURL ImageURLDelta `json:"image_url"`
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- ImageFile respjson.Field
- Text respjson.Field
- Refusal respjson.Field
- ImageURL respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyMessageContentDelta is implemented by each variant of
-// [MessageContentDeltaUnion] to add type safety for the return type of
-// [MessageContentDeltaUnion.AsAny]
-type anyMessageContentDelta interface {
- implMessageContentDeltaUnion()
-}
-
-func (ImageFileDeltaBlock) implMessageContentDeltaUnion() {}
-func (TextDeltaBlock) implMessageContentDeltaUnion() {}
-func (RefusalDeltaBlock) implMessageContentDeltaUnion() {}
-func (ImageURLDeltaBlock) implMessageContentDeltaUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := MessageContentDeltaUnion.AsAny().(type) {
-// case openai.ImageFileDeltaBlock:
-// case openai.TextDeltaBlock:
-// case openai.RefusalDeltaBlock:
-// case openai.ImageURLDeltaBlock:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u MessageContentDeltaUnion) AsAny() anyMessageContentDelta {
- switch u.Type {
- case "image_file":
- return u.AsImageFile()
- case "text":
- return u.AsText()
- case "refusal":
- return u.AsRefusal()
- case "image_url":
- return u.AsImageURL()
- }
- return nil
-}
-
-func (u MessageContentDeltaUnion) AsImageFile() (v ImageFileDeltaBlock) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u MessageContentDeltaUnion) AsText() (v TextDeltaBlock) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u MessageContentDeltaUnion) AsRefusal() (v RefusalDeltaBlock) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u MessageContentDeltaUnion) AsImageURL() (v ImageURLDeltaBlock) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u MessageContentDeltaUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *MessageContentDeltaUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-func MessageContentPartParamOfImageFile(imageFile ImageFileParam) MessageContentPartParamUnion {
- var variant ImageFileContentBlockParam
- variant.ImageFile = imageFile
- return MessageContentPartParamUnion{OfImageFile: &variant}
-}
-
-func MessageContentPartParamOfImageURL(imageURL ImageURLParam) MessageContentPartParamUnion {
- var variant ImageURLContentBlockParam
- variant.ImageURL = imageURL
- return MessageContentPartParamUnion{OfImageURL: &variant}
-}
-
-func MessageContentPartParamOfText(text string) MessageContentPartParamUnion {
- var variant TextContentBlockParam
- variant.Text = text
- return MessageContentPartParamUnion{OfText: &variant}
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type MessageContentPartParamUnion struct {
- OfImageFile *ImageFileContentBlockParam `json:",omitzero,inline"`
- OfImageURL *ImageURLContentBlockParam `json:",omitzero,inline"`
- OfText *TextContentBlockParam `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u MessageContentPartParamUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[MessageContentPartParamUnion](u.OfImageFile, u.OfImageURL, u.OfText)
-}
-func (u *MessageContentPartParamUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *MessageContentPartParamUnion) asAny() any {
- if !param.IsOmitted(u.OfImageFile) {
- return u.OfImageFile
- } else if !param.IsOmitted(u.OfImageURL) {
- return u.OfImageURL
- } else if !param.IsOmitted(u.OfText) {
- return u.OfText
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u MessageContentPartParamUnion) GetImageFile() *ImageFileParam {
- if vt := u.OfImageFile; vt != nil {
- return &vt.ImageFile
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u MessageContentPartParamUnion) GetImageURL() *ImageURLParam {
- if vt := u.OfImageURL; vt != nil {
- return &vt.ImageURL
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u MessageContentPartParamUnion) GetText() *string {
- if vt := u.OfText; vt != nil {
- return &vt.Text
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u MessageContentPartParamUnion) GetType() *string {
- if vt := u.OfImageFile; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfImageURL; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfText; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-func init() {
- apijson.RegisterUnion[MessageContentPartParamUnion](
- "type",
- apijson.Discriminator[ImageFileContentBlockParam]("image_file"),
- apijson.Discriminator[ImageURLContentBlockParam]("image_url"),
- apijson.Discriminator[TextContentBlockParam]("text"),
- )
-}
-
-type MessageDeleted struct {
- ID string `json:"id,required"`
- Deleted bool `json:"deleted,required"`
- Object constant.ThreadMessageDeleted `json:"object,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- Deleted respjson.Field
- Object respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r MessageDeleted) RawJSON() string { return r.JSON.raw }
-func (r *MessageDeleted) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The delta containing the fields that have changed on the Message.
-type MessageDelta struct {
- // The content of the message in array of text and/or images.
- Content []MessageContentDeltaUnion `json:"content"`
- // The entity that produced the message. One of `user` or `assistant`.
- //
- // Any of "user", "assistant".
- Role MessageDeltaRole `json:"role"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Content respjson.Field
- Role respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r MessageDelta) RawJSON() string { return r.JSON.raw }
-func (r *MessageDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The entity that produced the message. One of `user` or `assistant`.
-type MessageDeltaRole string
-
-const (
- MessageDeltaRoleUser MessageDeltaRole = "user"
- MessageDeltaRoleAssistant MessageDeltaRole = "assistant"
-)
-
-// Represents a message delta i.e. any changed fields on a message during
-// streaming.
-type MessageDeltaEvent struct {
- // The identifier of the message, which can be referenced in API endpoints.
- ID string `json:"id,required"`
- // The delta containing the fields that have changed on the Message.
- Delta MessageDelta `json:"delta,required"`
- // The object type, which is always `thread.message.delta`.
- Object constant.ThreadMessageDelta `json:"object,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- Delta respjson.Field
- Object respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r MessageDeltaEvent) RawJSON() string { return r.JSON.raw }
-func (r *MessageDeltaEvent) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The refusal content generated by the assistant.
-type RefusalContentBlock struct {
- Refusal string `json:"refusal,required"`
- // Always `refusal`.
- Type constant.Refusal `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Refusal respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RefusalContentBlock) RawJSON() string { return r.JSON.raw }
-func (r *RefusalContentBlock) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The refusal content that is part of a message.
-type RefusalDeltaBlock struct {
- // The index of the refusal part in the message.
- Index int64 `json:"index,required"`
- // Always `refusal`.
- Type constant.Refusal `json:"type,required"`
- Refusal string `json:"refusal"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- Refusal respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RefusalDeltaBlock) RawJSON() string { return r.JSON.raw }
-func (r *RefusalDeltaBlock) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type Text struct {
- Annotations []AnnotationUnion `json:"annotations,required"`
- // The data that makes up the text.
- Value string `json:"value,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Annotations respjson.Field
- Value respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r Text) RawJSON() string { return r.JSON.raw }
-func (r *Text) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The text content that is part of a message.
-type TextContentBlock struct {
- Text Text `json:"text,required"`
- // Always `text`.
- Type constant.Text `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Text respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r TextContentBlock) RawJSON() string { return r.JSON.raw }
-func (r *TextContentBlock) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The text content that is part of a message.
-//
-// The properties Text, Type are required.
-type TextContentBlockParam struct {
- // Text content to be sent to the model
- Text string `json:"text,required"`
- // Always `text`.
- //
- // This field can be elided, and will marshal its zero value as "text".
- Type constant.Text `json:"type,required"`
- paramObj
-}
-
-func (r TextContentBlockParam) MarshalJSON() (data []byte, err error) {
- type shadow TextContentBlockParam
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *TextContentBlockParam) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type TextDelta struct {
- Annotations []AnnotationDeltaUnion `json:"annotations"`
- // The data that makes up the text.
- Value string `json:"value"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Annotations respjson.Field
- Value respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r TextDelta) RawJSON() string { return r.JSON.raw }
-func (r *TextDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The text content that is part of a message.
-type TextDeltaBlock struct {
- // The index of the content part in the message.
- Index int64 `json:"index,required"`
- // Always `text`.
- Type constant.Text `json:"type,required"`
- Text TextDelta `json:"text"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- Text respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r TextDeltaBlock) RawJSON() string { return r.JSON.raw }
-func (r *TextDeltaBlock) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadMessageNewParams struct {
- // The text contents of the message.
- Content BetaThreadMessageNewParamsContentUnion `json:"content,omitzero,required"`
- // The role of the entity that is creating the message. Allowed values include:
- //
- // - `user`: Indicates the message is sent by an actual user and should be used in
- // most cases to represent user-generated messages.
- // - `assistant`: Indicates the message is generated by the assistant. Use this
- // value to insert messages from the assistant into the conversation.
- //
- // Any of "user", "assistant".
- Role BetaThreadMessageNewParamsRole `json:"role,omitzero,required"`
- // A list of files attached to the message, and the tools they should be added to.
- Attachments []BetaThreadMessageNewParamsAttachment `json:"attachments,omitzero"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- paramObj
-}
-
-func (r BetaThreadMessageNewParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadMessageNewParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadMessageNewParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadMessageNewParamsContentUnion struct {
- OfString param.Opt[string] `json:",omitzero,inline"`
- OfArrayOfContentParts []MessageContentPartParamUnion `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadMessageNewParamsContentUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadMessageNewParamsContentUnion](u.OfString, u.OfArrayOfContentParts)
-}
-func (u *BetaThreadMessageNewParamsContentUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadMessageNewParamsContentUnion) asAny() any {
- if !param.IsOmitted(u.OfString) {
- return &u.OfString.Value
- } else if !param.IsOmitted(u.OfArrayOfContentParts) {
- return &u.OfArrayOfContentParts
- }
- return nil
-}
-
-// The role of the entity that is creating the message. Allowed values include:
-//
-// - `user`: Indicates the message is sent by an actual user and should be used in
-// most cases to represent user-generated messages.
-// - `assistant`: Indicates the message is generated by the assistant. Use this
-// value to insert messages from the assistant into the conversation.
-type BetaThreadMessageNewParamsRole string
-
-const (
- BetaThreadMessageNewParamsRoleUser BetaThreadMessageNewParamsRole = "user"
- BetaThreadMessageNewParamsRoleAssistant BetaThreadMessageNewParamsRole = "assistant"
-)
-
-type BetaThreadMessageNewParamsAttachment struct {
- // The ID of the file to attach to the message.
- FileID param.Opt[string] `json:"file_id,omitzero"`
- // The tools to add this file to.
- Tools []BetaThreadMessageNewParamsAttachmentToolUnion `json:"tools,omitzero"`
- paramObj
-}
-
-func (r BetaThreadMessageNewParamsAttachment) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadMessageNewParamsAttachment
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadMessageNewParamsAttachment) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadMessageNewParamsAttachmentToolUnion struct {
- OfCodeInterpreter *CodeInterpreterToolParam `json:",omitzero,inline"`
- OfFileSearch *BetaThreadMessageNewParamsAttachmentToolFileSearch `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadMessageNewParamsAttachmentToolUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadMessageNewParamsAttachmentToolUnion](u.OfCodeInterpreter, u.OfFileSearch)
-}
-func (u *BetaThreadMessageNewParamsAttachmentToolUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadMessageNewParamsAttachmentToolUnion) asAny() any {
- if !param.IsOmitted(u.OfCodeInterpreter) {
- return u.OfCodeInterpreter
- } else if !param.IsOmitted(u.OfFileSearch) {
- return u.OfFileSearch
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaThreadMessageNewParamsAttachmentToolUnion) GetType() *string {
- if vt := u.OfCodeInterpreter; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfFileSearch; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-func init() {
- apijson.RegisterUnion[BetaThreadMessageNewParamsAttachmentToolUnion](
- "type",
- apijson.Discriminator[CodeInterpreterToolParam]("code_interpreter"),
- apijson.Discriminator[BetaThreadMessageNewParamsAttachmentToolFileSearch]("file_search"),
- )
-}
-
-func NewBetaThreadMessageNewParamsAttachmentToolFileSearch() BetaThreadMessageNewParamsAttachmentToolFileSearch {
- return BetaThreadMessageNewParamsAttachmentToolFileSearch{
- Type: "file_search",
- }
-}
-
-// This struct has a constant value, construct it with
-// [NewBetaThreadMessageNewParamsAttachmentToolFileSearch].
-type BetaThreadMessageNewParamsAttachmentToolFileSearch struct {
- // The type of tool being defined: `file_search`
- Type constant.FileSearch `json:"type,required"`
- paramObj
-}
-
-func (r BetaThreadMessageNewParamsAttachmentToolFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadMessageNewParamsAttachmentToolFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadMessageNewParamsAttachmentToolFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadMessageUpdateParams struct {
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- paramObj
-}
-
-func (r BetaThreadMessageUpdateParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadMessageUpdateParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadMessageUpdateParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadMessageListParams struct {
- // A cursor for use in pagination. `after` is an object ID that defines your place
- // in the list. For instance, if you make a list request and receive 100 objects,
- // ending with obj_foo, your subsequent call can include after=obj_foo in order to
- // fetch the next page of the list.
- After param.Opt[string] `query:"after,omitzero" json:"-"`
- // A cursor for use in pagination. `before` is an object ID that defines your place
- // in the list. For instance, if you make a list request and receive 100 objects,
- // starting with obj_foo, your subsequent call can include before=obj_foo in order
- // to fetch the previous page of the list.
- Before param.Opt[string] `query:"before,omitzero" json:"-"`
- // A limit on the number of objects to be returned. Limit can range between 1 and
- // 100, and the default is 20.
- Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
- // Filter messages by the run ID that generated them.
- RunID param.Opt[string] `query:"run_id,omitzero" json:"-"`
- // Sort order by the `created_at` timestamp of the objects. `asc` for ascending
- // order and `desc` for descending order.
- //
- // Any of "asc", "desc".
- Order BetaThreadMessageListParamsOrder `query:"order,omitzero" json:"-"`
- paramObj
-}
-
-// URLQuery serializes [BetaThreadMessageListParams]'s query parameters as
-// `url.Values`.
-func (r BetaThreadMessageListParams) URLQuery() (v url.Values, err error) {
- return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
- ArrayFormat: apiquery.ArrayQueryFormatBrackets,
- NestedFormat: apiquery.NestedQueryFormatBrackets,
- })
-}
-
-// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
-// order and `desc` for descending order.
-type BetaThreadMessageListParamsOrder string
-
-const (
- BetaThreadMessageListParamsOrderAsc BetaThreadMessageListParamsOrder = "asc"
- BetaThreadMessageListParamsOrderDesc BetaThreadMessageListParamsOrder = "desc"
-)
diff --git a/betathreadmessage_test.go b/betathreadmessage_test.go
deleted file mode 100644
index 20732ee1..00000000
--- a/betathreadmessage_test.go
+++ /dev/null
@@ -1,170 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai_test
-
-import (
- "context"
- "errors"
- "os"
- "testing"
-
- "github.com/openai/openai-go"
- "github.com/openai/openai-go/internal/testutil"
- "github.com/openai/openai-go/option"
- "github.com/openai/openai-go/shared"
-)
-
-func TestBetaThreadMessageNewWithOptionalParams(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.Beta.Threads.Messages.New(
- context.TODO(),
- "thread_id",
- openai.BetaThreadMessageNewParams{
- Content: openai.BetaThreadMessageNewParamsContentUnion{
- OfString: openai.String("string"),
- },
- Role: openai.BetaThreadMessageNewParamsRoleUser,
- Attachments: []openai.BetaThreadMessageNewParamsAttachment{{
- FileID: openai.String("file_id"),
- Tools: []openai.BetaThreadMessageNewParamsAttachmentToolUnion{{
- OfCodeInterpreter: &openai.CodeInterpreterToolParam{},
- }},
- }},
- Metadata: shared.Metadata{
- "foo": "string",
- },
- },
- )
- 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())
- }
-}
-
-func TestBetaThreadMessageGet(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.Beta.Threads.Messages.Get(
- context.TODO(),
- "thread_id",
- "message_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())
- }
-}
-
-func TestBetaThreadMessageUpdateWithOptionalParams(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.Beta.Threads.Messages.Update(
- context.TODO(),
- "thread_id",
- "message_id",
- openai.BetaThreadMessageUpdateParams{
- Metadata: shared.Metadata{
- "foo": "string",
- },
- },
- )
- 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())
- }
-}
-
-func TestBetaThreadMessageListWithOptionalParams(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.Beta.Threads.Messages.List(
- context.TODO(),
- "thread_id",
- openai.BetaThreadMessageListParams{
- After: openai.String("after"),
- Before: openai.String("before"),
- Limit: openai.Int(0),
- Order: openai.BetaThreadMessageListParamsOrderAsc,
- RunID: openai.String("run_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())
- }
-}
-
-func TestBetaThreadMessageDelete(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.Beta.Threads.Messages.Delete(
- context.TODO(),
- "thread_id",
- "message_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())
- }
-}
diff --git a/betathreadrun.go b/betathreadrun.go
deleted file mode 100644
index cb4ae1a8..00000000
--- a/betathreadrun.go
+++ /dev/null
@@ -1,961 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai
-
-import (
- "context"
- "errors"
- "fmt"
- "net/http"
- "net/url"
-
- "github.com/openai/openai-go/internal/apijson"
- "github.com/openai/openai-go/internal/apiquery"
- "github.com/openai/openai-go/internal/requestconfig"
- "github.com/openai/openai-go/option"
- "github.com/openai/openai-go/packages/pagination"
- "github.com/openai/openai-go/packages/param"
- "github.com/openai/openai-go/packages/respjson"
- "github.com/openai/openai-go/packages/ssestream"
- "github.com/openai/openai-go/shared"
- "github.com/openai/openai-go/shared/constant"
-)
-
-// BetaThreadRunService contains methods and other services that help with
-// interacting with the openai API.
-//
-// Note, unlike clients, this service does not read variables from the environment
-// automatically. You should not instantiate this service directly, and instead use
-// the [NewBetaThreadRunService] method instead.
-type BetaThreadRunService struct {
- Options []option.RequestOption
- Steps BetaThreadRunStepService
-}
-
-// NewBetaThreadRunService generates a new service that applies the given options
-// to each request. These options are applied after the parent client's options (if
-// there is one), and before any request-specific options.
-func NewBetaThreadRunService(opts ...option.RequestOption) (r BetaThreadRunService) {
- r = BetaThreadRunService{}
- r.Options = opts
- r.Steps = NewBetaThreadRunStepService(opts...)
- return
-}
-
-// Create a run.
-func (r *BetaThreadRunService) New(ctx context.Context, threadID string, params BetaThreadRunNewParams, opts ...option.RequestOption) (res *Run, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs", threadID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
- return
-}
-
-// Create a run and poll until task is completed.
-// Pass 0 to pollIntervalMs to use the default polling interval.
-func (r *BetaThreadRunService) NewAndPoll(ctx context.Context, threadID string, params BetaThreadRunNewParams, pollIntervalMs int, opts ...option.RequestOption) (res *Run, err error) {
- run, err := r.New(ctx, threadID, params, opts...)
- if err != nil {
- return nil, err
- }
- return r.PollStatus(ctx, threadID, run.ID, pollIntervalMs, opts...)
-}
-
-// Create a run.
-func (r *BetaThreadRunService) NewStreaming(ctx context.Context, threadID string, params BetaThreadRunNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[AssistantStreamEventUnion]) {
- var (
- raw *http.Response
- err error
- )
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithJSONSet("stream", true)}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs", threadID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &raw, opts...)
- return ssestream.NewStream[AssistantStreamEventUnion](ssestream.NewDecoder(raw), err)
-}
-
-// Retrieves a run.
-func (r *BetaThreadRunService) Get(ctx context.Context, threadID string, runID string, opts ...option.RequestOption) (res *Run, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if runID == "" {
- err = errors.New("missing required run_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs/%s", threadID, runID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
- return
-}
-
-// Modifies a run.
-func (r *BetaThreadRunService) Update(ctx context.Context, threadID string, runID string, body BetaThreadRunUpdateParams, opts ...option.RequestOption) (res *Run, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if runID == "" {
- err = errors.New("missing required run_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs/%s", threadID, runID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
-}
-
-// Returns a list of runs belonging to a thread.
-func (r *BetaThreadRunService) List(ctx context.Context, threadID string, query BetaThreadRunListParams, opts ...option.RequestOption) (res *pagination.CursorPage[Run], err error) {
- var raw *http.Response
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs", threadID)
- cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
- if err != nil {
- return nil, err
- }
- err = cfg.Execute()
- if err != nil {
- return nil, err
- }
- res.SetPageConfig(cfg, raw)
- return res, nil
-}
-
-// Returns a list of runs belonging to a thread.
-func (r *BetaThreadRunService) ListAutoPaging(ctx context.Context, threadID string, query BetaThreadRunListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[Run] {
- return pagination.NewCursorPageAutoPager(r.List(ctx, threadID, query, opts...))
-}
-
-// Cancels a run that is `in_progress`.
-func (r *BetaThreadRunService) Cancel(ctx context.Context, threadID string, runID string, opts ...option.RequestOption) (res *Run, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if runID == "" {
- err = errors.New("missing required run_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs/%s/cancel", threadID, runID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
- return
-}
-
-// When a run has the `status: "requires_action"` and `required_action.type` is
-// `submit_tool_outputs`, this endpoint can be used to submit the outputs from the
-// tool calls once they're all completed. All outputs must be submitted in a single
-// request.
-func (r *BetaThreadRunService) SubmitToolOutputs(ctx context.Context, threadID string, runID string, body BetaThreadRunSubmitToolOutputsParams, opts ...option.RequestOption) (res *Run, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if runID == "" {
- err = errors.New("missing required run_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs/%s/submit_tool_outputs", threadID, runID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
-}
-
-// A helper to submit a tool output to a run and poll for a terminal run state.
-// Pass 0 to pollIntervalMs to use the default polling interval.
-// More information on Run lifecycles can be found here:
-// https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
-func (r *BetaThreadRunService) SubmitToolOutputsAndPoll(ctx context.Context, threadID string, runID string, body BetaThreadRunSubmitToolOutputsParams, pollIntervalMs int, opts ...option.RequestOption) (*Run, error) {
- run, err := r.SubmitToolOutputs(ctx, threadID, runID, body, opts...)
- if err != nil {
- return nil, err
- }
- return r.PollStatus(ctx, threadID, run.ID, pollIntervalMs, opts...)
-}
-
-// When a run has the `status: "requires_action"` and `required_action.type` is
-// `submit_tool_outputs`, this endpoint can be used to submit the outputs from the
-// tool calls once they're all completed. All outputs must be submitted in a single
-// request.
-func (r *BetaThreadRunService) SubmitToolOutputsStreaming(ctx context.Context, threadID string, runID string, body BetaThreadRunSubmitToolOutputsParams, opts ...option.RequestOption) (stream *ssestream.Stream[AssistantStreamEventUnion]) {
- var (
- raw *http.Response
- err error
- )
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithJSONSet("stream", true)}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if runID == "" {
- err = errors.New("missing required run_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs/%s/submit_tool_outputs", threadID, runID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)
- return ssestream.NewStream[AssistantStreamEventUnion](ssestream.NewDecoder(raw), err)
-}
-
-// Tool call objects
-type RequiredActionFunctionToolCall struct {
- // The ID of the tool call. This ID must be referenced when you submit the tool
- // outputs in using the
- // [Submit tool outputs to run](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)
- // endpoint.
- ID string `json:"id,required"`
- // The function definition.
- Function RequiredActionFunctionToolCallFunction `json:"function,required"`
- // The type of tool call the output is required for. For now, this is always
- // `function`.
- Type constant.Function `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- Function respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RequiredActionFunctionToolCall) RawJSON() string { return r.JSON.raw }
-func (r *RequiredActionFunctionToolCall) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The function definition.
-type RequiredActionFunctionToolCallFunction struct {
- // The arguments that the model expects you to pass to the function.
- Arguments string `json:"arguments,required"`
- // The name of the function.
- Name string `json:"name,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Arguments respjson.Field
- Name respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RequiredActionFunctionToolCallFunction) RawJSON() string { return r.JSON.raw }
-func (r *RequiredActionFunctionToolCallFunction) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Represents an execution run on a
-// [thread](https://platform.openai.com/docs/api-reference/threads).
-type Run struct {
- // The identifier, which can be referenced in API endpoints.
- ID string `json:"id,required"`
- // The ID of the
- // [assistant](https://platform.openai.com/docs/api-reference/assistants) used for
- // execution of this run.
- AssistantID string `json:"assistant_id,required"`
- // The Unix timestamp (in seconds) for when the run was cancelled.
- CancelledAt int64 `json:"cancelled_at,required"`
- // The Unix timestamp (in seconds) for when the run was completed.
- CompletedAt int64 `json:"completed_at,required"`
- // The Unix timestamp (in seconds) for when the run was created.
- CreatedAt int64 `json:"created_at,required"`
- // The Unix timestamp (in seconds) for when the run will expire.
- ExpiresAt int64 `json:"expires_at,required"`
- // The Unix timestamp (in seconds) for when the run failed.
- FailedAt int64 `json:"failed_at,required"`
- // Details on why the run is incomplete. Will be `null` if the run is not
- // incomplete.
- IncompleteDetails RunIncompleteDetails `json:"incomplete_details,required"`
- // The instructions that the
- // [assistant](https://platform.openai.com/docs/api-reference/assistants) used for
- // this run.
- Instructions string `json:"instructions,required"`
- // The last error associated with this run. Will be `null` if there are no errors.
- LastError RunLastError `json:"last_error,required"`
- // The maximum number of completion tokens specified to have been used over the
- // course of the run.
- MaxCompletionTokens int64 `json:"max_completion_tokens,required"`
- // The maximum number of prompt tokens specified to have been used over the course
- // of the run.
- MaxPromptTokens int64 `json:"max_prompt_tokens,required"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,required"`
- // The model that the
- // [assistant](https://platform.openai.com/docs/api-reference/assistants) used for
- // this run.
- Model string `json:"model,required"`
- // The object type, which is always `thread.run`.
- Object constant.ThreadRun `json:"object,required"`
- // Whether to enable
- // [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
- // during tool use.
- ParallelToolCalls bool `json:"parallel_tool_calls,required"`
- // Details on the action required to continue the run. Will be `null` if no action
- // is required.
- RequiredAction RunRequiredAction `json:"required_action,required"`
- // Specifies the format that the model must output. Compatible with
- // [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
- // [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
- // and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
- //
- // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
- // Outputs which ensures the model will match your supplied JSON schema. Learn more
- // in the
- // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
- //
- // Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
- // message the model generates is valid JSON.
- //
- // **Important:** when using JSON mode, you **must** also instruct the model to
- // produce JSON yourself via a system or user message. Without this, the model may
- // generate an unending stream of whitespace until the generation reaches the token
- // limit, resulting in a long-running and seemingly "stuck" request. Also note that
- // the message content may be partially cut off if `finish_reason="length"`, which
- // indicates the generation exceeded `max_tokens` or the conversation exceeded the
- // max context length.
- ResponseFormat AssistantResponseFormatOptionUnion `json:"response_format,required"`
- // The Unix timestamp (in seconds) for when the run was started.
- StartedAt int64 `json:"started_at,required"`
- // The status of the run, which can be either `queued`, `in_progress`,
- // `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`,
- // `incomplete`, or `expired`.
- //
- // Any of "queued", "in_progress", "requires_action", "cancelling", "cancelled",
- // "failed", "completed", "incomplete", "expired".
- Status RunStatus `json:"status,required"`
- // The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)
- // that was executed on as a part of this run.
- ThreadID string `json:"thread_id,required"`
- // 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
- // and 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. Specifying a particular tool like `{"type": "file_search"}` or
- // `{"type": "function", "function": {"name": "my_function"}}` forces the model to
- // call that tool.
- ToolChoice AssistantToolChoiceOptionUnion `json:"tool_choice,required"`
- // The list of tools that the
- // [assistant](https://platform.openai.com/docs/api-reference/assistants) used for
- // this run.
- Tools []AssistantToolUnion `json:"tools,required"`
- // Controls for how a thread will be truncated prior to the run. Use this to
- // control the intial context window of the run.
- TruncationStrategy RunTruncationStrategy `json:"truncation_strategy,required"`
- // Usage statistics related to the run. This value will be `null` if the run is not
- // in a terminal state (i.e. `in_progress`, `queued`, etc.).
- Usage RunUsage `json:"usage,required"`
- // The sampling temperature used for this run. If not set, defaults to 1.
- Temperature float64 `json:"temperature,nullable"`
- // The nucleus sampling value used for this run. If not set, defaults to 1.
- TopP float64 `json:"top_p,nullable"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- AssistantID respjson.Field
- CancelledAt respjson.Field
- CompletedAt respjson.Field
- CreatedAt respjson.Field
- ExpiresAt respjson.Field
- FailedAt respjson.Field
- IncompleteDetails respjson.Field
- Instructions respjson.Field
- LastError respjson.Field
- MaxCompletionTokens respjson.Field
- MaxPromptTokens respjson.Field
- Metadata respjson.Field
- Model respjson.Field
- Object respjson.Field
- ParallelToolCalls respjson.Field
- RequiredAction respjson.Field
- ResponseFormat respjson.Field
- StartedAt respjson.Field
- Status respjson.Field
- ThreadID respjson.Field
- ToolChoice respjson.Field
- Tools respjson.Field
- TruncationStrategy respjson.Field
- Usage respjson.Field
- Temperature respjson.Field
- TopP respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r Run) RawJSON() string { return r.JSON.raw }
-func (r *Run) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Details on why the run is incomplete. Will be `null` if the run is not
-// incomplete.
-type RunIncompleteDetails struct {
- // The reason why the run is incomplete. This will point to which specific token
- // limit was reached over the course of the run.
- //
- // Any of "max_completion_tokens", "max_prompt_tokens".
- Reason string `json:"reason"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Reason respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunIncompleteDetails) RawJSON() string { return r.JSON.raw }
-func (r *RunIncompleteDetails) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The last error associated with this run. Will be `null` if there are no errors.
-type RunLastError struct {
- // One of `server_error`, `rate_limit_exceeded`, or `invalid_prompt`.
- //
- // Any of "server_error", "rate_limit_exceeded", "invalid_prompt".
- Code string `json:"code,required"`
- // A human-readable description of the error.
- Message string `json:"message,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Code respjson.Field
- Message respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunLastError) RawJSON() string { return r.JSON.raw }
-func (r *RunLastError) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Details on the action required to continue the run. Will be `null` if no action
-// is required.
-type RunRequiredAction struct {
- // Details on the tool outputs needed for this run to continue.
- SubmitToolOutputs RunRequiredActionSubmitToolOutputs `json:"submit_tool_outputs,required"`
- // For now, this is always `submit_tool_outputs`.
- Type constant.SubmitToolOutputs `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- SubmitToolOutputs respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunRequiredAction) RawJSON() string { return r.JSON.raw }
-func (r *RunRequiredAction) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Details on the tool outputs needed for this run to continue.
-type RunRequiredActionSubmitToolOutputs struct {
- // A list of the relevant tool calls.
- ToolCalls []RequiredActionFunctionToolCall `json:"tool_calls,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ToolCalls respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunRequiredActionSubmitToolOutputs) RawJSON() string { return r.JSON.raw }
-func (r *RunRequiredActionSubmitToolOutputs) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Controls for how a thread will be truncated prior to the run. Use this to
-// control the intial context window of the run.
-type RunTruncationStrategy struct {
- // The truncation strategy to use for the thread. The default is `auto`. If set to
- // `last_messages`, the thread will be truncated to the n most recent messages in
- // the thread. When set to `auto`, messages in the middle of the thread will be
- // dropped to fit the context length of the model, `max_prompt_tokens`.
- //
- // Any of "auto", "last_messages".
- Type string `json:"type,required"`
- // The number of most recent messages from the thread when constructing the context
- // for the run.
- LastMessages int64 `json:"last_messages,nullable"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Type respjson.Field
- LastMessages respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunTruncationStrategy) RawJSON() string { return r.JSON.raw }
-func (r *RunTruncationStrategy) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Usage statistics related to the run. This value will be `null` if the run is not
-// in a terminal state (i.e. `in_progress`, `queued`, etc.).
-type RunUsage struct {
- // Number of completion tokens used over the course of the run.
- CompletionTokens int64 `json:"completion_tokens,required"`
- // Number of prompt tokens used over the course of the run.
- PromptTokens int64 `json:"prompt_tokens,required"`
- // Total number of tokens used (prompt + completion).
- TotalTokens int64 `json:"total_tokens,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- CompletionTokens respjson.Field
- PromptTokens respjson.Field
- TotalTokens respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunUsage) RawJSON() string { return r.JSON.raw }
-func (r *RunUsage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The status of the run, which can be either `queued`, `in_progress`,
-// `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`,
-// `incomplete`, or `expired`.
-type RunStatus string
-
-const (
- RunStatusQueued RunStatus = "queued"
- RunStatusInProgress RunStatus = "in_progress"
- RunStatusRequiresAction RunStatus = "requires_action"
- RunStatusCancelling RunStatus = "cancelling"
- RunStatusCancelled RunStatus = "cancelled"
- RunStatusFailed RunStatus = "failed"
- RunStatusCompleted RunStatus = "completed"
- RunStatusIncomplete RunStatus = "incomplete"
- RunStatusExpired RunStatus = "expired"
-)
-
-type BetaThreadRunNewParams struct {
- // The ID of the
- // [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
- // execute this run.
- AssistantID string `json:"assistant_id,required"`
- // Appends additional instructions at the end of the instructions for the run. This
- // is useful for modifying the behavior on a per-run basis without overriding other
- // instructions.
- AdditionalInstructions param.Opt[string] `json:"additional_instructions,omitzero"`
- // Overrides the
- // [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
- // of the assistant. This is useful for modifying the behavior on a per-run basis.
- Instructions param.Opt[string] `json:"instructions,omitzero"`
- // The maximum number of completion tokens that may be used over the course of the
- // run. The run will make a best effort to use only the number of completion tokens
- // specified, across multiple turns of the run. If the run exceeds the number of
- // completion tokens specified, the run will end with status `incomplete`. See
- // `incomplete_details` for more info.
- MaxCompletionTokens param.Opt[int64] `json:"max_completion_tokens,omitzero"`
- // The maximum number of prompt tokens that may be used over the course of the run.
- // The run will make a best effort to use only the number of prompt tokens
- // specified, across multiple turns of the run. If the run exceeds the number of
- // prompt tokens specified, the run will end with status `incomplete`. See
- // `incomplete_details` for more info.
- MaxPromptTokens param.Opt[int64] `json:"max_prompt_tokens,omitzero"`
- // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
- // make the output more random, while lower values like 0.2 will make it more
- // focused and deterministic.
- Temperature param.Opt[float64] `json:"temperature,omitzero"`
- // An alternative to sampling with temperature, called nucleus sampling, where the
- // model considers the results of the tokens with top_p probability mass. So 0.1
- // means only the tokens comprising the top 10% probability mass are considered.
- //
- // We generally recommend altering this or temperature but not both.
- TopP param.Opt[float64] `json:"top_p,omitzero"`
- // Whether to enable
- // [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
- // during tool use.
- ParallelToolCalls param.Opt[bool] `json:"parallel_tool_calls,omitzero"`
- // Adds additional messages to the thread before creating the run.
- AdditionalMessages []BetaThreadRunNewParamsAdditionalMessage `json:"additional_messages,omitzero"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- // The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
- // be used to execute this run. If a value is provided here, it will override the
- // model associated with the assistant. If not, the model associated with the
- // assistant will be used.
- Model shared.ChatModel `json:"model,omitzero"`
- // **o-series models only**
- //
- // Constrains effort on reasoning for
- // [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
- // supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
- // result in faster responses and fewer tokens used on reasoning in a response.
- //
- // Any of "low", "medium", "high".
- ReasoningEffort shared.ReasoningEffort `json:"reasoning_effort,omitzero"`
- // Override the tools the assistant can use for this run. This is useful for
- // modifying the behavior on a per-run basis.
- Tools []AssistantToolUnionParam `json:"tools,omitzero"`
- // Controls for how a thread will be truncated prior to the run. Use this to
- // control the intial context window of the run.
- TruncationStrategy BetaThreadRunNewParamsTruncationStrategy `json:"truncation_strategy,omitzero"`
- // A list of additional fields to include in the response. Currently the only
- // supported value is `step_details.tool_calls[*].file_search.results[*].content`
- // to fetch the file search result content.
- //
- // See the
- // [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
- // for more information.
- Include []RunStepInclude `query:"include,omitzero" json:"-"`
- // Specifies the format that the model must output. Compatible with
- // [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
- // [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
- // and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
- //
- // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
- // Outputs which ensures the model will match your supplied JSON schema. Learn more
- // in the
- // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
- //
- // Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
- // message the model generates is valid JSON.
- //
- // **Important:** when using JSON mode, you **must** also instruct the model to
- // produce JSON yourself via a system or user message. Without this, the model may
- // generate an unending stream of whitespace until the generation reaches the token
- // limit, resulting in a long-running and seemingly "stuck" request. Also note that
- // the message content may be partially cut off if `finish_reason="length"`, which
- // indicates the generation exceeded `max_tokens` or the conversation exceeded the
- // max context length.
- ResponseFormat AssistantResponseFormatOptionUnionParam `json:"response_format,omitzero"`
- // 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
- // and 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. Specifying a particular tool like `{"type": "file_search"}` or
- // `{"type": "function", "function": {"name": "my_function"}}` forces the model to
- // call that tool.
- ToolChoice AssistantToolChoiceOptionUnionParam `json:"tool_choice,omitzero"`
- paramObj
-}
-
-func (r BetaThreadRunNewParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadRunNewParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadRunNewParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// URLQuery serializes [BetaThreadRunNewParams]'s query parameters as `url.Values`.
-func (r BetaThreadRunNewParams) URLQuery() (v url.Values, err error) {
- return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
- ArrayFormat: apiquery.ArrayQueryFormatBrackets,
- NestedFormat: apiquery.NestedQueryFormatBrackets,
- })
-}
-
-// The properties Content, Role are required.
-type BetaThreadRunNewParamsAdditionalMessage struct {
- // The text contents of the message.
- Content BetaThreadRunNewParamsAdditionalMessageContentUnion `json:"content,omitzero,required"`
- // The role of the entity that is creating the message. Allowed values include:
- //
- // - `user`: Indicates the message is sent by an actual user and should be used in
- // most cases to represent user-generated messages.
- // - `assistant`: Indicates the message is generated by the assistant. Use this
- // value to insert messages from the assistant into the conversation.
- //
- // Any of "user", "assistant".
- Role string `json:"role,omitzero,required"`
- // A list of files attached to the message, and the tools they should be added to.
- Attachments []BetaThreadRunNewParamsAdditionalMessageAttachment `json:"attachments,omitzero"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- paramObj
-}
-
-func (r BetaThreadRunNewParamsAdditionalMessage) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadRunNewParamsAdditionalMessage
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadRunNewParamsAdditionalMessage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-func init() {
- apijson.RegisterFieldValidator[BetaThreadRunNewParamsAdditionalMessage](
- "role", "user", "assistant",
- )
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadRunNewParamsAdditionalMessageContentUnion struct {
- OfString param.Opt[string] `json:",omitzero,inline"`
- OfArrayOfContentParts []MessageContentPartParamUnion `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadRunNewParamsAdditionalMessageContentUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadRunNewParamsAdditionalMessageContentUnion](u.OfString, u.OfArrayOfContentParts)
-}
-func (u *BetaThreadRunNewParamsAdditionalMessageContentUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadRunNewParamsAdditionalMessageContentUnion) asAny() any {
- if !param.IsOmitted(u.OfString) {
- return &u.OfString.Value
- } else if !param.IsOmitted(u.OfArrayOfContentParts) {
- return &u.OfArrayOfContentParts
- }
- return nil
-}
-
-type BetaThreadRunNewParamsAdditionalMessageAttachment struct {
- // The ID of the file to attach to the message.
- FileID param.Opt[string] `json:"file_id,omitzero"`
- // The tools to add this file to.
- Tools []BetaThreadRunNewParamsAdditionalMessageAttachmentToolUnion `json:"tools,omitzero"`
- paramObj
-}
-
-func (r BetaThreadRunNewParamsAdditionalMessageAttachment) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadRunNewParamsAdditionalMessageAttachment
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadRunNewParamsAdditionalMessageAttachment) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Only one field can be non-zero.
-//
-// Use [param.IsOmitted] to confirm if a field is set.
-type BetaThreadRunNewParamsAdditionalMessageAttachmentToolUnion struct {
- OfCodeInterpreter *CodeInterpreterToolParam `json:",omitzero,inline"`
- OfFileSearch *BetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch `json:",omitzero,inline"`
- paramUnion
-}
-
-func (u BetaThreadRunNewParamsAdditionalMessageAttachmentToolUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[BetaThreadRunNewParamsAdditionalMessageAttachmentToolUnion](u.OfCodeInterpreter, u.OfFileSearch)
-}
-func (u *BetaThreadRunNewParamsAdditionalMessageAttachmentToolUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, u)
-}
-
-func (u *BetaThreadRunNewParamsAdditionalMessageAttachmentToolUnion) asAny() any {
- if !param.IsOmitted(u.OfCodeInterpreter) {
- return u.OfCodeInterpreter
- } else if !param.IsOmitted(u.OfFileSearch) {
- return u.OfFileSearch
- }
- return nil
-}
-
-// Returns a pointer to the underlying variant's property, if present.
-func (u BetaThreadRunNewParamsAdditionalMessageAttachmentToolUnion) GetType() *string {
- if vt := u.OfCodeInterpreter; vt != nil {
- return (*string)(&vt.Type)
- } else if vt := u.OfFileSearch; vt != nil {
- return (*string)(&vt.Type)
- }
- return nil
-}
-
-func init() {
- apijson.RegisterUnion[BetaThreadRunNewParamsAdditionalMessageAttachmentToolUnion](
- "type",
- apijson.Discriminator[CodeInterpreterToolParam]("code_interpreter"),
- apijson.Discriminator[BetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch]("file_search"),
- )
-}
-
-func NewBetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch() BetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch {
- return BetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch{
- Type: "file_search",
- }
-}
-
-// This struct has a constant value, construct it with
-// [NewBetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch].
-type BetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch struct {
- // The type of tool being defined: `file_search`
- Type constant.FileSearch `json:"type,required"`
- paramObj
-}
-
-func (r BetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadRunNewParamsAdditionalMessageAttachmentToolFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Controls for how a thread will be truncated prior to the run. Use this to
-// control the intial context window of the run.
-//
-// The property Type is required.
-type BetaThreadRunNewParamsTruncationStrategy struct {
- // The truncation strategy to use for the thread. The default is `auto`. If set to
- // `last_messages`, the thread will be truncated to the n most recent messages in
- // the thread. When set to `auto`, messages in the middle of the thread will be
- // dropped to fit the context length of the model, `max_prompt_tokens`.
- //
- // Any of "auto", "last_messages".
- Type string `json:"type,omitzero,required"`
- // The number of most recent messages from the thread when constructing the context
- // for the run.
- LastMessages param.Opt[int64] `json:"last_messages,omitzero"`
- paramObj
-}
-
-func (r BetaThreadRunNewParamsTruncationStrategy) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadRunNewParamsTruncationStrategy
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadRunNewParamsTruncationStrategy) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-func init() {
- apijson.RegisterFieldValidator[BetaThreadRunNewParamsTruncationStrategy](
- "type", "auto", "last_messages",
- )
-}
-
-type BetaThreadRunUpdateParams struct {
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,omitzero"`
- paramObj
-}
-
-func (r BetaThreadRunUpdateParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadRunUpdateParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadRunUpdateParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadRunListParams struct {
- // A cursor for use in pagination. `after` is an object ID that defines your place
- // in the list. For instance, if you make a list request and receive 100 objects,
- // ending with obj_foo, your subsequent call can include after=obj_foo in order to
- // fetch the next page of the list.
- After param.Opt[string] `query:"after,omitzero" json:"-"`
- // A cursor for use in pagination. `before` is an object ID that defines your place
- // in the list. For instance, if you make a list request and receive 100 objects,
- // starting with obj_foo, your subsequent call can include before=obj_foo in order
- // to fetch the previous page of the list.
- Before param.Opt[string] `query:"before,omitzero" json:"-"`
- // A limit on the number of objects to be returned. Limit can range between 1 and
- // 100, and the default is 20.
- Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
- // Sort order by the `created_at` timestamp of the objects. `asc` for ascending
- // order and `desc` for descending order.
- //
- // Any of "asc", "desc".
- Order BetaThreadRunListParamsOrder `query:"order,omitzero" json:"-"`
- paramObj
-}
-
-// URLQuery serializes [BetaThreadRunListParams]'s query parameters as
-// `url.Values`.
-func (r BetaThreadRunListParams) URLQuery() (v url.Values, err error) {
- return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
- ArrayFormat: apiquery.ArrayQueryFormatBrackets,
- NestedFormat: apiquery.NestedQueryFormatBrackets,
- })
-}
-
-// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
-// order and `desc` for descending order.
-type BetaThreadRunListParamsOrder string
-
-const (
- BetaThreadRunListParamsOrderAsc BetaThreadRunListParamsOrder = "asc"
- BetaThreadRunListParamsOrderDesc BetaThreadRunListParamsOrder = "desc"
-)
-
-type BetaThreadRunSubmitToolOutputsParams struct {
- // A list of tools for which the outputs are being submitted.
- ToolOutputs []BetaThreadRunSubmitToolOutputsParamsToolOutput `json:"tool_outputs,omitzero,required"`
- paramObj
-}
-
-func (r BetaThreadRunSubmitToolOutputsParams) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadRunSubmitToolOutputsParams
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadRunSubmitToolOutputsParams) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadRunSubmitToolOutputsParamsToolOutput struct {
- // The output of the tool call to be submitted to continue the run.
- Output param.Opt[string] `json:"output,omitzero"`
- // The ID of the tool call in the `required_action` object within the run object
- // the output is being submitted for.
- ToolCallID param.Opt[string] `json:"tool_call_id,omitzero"`
- paramObj
-}
-
-func (r BetaThreadRunSubmitToolOutputsParamsToolOutput) MarshalJSON() (data []byte, err error) {
- type shadow BetaThreadRunSubmitToolOutputsParamsToolOutput
- return param.MarshalObject(r, (*shadow)(&r))
-}
-func (r *BetaThreadRunSubmitToolOutputsParamsToolOutput) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
diff --git a/betathreadrun_test.go b/betathreadrun_test.go
deleted file mode 100644
index 70723e52..00000000
--- a/betathreadrun_test.go
+++ /dev/null
@@ -1,231 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai_test
-
-import (
- "context"
- "errors"
- "os"
- "testing"
-
- "github.com/openai/openai-go"
- "github.com/openai/openai-go/internal/testutil"
- "github.com/openai/openai-go/option"
- "github.com/openai/openai-go/shared"
- "github.com/openai/openai-go/shared/constant"
-)
-
-func TestBetaThreadRunNewWithOptionalParams(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.Beta.Threads.Runs.New(
- context.TODO(),
- "thread_id",
- openai.BetaThreadRunNewParams{
- AssistantID: "assistant_id",
- Include: []openai.RunStepInclude{openai.RunStepIncludeStepDetailsToolCallsFileSearchResultsContent},
- AdditionalInstructions: openai.String("additional_instructions"),
- AdditionalMessages: []openai.BetaThreadRunNewParamsAdditionalMessage{{
- Content: openai.BetaThreadRunNewParamsAdditionalMessageContentUnion{
- OfString: openai.String("string"),
- },
- Role: "user",
- Attachments: []openai.BetaThreadRunNewParamsAdditionalMessageAttachment{{
- FileID: openai.String("file_id"),
- Tools: []openai.BetaThreadRunNewParamsAdditionalMessageAttachmentToolUnion{{
- OfCodeInterpreter: &openai.CodeInterpreterToolParam{},
- }},
- }},
- Metadata: shared.Metadata{
- "foo": "string",
- },
- }},
- Instructions: openai.String("instructions"),
- MaxCompletionTokens: openai.Int(256),
- MaxPromptTokens: openai.Int(256),
- Metadata: shared.Metadata{
- "foo": "string",
- },
- Model: shared.ChatModelGPT4_1,
- ParallelToolCalls: openai.Bool(true),
- ReasoningEffort: shared.ReasoningEffortLow,
- ResponseFormat: openai.AssistantResponseFormatOptionUnionParam{
- OfAuto: constant.ValueOf[constant.Auto](),
- },
- Temperature: openai.Float(1),
- ToolChoice: openai.AssistantToolChoiceOptionUnionParam{
- OfAuto: openai.String("none"),
- },
- Tools: []openai.AssistantToolUnionParam{{
- OfCodeInterpreter: &openai.CodeInterpreterToolParam{},
- }},
- TopP: openai.Float(1),
- TruncationStrategy: openai.BetaThreadRunNewParamsTruncationStrategy{
- Type: "auto",
- LastMessages: openai.Int(1),
- },
- },
- )
- 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())
- }
-}
-
-func TestBetaThreadRunGet(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.Beta.Threads.Runs.Get(
- context.TODO(),
- "thread_id",
- "run_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())
- }
-}
-
-func TestBetaThreadRunUpdateWithOptionalParams(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.Beta.Threads.Runs.Update(
- context.TODO(),
- "thread_id",
- "run_id",
- openai.BetaThreadRunUpdateParams{
- Metadata: shared.Metadata{
- "foo": "string",
- },
- },
- )
- 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())
- }
-}
-
-func TestBetaThreadRunListWithOptionalParams(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.Beta.Threads.Runs.List(
- context.TODO(),
- "thread_id",
- openai.BetaThreadRunListParams{
- After: openai.String("after"),
- Before: openai.String("before"),
- Limit: openai.Int(0),
- Order: openai.BetaThreadRunListParamsOrderAsc,
- },
- )
- 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())
- }
-}
-
-func TestBetaThreadRunCancel(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.Beta.Threads.Runs.Cancel(
- context.TODO(),
- "thread_id",
- "run_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())
- }
-}
-
-func TestBetaThreadRunSubmitToolOutputsWithOptionalParams(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.Beta.Threads.Runs.SubmitToolOutputs(
- context.TODO(),
- "thread_id",
- "run_id",
- openai.BetaThreadRunSubmitToolOutputsParams{
- ToolOutputs: []openai.BetaThreadRunSubmitToolOutputsParamsToolOutput{{
- Output: openai.String("output"),
- ToolCallID: openai.String("tool_call_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())
- }
-}
diff --git a/betathreadrunstep.go b/betathreadrunstep.go
deleted file mode 100644
index e3466e1b..00000000
--- a/betathreadrunstep.go
+++ /dev/null
@@ -1,1385 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai
-
-import (
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "net/http"
- "net/url"
-
- "github.com/openai/openai-go/internal/apijson"
- "github.com/openai/openai-go/internal/apiquery"
- "github.com/openai/openai-go/internal/requestconfig"
- "github.com/openai/openai-go/option"
- "github.com/openai/openai-go/packages/pagination"
- "github.com/openai/openai-go/packages/param"
- "github.com/openai/openai-go/packages/respjson"
- "github.com/openai/openai-go/shared"
- "github.com/openai/openai-go/shared/constant"
-)
-
-// BetaThreadRunStepService contains methods and other services that help with
-// interacting with the openai API.
-//
-// Note, unlike clients, this service does not read variables from the environment
-// automatically. You should not instantiate this service directly, and instead use
-// the [NewBetaThreadRunStepService] method instead.
-type BetaThreadRunStepService struct {
- Options []option.RequestOption
-}
-
-// NewBetaThreadRunStepService generates a new service that applies the given
-// options to each request. These options are applied after the parent client's
-// options (if there is one), and before any request-specific options.
-func NewBetaThreadRunStepService(opts ...option.RequestOption) (r BetaThreadRunStepService) {
- r = BetaThreadRunStepService{}
- r.Options = opts
- return
-}
-
-// Retrieves a run step.
-func (r *BetaThreadRunStepService) Get(ctx context.Context, threadID string, runID string, stepID string, query BetaThreadRunStepGetParams, opts ...option.RequestOption) (res *RunStep, err error) {
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if runID == "" {
- err = errors.New("missing required run_id parameter")
- return
- }
- if stepID == "" {
- err = errors.New("missing required step_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs/%s/steps/%s", threadID, runID, stepID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
- return
-}
-
-// Returns a list of run steps belonging to a run.
-func (r *BetaThreadRunStepService) List(ctx context.Context, threadID string, runID string, query BetaThreadRunStepListParams, opts ...option.RequestOption) (res *pagination.CursorPage[RunStep], err error) {
- var raw *http.Response
- opts = append(r.Options[:], opts...)
- opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
- if threadID == "" {
- err = errors.New("missing required thread_id parameter")
- return
- }
- if runID == "" {
- err = errors.New("missing required run_id parameter")
- return
- }
- path := fmt.Sprintf("threads/%s/runs/%s/steps", threadID, runID)
- cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
- if err != nil {
- return nil, err
- }
- err = cfg.Execute()
- if err != nil {
- return nil, err
- }
- res.SetPageConfig(cfg, raw)
- return res, nil
-}
-
-// Returns a list of run steps belonging to a run.
-func (r *BetaThreadRunStepService) ListAutoPaging(ctx context.Context, threadID string, runID string, query BetaThreadRunStepListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[RunStep] {
- return pagination.NewCursorPageAutoPager(r.List(ctx, threadID, runID, query, opts...))
-}
-
-// Text output from the Code Interpreter tool call as part of a run step.
-type CodeInterpreterLogs struct {
- // The index of the output in the outputs array.
- Index int64 `json:"index,required"`
- // Always `logs`.
- Type constant.Logs `json:"type,required"`
- // The text output from the Code Interpreter tool call.
- Logs string `json:"logs"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- Logs respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterLogs) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterLogs) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type CodeInterpreterOutputImage struct {
- // The index of the output in the outputs array.
- Index int64 `json:"index,required"`
- // Always `image`.
- Type constant.Image `json:"type,required"`
- Image CodeInterpreterOutputImageImage `json:"image"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- Image respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterOutputImage) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterOutputImage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type CodeInterpreterOutputImageImage struct {
- // The [file](https://platform.openai.com/docs/api-reference/files) ID of the
- // image.
- FileID string `json:"file_id"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterOutputImageImage) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterOutputImageImage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Details of the Code Interpreter tool call the run step was involved in.
-type CodeInterpreterToolCall struct {
- // The ID of the tool call.
- ID string `json:"id,required"`
- // The Code Interpreter tool call definition.
- CodeInterpreter CodeInterpreterToolCallCodeInterpreter `json:"code_interpreter,required"`
- // The type of tool call. This is always going to be `code_interpreter` for this
- // type of tool call.
- Type constant.CodeInterpreter `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- CodeInterpreter respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterToolCall) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterToolCall) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The Code Interpreter tool call definition.
-type CodeInterpreterToolCallCodeInterpreter struct {
- // The input to the Code Interpreter tool call.
- Input string `json:"input,required"`
- // The outputs from the Code Interpreter tool call. Code Interpreter can output one
- // or more items, including text (`logs`) or images (`image`). Each of these are
- // represented by a different object type.
- Outputs []CodeInterpreterToolCallCodeInterpreterOutputUnion `json:"outputs,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Input respjson.Field
- Outputs respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterToolCallCodeInterpreter) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterToolCallCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// CodeInterpreterToolCallCodeInterpreterOutputUnion contains all possible
-// properties and values from [CodeInterpreterToolCallCodeInterpreterOutputLogs],
-// [CodeInterpreterToolCallCodeInterpreterOutputImage].
-//
-// Use the [CodeInterpreterToolCallCodeInterpreterOutputUnion.AsAny] method to
-// switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type CodeInterpreterToolCallCodeInterpreterOutputUnion struct {
- // This field is from variant [CodeInterpreterToolCallCodeInterpreterOutputLogs].
- Logs string `json:"logs"`
- // Any of "logs", "image".
- Type string `json:"type"`
- // This field is from variant [CodeInterpreterToolCallCodeInterpreterOutputImage].
- Image CodeInterpreterToolCallCodeInterpreterOutputImageImage `json:"image"`
- JSON struct {
- Logs respjson.Field
- Type respjson.Field
- Image respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyCodeInterpreterToolCallCodeInterpreterOutput is implemented by each variant
-// of [CodeInterpreterToolCallCodeInterpreterOutputUnion] to add type safety for
-// the return type of [CodeInterpreterToolCallCodeInterpreterOutputUnion.AsAny]
-type anyCodeInterpreterToolCallCodeInterpreterOutput interface {
- implCodeInterpreterToolCallCodeInterpreterOutputUnion()
-}
-
-func (CodeInterpreterToolCallCodeInterpreterOutputLogs) implCodeInterpreterToolCallCodeInterpreterOutputUnion() {
-}
-func (CodeInterpreterToolCallCodeInterpreterOutputImage) implCodeInterpreterToolCallCodeInterpreterOutputUnion() {
-}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := CodeInterpreterToolCallCodeInterpreterOutputUnion.AsAny().(type) {
-// case openai.CodeInterpreterToolCallCodeInterpreterOutputLogs:
-// case openai.CodeInterpreterToolCallCodeInterpreterOutputImage:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) AsAny() anyCodeInterpreterToolCallCodeInterpreterOutput {
- switch u.Type {
- case "logs":
- return u.AsLogs()
- case "image":
- return u.AsImage()
- }
- return nil
-}
-
-func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) AsLogs() (v CodeInterpreterToolCallCodeInterpreterOutputLogs) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) AsImage() (v CodeInterpreterToolCallCodeInterpreterOutputImage) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *CodeInterpreterToolCallCodeInterpreterOutputUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Text output from the Code Interpreter tool call as part of a run step.
-type CodeInterpreterToolCallCodeInterpreterOutputLogs struct {
- // The text output from the Code Interpreter tool call.
- Logs string `json:"logs,required"`
- // Always `logs`.
- Type constant.Logs `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Logs respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterToolCallCodeInterpreterOutputLogs) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterToolCallCodeInterpreterOutputLogs) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type CodeInterpreterToolCallCodeInterpreterOutputImage struct {
- Image CodeInterpreterToolCallCodeInterpreterOutputImageImage `json:"image,required"`
- // Always `image`.
- Type constant.Image `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Image respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterToolCallCodeInterpreterOutputImage) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterToolCallCodeInterpreterOutputImage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type CodeInterpreterToolCallCodeInterpreterOutputImageImage struct {
- // The [file](https://platform.openai.com/docs/api-reference/files) ID of the
- // image.
- FileID string `json:"file_id,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterToolCallCodeInterpreterOutputImageImage) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterToolCallCodeInterpreterOutputImageImage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Details of the Code Interpreter tool call the run step was involved in.
-type CodeInterpreterToolCallDelta struct {
- // The index of the tool call in the tool calls array.
- Index int64 `json:"index,required"`
- // The type of tool call. This is always going to be `code_interpreter` for this
- // type of tool call.
- Type constant.CodeInterpreter `json:"type,required"`
- // The ID of the tool call.
- ID string `json:"id"`
- // The Code Interpreter tool call definition.
- CodeInterpreter CodeInterpreterToolCallDeltaCodeInterpreter `json:"code_interpreter"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- ID respjson.Field
- CodeInterpreter respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterToolCallDelta) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterToolCallDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The Code Interpreter tool call definition.
-type CodeInterpreterToolCallDeltaCodeInterpreter struct {
- // The input to the Code Interpreter tool call.
- Input string `json:"input"`
- // The outputs from the Code Interpreter tool call. Code Interpreter can output one
- // or more items, including text (`logs`) or images (`image`). Each of these are
- // represented by a different object type.
- Outputs []CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion `json:"outputs"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Input respjson.Field
- Outputs respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r CodeInterpreterToolCallDeltaCodeInterpreter) RawJSON() string { return r.JSON.raw }
-func (r *CodeInterpreterToolCallDeltaCodeInterpreter) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion contains all possible
-// properties and values from [CodeInterpreterLogs], [CodeInterpreterOutputImage].
-//
-// Use the [CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion.AsAny] method to
-// switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion struct {
- Index int64 `json:"index"`
- // Any of "logs", "image".
- Type string `json:"type"`
- // This field is from variant [CodeInterpreterLogs].
- Logs string `json:"logs"`
- // This field is from variant [CodeInterpreterOutputImage].
- Image CodeInterpreterOutputImageImage `json:"image"`
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- Logs respjson.Field
- Image respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyCodeInterpreterToolCallDeltaCodeInterpreterOutput is implemented by each
-// variant of [CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion] to add type
-// safety for the return type of
-// [CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion.AsAny]
-type anyCodeInterpreterToolCallDeltaCodeInterpreterOutput interface {
- implCodeInterpreterToolCallDeltaCodeInterpreterOutputUnion()
-}
-
-func (CodeInterpreterLogs) implCodeInterpreterToolCallDeltaCodeInterpreterOutputUnion() {}
-func (CodeInterpreterOutputImage) implCodeInterpreterToolCallDeltaCodeInterpreterOutputUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion.AsAny().(type) {
-// case openai.CodeInterpreterLogs:
-// case openai.CodeInterpreterOutputImage:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) AsAny() anyCodeInterpreterToolCallDeltaCodeInterpreterOutput {
- switch u.Type {
- case "logs":
- return u.AsLogs()
- case "image":
- return u.AsImage()
- }
- return nil
-}
-
-func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) AsLogs() (v CodeInterpreterLogs) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) AsImage() (v CodeInterpreterOutputImage) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FileSearchToolCall struct {
- // The ID of the tool call object.
- ID string `json:"id,required"`
- // For now, this is always going to be an empty object.
- FileSearch FileSearchToolCallFileSearch `json:"file_search,required"`
- // The type of tool call. This is always going to be `file_search` for this type of
- // tool call.
- Type constant.FileSearch `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- FileSearch respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileSearchToolCall) RawJSON() string { return r.JSON.raw }
-func (r *FileSearchToolCall) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// For now, this is always going to be an empty object.
-type FileSearchToolCallFileSearch struct {
- // The ranking options for the file search.
- RankingOptions FileSearchToolCallFileSearchRankingOptions `json:"ranking_options"`
- // The results of the file search.
- Results []FileSearchToolCallFileSearchResult `json:"results"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- RankingOptions respjson.Field
- Results respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileSearchToolCallFileSearch) RawJSON() string { return r.JSON.raw }
-func (r *FileSearchToolCallFileSearch) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The ranking options for the file search.
-type FileSearchToolCallFileSearchRankingOptions struct {
- // The ranker to use for the file search. If not specified will use the `auto`
- // ranker.
- //
- // Any of "auto", "default_2024_08_21".
- Ranker string `json:"ranker,required"`
- // The score threshold for the file search. All values must be a floating point
- // number between 0 and 1.
- ScoreThreshold float64 `json:"score_threshold,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Ranker respjson.Field
- ScoreThreshold respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileSearchToolCallFileSearchRankingOptions) RawJSON() string { return r.JSON.raw }
-func (r *FileSearchToolCallFileSearchRankingOptions) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// A result instance of the file search.
-type FileSearchToolCallFileSearchResult struct {
- // The ID of the file that result was found in.
- FileID string `json:"file_id,required"`
- // The name of the file that result was found in.
- FileName string `json:"file_name,required"`
- // The score of the result. All values must be a floating point number between 0
- // and 1.
- Score float64 `json:"score,required"`
- // The content of the result that was found. The content is only included if
- // requested via the include query parameter.
- Content []FileSearchToolCallFileSearchResultContent `json:"content"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileID respjson.Field
- FileName respjson.Field
- Score respjson.Field
- Content respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileSearchToolCallFileSearchResult) RawJSON() string { return r.JSON.raw }
-func (r *FileSearchToolCallFileSearchResult) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FileSearchToolCallFileSearchResultContent struct {
- // The text content of the file.
- Text string `json:"text"`
- // The type of the content.
- //
- // Any of "text".
- Type string `json:"type"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Text respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileSearchToolCallFileSearchResultContent) RawJSON() string { return r.JSON.raw }
-func (r *FileSearchToolCallFileSearchResultContent) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FileSearchToolCallDelta struct {
- // For now, this is always going to be an empty object.
- FileSearch any `json:"file_search,required"`
- // The index of the tool call in the tool calls array.
- Index int64 `json:"index,required"`
- // The type of tool call. This is always going to be `file_search` for this type of
- // tool call.
- Type constant.FileSearch `json:"type,required"`
- // The ID of the tool call object.
- ID string `json:"id"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- FileSearch respjson.Field
- Index respjson.Field
- Type respjson.Field
- ID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FileSearchToolCallDelta) RawJSON() string { return r.JSON.raw }
-func (r *FileSearchToolCallDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FunctionToolCall struct {
- // The ID of the tool call object.
- ID string `json:"id,required"`
- // The definition of the function that was called.
- Function FunctionToolCallFunction `json:"function,required"`
- // The type of tool call. This is always going to be `function` for this type of
- // tool call.
- Type constant.Function `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- Function respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FunctionToolCall) RawJSON() string { return r.JSON.raw }
-func (r *FunctionToolCall) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The definition of the function that was called.
-type FunctionToolCallFunction struct {
- // The arguments passed to the function.
- Arguments string `json:"arguments,required"`
- // The name of the function.
- Name string `json:"name,required"`
- // The output of the function. This will be `null` if the outputs have not been
- // [submitted](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)
- // yet.
- Output string `json:"output,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Arguments respjson.Field
- Name respjson.Field
- Output respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FunctionToolCallFunction) RawJSON() string { return r.JSON.raw }
-func (r *FunctionToolCallFunction) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FunctionToolCallDelta struct {
- // The index of the tool call in the tool calls array.
- Index int64 `json:"index,required"`
- // The type of tool call. This is always going to be `function` for this type of
- // tool call.
- Type constant.Function `json:"type,required"`
- // The ID of the tool call object.
- ID string `json:"id"`
- // The definition of the function that was called.
- Function FunctionToolCallDeltaFunction `json:"function"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- ID respjson.Field
- Function respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FunctionToolCallDelta) RawJSON() string { return r.JSON.raw }
-func (r *FunctionToolCallDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The definition of the function that was called.
-type FunctionToolCallDeltaFunction struct {
- // The arguments passed to the function.
- Arguments string `json:"arguments"`
- // The name of the function.
- Name string `json:"name"`
- // The output of the function. This will be `null` if the outputs have not been
- // [submitted](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)
- // yet.
- Output string `json:"output,nullable"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Arguments respjson.Field
- Name respjson.Field
- Output respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FunctionToolCallDeltaFunction) RawJSON() string { return r.JSON.raw }
-func (r *FunctionToolCallDeltaFunction) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Details of the message creation by the run step.
-type MessageCreationStepDetails struct {
- MessageCreation MessageCreationStepDetailsMessageCreation `json:"message_creation,required"`
- // Always `message_creation`.
- Type constant.MessageCreation `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- MessageCreation respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r MessageCreationStepDetails) RawJSON() string { return r.JSON.raw }
-func (r *MessageCreationStepDetails) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type MessageCreationStepDetailsMessageCreation struct {
- // The ID of the message that was created by this run step.
- MessageID string `json:"message_id,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- MessageID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r MessageCreationStepDetailsMessageCreation) RawJSON() string { return r.JSON.raw }
-func (r *MessageCreationStepDetailsMessageCreation) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Represents a step in execution of a run.
-type RunStep struct {
- // The identifier of the run step, which can be referenced in API endpoints.
- ID string `json:"id,required"`
- // The ID of the
- // [assistant](https://platform.openai.com/docs/api-reference/assistants)
- // associated with the run step.
- AssistantID string `json:"assistant_id,required"`
- // The Unix timestamp (in seconds) for when the run step was cancelled.
- CancelledAt int64 `json:"cancelled_at,required"`
- // The Unix timestamp (in seconds) for when the run step completed.
- CompletedAt int64 `json:"completed_at,required"`
- // The Unix timestamp (in seconds) for when the run step was created.
- CreatedAt int64 `json:"created_at,required"`
- // The Unix timestamp (in seconds) for when the run step expired. A step is
- // considered expired if the parent run is expired.
- ExpiredAt int64 `json:"expired_at,required"`
- // The Unix timestamp (in seconds) for when the run step failed.
- FailedAt int64 `json:"failed_at,required"`
- // The last error associated with this run step. Will be `null` if there are no
- // errors.
- LastError RunStepLastError `json:"last_error,required"`
- // Set of 16 key-value pairs that can be attached to an object. This can be useful
- // for storing additional information about the object in a structured format, and
- // querying for objects via API or the dashboard.
- //
- // Keys are strings with a maximum length of 64 characters. Values are strings with
- // a maximum length of 512 characters.
- Metadata shared.Metadata `json:"metadata,required"`
- // The object type, which is always `thread.run.step`.
- Object constant.ThreadRunStep `json:"object,required"`
- // The ID of the [run](https://platform.openai.com/docs/api-reference/runs) that
- // this run step is a part of.
- RunID string `json:"run_id,required"`
- // The status of the run step, which can be either `in_progress`, `cancelled`,
- // `failed`, `completed`, or `expired`.
- //
- // Any of "in_progress", "cancelled", "failed", "completed", "expired".
- Status RunStepStatus `json:"status,required"`
- // The details of the run step.
- StepDetails RunStepStepDetailsUnion `json:"step_details,required"`
- // The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)
- // that was run.
- ThreadID string `json:"thread_id,required"`
- // The type of run step, which can be either `message_creation` or `tool_calls`.
- //
- // Any of "message_creation", "tool_calls".
- Type RunStepType `json:"type,required"`
- // Usage statistics related to the run step. This value will be `null` while the
- // run step's status is `in_progress`.
- Usage RunStepUsage `json:"usage,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- AssistantID respjson.Field
- CancelledAt respjson.Field
- CompletedAt respjson.Field
- CreatedAt respjson.Field
- ExpiredAt respjson.Field
- FailedAt respjson.Field
- LastError respjson.Field
- Metadata respjson.Field
- Object respjson.Field
- RunID respjson.Field
- Status respjson.Field
- StepDetails respjson.Field
- ThreadID respjson.Field
- Type respjson.Field
- Usage respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunStep) RawJSON() string { return r.JSON.raw }
-func (r *RunStep) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The last error associated with this run step. Will be `null` if there are no
-// errors.
-type RunStepLastError struct {
- // One of `server_error` or `rate_limit_exceeded`.
- //
- // Any of "server_error", "rate_limit_exceeded".
- Code string `json:"code,required"`
- // A human-readable description of the error.
- Message string `json:"message,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Code respjson.Field
- Message respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunStepLastError) RawJSON() string { return r.JSON.raw }
-func (r *RunStepLastError) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The status of the run step, which can be either `in_progress`, `cancelled`,
-// `failed`, `completed`, or `expired`.
-type RunStepStatus string
-
-const (
- RunStepStatusInProgress RunStepStatus = "in_progress"
- RunStepStatusCancelled RunStepStatus = "cancelled"
- RunStepStatusFailed RunStepStatus = "failed"
- RunStepStatusCompleted RunStepStatus = "completed"
- RunStepStatusExpired RunStepStatus = "expired"
-)
-
-// RunStepStepDetailsUnion contains all possible properties and values from
-// [MessageCreationStepDetails], [ToolCallsStepDetails].
-//
-// Use the [RunStepStepDetailsUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type RunStepStepDetailsUnion struct {
- // This field is from variant [MessageCreationStepDetails].
- MessageCreation MessageCreationStepDetailsMessageCreation `json:"message_creation"`
- // Any of "message_creation", "tool_calls".
- Type string `json:"type"`
- // This field is from variant [ToolCallsStepDetails].
- ToolCalls []ToolCallUnion `json:"tool_calls"`
- JSON struct {
- MessageCreation respjson.Field
- Type respjson.Field
- ToolCalls respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyRunStepStepDetails is implemented by each variant of
-// [RunStepStepDetailsUnion] to add type safety for the return type of
-// [RunStepStepDetailsUnion.AsAny]
-type anyRunStepStepDetails interface {
- implRunStepStepDetailsUnion()
-}
-
-func (MessageCreationStepDetails) implRunStepStepDetailsUnion() {}
-func (ToolCallsStepDetails) implRunStepStepDetailsUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := RunStepStepDetailsUnion.AsAny().(type) {
-// case openai.MessageCreationStepDetails:
-// case openai.ToolCallsStepDetails:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u RunStepStepDetailsUnion) AsAny() anyRunStepStepDetails {
- switch u.Type {
- case "message_creation":
- return u.AsMessageCreation()
- case "tool_calls":
- return u.AsToolCalls()
- }
- return nil
-}
-
-func (u RunStepStepDetailsUnion) AsMessageCreation() (v MessageCreationStepDetails) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u RunStepStepDetailsUnion) AsToolCalls() (v ToolCallsStepDetails) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u RunStepStepDetailsUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *RunStepStepDetailsUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The type of run step, which can be either `message_creation` or `tool_calls`.
-type RunStepType string
-
-const (
- RunStepTypeMessageCreation RunStepType = "message_creation"
- RunStepTypeToolCalls RunStepType = "tool_calls"
-)
-
-// Usage statistics related to the run step. This value will be `null` while the
-// run step's status is `in_progress`.
-type RunStepUsage struct {
- // Number of completion tokens used over the course of the run step.
- CompletionTokens int64 `json:"completion_tokens,required"`
- // Number of prompt tokens used over the course of the run step.
- PromptTokens int64 `json:"prompt_tokens,required"`
- // Total number of tokens used (prompt + completion).
- TotalTokens int64 `json:"total_tokens,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- CompletionTokens respjson.Field
- PromptTokens respjson.Field
- TotalTokens respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunStepUsage) RawJSON() string { return r.JSON.raw }
-func (r *RunStepUsage) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// The delta containing the fields that have changed on the run step.
-type RunStepDelta struct {
- // The details of the run step.
- StepDetails RunStepDeltaStepDetailsUnion `json:"step_details"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- StepDetails respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunStepDelta) RawJSON() string { return r.JSON.raw }
-func (r *RunStepDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// RunStepDeltaStepDetailsUnion contains all possible properties and values from
-// [RunStepDeltaMessageDelta], [ToolCallDeltaObject].
-//
-// Use the [RunStepDeltaStepDetailsUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type RunStepDeltaStepDetailsUnion struct {
- // Any of "message_creation", "tool_calls".
- Type string `json:"type"`
- // This field is from variant [RunStepDeltaMessageDelta].
- MessageCreation RunStepDeltaMessageDeltaMessageCreation `json:"message_creation"`
- // This field is from variant [ToolCallDeltaObject].
- ToolCalls []ToolCallDeltaUnion `json:"tool_calls"`
- JSON struct {
- Type respjson.Field
- MessageCreation respjson.Field
- ToolCalls respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyRunStepDeltaStepDetails is implemented by each variant of
-// [RunStepDeltaStepDetailsUnion] to add type safety for the return type of
-// [RunStepDeltaStepDetailsUnion.AsAny]
-type anyRunStepDeltaStepDetails interface {
- implRunStepDeltaStepDetailsUnion()
-}
-
-func (RunStepDeltaMessageDelta) implRunStepDeltaStepDetailsUnion() {}
-func (ToolCallDeltaObject) implRunStepDeltaStepDetailsUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := RunStepDeltaStepDetailsUnion.AsAny().(type) {
-// case openai.RunStepDeltaMessageDelta:
-// case openai.ToolCallDeltaObject:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u RunStepDeltaStepDetailsUnion) AsAny() anyRunStepDeltaStepDetails {
- switch u.Type {
- case "message_creation":
- return u.AsMessageCreation()
- case "tool_calls":
- return u.AsToolCalls()
- }
- return nil
-}
-
-func (u RunStepDeltaStepDetailsUnion) AsMessageCreation() (v RunStepDeltaMessageDelta) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u RunStepDeltaStepDetailsUnion) AsToolCalls() (v ToolCallDeltaObject) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u RunStepDeltaStepDetailsUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *RunStepDeltaStepDetailsUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Represents a run step delta i.e. any changed fields on a run step during
-// streaming.
-type RunStepDeltaEvent struct {
- // The identifier of the run step, which can be referenced in API endpoints.
- ID string `json:"id,required"`
- // The delta containing the fields that have changed on the run step.
- Delta RunStepDelta `json:"delta,required"`
- // The object type, which is always `thread.run.step.delta`.
- Object constant.ThreadRunStepDelta `json:"object,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ID respjson.Field
- Delta respjson.Field
- Object respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunStepDeltaEvent) RawJSON() string { return r.JSON.raw }
-func (r *RunStepDeltaEvent) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Details of the message creation by the run step.
-type RunStepDeltaMessageDelta struct {
- // Always `message_creation`.
- Type constant.MessageCreation `json:"type,required"`
- MessageCreation RunStepDeltaMessageDeltaMessageCreation `json:"message_creation"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Type respjson.Field
- MessageCreation respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunStepDeltaMessageDelta) RawJSON() string { return r.JSON.raw }
-func (r *RunStepDeltaMessageDelta) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type RunStepDeltaMessageDeltaMessageCreation struct {
- // The ID of the message that was created by this run step.
- MessageID string `json:"message_id"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- MessageID respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r RunStepDeltaMessageDeltaMessageCreation) RawJSON() string { return r.JSON.raw }
-func (r *RunStepDeltaMessageDeltaMessageCreation) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type RunStepInclude string
-
-const (
- RunStepIncludeStepDetailsToolCallsFileSearchResultsContent RunStepInclude = "step_details.tool_calls[*].file_search.results[*].content"
-)
-
-// ToolCallUnion contains all possible properties and values from
-// [CodeInterpreterToolCall], [FileSearchToolCall], [FunctionToolCall].
-//
-// Use the [ToolCallUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type ToolCallUnion struct {
- ID string `json:"id"`
- // This field is from variant [CodeInterpreterToolCall].
- CodeInterpreter CodeInterpreterToolCallCodeInterpreter `json:"code_interpreter"`
- // Any of "code_interpreter", "file_search", "function".
- Type string `json:"type"`
- // This field is from variant [FileSearchToolCall].
- FileSearch FileSearchToolCallFileSearch `json:"file_search"`
- // This field is from variant [FunctionToolCall].
- Function FunctionToolCallFunction `json:"function"`
- JSON struct {
- ID respjson.Field
- CodeInterpreter respjson.Field
- Type respjson.Field
- FileSearch respjson.Field
- Function respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyToolCall is implemented by each variant of [ToolCallUnion] to add type safety
-// for the return type of [ToolCallUnion.AsAny]
-type anyToolCall interface {
- implToolCallUnion()
-}
-
-func (CodeInterpreterToolCall) implToolCallUnion() {}
-func (FileSearchToolCall) implToolCallUnion() {}
-func (FunctionToolCall) implToolCallUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := ToolCallUnion.AsAny().(type) {
-// case openai.CodeInterpreterToolCall:
-// case openai.FileSearchToolCall:
-// case openai.FunctionToolCall:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u ToolCallUnion) AsAny() anyToolCall {
- switch u.Type {
- case "code_interpreter":
- return u.AsCodeInterpreter()
- case "file_search":
- return u.AsFileSearch()
- case "function":
- return u.AsFunction()
- }
- return nil
-}
-
-func (u ToolCallUnion) AsCodeInterpreter() (v CodeInterpreterToolCall) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u ToolCallUnion) AsFileSearch() (v FileSearchToolCall) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u ToolCallUnion) AsFunction() (v FunctionToolCall) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u ToolCallUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *ToolCallUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToolCallDeltaUnion contains all possible properties and values from
-// [CodeInterpreterToolCallDelta], [FileSearchToolCallDelta],
-// [FunctionToolCallDelta].
-//
-// Use the [ToolCallDeltaUnion.AsAny] method to switch on the variant.
-//
-// Use the methods beginning with 'As' to cast the union to one of its variants.
-type ToolCallDeltaUnion struct {
- Index int64 `json:"index"`
- // Any of "code_interpreter", "file_search", "function".
- Type string `json:"type"`
- ID string `json:"id"`
- // This field is from variant [CodeInterpreterToolCallDelta].
- CodeInterpreter CodeInterpreterToolCallDeltaCodeInterpreter `json:"code_interpreter"`
- // This field is from variant [FileSearchToolCallDelta].
- FileSearch any `json:"file_search"`
- // This field is from variant [FunctionToolCallDelta].
- Function FunctionToolCallDeltaFunction `json:"function"`
- JSON struct {
- Index respjson.Field
- Type respjson.Field
- ID respjson.Field
- CodeInterpreter respjson.Field
- FileSearch respjson.Field
- Function respjson.Field
- raw string
- } `json:"-"`
-}
-
-// anyToolCallDelta is implemented by each variant of [ToolCallDeltaUnion] to add
-// type safety for the return type of [ToolCallDeltaUnion.AsAny]
-type anyToolCallDelta interface {
- implToolCallDeltaUnion()
-}
-
-func (CodeInterpreterToolCallDelta) implToolCallDeltaUnion() {}
-func (FileSearchToolCallDelta) implToolCallDeltaUnion() {}
-func (FunctionToolCallDelta) implToolCallDeltaUnion() {}
-
-// Use the following switch statement to find the correct variant
-//
-// switch variant := ToolCallDeltaUnion.AsAny().(type) {
-// case openai.CodeInterpreterToolCallDelta:
-// case openai.FileSearchToolCallDelta:
-// case openai.FunctionToolCallDelta:
-// default:
-// fmt.Errorf("no variant present")
-// }
-func (u ToolCallDeltaUnion) AsAny() anyToolCallDelta {
- switch u.Type {
- case "code_interpreter":
- return u.AsCodeInterpreter()
- case "file_search":
- return u.AsFileSearch()
- case "function":
- return u.AsFunction()
- }
- return nil
-}
-
-func (u ToolCallDeltaUnion) AsCodeInterpreter() (v CodeInterpreterToolCallDelta) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u ToolCallDeltaUnion) AsFileSearch() (v FileSearchToolCallDelta) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-func (u ToolCallDeltaUnion) AsFunction() (v FunctionToolCallDelta) {
- apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
- return
-}
-
-// Returns the unmodified JSON received from the API
-func (u ToolCallDeltaUnion) RawJSON() string { return u.JSON.raw }
-
-func (r *ToolCallDeltaUnion) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Details of the tool call.
-type ToolCallDeltaObject struct {
- // Always `tool_calls`.
- Type constant.ToolCalls `json:"type,required"`
- // An array of tool calls the run step was involved in. These can be associated
- // with one of three types of tools: `code_interpreter`, `file_search`, or
- // `function`.
- ToolCalls []ToolCallDeltaUnion `json:"tool_calls"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Type respjson.Field
- ToolCalls respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ToolCallDeltaObject) RawJSON() string { return r.JSON.raw }
-func (r *ToolCallDeltaObject) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// Details of the tool call.
-type ToolCallsStepDetails struct {
- // An array of tool calls the run step was involved in. These can be associated
- // with one of three types of tools: `code_interpreter`, `file_search`, or
- // `function`.
- ToolCalls []ToolCallUnion `json:"tool_calls,required"`
- // Always `tool_calls`.
- Type constant.ToolCalls `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- ToolCalls respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ToolCallsStepDetails) RawJSON() string { return r.JSON.raw }
-func (r *ToolCallsStepDetails) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type BetaThreadRunStepGetParams struct {
- // A list of additional fields to include in the response. Currently the only
- // supported value is `step_details.tool_calls[*].file_search.results[*].content`
- // to fetch the file search result content.
- //
- // See the
- // [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
- // for more information.
- Include []RunStepInclude `query:"include,omitzero" json:"-"`
- paramObj
-}
-
-// URLQuery serializes [BetaThreadRunStepGetParams]'s query parameters as
-// `url.Values`.
-func (r BetaThreadRunStepGetParams) URLQuery() (v url.Values, err error) {
- return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
- ArrayFormat: apiquery.ArrayQueryFormatBrackets,
- NestedFormat: apiquery.NestedQueryFormatBrackets,
- })
-}
-
-type BetaThreadRunStepListParams struct {
- // A cursor for use in pagination. `after` is an object ID that defines your place
- // in the list. For instance, if you make a list request and receive 100 objects,
- // ending with obj_foo, your subsequent call can include after=obj_foo in order to
- // fetch the next page of the list.
- After param.Opt[string] `query:"after,omitzero" json:"-"`
- // A cursor for use in pagination. `before` is an object ID that defines your place
- // in the list. For instance, if you make a list request and receive 100 objects,
- // starting with obj_foo, your subsequent call can include before=obj_foo in order
- // to fetch the previous page of the list.
- Before param.Opt[string] `query:"before,omitzero" json:"-"`
- // A limit on the number of objects to be returned. Limit can range between 1 and
- // 100, and the default is 20.
- Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
- // A list of additional fields to include in the response. Currently the only
- // supported value is `step_details.tool_calls[*].file_search.results[*].content`
- // to fetch the file search result content.
- //
- // See the
- // [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
- // for more information.
- Include []RunStepInclude `query:"include,omitzero" json:"-"`
- // Sort order by the `created_at` timestamp of the objects. `asc` for ascending
- // order and `desc` for descending order.
- //
- // Any of "asc", "desc".
- Order BetaThreadRunStepListParamsOrder `query:"order,omitzero" json:"-"`
- paramObj
-}
-
-// URLQuery serializes [BetaThreadRunStepListParams]'s query parameters as
-// `url.Values`.
-func (r BetaThreadRunStepListParams) URLQuery() (v url.Values, err error) {
- return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
- ArrayFormat: apiquery.ArrayQueryFormatBrackets,
- NestedFormat: apiquery.NestedQueryFormatBrackets,
- })
-}
-
-// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
-// order and `desc` for descending order.
-type BetaThreadRunStepListParamsOrder string
-
-const (
- BetaThreadRunStepListParamsOrderAsc BetaThreadRunStepListParamsOrder = "asc"
- BetaThreadRunStepListParamsOrderDesc BetaThreadRunStepListParamsOrder = "desc"
-)
diff --git a/betathreadrunstep_test.go b/betathreadrunstep_test.go
deleted file mode 100644
index 7da3a8e8..00000000
--- a/betathreadrunstep_test.go
+++ /dev/null
@@ -1,77 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-package openai_test
-
-import (
- "context"
- "errors"
- "os"
- "testing"
-
- "github.com/openai/openai-go"
- "github.com/openai/openai-go/internal/testutil"
- "github.com/openai/openai-go/option"
-)
-
-func TestBetaThreadRunStepGetWithOptionalParams(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.Beta.Threads.Runs.Steps.Get(
- context.TODO(),
- "thread_id",
- "run_id",
- "step_id",
- openai.BetaThreadRunStepGetParams{
- Include: []openai.RunStepInclude{openai.RunStepIncludeStepDetailsToolCallsFileSearchResultsContent},
- },
- )
- 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())
- }
-}
-
-func TestBetaThreadRunStepListWithOptionalParams(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.Beta.Threads.Runs.Steps.List(
- context.TODO(),
- "thread_id",
- "run_id",
- openai.BetaThreadRunStepListParams{
- After: openai.String("after"),
- Before: openai.String("before"),
- Include: []openai.RunStepInclude{openai.RunStepIncludeStepDetailsToolCallsFileSearchResultsContent},
- Limit: openai.Int(0),
- Order: openai.BetaThreadRunStepListParamsOrderAsc,
- },
- )
- 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())
- }
-}
diff --git a/chatcompletion.go b/chatcompletion.go
index bb490e79..874bcb1c 100644
--- a/chatcompletion.go
+++ b/chatcompletion.go
@@ -360,8 +360,8 @@ func (r *ChatCompletionAssistantMessageParamAudio) UnmarshalJSON(data []byte) er
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionAssistantMessageParamContentUnion struct {
- OfString param.Opt[string] `json:",omitzero,inline"`
- OfArrayOfContentParts []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion `json:",omitzero,inline"`
+ OfString param.Opt[string] `json:",omitzero,inline"`
+ OfArrayOfContentParts []ChatCompletionAssistantMessagePartUnion `json:",omitzero,inline"`
paramUnion
}
@@ -384,20 +384,20 @@ func (u *ChatCompletionAssistantMessageParamContentUnion) asAny() any {
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
-type ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion struct {
+type ChatCompletionAssistantMessagePartUnion struct {
OfText *ChatCompletionContentPartTextParam `json:",omitzero,inline"`
OfRefusal *ChatCompletionContentPartRefusalParam `json:",omitzero,inline"`
paramUnion
}
-func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion](u.OfText, u.OfRefusal)
+func (u ChatCompletionAssistantMessagePartUnion) MarshalJSON() ([]byte, error) {
+ return param.MarshalUnion[ChatCompletionAssistantMessagePartUnion](u.OfText, u.OfRefusal)
}
-func (u *ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) UnmarshalJSON(data []byte) error {
+func (u *ChatCompletionAssistantMessagePartUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
-func (u *ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) asAny() any {
+func (u *ChatCompletionAssistantMessagePartUnion) asAny() any {
if !param.IsOmitted(u.OfText) {
return u.OfText
} else if !param.IsOmitted(u.OfRefusal) {
@@ -407,7 +407,7 @@ func (u *ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) asAn
}
// Returns a pointer to the underlying variant's property, if present.
-func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetText() *string {
+func (u ChatCompletionAssistantMessagePartUnion) GetText() *string {
if vt := u.OfText; vt != nil {
return &vt.Text
}
@@ -415,7 +415,7 @@ func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetTe
}
// Returns a pointer to the underlying variant's property, if present.
-func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetRefusal() *string {
+func (u ChatCompletionAssistantMessagePartUnion) GetRefusal() *string {
if vt := u.OfRefusal; vt != nil {
return &vt.Refusal
}
@@ -423,7 +423,7 @@ func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetRe
}
// Returns a pointer to the underlying variant's property, if present.
-func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetType() *string {
+func (u ChatCompletionAssistantMessagePartUnion) GetType() *string {
if vt := u.OfText; vt != nil {
return (*string)(&vt.Type)
} else if vt := u.OfRefusal; vt != nil {
@@ -433,7 +433,7 @@ func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetTy
}
func init() {
- apijson.RegisterUnion[ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion](
+ apijson.RegisterUnion[ChatCompletionAssistantMessagePartUnion](
"type",
apijson.Discriminator[ChatCompletionContentPartTextParam]("text"),
apijson.Discriminator[ChatCompletionContentPartRefusalParam]("refusal"),
@@ -669,8 +669,8 @@ type ChatCompletionChunkChoiceDelta struct {
// The role of the author of this message.
//
// Any of "developer", "system", "user", "assistant", "tool".
- Role string `json:"role"`
- ToolCalls []ChatCompletionChunkChoiceDeltaToolCall `json:"tool_calls"`
+ Role string `json:"role"`
+ ToolCalls []ChatCompletionToolCallDelta `json:"tool_calls"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Content respjson.Field
@@ -716,7 +716,7 @@ func (r *ChatCompletionChunkChoiceDeltaFunctionCall) UnmarshalJSON(data []byte)
return apijson.UnmarshalRoot(data, r)
}
-type ChatCompletionChunkChoiceDeltaToolCall struct {
+type ChatCompletionToolCallDelta struct {
Index int64 `json:"index,required"`
// The ID of the tool call.
ID string `json:"id"`
@@ -737,8 +737,8 @@ type ChatCompletionChunkChoiceDeltaToolCall struct {
}
// Returns the unmodified JSON received from the API
-func (r ChatCompletionChunkChoiceDeltaToolCall) RawJSON() string { return r.JSON.raw }
-func (r *ChatCompletionChunkChoiceDeltaToolCall) UnmarshalJSON(data []byte) error {
+func (r ChatCompletionToolCallDelta) RawJSON() string { return r.JSON.raw }
+func (r *ChatCompletionToolCallDelta) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
@@ -823,13 +823,13 @@ func ImageContentPart(imageURL ChatCompletionContentPartImageImageURLParam) Chat
return ChatCompletionContentPartUnionParam{OfImageURL: &variant}
}
-func InputAudioContentPart(inputAudio ChatCompletionContentPartInputAudioInputAudioParam) ChatCompletionContentPartUnionParam {
+func InputAudioContentPart(inputAudio ChatCompletionInputAudioDataParam) ChatCompletionContentPartUnionParam {
var variant ChatCompletionContentPartInputAudioParam
variant.InputAudio = inputAudio
return ChatCompletionContentPartUnionParam{OfInputAudio: &variant}
}
-func FileContentPart(file ChatCompletionContentPartFileFileParam) ChatCompletionContentPartUnionParam {
+func FileContentPart(file ChatCompletionFileContentPartParam) ChatCompletionContentPartUnionParam {
var variant ChatCompletionContentPartFileParam
variant.File = file
return ChatCompletionContentPartUnionParam{OfFile: &variant}
@@ -883,7 +883,7 @@ func (u ChatCompletionContentPartUnionParam) GetImageURL() *ChatCompletionConten
}
// Returns a pointer to the underlying variant's property, if present.
-func (u ChatCompletionContentPartUnionParam) GetInputAudio() *ChatCompletionContentPartInputAudioInputAudioParam {
+func (u ChatCompletionContentPartUnionParam) GetInputAudio() *ChatCompletionInputAudioDataParam {
if vt := u.OfInputAudio; vt != nil {
return &vt.InputAudio
}
@@ -891,7 +891,7 @@ func (u ChatCompletionContentPartUnionParam) GetInputAudio() *ChatCompletionCont
}
// Returns a pointer to the underlying variant's property, if present.
-func (u ChatCompletionContentPartUnionParam) GetFile() *ChatCompletionContentPartFileFileParam {
+func (u ChatCompletionContentPartUnionParam) GetFile() *ChatCompletionFileContentPartParam {
if vt := u.OfFile; vt != nil {
return &vt.File
}
@@ -927,7 +927,7 @@ func init() {
//
// The properties File, Type are required.
type ChatCompletionContentPartFileParam struct {
- File ChatCompletionContentPartFileFileParam `json:"file,omitzero,required"`
+ File ChatCompletionFileContentPartParam `json:"file,omitzero,required"`
// The type of the content part. Always `file`.
//
// This field can be elided, and will marshal its zero value as "file".
@@ -943,7 +943,7 @@ func (r *ChatCompletionContentPartFileParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
-type ChatCompletionContentPartFileFileParam struct {
+type ChatCompletionFileContentPartParam struct {
// The base64 encoded file data, used when passing the file to the model as a
// string.
FileData param.Opt[string] `json:"file_data,omitzero"`
@@ -954,11 +954,11 @@ type ChatCompletionContentPartFileFileParam struct {
paramObj
}
-func (r ChatCompletionContentPartFileFileParam) MarshalJSON() (data []byte, err error) {
- type shadow ChatCompletionContentPartFileFileParam
+func (r ChatCompletionFileContentPartParam) MarshalJSON() (data []byte, err error) {
+ type shadow ChatCompletionFileContentPartParam
return param.MarshalObject(r, (*shadow)(&r))
}
-func (r *ChatCompletionContentPartFileFileParam) UnmarshalJSON(data []byte) error {
+func (r *ChatCompletionFileContentPartParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
@@ -1012,7 +1012,7 @@ func init() {
//
// The properties InputAudio, Type are required.
type ChatCompletionContentPartInputAudioParam struct {
- InputAudio ChatCompletionContentPartInputAudioInputAudioParam `json:"input_audio,omitzero,required"`
+ InputAudio ChatCompletionInputAudioDataParam `json:"input_audio,omitzero,required"`
// The type of the content part. Always `input_audio`.
//
// This field can be elided, and will marshal its zero value as "input_audio".
@@ -1029,7 +1029,7 @@ func (r *ChatCompletionContentPartInputAudioParam) UnmarshalJSON(data []byte) er
}
// The properties Data, Format are required.
-type ChatCompletionContentPartInputAudioInputAudioParam struct {
+type ChatCompletionInputAudioDataParam struct {
// Base64 encoded audio data.
Data string `json:"data,required"`
// The format of the encoded audio data. Currently supports "wav" and "mp3".
@@ -1039,16 +1039,16 @@ type ChatCompletionContentPartInputAudioInputAudioParam struct {
paramObj
}
-func (r ChatCompletionContentPartInputAudioInputAudioParam) MarshalJSON() (data []byte, err error) {
- type shadow ChatCompletionContentPartInputAudioInputAudioParam
+func (r ChatCompletionInputAudioDataParam) MarshalJSON() (data []byte, err error) {
+ type shadow ChatCompletionInputAudioDataParam
return param.MarshalObject(r, (*shadow)(&r))
}
-func (r *ChatCompletionContentPartInputAudioInputAudioParam) UnmarshalJSON(data []byte) error {
+func (r *ChatCompletionInputAudioDataParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
func init() {
- apijson.RegisterFieldValidator[ChatCompletionContentPartInputAudioInputAudioParam](
+ apijson.RegisterFieldValidator[ChatCompletionInputAudioDataParam](
"format", "wav", "mp3",
)
}
@@ -1362,12 +1362,12 @@ func (r *ChatCompletionMessageFunctionCall) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
-func AssistantMessage[T string | []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion](content T) ChatCompletionMessageParamUnion {
+func AssistantMessage[T string | []ChatCompletionAssistantMessagePartUnion](content T) ChatCompletionMessageParamUnion {
var assistant ChatCompletionAssistantMessageParam
switch v := any(content).(type) {
case string:
assistant.Content.OfString = param.NewOpt(v)
- case []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion:
+ case []ChatCompletionAssistantMessagePartUnion:
assistant.Content.OfArrayOfContentParts = v
}
return ChatCompletionMessageParamUnion{OfAssistant: &assistant}
@@ -1563,7 +1563,7 @@ func (u ChatCompletionMessageParamUnion) GetContent() (res chatCompletionMessage
// Can have the runtime types [*string], [_[]ChatCompletionContentPartTextParam],
// [_[]ChatCompletionContentPartUnionParam],
-// [\*[]ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion]
+// [\*[]ChatCompletionAssistantMessagePartUnion]
type chatCompletionMessageParamUnionContent struct{ any }
// Use the following switch statement to get the type of the union:
@@ -1572,7 +1572,7 @@ type chatCompletionMessageParamUnionContent struct{ any }
// case *string:
// case *[]openai.ChatCompletionContentPartTextParam:
// case *[]openai.ChatCompletionContentPartUnionParam:
-// case *[]openai.ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion:
+// case *[]openai.ChatCompletionAssistantMessagePartUnion:
// default:
// fmt.Errorf("not present")
// }
@@ -1946,7 +1946,7 @@ func (r *ChatCompletionToolParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
-func ChatCompletionToolChoiceOptionParamOfChatCompletionNamedToolChoice(function ChatCompletionNamedToolChoiceFunctionParam) ChatCompletionToolChoiceOptionUnionParam {
+func ToolChoiceNamedFunction(function ChatCompletionNamedToolChoiceFunctionParam) ChatCompletionToolChoiceOptionUnionParam {
var variant ChatCompletionNamedToolChoiceParam
variant.Function = function
return ChatCompletionToolChoiceOptionUnionParam{OfChatCompletionNamedToolChoice: &variant}
@@ -2459,7 +2459,7 @@ func (u *ChatCompletionNewParamsStopUnion) asAny() any {
// [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
type ChatCompletionNewParamsWebSearchOptions struct {
// Approximate location parameters for the search.
- UserLocation ChatCompletionNewParamsWebSearchOptionsUserLocation `json:"user_location,omitzero"`
+ UserLocation ChatCompletionWebSearchUserLocation `json:"user_location,omitzero"`
// High level guidance for the amount of context window space to use for the
// search. One of `low`, `medium`, or `high`. `medium` is the default.
//
@@ -2485,9 +2485,9 @@ func init() {
// Approximate location parameters for the search.
//
// The properties Approximate, Type are required.
-type ChatCompletionNewParamsWebSearchOptionsUserLocation struct {
+type ChatCompletionWebSearchUserLocation struct {
// Approximate location parameters for the search.
- Approximate ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate `json:"approximate,omitzero,required"`
+ Approximate ChatCompletionWebSearchApproximateUserLocation `json:"approximate,omitzero,required"`
// The type of location approximation. Always `approximate`.
//
// This field can be elided, and will marshal its zero value as "approximate".
@@ -2495,16 +2495,16 @@ type ChatCompletionNewParamsWebSearchOptionsUserLocation struct {
paramObj
}
-func (r ChatCompletionNewParamsWebSearchOptionsUserLocation) MarshalJSON() (data []byte, err error) {
- type shadow ChatCompletionNewParamsWebSearchOptionsUserLocation
+func (r ChatCompletionWebSearchUserLocation) MarshalJSON() (data []byte, err error) {
+ type shadow ChatCompletionWebSearchUserLocation
return param.MarshalObject(r, (*shadow)(&r))
}
-func (r *ChatCompletionNewParamsWebSearchOptionsUserLocation) UnmarshalJSON(data []byte) error {
+func (r *ChatCompletionWebSearchUserLocation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Approximate location parameters for the search.
-type ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate struct {
+type ChatCompletionWebSearchApproximateUserLocation struct {
// Free text input for the city of the user, e.g. `San Francisco`.
City param.Opt[string] `json:"city,omitzero"`
// The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of
@@ -2518,11 +2518,11 @@ type ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate struct {
paramObj
}
-func (r ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate) MarshalJSON() (data []byte, err error) {
- type shadow ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate
+func (r ChatCompletionWebSearchApproximateUserLocation) MarshalJSON() (data []byte, err error) {
+ type shadow ChatCompletionWebSearchApproximateUserLocation
return param.MarshalObject(r, (*shadow)(&r))
}
-func (r *ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate) UnmarshalJSON(data []byte) error {
+func (r *ChatCompletionWebSearchApproximateUserLocation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
diff --git a/chatcompletion_test.go b/chatcompletion_test.go
index 5578962c..70db55af 100644
--- a/chatcompletion_test.go
+++ b/chatcompletion_test.go
@@ -101,8 +101,8 @@ func TestChatCompletionNewWithOptionalParams(t *testing.T) {
User: openai.String("user-1234"),
WebSearchOptions: openai.ChatCompletionNewParamsWebSearchOptions{
SearchContextSize: "low",
- UserLocation: openai.ChatCompletionNewParamsWebSearchOptionsUserLocation{
- Approximate: openai.ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate{
+ UserLocation: openai.ChatCompletionWebSearchUserLocation{
+ Approximate: openai.ChatCompletionWebSearchApproximateUserLocation{
City: openai.String("city"),
Country: openai.String("country"),
Region: openai.String("region"),
diff --git a/examples/beta/assistant-streaming/main.go b/examples/beta/assistant-streaming/main.go
deleted file mode 100644
index 0991582b..00000000
--- a/examples/beta/assistant-streaming/main.go
+++ /dev/null
@@ -1,64 +0,0 @@
-package main
-
-import (
- "context"
- "fmt"
-
- "github.com/openai/openai-go"
-)
-
-func main() {
- client := openai.NewClient()
-
- ctx := context.Background()
-
- // Create an assistant
- println("Create an assistant")
- assistant, err := client.Beta.Assistants.New(ctx, openai.BetaAssistantNewParams{
- Name: openai.String("Math Tutor"),
- Instructions: openai.String("You are a personal math tutor. Write and run code to answer math questions."),
- Tools: []openai.AssistantToolUnionParam{
- {OfCodeInterpreter: &openai.CodeInterpreterToolParam{Type: "code_interpreter"}},
- },
- Model: openai.ChatModelGPT4_1106Preview,
- })
-
- if err != nil {
- panic(err)
- }
-
- // Create a thread
- println("Create an thread")
- thread, err := client.Beta.Threads.New(ctx, openai.BetaThreadNewParams{})
- if err != nil {
- panic(err)
- }
-
- // Create a message in the thread
- println("Create a message")
- _, err = client.Beta.Threads.Messages.New(ctx, thread.ID, openai.BetaThreadMessageNewParams{
- Role: openai.BetaThreadMessageNewParamsRoleAssistant,
- Content: openai.BetaThreadMessageNewParamsContentUnion{
- OfString: openai.String("I need to solve the equation `3x + 11 = 14`. Can you help me?"),
- },
- })
- if err != nil {
- panic(err)
- }
-
- // Create a run
- println("Create a run")
- stream := client.Beta.Threads.Runs.NewStreaming(ctx, thread.ID, openai.BetaThreadRunNewParams{
- AssistantID: assistant.ID,
- Instructions: openai.String("Please address the user as Jane Doe. The user has a premium account."),
- })
-
- for stream.Next() {
- evt := stream.Current()
- println(fmt.Sprintf("%T", evt.Data))
- }
-
- if stream.Err() != nil {
- panic(stream.Err())
- }
-}
diff --git a/examples/beta/assistants/main.go b/examples/beta/assistants/main.go
deleted file mode 100644
index 13ad3bc8..00000000
--- a/examples/beta/assistants/main.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package main
-
-import (
- "context"
-
- "github.com/openai/openai-go"
-)
-
-func main() {
- ctx := context.Background()
- client := openai.NewClient()
-
- assistant, err := client.Beta.Assistants.New(ctx, openai.BetaAssistantNewParams{
- Model: openai.ChatModelGPT4_1106Preview,
- Name: openai.String("Math tutor"),
- Instructions: openai.String("You are a personal math tutor. Write and run code to answer math questions."),
- })
-
- if err != nil {
- panic(err.Error())
- }
-
- println("Created and assistant with id", assistant.ID)
-
- prompt := "I need to solve the equation 3x + 11 = 14. Can you help me?"
-
- thread, err := client.Beta.Threads.New(ctx, openai.BetaThreadNewParams{
- Messages: []openai.BetaThreadNewParamsMessage{
- {
- Content: openai.BetaThreadNewParamsMessageContentUnion{
- OfString: openai.String(prompt),
- },
- Role: "user",
- },
- },
- })
-
- if err != nil {
- panic(err.Error())
- }
-
- println("Created thread with id", thread.ID)
-
- // pollIntervalMs of 0 uses default polling interval.
- run, err := client.Beta.Threads.Runs.NewAndPoll(ctx, thread.ID, openai.BetaThreadRunNewParams{
- AssistantID: assistant.ID,
- AdditionalInstructions: openai.String("Please address the user as Jane Doe. The user has a premium account."),
- }, 0)
-
- if err != nil {
- panic(err.Error())
- }
-
- if run.Status == openai.RunStatusCompleted {
- messages, err := client.Beta.Threads.Messages.List(ctx, thread.ID, openai.BetaThreadMessageListParams{})
-
- if err != nil {
- panic(err.Error())
- }
-
- for _, data := range messages.Data {
- for _, content := range data.Content {
- println(content.Text.Value)
- }
- }
- }
-}
diff --git a/examples/fine-tuning/main.go b/examples/fine-tuning/main.go
index f9a22bb6..29fbfc10 100644
--- a/examples/fine-tuning/main.go
+++ b/examples/fine-tuning/main.go
@@ -16,6 +16,9 @@ func main() {
fmt.Println("==> Uploading file")
data, err := os.Open("./fine-tuning-data.jsonl")
+ if err != nil {
+ panic(err)
+ }
file, err := client.Files.New(ctx, openai.FileNewParams{
File: data,
Purpose: openai.FilePurposeFineTune,
@@ -41,7 +44,7 @@ func main() {
fmt.Println("")
fmt.Println("==> Starting fine-tuning")
fineTune, err := client.FineTuning.Jobs.New(ctx, openai.FineTuningJobNewParams{
- Model: openai.ChatModelGPT3_5Turbo,
+ Model: openai.FineTuningJobNewParamsModelGPT3_5Turbo,
TrainingFile: file.ID,
})
if err != nil {
diff --git a/examples/responses-streaming/main.go b/examples/responses-streaming/main.go
index da1b26e1..830bbd48 100644
--- a/examples/responses-streaming/main.go
+++ b/examples/responses-streaming/main.go
@@ -23,7 +23,7 @@ func main() {
for stream.Next() {
data := stream.Current()
print(data.Delta)
- if data.JSON.Text.IsPresent() {
+ if data.JSON.Text.Valid() {
println()
println("Finished Content")
completeText = data.Text
diff --git a/examples/vectorstorefilebatch/main.go b/examples/vectorstorefilebatch/main.go
index c38786f6..a538faa7 100644
--- a/examples/vectorstorefilebatch/main.go
+++ b/examples/vectorstorefilebatch/main.go
@@ -60,12 +60,14 @@ func main() {
println("Listing the files from the vector store")
vector := openai.VectorStoreFileBatchListFilesParams{
- Order: openai.VectorStoreFileBatchListFilesParamsOrderAsc,
+ Order: openai.VectorStoreFileBatchListFilesParamsOrderAsc,
+ VectorStoreID: vectorStore.ID,
}
- println("Vector JSON:", vector.URLQuery())
+ q, _ := vector.URLQuery()
+ println("Vector JSON:", q)
- filesCursor, err := client.VectorStores.FileBatches.ListFiles(ctx, vectorStore.ID, batch.ID, vector)
+ filesCursor, err := client.VectorStores.FileBatches.ListFiles(ctx, batch.ID, vector)
if err != nil {
panic(err)
diff --git a/file.go b/file.go
index bc52c1e0..1a0fa36e 100644
--- a/file.go
+++ b/file.go
@@ -262,6 +262,9 @@ func (r FileNewParams) MarshalMultipart() (data []byte, contentType string, err
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
+ if err == nil {
+ err = apiform.WriteExtras(writer, r.ExtraFields())
+ }
if err != nil {
writer.Close()
return nil, "", err
diff --git a/finetuningcheckpointpermission.go b/finetuningcheckpointpermission.go
index 27992919..3062d8b8 100644
--- a/finetuningcheckpointpermission.go
+++ b/finetuningcheckpointpermission.go
@@ -90,9 +90,9 @@ func (r *FineTuningCheckpointPermissionService) Get(ctx context.Context, fineTun
//
// Organization owners can use this endpoint to delete a permission for a
// fine-tuned model checkpoint.
-func (r *FineTuningCheckpointPermissionService) Delete(ctx context.Context, fineTunedModelCheckpoint string, permissionID string, opts ...option.RequestOption) (res *FineTuningCheckpointPermissionDeleteResponse, err error) {
+func (r *FineTuningCheckpointPermissionService) Delete(ctx context.Context, permissionID string, body FineTuningCheckpointPermissionDeleteParams, opts ...option.RequestOption) (res *FineTuningCheckpointPermissionDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
- if fineTunedModelCheckpoint == "" {
+ if body.FineTunedModelCheckpoint == "" {
err = errors.New("missing required fine_tuned_model_checkpoint parameter")
return
}
@@ -100,7 +100,7 @@ func (r *FineTuningCheckpointPermissionService) Delete(ctx context.Context, fine
err = errors.New("missing required permission_id parameter")
return
}
- path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions/%s", fineTunedModelCheckpoint, permissionID)
+ path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions/%s", body.FineTunedModelCheckpoint, permissionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
@@ -252,3 +252,8 @@ const (
FineTuningCheckpointPermissionGetParamsOrderAscending FineTuningCheckpointPermissionGetParamsOrder = "ascending"
FineTuningCheckpointPermissionGetParamsOrderDescending FineTuningCheckpointPermissionGetParamsOrder = "descending"
)
+
+type FineTuningCheckpointPermissionDeleteParams struct {
+ FineTunedModelCheckpoint string `path:"fine_tuned_model_checkpoint,required" json:"-"`
+ paramObj
+}
diff --git a/finetuningcheckpointpermission_test.go b/finetuningcheckpointpermission_test.go
index 10a672a3..18e3e41a 100644
--- a/finetuningcheckpointpermission_test.go
+++ b/finetuningcheckpointpermission_test.go
@@ -86,8 +86,10 @@ func TestFineTuningCheckpointPermissionDelete(t *testing.T) {
)
_, err := client.FineTuning.Checkpoints.Permissions.Delete(
context.TODO(),
- "ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
"cp_zc4Q7MP6XxulcVzj4MZdwsAB",
+ openai.FineTuningCheckpointPermissionDeleteParams{
+ FineTunedModelCheckpoint: "ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
+ },
)
if err != nil {
var apierr *openai.Error
diff --git a/finetuningjob_test.go b/finetuningjob_test.go
index 40f9b353..9ec1196a 100644
--- a/finetuningjob_test.go
+++ b/finetuningjob_test.go
@@ -83,16 +83,16 @@ func TestFineTuningJobNewWithOptionalParams(t *testing.T) {
BatchSize: openai.ReinforcementHyperparametersBatchSizeUnion{
OfAuto: constant.ValueOf[constant.Auto](),
},
- ComputeMultiplier: openai.ReinforcementHyperparametersComputeMultiplierUnion{
+ ComputeMultiplier: openai.ReinforcementComputeMultiplierUnion{
OfAuto: constant.ValueOf[constant.Auto](),
},
EvalInterval: openai.ReinforcementHyperparametersEvalIntervalUnion{
OfAuto: constant.ValueOf[constant.Auto](),
},
- EvalSamples: openai.ReinforcementHyperparametersEvalSamplesUnion{
+ EvalSamples: openai.ReinforcementEvalSamplesUnion{
OfAuto: constant.ValueOf[constant.Auto](),
},
- LearningRateMultiplier: openai.ReinforcementHyperparametersLearningRateMultiplierUnion{
+ LearningRateMultiplier: openai.ReinforcementLearningRateMultiplierUnion{
OfAuto: constant.ValueOf[constant.Auto](),
},
NEpochs: openai.ReinforcementHyperparametersNEpochsUnion{
diff --git a/finetuningmethod.go b/finetuningmethod.go
index 1ccddaaa..95a594dd 100644
--- a/finetuningmethod.go
+++ b/finetuningmethod.go
@@ -396,14 +396,14 @@ type ReinforcementHyperparametersResp struct {
// parameters are updated less frequently, but with lower variance.
BatchSize ReinforcementHyperparametersBatchSizeUnionResp `json:"batch_size"`
// Multiplier on amount of compute used for exploring search space during training.
- ComputeMultiplier ReinforcementHyperparametersComputeMultiplierUnionResp `json:"compute_multiplier"`
+ ComputeMultiplier ReinforcementComputeMultiplierUnionResp `json:"compute_multiplier"`
// The number of training steps between evaluation runs.
EvalInterval ReinforcementHyperparametersEvalIntervalUnionResp `json:"eval_interval"`
// Number of evaluation samples to generate per training step.
- EvalSamples ReinforcementHyperparametersEvalSamplesUnionResp `json:"eval_samples"`
+ EvalSamples ReinforcementEvalSamplesUnionResp `json:"eval_samples"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
- LearningRateMultiplier ReinforcementHyperparametersLearningRateMultiplierUnionResp `json:"learning_rate_multiplier"`
+ LearningRateMultiplier ReinforcementLearningRateMultiplierUnionResp `json:"learning_rate_multiplier"`
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
NEpochs ReinforcementHyperparametersNEpochsUnionResp `json:"n_epochs"`
@@ -478,14 +478,14 @@ func (r *ReinforcementHyperparametersBatchSizeUnionResp) UnmarshalJSON(data []by
return apijson.UnmarshalRoot(data, r)
}
-// ReinforcementHyperparametersComputeMultiplierUnionResp contains all possible
-// properties and values from [constant.Auto], [float64].
+// ReinforcementComputeMultiplierUnionResp contains all possible properties and
+// values from [constant.Auto], [float64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfFloat]
-type ReinforcementHyperparametersComputeMultiplierUnionResp struct {
+type ReinforcementComputeMultiplierUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
@@ -498,20 +498,20 @@ type ReinforcementHyperparametersComputeMultiplierUnionResp struct {
} `json:"-"`
}
-func (u ReinforcementHyperparametersComputeMultiplierUnionResp) AsAuto() (v constant.Auto) {
+func (u ReinforcementComputeMultiplierUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
-func (u ReinforcementHyperparametersComputeMultiplierUnionResp) AsFloat() (v float64) {
+func (u ReinforcementComputeMultiplierUnionResp) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
-func (u ReinforcementHyperparametersComputeMultiplierUnionResp) RawJSON() string { return u.JSON.raw }
+func (u ReinforcementComputeMultiplierUnionResp) RawJSON() string { return u.JSON.raw }
-func (r *ReinforcementHyperparametersComputeMultiplierUnionResp) UnmarshalJSON(data []byte) error {
+func (r *ReinforcementComputeMultiplierUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
@@ -552,14 +552,14 @@ func (r *ReinforcementHyperparametersEvalIntervalUnionResp) UnmarshalJSON(data [
return apijson.UnmarshalRoot(data, r)
}
-// ReinforcementHyperparametersEvalSamplesUnionResp contains all possible
-// properties and values from [constant.Auto], [int64].
+// ReinforcementEvalSamplesUnionResp contains all possible properties and values
+// from [constant.Auto], [int64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfInt]
-type ReinforcementHyperparametersEvalSamplesUnionResp struct {
+type ReinforcementEvalSamplesUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
@@ -572,31 +572,31 @@ type ReinforcementHyperparametersEvalSamplesUnionResp struct {
} `json:"-"`
}
-func (u ReinforcementHyperparametersEvalSamplesUnionResp) AsAuto() (v constant.Auto) {
+func (u ReinforcementEvalSamplesUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
-func (u ReinforcementHyperparametersEvalSamplesUnionResp) AsInt() (v int64) {
+func (u ReinforcementEvalSamplesUnionResp) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
-func (u ReinforcementHyperparametersEvalSamplesUnionResp) RawJSON() string { return u.JSON.raw }
+func (u ReinforcementEvalSamplesUnionResp) RawJSON() string { return u.JSON.raw }
-func (r *ReinforcementHyperparametersEvalSamplesUnionResp) UnmarshalJSON(data []byte) error {
+func (r *ReinforcementEvalSamplesUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
-// ReinforcementHyperparametersLearningRateMultiplierUnionResp contains all
-// possible properties and values from [constant.Auto], [float64].
+// ReinforcementLearningRateMultiplierUnionResp contains all possible properties
+// and values from [constant.Auto], [float64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfFloat]
-type ReinforcementHyperparametersLearningRateMultiplierUnionResp struct {
+type ReinforcementLearningRateMultiplierUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
@@ -609,22 +609,20 @@ type ReinforcementHyperparametersLearningRateMultiplierUnionResp struct {
} `json:"-"`
}
-func (u ReinforcementHyperparametersLearningRateMultiplierUnionResp) AsAuto() (v constant.Auto) {
+func (u ReinforcementLearningRateMultiplierUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
-func (u ReinforcementHyperparametersLearningRateMultiplierUnionResp) AsFloat() (v float64) {
+func (u ReinforcementLearningRateMultiplierUnionResp) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
-func (u ReinforcementHyperparametersLearningRateMultiplierUnionResp) RawJSON() string {
- return u.JSON.raw
-}
+func (u ReinforcementLearningRateMultiplierUnionResp) RawJSON() string { return u.JSON.raw }
-func (r *ReinforcementHyperparametersLearningRateMultiplierUnionResp) UnmarshalJSON(data []byte) error {
+func (r *ReinforcementLearningRateMultiplierUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
@@ -681,14 +679,14 @@ type ReinforcementHyperparameters struct {
// parameters are updated less frequently, but with lower variance.
BatchSize ReinforcementHyperparametersBatchSizeUnion `json:"batch_size,omitzero"`
// Multiplier on amount of compute used for exploring search space during training.
- ComputeMultiplier ReinforcementHyperparametersComputeMultiplierUnion `json:"compute_multiplier,omitzero"`
+ ComputeMultiplier ReinforcementComputeMultiplierUnion `json:"compute_multiplier,omitzero"`
// The number of training steps between evaluation runs.
EvalInterval ReinforcementHyperparametersEvalIntervalUnion `json:"eval_interval,omitzero"`
// Number of evaluation samples to generate per training step.
- EvalSamples ReinforcementHyperparametersEvalSamplesUnion `json:"eval_samples,omitzero"`
+ EvalSamples ReinforcementEvalSamplesUnion `json:"eval_samples,omitzero"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
- LearningRateMultiplier ReinforcementHyperparametersLearningRateMultiplierUnion `json:"learning_rate_multiplier,omitzero"`
+ LearningRateMultiplier ReinforcementLearningRateMultiplierUnion `json:"learning_rate_multiplier,omitzero"`
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
NEpochs ReinforcementHyperparametersNEpochsUnion `json:"n_epochs,omitzero"`
@@ -736,21 +734,21 @@ func (u *ReinforcementHyperparametersBatchSizeUnion) asAny() any {
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
-type ReinforcementHyperparametersComputeMultiplierUnion struct {
+type ReinforcementComputeMultiplierUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
-func (u ReinforcementHyperparametersComputeMultiplierUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[ReinforcementHyperparametersComputeMultiplierUnion](u.OfAuto, u.OfFloat)
+func (u ReinforcementComputeMultiplierUnion) MarshalJSON() ([]byte, error) {
+ return param.MarshalUnion[ReinforcementComputeMultiplierUnion](u.OfAuto, u.OfFloat)
}
-func (u *ReinforcementHyperparametersComputeMultiplierUnion) UnmarshalJSON(data []byte) error {
+func (u *ReinforcementComputeMultiplierUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
-func (u *ReinforcementHyperparametersComputeMultiplierUnion) asAny() any {
+func (u *ReinforcementComputeMultiplierUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfFloat) {
@@ -788,21 +786,21 @@ func (u *ReinforcementHyperparametersEvalIntervalUnion) asAny() any {
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
-type ReinforcementHyperparametersEvalSamplesUnion struct {
+type ReinforcementEvalSamplesUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfInt param.Opt[int64] `json:",omitzero,inline"`
paramUnion
}
-func (u ReinforcementHyperparametersEvalSamplesUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[ReinforcementHyperparametersEvalSamplesUnion](u.OfAuto, u.OfInt)
+func (u ReinforcementEvalSamplesUnion) MarshalJSON() ([]byte, error) {
+ return param.MarshalUnion[ReinforcementEvalSamplesUnion](u.OfAuto, u.OfInt)
}
-func (u *ReinforcementHyperparametersEvalSamplesUnion) UnmarshalJSON(data []byte) error {
+func (u *ReinforcementEvalSamplesUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
-func (u *ReinforcementHyperparametersEvalSamplesUnion) asAny() any {
+func (u *ReinforcementEvalSamplesUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfInt) {
@@ -814,21 +812,21 @@ func (u *ReinforcementHyperparametersEvalSamplesUnion) asAny() any {
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
-type ReinforcementHyperparametersLearningRateMultiplierUnion struct {
+type ReinforcementLearningRateMultiplierUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
-func (u ReinforcementHyperparametersLearningRateMultiplierUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[ReinforcementHyperparametersLearningRateMultiplierUnion](u.OfAuto, u.OfFloat)
+func (u ReinforcementLearningRateMultiplierUnion) MarshalJSON() ([]byte, error) {
+ return param.MarshalUnion[ReinforcementLearningRateMultiplierUnion](u.OfAuto, u.OfFloat)
}
-func (u *ReinforcementHyperparametersLearningRateMultiplierUnion) UnmarshalJSON(data []byte) error {
+func (u *ReinforcementLearningRateMultiplierUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
-func (u *ReinforcementHyperparametersLearningRateMultiplierUnion) asAny() any {
+func (u *ReinforcementLearningRateMultiplierUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfFloat) {
diff --git a/image.go b/image.go
index c47b2139..dc4ee55b 100644
--- a/image.go
+++ b/image.go
@@ -201,6 +201,9 @@ func (r ImageNewVariationParams) MarshalMultipart() (data []byte, contentType st
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
+ if err == nil {
+ err = apiform.WriteExtras(writer, r.ExtraFields())
+ }
if err != nil {
writer.Close()
return nil, "", err
@@ -295,6 +298,9 @@ func (r ImageEditParams) MarshalMultipart() (data []byte, contentType string, er
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
+ if err == nil {
+ err = apiform.WriteExtras(writer, r.ExtraFields())
+ }
if err != nil {
writer.Close()
return nil, "", err
@@ -310,13 +316,13 @@ func (r ImageEditParams) MarshalMultipart() (data []byte, contentType string, er
//
// Use [param.IsOmitted] to confirm if a field is set.
type ImageEditParamsImageUnion struct {
- OfFile io.Reader `json:",omitzero,inline"`
- OfBinaryArray []io.Reader `json:",omitzero,inline"`
+ OfFile io.Reader `json:",omitzero,inline"`
+ OfFileArray []io.Reader `json:",omitzero,inline"`
paramUnion
}
func (u ImageEditParamsImageUnion) MarshalJSON() ([]byte, error) {
- return param.MarshalUnion[ImageEditParamsImageUnion](u.OfFile, u.OfBinaryArray)
+ return param.MarshalUnion[ImageEditParamsImageUnion](u.OfFile, u.OfFileArray)
}
func (u *ImageEditParamsImageUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
@@ -325,8 +331,8 @@ func (u *ImageEditParamsImageUnion) UnmarshalJSON(data []byte) error {
func (u *ImageEditParamsImageUnion) asAny() any {
if !param.IsOmitted(u.OfFile) {
return &u.OfFile
- } else if !param.IsOmitted(u.OfBinaryArray) {
- return &u.OfBinaryArray
+ } else if !param.IsOmitted(u.OfFileArray) {
+ return &u.OfFileArray
}
return nil
}
diff --git a/internal/apiform/encoder.go b/internal/apiform/encoder.go
index d088f076..f1bd1649 100644
--- a/internal/apiform/encoder.go
+++ b/internal/apiform/encoder.go
@@ -449,3 +449,17 @@ func (e *encoder) newMapEncoder(_ reflect.Type) encoderFunc {
return e.encodeMapEntries(key, value, writer)
}
}
+
+func WriteExtras(writer *multipart.Writer, extras map[string]any) (err error) {
+ for k, v := range extras {
+ str, ok := v.(string)
+ if !ok {
+ break
+ }
+ err = writer.WriteField(k, str)
+ if err != nil {
+ break
+ }
+ }
+ return
+}
diff --git a/internal/apijson/decoder.go b/internal/apijson/decoder.go
index e181b233..b3f1bf7a 100644
--- a/internal/apijson/decoder.go
+++ b/internal/apijson/decoder.go
@@ -461,7 +461,7 @@ func (d *decoderBuilder) newStructTypeDecoder(t reflect.Type) decoderFunc {
}
// Handle null [param.Opt]
- if itemNode.Type == gjson.Null && dest.Type().Implements(reflect.TypeOf((*param.Optional)(nil)).Elem()) {
+ if itemNode.Type == gjson.Null && dest.IsValid() && dest.Type().Implements(reflect.TypeOf((*param.Optional)(nil)).Elem()) {
dest.Addr().Interface().(json.Unmarshaler).UnmarshalJSON([]byte(itemNode.Raw))
continue
}
diff --git a/internal/apijson/decoderesp_test.go b/internal/apijson/decoderesp_test.go
new file mode 100644
index 00000000..f6ead8de
--- /dev/null
+++ b/internal/apijson/decoderesp_test.go
@@ -0,0 +1,30 @@
+package apijson_test
+
+import (
+ "encoding/json"
+ "github.com/openai/openai-go/internal/apijson"
+ "github.com/openai/openai-go/packages/respjson"
+ "testing"
+)
+
+type StructWithNullExtraField struct {
+ Results []string `json:"results,required"`
+ JSON struct {
+ Results respjson.Field
+ ExtraFields map[string]respjson.Field
+ raw string
+ } `json:"-"`
+}
+
+func (r *StructWithNullExtraField) UnmarshalJSON(data []byte) error {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func TestDecodeWithNullExtraField(t *testing.T) {
+ raw := `{"something_else":null}`
+ var dst *StructWithNullExtraField
+ err := json.Unmarshal([]byte(raw), &dst)
+ if err != nil {
+ t.Fatalf("error: %s", err.Error())
+ }
+}
diff --git a/internal/version.go b/internal/version.go
index 4ccf91c0..c42113a2 100644
--- a/internal/version.go
+++ b/internal/version.go
@@ -2,4 +2,4 @@
package internal
-const PackageVersion = "0.1.0-beta.11" // x-release-please-version
+const PackageVersion = "1.0.0" // x-release-please-version
diff --git a/packages/ssestream/ssestream.go b/packages/ssestream/ssestream.go
index 097a9098..6d9347fc 100644
--- a/packages/ssestream/ssestream.go
+++ b/packages/ssestream/ssestream.go
@@ -31,7 +31,9 @@ func NewDecoder(res *http.Response) Decoder {
if t, ok := decoderTypes[contentType]; ok {
decoder = t(res.Body)
} else {
- decoder = &eventStreamDecoder{rc: res.Body, rdr: bufio.NewReader(res.Body)}
+ scn := bufio.NewScanner(res.Body)
+ scn.Buffer(nil, bufio.MaxScanTokenSize<<4)
+ decoder = &eventStreamDecoder{rc: res.Body, scn: scn}
}
return decoder
}
@@ -51,48 +53,10 @@ type Event struct {
type eventStreamDecoder struct {
evt Event
rc io.ReadCloser
- rdr *bufio.Reader
+ scn *bufio.Scanner
err error
}
-func line(r *bufio.Reader) ([]byte, error) {
- var overflow bytes.Buffer
-
- // To prevent infinite loops, the failsafe stops when a line is
- // 100 times longer than the [io.Reader] default buffer size,
- // or after 20 failed attempts to find an end of line.
- for f := 0; f < 100; f++ {
- part, isPrefix, err := r.ReadLine()
- if err != nil {
- return nil, err
- }
-
- // Happy case, the line fits in the default buffer.
- if !isPrefix && overflow.Len() == 0 {
- return part, nil
- }
-
- // Overflow case, append to the buffer.
- if isPrefix || overflow.Len() > 0 {
- n, err := overflow.Write(part)
- if err != nil {
- return nil, err
- }
-
- // Didn't find an end of line, heavily increment the failsafe.
- if n != r.Size() {
- f += 5
- }
- }
-
- if !isPrefix {
- return overflow.Bytes(), nil
- }
- }
-
- return nil, fmt.Errorf("ssestream: too many attempts to read a line")
-}
-
func (s *eventStreamDecoder) Next() bool {
if s.err != nil {
return false
@@ -101,16 +65,8 @@ func (s *eventStreamDecoder) Next() bool {
event := ""
data := bytes.NewBuffer(nil)
- for {
- txt, err := line(s.rdr)
- if err == io.EOF {
- return false
- }
-
- if err != nil {
- s.err = err
- break
- }
+ for s.scn.Scan() {
+ txt := s.scn.Bytes()
// Dispatch event on an empty line
if len(txt) == 0 {
@@ -147,6 +103,10 @@ func (s *eventStreamDecoder) Next() bool {
}
}
+ if s.scn.Err() != nil {
+ s.err = s.scn.Err()
+ }
+
return false
}
diff --git a/polling.go b/polling.go
index 4f58f45f..1da5cd49 100644
--- a/polling.go
+++ b/polling.go
@@ -32,7 +32,9 @@ func (r *VectorStoreFileService) PollStatus(ctx context.Context, vectorStoreID s
opts = append(opts, mkPollingOptions(pollIntervalMs)...)
opts = append(opts, option.WithResponseInto(&raw))
for {
- file, err := r.Get(ctx, vectorStoreID, fileID, opts...)
+ file, err := r.Get(ctx, fileID, VectorStoreFileGetParams{
+ VectorStoreID: vectorStoreID,
+ }, opts...)
if err != nil {
return nil, fmt.Errorf("vector store file poll: received %w", err)
}
@@ -67,7 +69,9 @@ func (r *VectorStoreFileBatchService) PollStatus(ctx context.Context, vectorStor
opts = append(opts, option.WithResponseInto(&raw))
opts = append(opts, mkPollingOptions(pollIntervalMs)...)
for {
- batch, err := r.Get(ctx, vectorStoreID, batchID, opts...)
+ batch, err := r.Get(ctx, batchID, VectorStoreFileBatchGetParams{
+ VectorStoreID: vectorStoreID,
+ }, opts...)
if err != nil {
return nil, fmt.Errorf("vector store file batch poll: received %w", err)
}
@@ -93,42 +97,3 @@ func (r *VectorStoreFileBatchService) PollStatus(ctx context.Context, vectorStor
}
}
}
-
-// PollStatus waits until a Run is no longer in an incomplete state and returns it.
-// Pass 0 as pollIntervalMs to use the default polling interval of 1 second.
-func (r *BetaThreadRunService) PollStatus(ctx context.Context, threadID string, runID string, pollIntervalMs int, opts ...option.RequestOption) (res *Run, err error) {
- var raw *http.Response
- opts = append(opts, mkPollingOptions(pollIntervalMs)...)
- opts = append(opts, option.WithResponseInto(&raw))
- for {
- run, err := r.Get(ctx, threadID, runID, opts...)
- if err != nil {
- return nil, fmt.Errorf("thread run poll: received %w", err)
- }
-
- switch run.Status {
- case RunStatusInProgress,
- RunStatusQueued:
- if pollIntervalMs <= 0 {
- pollIntervalMs = getPollInterval(raw)
- }
- time.Sleep(time.Duration(pollIntervalMs) * time.Millisecond)
- case RunStatusRequiresAction,
- RunStatusCancelled,
- RunStatusCompleted,
- RunStatusFailed,
- RunStatusExpired,
- RunStatusIncomplete:
- return run, nil
- default:
- return nil, fmt.Errorf("invalid thread run status during polling: received %s", run.Status)
- }
-
- select {
- case <-ctx.Done():
- return nil, ctx.Err()
- default:
- break
- }
- }
-}
diff --git a/responses/aliases.go b/responses/aliases.go
index 47347fa6..e64d329e 100644
--- a/responses/aliases.go
+++ b/responses/aliases.go
@@ -256,12 +256,6 @@ const CompoundFilterTypeOr = shared.CompoundFilterTypeOr
// This is an alias to an internal type.
type CompoundFilterParam = shared.CompoundFilterParam
-// This is an alias to an internal type.
-type ErrorObject = shared.ErrorObject
-
-// This is an alias to an internal type.
-type FunctionDefinition = shared.FunctionDefinition
-
// This is an alias to an internal type.
type FunctionDefinitionParam = shared.FunctionDefinitionParam
@@ -369,18 +363,6 @@ type ResponseFormatJSONObject = shared.ResponseFormatJSONObject
// This is an alias to an internal type.
type ResponseFormatJSONObjectParam = shared.ResponseFormatJSONObjectParam
-// JSON Schema response format. Used to generate structured JSON responses. Learn
-// more about
-// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
-//
-// This is an alias to an internal type.
-type ResponseFormatJSONSchema = shared.ResponseFormatJSONSchema
-
-// Structured Outputs configuration options, including a JSON Schema.
-//
-// This is an alias to an internal type.
-type ResponseFormatJSONSchemaJSONSchema = shared.ResponseFormatJSONSchemaJSONSchema
-
// JSON Schema response format. Used to generate structured JSON responses. Learn
// more about
// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
diff --git a/responses/response.go b/responses/response.go
index c4d55754..2fbdb20c 100644
--- a/responses/response.go
+++ b/responses/response.go
@@ -1082,7 +1082,7 @@ type ResponseCodeInterpreterToolCallResultUnion struct {
// Any of "logs", "files".
Type string `json:"type"`
// This field is from variant [ResponseCodeInterpreterToolCallResultFiles].
- Files []ResponseCodeInterpreterToolCallResultFilesFile `json:"files"`
+ Files []ResponseCodeInterpreterFile `json:"files"`
JSON struct {
Logs respjson.Field
Type respjson.Field
@@ -1159,7 +1159,7 @@ func (r *ResponseCodeInterpreterToolCallResultLogs) UnmarshalJSON(data []byte) e
// The output of a code interpreter tool call that is a file.
type ResponseCodeInterpreterToolCallResultFiles struct {
- Files []ResponseCodeInterpreterToolCallResultFilesFile `json:"files,required"`
+ Files []ResponseCodeInterpreterFile `json:"files,required"`
// The type of the code interpreter file output. Always `files`.
Type constant.Files `json:"type,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
@@ -1177,7 +1177,7 @@ func (r *ResponseCodeInterpreterToolCallResultFiles) UnmarshalJSON(data []byte)
return apijson.UnmarshalRoot(data, r)
}
-type ResponseCodeInterpreterToolCallResultFilesFile struct {
+type ResponseCodeInterpreterFile struct {
// The ID of the file.
FileID string `json:"file_id,required"`
// The MIME type of the file.
@@ -1192,8 +1192,8 @@ type ResponseCodeInterpreterToolCallResultFilesFile struct {
}
// Returns the unmodified JSON received from the API
-func (r ResponseCodeInterpreterToolCallResultFilesFile) RawJSON() string { return r.JSON.raw }
-func (r *ResponseCodeInterpreterToolCallResultFilesFile) UnmarshalJSON(data []byte) error {
+func (r ResponseCodeInterpreterFile) RawJSON() string { return r.JSON.raw }
+func (r *ResponseCodeInterpreterFile) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
diff --git a/shared/constant/constants.go b/shared/constant/constants.go
index bde8d072..64a437ed 100644
--- a/shared/constant/constants.go
+++ b/shared/constant/constants.go
@@ -20,7 +20,6 @@ func ValueOf[T Constant[T]]() T {
type Approximate string // Always "approximate"
type Assistant string // Always "assistant"
-type AssistantDeleted string // Always "assistant.deleted"
type Auto string // Always "auto"
type Batch string // Always "batch"
type ChatCompletion string // Always "chat.completion"
@@ -28,7 +27,6 @@ type ChatCompletionChunk string // Always "chat.completion.c
type ChatCompletionDeleted string // Always "chat.completion.deleted"
type CheckpointPermission string // Always "checkpoint.permission"
type Click string // Always "click"
-type CodeInterpreter string // Always "code_interpreter"
type CodeInterpreterCall string // Always "code_interpreter_call"
type ComputerCallOutput string // Always "computer_call_output"
type ComputerScreenshot string // Always "computer_screenshot"
@@ -51,8 +49,6 @@ type FineTuningJobEvent string // Always "fine_tuning.job.e
type Function string // Always "function"
type FunctionCall string // Always "function_call"
type FunctionCallOutput string // Always "function_call_output"
-type Image string // Always "image"
-type ImageFile string // Always "image_file"
type ImageURL string // Always "image_url"
type InputAudio string // Always "input_audio"
type InputFile string // Always "input_file"
@@ -66,7 +62,6 @@ type LastActiveAt string // Always "last_active_at"
type List string // Always "list"
type Logs string // Always "logs"
type Message string // Always "message"
-type MessageCreation string // Always "message_creation"
type Model string // Always "model"
type Move string // Always "move"
type Multi string // Always "multi"
@@ -117,43 +112,12 @@ type Screenshot string // Always "screenshot"
type Scroll string // Always "scroll"
type Static string // Always "static"
type StringCheck string // Always "string_check"
-type SubmitToolOutputs string // Always "submit_tool_outputs"
type SummaryText string // Always "summary_text"
type System string // Always "system"
type Text string // Always "text"
type TextCompletion string // Always "text_completion"
type TextSimilarity string // Always "text_similarity"
-type Thread string // Always "thread"
-type ThreadCreated string // Always "thread.created"
-type ThreadDeleted string // Always "thread.deleted"
-type ThreadMessage string // Always "thread.message"
-type ThreadMessageCompleted string // Always "thread.message.completed"
-type ThreadMessageCreated string // Always "thread.message.created"
-type ThreadMessageDeleted string // Always "thread.message.deleted"
-type ThreadMessageDelta string // Always "thread.message.delta"
-type ThreadMessageInProgress string // Always "thread.message.in_progress"
-type ThreadMessageIncomplete string // Always "thread.message.incomplete"
-type ThreadRun string // Always "thread.run"
-type ThreadRunCancelled string // Always "thread.run.cancelled"
-type ThreadRunCancelling string // Always "thread.run.cancelling"
-type ThreadRunCompleted string // Always "thread.run.completed"
-type ThreadRunCreated string // Always "thread.run.created"
-type ThreadRunExpired string // Always "thread.run.expired"
-type ThreadRunFailed string // Always "thread.run.failed"
-type ThreadRunInProgress string // Always "thread.run.in_progress"
-type ThreadRunIncomplete string // Always "thread.run.incomplete"
-type ThreadRunQueued string // Always "thread.run.queued"
-type ThreadRunRequiresAction string // Always "thread.run.requires_action"
-type ThreadRunStep string // Always "thread.run.step"
-type ThreadRunStepCancelled string // Always "thread.run.step.cancelled"
-type ThreadRunStepCompleted string // Always "thread.run.step.completed"
-type ThreadRunStepCreated string // Always "thread.run.step.created"
-type ThreadRunStepDelta string // Always "thread.run.step.delta"
-type ThreadRunStepExpired string // Always "thread.run.step.expired"
-type ThreadRunStepFailed string // Always "thread.run.step.failed"
-type ThreadRunStepInProgress string // Always "thread.run.step.in_progress"
type Tool string // Always "tool"
-type ToolCalls string // Always "tool_calls"
type TranscriptTextDelta string // Always "transcript.text.delta"
type TranscriptTextDone string // Always "transcript.text.done"
type Type string // Always "type"
@@ -174,7 +138,6 @@ type WebSearchCall string // Always "web_search_call"
func (c Approximate) Default() Approximate { return "approximate" }
func (c Assistant) Default() Assistant { return "assistant" }
-func (c AssistantDeleted) Default() AssistantDeleted { return "assistant.deleted" }
func (c Auto) Default() Auto { return "auto" }
func (c Batch) Default() Batch { return "batch" }
func (c ChatCompletion) Default() ChatCompletion { return "chat.completion" }
@@ -182,7 +145,6 @@ func (c ChatCompletionChunk) Default() ChatCompletionChunk { return "chat.co
func (c ChatCompletionDeleted) Default() ChatCompletionDeleted { return "chat.completion.deleted" }
func (c CheckpointPermission) Default() CheckpointPermission { return "checkpoint.permission" }
func (c Click) Default() Click { return "click" }
-func (c CodeInterpreter) Default() CodeInterpreter { return "code_interpreter" }
func (c CodeInterpreterCall) Default() CodeInterpreterCall { return "code_interpreter_call" }
func (c ComputerCallOutput) Default() ComputerCallOutput { return "computer_call_output" }
func (c ComputerScreenshot) Default() ComputerScreenshot { return "computer_screenshot" }
@@ -207,8 +169,6 @@ func (c FineTuningJobEvent) Default() FineTuningJobEvent { return "fine_tuning.j
func (c Function) Default() Function { return "function" }
func (c FunctionCall) Default() FunctionCall { return "function_call" }
func (c FunctionCallOutput) Default() FunctionCallOutput { return "function_call_output" }
-func (c Image) Default() Image { return "image" }
-func (c ImageFile) Default() ImageFile { return "image_file" }
func (c ImageURL) Default() ImageURL { return "image_url" }
func (c InputAudio) Default() InputAudio { return "input_audio" }
func (c InputFile) Default() InputFile { return "input_file" }
@@ -222,7 +182,6 @@ func (c LastActiveAt) Default() LastActiveAt { return "last_active_a
func (c List) Default() List { return "list" }
func (c Logs) Default() Logs { return "logs" }
func (c Message) Default() Message { return "message" }
-func (c MessageCreation) Default() MessageCreation { return "message_creation" }
func (c Model) Default() Model { return "model" }
func (c Move) Default() Move { return "move" }
func (c Multi) Default() Multi { return "multi" }
@@ -316,56 +275,17 @@ func (c ResponseWebSearchCallInProgress) Default() ResponseWebSearchCallInProgre
func (c ResponseWebSearchCallSearching) Default() ResponseWebSearchCallSearching {
return "response.web_search_call.searching"
}
-func (c ScoreModel) Default() ScoreModel { return "score_model" }
-func (c Screenshot) Default() Screenshot { return "screenshot" }
-func (c Scroll) Default() Scroll { return "scroll" }
-func (c Static) Default() Static { return "static" }
-func (c StringCheck) Default() StringCheck { return "string_check" }
-func (c SubmitToolOutputs) Default() SubmitToolOutputs { return "submit_tool_outputs" }
-func (c SummaryText) Default() SummaryText { return "summary_text" }
-func (c System) Default() System { return "system" }
-func (c Text) Default() Text { return "text" }
-func (c TextCompletion) Default() TextCompletion { return "text_completion" }
-func (c TextSimilarity) Default() TextSimilarity { return "text_similarity" }
-func (c Thread) Default() Thread { return "thread" }
-func (c ThreadCreated) Default() ThreadCreated { return "thread.created" }
-func (c ThreadDeleted) Default() ThreadDeleted { return "thread.deleted" }
-func (c ThreadMessage) Default() ThreadMessage { return "thread.message" }
-func (c ThreadMessageCompleted) Default() ThreadMessageCompleted { return "thread.message.completed" }
-func (c ThreadMessageCreated) Default() ThreadMessageCreated { return "thread.message.created" }
-func (c ThreadMessageDeleted) Default() ThreadMessageDeleted { return "thread.message.deleted" }
-func (c ThreadMessageDelta) Default() ThreadMessageDelta { return "thread.message.delta" }
-func (c ThreadMessageInProgress) Default() ThreadMessageInProgress {
- return "thread.message.in_progress"
-}
-func (c ThreadMessageIncomplete) Default() ThreadMessageIncomplete {
- return "thread.message.incomplete"
-}
-func (c ThreadRun) Default() ThreadRun { return "thread.run" }
-func (c ThreadRunCancelled) Default() ThreadRunCancelled { return "thread.run.cancelled" }
-func (c ThreadRunCancelling) Default() ThreadRunCancelling { return "thread.run.cancelling" }
-func (c ThreadRunCompleted) Default() ThreadRunCompleted { return "thread.run.completed" }
-func (c ThreadRunCreated) Default() ThreadRunCreated { return "thread.run.created" }
-func (c ThreadRunExpired) Default() ThreadRunExpired { return "thread.run.expired" }
-func (c ThreadRunFailed) Default() ThreadRunFailed { return "thread.run.failed" }
-func (c ThreadRunInProgress) Default() ThreadRunInProgress { return "thread.run.in_progress" }
-func (c ThreadRunIncomplete) Default() ThreadRunIncomplete { return "thread.run.incomplete" }
-func (c ThreadRunQueued) Default() ThreadRunQueued { return "thread.run.queued" }
-func (c ThreadRunRequiresAction) Default() ThreadRunRequiresAction {
- return "thread.run.requires_action"
-}
-func (c ThreadRunStep) Default() ThreadRunStep { return "thread.run.step" }
-func (c ThreadRunStepCancelled) Default() ThreadRunStepCancelled { return "thread.run.step.cancelled" }
-func (c ThreadRunStepCompleted) Default() ThreadRunStepCompleted { return "thread.run.step.completed" }
-func (c ThreadRunStepCreated) Default() ThreadRunStepCreated { return "thread.run.step.created" }
-func (c ThreadRunStepDelta) Default() ThreadRunStepDelta { return "thread.run.step.delta" }
-func (c ThreadRunStepExpired) Default() ThreadRunStepExpired { return "thread.run.step.expired" }
-func (c ThreadRunStepFailed) Default() ThreadRunStepFailed { return "thread.run.step.failed" }
-func (c ThreadRunStepInProgress) Default() ThreadRunStepInProgress {
- return "thread.run.step.in_progress"
-}
+func (c ScoreModel) Default() ScoreModel { return "score_model" }
+func (c Screenshot) Default() Screenshot { return "screenshot" }
+func (c Scroll) Default() Scroll { return "scroll" }
+func (c Static) Default() Static { return "static" }
+func (c StringCheck) Default() StringCheck { return "string_check" }
+func (c SummaryText) Default() SummaryText { return "summary_text" }
+func (c System) Default() System { return "system" }
+func (c Text) Default() Text { return "text" }
+func (c TextCompletion) Default() TextCompletion { return "text_completion" }
+func (c TextSimilarity) Default() TextSimilarity { return "text_similarity" }
func (c Tool) Default() Tool { return "tool" }
-func (c ToolCalls) Default() ToolCalls { return "tool_calls" }
func (c TranscriptTextDelta) Default() TranscriptTextDelta { return "transcript.text.delta" }
func (c TranscriptTextDone) Default() TranscriptTextDone { return "transcript.text.done" }
func (c Type) Default() Type { return "type" }
@@ -390,7 +310,6 @@ func (c WebSearchCall) Default() WebSearchCall { return "web_search_call" }
func (c Approximate) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Assistant) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c AssistantDeleted) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Auto) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Batch) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c ChatCompletion) MarshalJSON() ([]byte, error) { return marshalString(c) }
@@ -398,7 +317,6 @@ func (c ChatCompletionChunk) MarshalJSON() ([]byte, error) { r
func (c ChatCompletionDeleted) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c CheckpointPermission) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Click) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c CodeInterpreter) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c CodeInterpreterCall) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c ComputerCallOutput) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c ComputerScreenshot) MarshalJSON() ([]byte, error) { return marshalString(c) }
@@ -421,8 +339,6 @@ func (c FineTuningJobEvent) MarshalJSON() ([]byte, error) { r
func (c Function) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c FunctionCall) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c FunctionCallOutput) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c Image) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ImageFile) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c ImageURL) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c InputAudio) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c InputFile) MarshalJSON() ([]byte, error) { return marshalString(c) }
@@ -436,7 +352,6 @@ func (c LastActiveAt) MarshalJSON() ([]byte, error) { r
func (c List) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Logs) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Message) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c MessageCreation) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Model) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Move) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Multi) MarshalJSON() ([]byte, error) { return marshalString(c) }
@@ -489,43 +404,12 @@ func (c Screenshot) MarshalJSON() ([]byte, error) { retu
func (c Scroll) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Static) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c StringCheck) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c SubmitToolOutputs) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c SummaryText) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c System) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Text) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c TextCompletion) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c TextSimilarity) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c Thread) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadCreated) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadDeleted) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadMessage) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadMessageCompleted) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadMessageCreated) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadMessageDeleted) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadMessageDelta) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadMessageInProgress) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadMessageIncomplete) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRun) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunCancelled) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunCancelling) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunCompleted) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunCreated) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunExpired) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunFailed) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunInProgress) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunIncomplete) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunQueued) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunRequiresAction) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunStep) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunStepCancelled) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunStepCompleted) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunStepCreated) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunStepDelta) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunStepExpired) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunStepFailed) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ThreadRunStepInProgress) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Tool) MarshalJSON() ([]byte, error) { return marshalString(c) }
-func (c ToolCalls) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c TranscriptTextDelta) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c TranscriptTextDone) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Type) MarshalJSON() ([]byte, error) { return marshalString(c) }
diff --git a/shared/shared.go b/shared/shared.go
index 30f7b266..7d30bda5 100644
--- a/shared/shared.go
+++ b/shared/shared.go
@@ -307,75 +307,6 @@ func (r *CompoundFilterParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
-type ErrorObject struct {
- Code string `json:"code,required"`
- Message string `json:"message,required"`
- Param string `json:"param,required"`
- Type string `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Code respjson.Field
- Message respjson.Field
- Param respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ErrorObject) RawJSON() string { return r.JSON.raw }
-func (r *ErrorObject) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-type FunctionDefinition struct {
- // The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
- // underscores and dashes, with a maximum length of 64.
- Name string `json:"name,required"`
- // A description of what the function does, used by the model to choose when and
- // how to call the function.
- Description string `json:"description"`
- // The parameters the functions accepts, described as a JSON Schema object. See the
- // [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
- // and the
- // [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
- // documentation about the format.
- //
- // Omitting `parameters` defines a function with an empty parameter list.
- Parameters FunctionParameters `json:"parameters"`
- // Whether to enable strict schema adherence when generating the function call. If
- // set to true, the model will follow the exact schema defined in the `parameters`
- // field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn
- // more about Structured Outputs in the
- // [function calling guide](docs/guides/function-calling).
- Strict bool `json:"strict,nullable"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Name respjson.Field
- Description respjson.Field
- Parameters respjson.Field
- Strict respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r FunctionDefinition) RawJSON() string { return r.JSON.raw }
-func (r *FunctionDefinition) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this FunctionDefinition to a FunctionDefinitionParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// FunctionDefinitionParam.Overrides()
-func (r FunctionDefinition) ToParam() FunctionDefinitionParam {
- return param.Override[FunctionDefinitionParam](r.RawJSON())
-}
-
// The property Name is required.
type FunctionDefinitionParam struct {
// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
@@ -605,73 +536,6 @@ func (r *ResponseFormatJSONObjectParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
-// JSON Schema response format. Used to generate structured JSON responses. Learn
-// more about
-// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
-type ResponseFormatJSONSchema struct {
- // Structured Outputs configuration options, including a JSON Schema.
- JSONSchema ResponseFormatJSONSchemaJSONSchema `json:"json_schema,required"`
- // The type of response format being defined. Always `json_schema`.
- Type constant.JSONSchema `json:"type,required"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- JSONSchema respjson.Field
- Type respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ResponseFormatJSONSchema) RawJSON() string { return r.JSON.raw }
-func (r *ResponseFormatJSONSchema) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
-// ToParam converts this ResponseFormatJSONSchema to a
-// ResponseFormatJSONSchemaParam.
-//
-// Warning: the fields of the param type will not be present. ToParam should only
-// be used at the last possible moment before sending a request. Test for this with
-// ResponseFormatJSONSchemaParam.Overrides()
-func (r ResponseFormatJSONSchema) ToParam() ResponseFormatJSONSchemaParam {
- return param.Override[ResponseFormatJSONSchemaParam](r.RawJSON())
-}
-
-// Structured Outputs configuration options, including a JSON Schema.
-type ResponseFormatJSONSchemaJSONSchema struct {
- // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores
- // and dashes, with a maximum length of 64.
- Name string `json:"name,required"`
- // A description of what the response format is for, used by the model to determine
- // how to respond in the format.
- Description string `json:"description"`
- // The schema for the response format, described as a JSON Schema object. Learn how
- // to build JSON schemas [here](https://json-schema.org/).
- Schema map[string]any `json:"schema"`
- // Whether to enable strict schema adherence when generating the output. If set to
- // true, the model will always follow the exact schema defined in the `schema`
- // field. Only a subset of JSON Schema is supported when `strict` is `true`. To
- // learn more, read the
- // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
- Strict bool `json:"strict,nullable"`
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
- JSON struct {
- Name respjson.Field
- Description respjson.Field
- Schema respjson.Field
- Strict respjson.Field
- ExtraFields map[string]respjson.Field
- raw string
- } `json:"-"`
-}
-
-// Returns the unmodified JSON received from the API
-func (r ResponseFormatJSONSchemaJSONSchema) RawJSON() string { return r.JSON.raw }
-func (r *ResponseFormatJSONSchemaJSONSchema) UnmarshalJSON(data []byte) error {
- return apijson.UnmarshalRoot(data, r)
-}
-
// JSON Schema response format. Used to generate structured JSON responses. Learn
// more about
// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
diff --git a/streamaccumulator.go b/streamaccumulator.go
index bf022c9d..53b7069f 100644
--- a/streamaccumulator.go
+++ b/streamaccumulator.go
@@ -13,7 +13,7 @@ type ChatCompletionAccumulator struct {
type FinishedChatCompletionToolCall struct {
ChatCompletionMessageToolCallFunction
Index int
- Id string
+ ID string
}
type chatCompletionResponseState struct {
@@ -52,7 +52,7 @@ func (acc *ChatCompletionAccumulator) AddChunk(chunk ChatCompletionChunk) bool {
return true
}
-// JustFinishedRefusal retrieves the chat completion refusal when it is known to have just been completed.
+// JustFinishedContent retrieves the chat completion content when it is known to have just been completed.
// The content is "just completed" when the last added chunk no longer contains a content
// delta. If the content is just completed, the content is returned and the boolean is true. Otherwise,
// an empty string is returned and the boolean will be false.
@@ -86,7 +86,7 @@ func (acc *ChatCompletionAccumulator) JustFinishedToolCall() (toolcall FinishedC
f := acc.Choices[0].Message.ToolCalls[acc.justFinished.index].Function
id := acc.Choices[0].Message.ToolCalls[acc.justFinished.index].ID
return FinishedChatCompletionToolCall{
- Id: id,
+ ID: id,
Index: acc.justFinished.index,
ChatCompletionMessageToolCallFunction: ChatCompletionMessageToolCallFunction{
Name: f.Name,
diff --git a/uploadpart.go b/uploadpart.go
index 19af8e42..e3e40e11 100644
--- a/uploadpart.go
+++ b/uploadpart.go
@@ -97,6 +97,9 @@ func (r UploadPartNewParams) MarshalMultipart() (data []byte, contentType string
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
+ if err == nil {
+ err = apiform.WriteExtras(writer, r.ExtraFields())
+ }
if err != nil {
writer.Close()
return nil, "", err
diff --git a/vectorstorefile.go b/vectorstorefile.go
index bc049830..7bc940ed 100644
--- a/vectorstorefile.go
+++ b/vectorstorefile.go
@@ -94,10 +94,10 @@ func (r *VectorStoreFileService) UploadAndPoll(ctx context.Context, vectorStoreI
}
// Retrieves a vector store file.
-func (r *VectorStoreFileService) Get(ctx context.Context, vectorStoreID string, fileID string, opts ...option.RequestOption) (res *VectorStoreFile, err error) {
+func (r *VectorStoreFileService) Get(ctx context.Context, fileID string, query VectorStoreFileGetParams, opts ...option.RequestOption) (res *VectorStoreFile, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if vectorStoreID == "" {
+ if query.VectorStoreID == "" {
err = errors.New("missing required vector_store_id parameter")
return
}
@@ -105,16 +105,16 @@ func (r *VectorStoreFileService) Get(ctx context.Context, vectorStoreID string,
err = errors.New("missing required file_id parameter")
return
}
- path := fmt.Sprintf("vector_stores/%s/files/%s", vectorStoreID, fileID)
+ path := fmt.Sprintf("vector_stores/%s/files/%s", query.VectorStoreID, fileID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Update attributes on a vector store file.
-func (r *VectorStoreFileService) Update(ctx context.Context, vectorStoreID string, fileID string, body VectorStoreFileUpdateParams, opts ...option.RequestOption) (res *VectorStoreFile, err error) {
+func (r *VectorStoreFileService) Update(ctx context.Context, fileID string, params VectorStoreFileUpdateParams, opts ...option.RequestOption) (res *VectorStoreFile, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if vectorStoreID == "" {
+ if params.VectorStoreID == "" {
err = errors.New("missing required vector_store_id parameter")
return
}
@@ -122,8 +122,8 @@ func (r *VectorStoreFileService) Update(ctx context.Context, vectorStoreID strin
err = errors.New("missing required file_id parameter")
return
}
- path := fmt.Sprintf("vector_stores/%s/files/%s", vectorStoreID, fileID)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
+ path := fmt.Sprintf("vector_stores/%s/files/%s", params.VectorStoreID, fileID)
+ err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return
}
@@ -158,10 +158,10 @@ func (r *VectorStoreFileService) ListAutoPaging(ctx context.Context, vectorStore
// the file itself will not be deleted. To delete the file, use the
// [delete file](https://platform.openai.com/docs/api-reference/files/delete)
// endpoint.
-func (r *VectorStoreFileService) Delete(ctx context.Context, vectorStoreID string, fileID string, opts ...option.RequestOption) (res *VectorStoreFileDeleted, err error) {
+func (r *VectorStoreFileService) Delete(ctx context.Context, fileID string, body VectorStoreFileDeleteParams, opts ...option.RequestOption) (res *VectorStoreFileDeleted, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if vectorStoreID == "" {
+ if body.VectorStoreID == "" {
err = errors.New("missing required vector_store_id parameter")
return
}
@@ -169,17 +169,17 @@ func (r *VectorStoreFileService) Delete(ctx context.Context, vectorStoreID strin
err = errors.New("missing required file_id parameter")
return
}
- path := fmt.Sprintf("vector_stores/%s/files/%s", vectorStoreID, fileID)
+ path := fmt.Sprintf("vector_stores/%s/files/%s", body.VectorStoreID, fileID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Retrieve the parsed contents of a vector store file.
-func (r *VectorStoreFileService) Content(ctx context.Context, vectorStoreID string, fileID string, opts ...option.RequestOption) (res *pagination.Page[VectorStoreFileContentResponse], err error) {
+func (r *VectorStoreFileService) Content(ctx context.Context, fileID string, query VectorStoreFileContentParams, opts ...option.RequestOption) (res *pagination.Page[VectorStoreFileContentResponse], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
- if vectorStoreID == "" {
+ if query.VectorStoreID == "" {
err = errors.New("missing required vector_store_id parameter")
return
}
@@ -187,7 +187,7 @@ func (r *VectorStoreFileService) Content(ctx context.Context, vectorStoreID stri
err = errors.New("missing required file_id parameter")
return
}
- path := fmt.Sprintf("vector_stores/%s/files/%s/content", vectorStoreID, fileID)
+ path := fmt.Sprintf("vector_stores/%s/files/%s/content", query.VectorStoreID, fileID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, nil, &res, opts...)
if err != nil {
return nil, err
@@ -201,8 +201,8 @@ func (r *VectorStoreFileService) Content(ctx context.Context, vectorStoreID stri
}
// Retrieve the parsed contents of a vector store file.
-func (r *VectorStoreFileService) ContentAutoPaging(ctx context.Context, vectorStoreID string, fileID string, opts ...option.RequestOption) *pagination.PageAutoPager[VectorStoreFileContentResponse] {
- return pagination.NewPageAutoPager(r.Content(ctx, vectorStoreID, fileID, opts...))
+func (r *VectorStoreFileService) ContentAutoPaging(ctx context.Context, fileID string, query VectorStoreFileContentParams, opts ...option.RequestOption) *pagination.PageAutoPager[VectorStoreFileContentResponse] {
+ return pagination.NewPageAutoPager(r.Content(ctx, fileID, query, opts...))
}
// A list of files attached to a vector store.
@@ -433,13 +433,19 @@ func (u *VectorStoreFileNewParamsAttributeUnion) asAny() any {
return nil
}
+type VectorStoreFileGetParams struct {
+ VectorStoreID string `path:"vector_store_id,required" json:"-"`
+ paramObj
+}
+
type VectorStoreFileUpdateParams struct {
// Set of 16 key-value pairs that can be attached to an object. This can be useful
// for storing additional information about the object in a structured format, and
// querying for objects via API or the dashboard. Keys are strings with a maximum
// length of 64 characters. Values are strings with a maximum length of 512
// characters, booleans, or numbers.
- Attributes map[string]VectorStoreFileUpdateParamsAttributeUnion `json:"attributes,omitzero,required"`
+ Attributes map[string]VectorStoreFileUpdateParamsAttributeUnion `json:"attributes,omitzero,required"`
+ VectorStoreID string `path:"vector_store_id,required" json:"-"`
paramObj
}
@@ -532,3 +538,13 @@ const (
VectorStoreFileListParamsOrderAsc VectorStoreFileListParamsOrder = "asc"
VectorStoreFileListParamsOrderDesc VectorStoreFileListParamsOrder = "desc"
)
+
+type VectorStoreFileDeleteParams struct {
+ VectorStoreID string `path:"vector_store_id,required" json:"-"`
+ paramObj
+}
+
+type VectorStoreFileContentParams struct {
+ VectorStoreID string `path:"vector_store_id,required" json:"-"`
+ paramObj
+}
diff --git a/vectorstorefile_test.go b/vectorstorefile_test.go
index 8acab088..d98405fe 100644
--- a/vectorstorefile_test.go
+++ b/vectorstorefile_test.go
@@ -63,8 +63,10 @@ func TestVectorStoreFileGet(t *testing.T) {
)
_, err := client.VectorStores.Files.Get(
context.TODO(),
- "vs_abc123",
"file-abc123",
+ openai.VectorStoreFileGetParams{
+ VectorStoreID: "vs_abc123",
+ },
)
if err != nil {
var apierr *openai.Error
@@ -89,9 +91,9 @@ func TestVectorStoreFileUpdate(t *testing.T) {
)
_, err := client.VectorStores.Files.Update(
context.TODO(),
- "vs_abc123",
"file-abc123",
openai.VectorStoreFileUpdateParams{
+ VectorStoreID: "vs_abc123",
Attributes: map[string]openai.VectorStoreFileUpdateParamsAttributeUnion{
"foo": {
OfString: openai.String("string"),
@@ -154,8 +156,10 @@ func TestVectorStoreFileDelete(t *testing.T) {
)
_, err := client.VectorStores.Files.Delete(
context.TODO(),
- "vector_store_id",
"file_id",
+ openai.VectorStoreFileDeleteParams{
+ VectorStoreID: "vector_store_id",
+ },
)
if err != nil {
var apierr *openai.Error
@@ -180,8 +184,10 @@ func TestVectorStoreFileContent(t *testing.T) {
)
_, err := client.VectorStores.Files.Content(
context.TODO(),
- "vs_abc123",
"file-abc123",
+ openai.VectorStoreFileContentParams{
+ VectorStoreID: "vs_abc123",
+ },
)
if err != nil {
var apierr *openai.Error
diff --git a/vectorstorefilebatch.go b/vectorstorefilebatch.go
index b9d3a159..610dabdb 100644
--- a/vectorstorefilebatch.go
+++ b/vectorstorefilebatch.go
@@ -112,10 +112,10 @@ func (r *VectorStoreFileBatchService) UploadAndPoll(ctx context.Context, vectorS
}
// Retrieves a vector store file batch.
-func (r *VectorStoreFileBatchService) Get(ctx context.Context, vectorStoreID string, batchID string, opts ...option.RequestOption) (res *VectorStoreFileBatch, err error) {
+func (r *VectorStoreFileBatchService) Get(ctx context.Context, batchID string, query VectorStoreFileBatchGetParams, opts ...option.RequestOption) (res *VectorStoreFileBatch, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if vectorStoreID == "" {
+ if query.VectorStoreID == "" {
err = errors.New("missing required vector_store_id parameter")
return
}
@@ -123,17 +123,17 @@ func (r *VectorStoreFileBatchService) Get(ctx context.Context, vectorStoreID str
err = errors.New("missing required batch_id parameter")
return
}
- path := fmt.Sprintf("vector_stores/%s/file_batches/%s", vectorStoreID, batchID)
+ path := fmt.Sprintf("vector_stores/%s/file_batches/%s", query.VectorStoreID, batchID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Cancel a vector store file batch. This attempts to cancel the processing of
// files in this batch as soon as possible.
-func (r *VectorStoreFileBatchService) Cancel(ctx context.Context, vectorStoreID string, batchID string, opts ...option.RequestOption) (res *VectorStoreFileBatch, err error) {
+func (r *VectorStoreFileBatchService) Cancel(ctx context.Context, batchID string, body VectorStoreFileBatchCancelParams, opts ...option.RequestOption) (res *VectorStoreFileBatch, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
- if vectorStoreID == "" {
+ if body.VectorStoreID == "" {
err = errors.New("missing required vector_store_id parameter")
return
}
@@ -141,17 +141,17 @@ func (r *VectorStoreFileBatchService) Cancel(ctx context.Context, vectorStoreID
err = errors.New("missing required batch_id parameter")
return
}
- path := fmt.Sprintf("vector_stores/%s/file_batches/%s/cancel", vectorStoreID, batchID)
+ path := fmt.Sprintf("vector_stores/%s/file_batches/%s/cancel", body.VectorStoreID, batchID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// Returns a list of vector store files in a batch.
-func (r *VectorStoreFileBatchService) ListFiles(ctx context.Context, vectorStoreID string, batchID string, query VectorStoreFileBatchListFilesParams, opts ...option.RequestOption) (res *pagination.CursorPage[VectorStoreFile], err error) {
+func (r *VectorStoreFileBatchService) ListFiles(ctx context.Context, batchID string, params VectorStoreFileBatchListFilesParams, opts ...option.RequestOption) (res *pagination.CursorPage[VectorStoreFile], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
- if vectorStoreID == "" {
+ if params.VectorStoreID == "" {
err = errors.New("missing required vector_store_id parameter")
return
}
@@ -159,8 +159,8 @@ func (r *VectorStoreFileBatchService) ListFiles(ctx context.Context, vectorStore
err = errors.New("missing required batch_id parameter")
return
}
- path := fmt.Sprintf("vector_stores/%s/file_batches/%s/files", vectorStoreID, batchID)
- cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
+ path := fmt.Sprintf("vector_stores/%s/file_batches/%s/files", params.VectorStoreID, batchID)
+ cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
if err != nil {
return nil, err
}
@@ -173,8 +173,8 @@ func (r *VectorStoreFileBatchService) ListFiles(ctx context.Context, vectorStore
}
// Returns a list of vector store files in a batch.
-func (r *VectorStoreFileBatchService) ListFilesAutoPaging(ctx context.Context, vectorStoreID string, batchID string, query VectorStoreFileBatchListFilesParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[VectorStoreFile] {
- return pagination.NewCursorPageAutoPager(r.ListFiles(ctx, vectorStoreID, batchID, query, opts...))
+func (r *VectorStoreFileBatchService) ListFilesAutoPaging(ctx context.Context, batchID string, params VectorStoreFileBatchListFilesParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[VectorStoreFile] {
+ return pagination.NewCursorPageAutoPager(r.ListFiles(ctx, batchID, params, opts...))
}
// A batch of files attached to a vector store.
@@ -309,7 +309,18 @@ func (u *VectorStoreFileBatchNewParamsAttributeUnion) asAny() any {
return nil
}
+type VectorStoreFileBatchGetParams struct {
+ VectorStoreID string `path:"vector_store_id,required" json:"-"`
+ paramObj
+}
+
+type VectorStoreFileBatchCancelParams struct {
+ VectorStoreID string `path:"vector_store_id,required" json:"-"`
+ paramObj
+}
+
type VectorStoreFileBatchListFilesParams struct {
+ VectorStoreID string `path:"vector_store_id,required" json:"-"`
// A cursor for use in pagination. `after` is an object ID that defines your place
// in the list. For instance, if you make a list request and receive 100 objects,
// ending with obj_foo, your subsequent call can include after=obj_foo in order to
diff --git a/vectorstorefilebatch_test.go b/vectorstorefilebatch_test.go
index 65594f46..db27738b 100644
--- a/vectorstorefilebatch_test.go
+++ b/vectorstorefilebatch_test.go
@@ -63,8 +63,10 @@ func TestVectorStoreFileBatchGet(t *testing.T) {
)
_, err := client.VectorStores.FileBatches.Get(
context.TODO(),
- "vs_abc123",
"vsfb_abc123",
+ openai.VectorStoreFileBatchGetParams{
+ VectorStoreID: "vs_abc123",
+ },
)
if err != nil {
var apierr *openai.Error
@@ -89,8 +91,10 @@ func TestVectorStoreFileBatchCancel(t *testing.T) {
)
_, err := client.VectorStores.FileBatches.Cancel(
context.TODO(),
- "vector_store_id",
"batch_id",
+ openai.VectorStoreFileBatchCancelParams{
+ VectorStoreID: "vector_store_id",
+ },
)
if err != nil {
var apierr *openai.Error
@@ -115,14 +119,14 @@ func TestVectorStoreFileBatchListFilesWithOptionalParams(t *testing.T) {
)
_, err := client.VectorStores.FileBatches.ListFiles(
context.TODO(),
- "vector_store_id",
"batch_id",
openai.VectorStoreFileBatchListFilesParams{
- After: openai.String("after"),
- Before: openai.String("before"),
- Filter: openai.VectorStoreFileBatchListFilesParamsFilterInProgress,
- Limit: openai.Int(0),
- Order: openai.VectorStoreFileBatchListFilesParamsOrderAsc,
+ VectorStoreID: "vector_store_id",
+ After: openai.String("after"),
+ Before: openai.String("before"),
+ Filter: openai.VectorStoreFileBatchListFilesParamsFilterInProgress,
+ Limit: openai.Int(0),
+ Order: openai.VectorStoreFileBatchListFilesParamsOrderAsc,
},
)
if err != nil {