From 672f13fd59d05558ea75e00f4f8aad604c0747b6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 20:30:51 -0300 Subject: [PATCH] ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.396.6 (#6) Co-authored-by: speakeasybot --- .speakeasy/gen.lock | 196 ++++--- .speakeasy/gen.yaml | 2 +- README.md | 48 +- RELEASES.md | 12 +- USAGE.md | 8 +- codeSamples.yaml | 144 +++-- ...odysegmentanything2segmentanything2post.md | 16 + ...gmentanything2segmentanything2postimage.md | 9 + docs/models/components/masksresponse.md | 12 + .../operations/segmentanything2response.md | 9 + internal/utils/json.go | 25 +- internal/utils/requestbody.go | 5 +- livepeerai.go | 527 +++++++++++++++++- ...odysegmentanything2segmentanything2post.go | 122 ++++ models/components/masksresponse.go | 34 ++ models/operations/segmentanything2.go | 27 + types/pointers.go | 1 + 17 files changed, 1019 insertions(+), 178 deletions(-) create mode 100644 docs/models/components/bodysegmentanything2segmentanything2post.md create mode 100644 docs/models/components/bodysegmentanything2segmentanything2postimage.md create mode 100644 docs/models/components/masksresponse.md create mode 100644 docs/models/operations/segmentanything2response.md create mode 100644 models/components/bodysegmentanything2segmentanything2post.go create mode 100644 models/components/masksresponse.go create mode 100644 models/operations/segmentanything2.go diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index ae46f81..ceb686b 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,19 +1,19 @@ lockVersion: 2.0.0 id: 98621ff3-f200-4a5c-9c69-bc1fe845e39c management: - docChecksum: 24fe39a0fb7794800b7d995f98944b86 - docVersion: v0.1.3 - speakeasyVersion: 1.383.2 - generationVersion: 2.407.0 - releaseVersion: 0.1.6 - configChecksum: b79d412bf611ded8132ffbd0799067b8 + docChecksum: 57e99cb8e6e8b32242245c05aacb18c7 + docVersion: v0.2.0 + speakeasyVersion: 1.396.6 + generationVersion: 2.415.6 + releaseVersion: 0.2.0 + configChecksum: 31041836967656151854b3e329d03919 repoURL: https://github.com/livepeer/livepeer-ai-go.git installationURL: https://github.com/livepeer/livepeer-ai-go features: go: additionalDependencies: 0.1.0 constsAndDefaults: 0.1.6 - core: 3.5.5 + core: 3.5.8 defaultEnabledRetries: 0.2.0 devContainers: 2.90.0 envVarSecurityUsage: 0.3.1 @@ -28,77 +28,145 @@ features: unions: 2.85.9 uploadStreams: 0.1.0 generatedFiles: - - livepeerai.go - - go.mod - - models/sdkerrors/sdkerror.go - - retry/config.go - - types/bigint.go - - types/date.go - - types/datetime.go - - types/decimal.go - - types/pointers.go - - internal/utils/contenttype.go - - internal/utils/form.go - - internal/utils/headers.go - - internal/utils/json.go - - internal/utils/pathparams.go - - internal/utils/queryparams.go - - internal/utils/requestbody.go - - internal/utils/retries.go - - internal/utils/security.go - - internal/utils/utils.go - - /models/operations/texttoimage.go - - /models/operations/imagetoimage.go - - /models/operations/imagetovideo.go - - /models/operations/upscale.go - - /models/operations/audiototext.go - - /models/components/imageresponse.go - - /models/components/media.go - - /models/components/httpmetadata.go + - .devcontainer/README.md + - .devcontainer/devcontainer.json + - .devcontainer/setup.sh + - .gitattributes - /models/components/apierror.go - - /models/components/validationerror.go - - /models/components/texttoimageparams.go + - /models/components/bodyaudiototextaudiototextpost.go - /models/components/bodyimagetoimageimagetoimagepost.go - - /models/components/videoresponse.go - /models/components/bodyimagetovideoimagetovideopost.go + - /models/components/bodysegmentanything2segmentanything2post.go - /models/components/bodyupscaleupscalepost.go - - /models/components/textresponse.go - /models/components/chunk.go - - /models/components/bodyaudiototextaudiototextpost.go + - /models/components/httpmetadata.go + - /models/components/imageresponse.go + - /models/components/masksresponse.go + - /models/components/media.go - /models/components/security.go + - /models/components/textresponse.go + - /models/components/texttoimageparams.go + - /models/components/validationerror.go + - /models/components/videoresponse.go + - /models/operations/audiototext.go + - /models/operations/imagetoimage.go + - /models/operations/imagetovideo.go + - /models/operations/segmentanything2.go + - /models/operations/texttoimage.go + - /models/operations/upscale.go - /models/sdkerrors/httperror.go - /models/sdkerrors/httpvalidationerror.go - - docs/models/operations/texttoimageresponse.md - - docs/models/operations/imagetoimageresponse.md - - docs/models/operations/imagetovideoresponse.md - - docs/models/operations/upscaleresponse.md - - docs/models/operations/audiototextresponse.md - - docs/models/components/imageresponse.md - - docs/models/components/media.md - - docs/models/components/httpmetadata.md + - CONTRIBUTING.md + - USAGE.md - docs/models/components/apierror.md - - docs/models/components/loc.md - - docs/models/components/validationerror.md - - docs/models/components/texttoimageparams.md - - docs/models/components/image.md + - docs/models/components/audio.md + - docs/models/components/bodyaudiototextaudiototextpost.md - docs/models/components/bodyimagetoimageimagetoimagepost.md - - docs/models/components/videoresponse.md - - docs/models/components/bodyimagetovideoimagetovideopostimage.md - docs/models/components/bodyimagetovideoimagetovideopost.md - - docs/models/components/bodyupscaleupscalepostimage.md + - docs/models/components/bodyimagetovideoimagetovideopostimage.md + - docs/models/components/bodysegmentanything2segmentanything2post.md + - docs/models/components/bodysegmentanything2segmentanything2postimage.md - docs/models/components/bodyupscaleupscalepost.md - - docs/models/components/textresponse.md + - docs/models/components/bodyupscaleupscalepostimage.md - docs/models/components/chunk.md - - docs/models/components/audio.md - - docs/models/components/bodyaudiototextaudiototextpost.md + - docs/models/components/httpmetadata.md + - docs/models/components/image.md + - docs/models/components/imageresponse.md + - docs/models/components/loc.md + - docs/models/components/masksresponse.md + - docs/models/components/media.md - docs/models/components/security.md + - docs/models/components/textresponse.md + - docs/models/components/texttoimageparams.md + - docs/models/components/validationerror.md + - docs/models/components/videoresponse.md + - docs/models/operations/audiototextresponse.md + - docs/models/operations/imagetoimageresponse.md + - docs/models/operations/imagetovideoresponse.md + - docs/models/operations/segmentanything2response.md + - docs/models/operations/texttoimageresponse.md + - docs/models/operations/upscaleresponse.md - docs/models/sdkerrors/httperror.md - docs/models/sdkerrors/httpvalidationerror.md - - USAGE.md - - models/operations/options.go - - .gitattributes - - .devcontainer/README.md - - .devcontainer/devcontainer.json - - .devcontainer/setup.sh + - go.mod - internal/hooks/hooks.go - - CONTRIBUTING.md + - internal/utils/contenttype.go + - internal/utils/form.go + - internal/utils/headers.go + - internal/utils/json.go + - internal/utils/pathparams.go + - internal/utils/queryparams.go + - internal/utils/requestbody.go + - internal/utils/retries.go + - internal/utils/security.go + - internal/utils/utils.go + - livepeerai.go + - models/operations/options.go + - models/sdkerrors/sdkerror.go + - retry/config.go + - types/bigint.go + - types/date.go + - types/datetime.go + - types/decimal.go + - types/pointers.go +examples: + text_to_image: + speakeasy-default-text-to-image: + requestBody: + application/json: {"prompt": ""} + responses: + "200": + application/json: {"images": []} + "400": + application/json: {"detail": {"msg": ""}} + "422": {} + image_to_image: + speakeasy-default-image-to-image: + requestBody: + multipart/form-data: {"prompt": "", "image": {}} + responses: + "200": + application/json: {"images": []} + "400": + application/json: {"detail": {"msg": ""}} + "422": {} + image_to_video: + speakeasy-default-image-to-video: + requestBody: + multipart/form-data: {"image": {}} + responses: + "200": + application/json: {"images": []} + "400": + application/json: {"detail": {"msg": ""}} + "422": {} + upscale: + speakeasy-default-upscale: + requestBody: + multipart/form-data: {"prompt": "", "image": {}} + responses: + "200": + application/json: {"images": []} + "400": + application/json: {"detail": {"msg": ""}} + "422": {} + audio_to_text: + speakeasy-default-audio-to-text: + requestBody: + multipart/form-data: {"audio": {}} + responses: + "200": + application/json: {"text": "", "chunks": []} + "400": + application/json: {"detail": {"msg": ""}} + "422": {} + segment_anything_2: + speakeasy-default-segment-anything-2: + requestBody: + multipart/form-data: {"image": {}} + responses: + "200": + application/json: {"masks": "", "scores": "", "logits": ""} + "400": + application/json: {"detail": {"msg": ""}} + "422": {} diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 21592dc..98eff6c 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -16,7 +16,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: false go: - version: 0.1.6 + version: 0.2.0 additionalDependencies: {} allowUnknownFieldsInWeakUnions: false clientServerStatusCodesAsErrors: true diff --git a/README.md b/README.md index 1a7d139..8da1883 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,11 @@ func main() { s := livepeeraigo.New( livepeeraigo.WithSecurity(""), ) - request := components.TextToImageParams{ - Prompt: "", - } + ctx := context.Background() - res, err := s.TextToImage(ctx, request, operations.WithRetries( + res, err := s.TextToImage(ctx, components.TextToImageParams{ + Prompt: "", + }, operations.WithRetries( retry.Config{ Strategy: "backoff", Backoff: &retry.BackoffStrategy{ @@ -79,11 +79,11 @@ func main() { }), livepeeraigo.WithSecurity(""), ) - request := components.TextToImageParams{ - Prompt: "", - } + ctx := context.Background() - res, err := s.TextToImage(ctx, request) + res, err := s.TextToImage(ctx, components.TextToImageParams{ + Prompt: "", + }) if err != nil { log.Fatal(err) } @@ -124,11 +124,11 @@ func main() { s := livepeeraigo.New( livepeeraigo.WithSecurity(""), ) - request := components.TextToImageParams{ - Prompt: "", - } + ctx := context.Background() - res, err := s.TextToImage(ctx, request) + res, err := s.TextToImage(ctx, components.TextToImageParams{ + Prompt: "", + }) if err != nil { var e *sdkerrors.HTTPError @@ -183,11 +183,11 @@ func main() { livepeeraigo.WithServerIndex(1), livepeeraigo.WithSecurity(""), ) - request := components.TextToImageParams{ - Prompt: "", - } + ctx := context.Background() - res, err := s.TextToImage(ctx, request) + res, err := s.TextToImage(ctx, components.TextToImageParams{ + Prompt: "", + }) if err != nil { log.Fatal(err) } @@ -217,11 +217,11 @@ func main() { livepeeraigo.WithServerURL("https://dream-gateway.livepeer.cloud"), livepeeraigo.WithSecurity(""), ) - request := components.TextToImageParams{ - Prompt: "", - } + ctx := context.Background() - res, err := s.TextToImage(ctx, request) + res, err := s.TextToImage(ctx, components.TextToImageParams{ + Prompt: "", + }) if err != nil { log.Fatal(err) } @@ -288,11 +288,11 @@ func main() { s := livepeeraigo.New( livepeeraigo.WithSecurity(""), ) - request := components.TextToImageParams{ - Prompt: "", - } + ctx := context.Background() - res, err := s.TextToImage(ctx, request) + res, err := s.TextToImage(ctx, components.TextToImageParams{ + Prompt: "", + }) if err != nil { log.Fatal(err) } diff --git a/RELEASES.md b/RELEASES.md index 68d3a04..1476cd1 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -28,4 +28,14 @@ Based on: ### Generated - [go v0.1.6] . ### Releases -- [Go v0.1.6] https://github.com/livepeer/livepeer-ai-go/releases/tag/v0.1.6 - . \ No newline at end of file +- [Go v0.1.6] https://github.com/livepeer/livepeer-ai-go/releases/tag/v0.1.6 - . + +## 2024-09-13 00:24:35 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.396.6 (2.415.6) https://github.com/speakeasy-api/speakeasy +### Generated +- [go v0.2.0] . +### Releases +- [Go v0.2.0] https://github.com/livepeer/livepeer-ai-go/releases/tag/v0.2.0 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index 71ee9a2..ffffd7f 100644 --- a/USAGE.md +++ b/USAGE.md @@ -13,11 +13,11 @@ func main() { s := livepeeraigo.New( livepeeraigo.WithSecurity(""), ) - request := components.TextToImageParams{ - Prompt: "", - } + ctx := context.Background() - res, err := s.TextToImage(ctx, request) + res, err := s.TextToImage(ctx, components.TextToImageParams{ + Prompt: "", + }) if err != nil { log.Fatal(err) } diff --git a/codeSamples.yaml b/codeSamples.yaml index 026037c..3cd5632 100644 --- a/codeSamples.yaml +++ b/codeSamples.yaml @@ -3,18 +3,19 @@ info: title: CodeSamples overlay for go target version: 0.0.0 actions: - - target: $["paths"]["/text-to-image"]["post"] + - target: $["paths"]["/audio-to-text"]["post"] update: x-codeSamples: - lang: go - label: text_to_image + label: audio_to_text source: |- package main import( livepeeraigo "github.com/livepeer/livepeer-ai-go" - "github.com/livepeer/livepeer-ai-go/models/components" + "os" "context" + "github.com/livepeer/livepeer-ai-go/models/components" "log" ) @@ -22,15 +23,23 @@ actions: s := livepeeraigo.New( livepeeraigo.WithSecurity(""), ) - request := components.TextToImageParams{ - Prompt: "", + + content, fileErr := os.Open("example.file") + if fileErr != nil { + panic(fileErr) } + ctx := context.Background() - res, err := s.TextToImage(ctx, request) + res, err := s.AudioToText(ctx, components.BodyAudioToTextAudioToTextPost{ + Audio: components.Audio{ + FileName: "example.file", + Content: content, + }, + }) if err != nil { log.Fatal(err) } - if res.ImageResponse != nil { + if res.TextResponse != nil { // handle response } } @@ -44,8 +53,9 @@ actions: import( livepeeraigo "github.com/livepeer/livepeer-ai-go" - "github.com/livepeer/livepeer-ai-go/models/components" + "os" "context" + "github.com/livepeer/livepeer-ai-go/models/components" "log" ) @@ -53,15 +63,20 @@ actions: s := livepeeraigo.New( livepeeraigo.WithSecurity(""), ) - request := components.BodyImageToImageImageToImagePost{ + + content, fileErr := os.Open("example.file") + if fileErr != nil { + panic(fileErr) + } + + ctx := context.Background() + res, err := s.ImageToImage(ctx, components.BodyImageToImageImageToImagePost{ Prompt: "", Image: components.Image{ - FileName: "your_file_here", - Content: os.Open(""), + FileName: "example.file", + Content: content, }, - } - ctx := context.Background() - res, err := s.ImageToImage(ctx, request) + }) if err != nil { log.Fatal(err) } @@ -79,8 +94,9 @@ actions: import( livepeeraigo "github.com/livepeer/livepeer-ai-go" - "github.com/livepeer/livepeer-ai-go/models/components" + "os" "context" + "github.com/livepeer/livepeer-ai-go/models/components" "log" ) @@ -88,14 +104,19 @@ actions: s := livepeeraigo.New( livepeeraigo.WithSecurity(""), ) - request := components.BodyImageToVideoImageToVideoPost{ - Image: components.BodyImageToVideoImageToVideoPostImage{ - FileName: "your_file_here", - Content: os.Open(""), - }, + + content, fileErr := os.Open("example.file") + if fileErr != nil { + panic(fileErr) } + ctx := context.Background() - res, err := s.ImageToVideo(ctx, request) + res, err := s.ImageToVideo(ctx, components.BodyImageToVideoImageToVideoPost{ + Image: components.BodyImageToVideoImageToVideoPostImage{ + FileName: "example.file", + Content: content, + }, + }) if err != nil { log.Fatal(err) } @@ -103,18 +124,19 @@ actions: // handle response } } - - target: $["paths"]["/upscale"]["post"] + - target: $["paths"]["/segment-anything-2"]["post"] update: x-codeSamples: - lang: go - label: upscale + label: segment_anything_2 source: |- package main import( livepeeraigo "github.com/livepeer/livepeer-ai-go" - "github.com/livepeer/livepeer-ai-go/models/components" + "os" "context" + "github.com/livepeer/livepeer-ai-go/models/components" "log" ) @@ -122,15 +144,50 @@ actions: s := livepeeraigo.New( livepeeraigo.WithSecurity(""), ) - request := components.BodyUpscaleUpscalePost{ - Prompt: "", - Image: components.BodyUpscaleUpscalePostImage{ - FileName: "your_file_here", - Content: os.Open(""), + + content, fileErr := os.Open("example.file") + if fileErr != nil { + panic(fileErr) + } + + ctx := context.Background() + res, err := s.SegmentAnything2(ctx, components.BodySegmentAnything2SegmentAnything2Post{ + Image: components.BodySegmentAnything2SegmentAnything2PostImage{ + FileName: "example.file", + Content: content, }, + }) + if err != nil { + log.Fatal(err) + } + if res.MasksResponse != nil { + // handle response } + } + - target: $["paths"]["/text-to-image"]["post"] + update: + x-codeSamples: + - lang: go + label: text_to_image + source: |- + package main + + import( + livepeeraigo "github.com/livepeer/livepeer-ai-go" + "context" + "github.com/livepeer/livepeer-ai-go/models/components" + "log" + ) + + func main() { + s := livepeeraigo.New( + livepeeraigo.WithSecurity(""), + ) + ctx := context.Background() - res, err := s.Upscale(ctx, request) + res, err := s.TextToImage(ctx, components.TextToImageParams{ + Prompt: "", + }) if err != nil { log.Fatal(err) } @@ -138,18 +195,19 @@ actions: // handle response } } - - target: $["paths"]["/audio-to-text"]["post"] + - target: $["paths"]["/upscale"]["post"] update: x-codeSamples: - lang: go - label: audio_to_text + label: upscale source: |- package main import( livepeeraigo "github.com/livepeer/livepeer-ai-go" - "github.com/livepeer/livepeer-ai-go/models/components" + "os" "context" + "github.com/livepeer/livepeer-ai-go/models/components" "log" ) @@ -157,18 +215,24 @@ actions: s := livepeeraigo.New( livepeeraigo.WithSecurity(""), ) - request := components.BodyAudioToTextAudioToTextPost{ - Audio: components.Audio{ - FileName: "your_file_here", - Content: os.Open(""), - }, + + content, fileErr := os.Open("example.file") + if fileErr != nil { + panic(fileErr) } + ctx := context.Background() - res, err := s.AudioToText(ctx, request) + res, err := s.Upscale(ctx, components.BodyUpscaleUpscalePost{ + Prompt: "", + Image: components.BodyUpscaleUpscalePostImage{ + FileName: "example.file", + Content: content, + }, + }) if err != nil { log.Fatal(err) } - if res.TextResponse != nil { + if res.ImageResponse != nil { // handle response } } diff --git a/docs/models/components/bodysegmentanything2segmentanything2post.md b/docs/models/components/bodysegmentanything2segmentanything2post.md new file mode 100644 index 0000000..a9527d0 --- /dev/null +++ b/docs/models/components/bodysegmentanything2segmentanything2post.md @@ -0,0 +1,16 @@ +# BodySegmentAnything2SegmentAnything2Post + + +## Fields + +| Field | Type | Required | Description | +| ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | +| `Image` | [components.BodySegmentAnything2SegmentAnything2PostImage](../../models/components/bodysegmentanything2segmentanything2postimage.md) | :heavy_check_mark: | Image to segment. | +| `ModelID` | **string* | :heavy_minus_sign: | Hugging Face model ID used for image generation. | +| `PointCoords` | **string* | :heavy_minus_sign: | Nx2 array of point prompts to the model, where each point is in (X,Y) in pixels. | +| `PointLabels` | **string* | :heavy_minus_sign: | Labels for the point prompts, where 1 indicates a foreground point and 0 indicates a background point. | +| `Box` | **string* | :heavy_minus_sign: | A length 4 array given as a box prompt to the model, in XYXY format. | +| `MaskInput` | **string* | :heavy_minus_sign: | A low-resolution mask input to the model, typically from a previous prediction iteration, with the form 1xHxW (H=W=256 for SAM). | +| `MultimaskOutput` | **bool* | :heavy_minus_sign: | If true, the model will return three masks for ambiguous input prompts, often producing better masks than a single prediction. | +| `ReturnLogits` | **bool* | :heavy_minus_sign: | If true, returns un-thresholded mask logits instead of a binary mask. | +| `NormalizeCoords` | **bool* | :heavy_minus_sign: | If true, the point coordinates will be normalized to the range [0,1], with point_coords expected to be with respect to image dimensions. | \ No newline at end of file diff --git a/docs/models/components/bodysegmentanything2segmentanything2postimage.md b/docs/models/components/bodysegmentanything2segmentanything2postimage.md new file mode 100644 index 0000000..2488730 --- /dev/null +++ b/docs/models/components/bodysegmentanything2segmentanything2postimage.md @@ -0,0 +1,9 @@ +# BodySegmentAnything2SegmentAnything2PostImage + + +## Fields + +| Field | Type | Required | Description | +| ------------------ | ------------------ | ------------------ | ------------------ | +| `FileName` | *string* | :heavy_check_mark: | N/A | +| `Content` | *any* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/models/components/masksresponse.md b/docs/models/components/masksresponse.md new file mode 100644 index 0000000..8a5c5c0 --- /dev/null +++ b/docs/models/components/masksresponse.md @@ -0,0 +1,12 @@ +# MasksResponse + +Response model for object segmentation. + + +## Fields + +| Field | Type | Required | Description | +| --------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------- | +| `Masks` | *string* | :heavy_check_mark: | The generated masks. | +| `Scores` | *string* | :heavy_check_mark: | The model's confidence scores for each generated mask. | +| `Logits` | *string* | :heavy_check_mark: | The raw, unnormalized predictions (logits) for the masks. | \ No newline at end of file diff --git a/docs/models/operations/segmentanything2response.md b/docs/models/operations/segmentanything2response.md new file mode 100644 index 0000000..e35e37d --- /dev/null +++ b/docs/models/operations/segmentanything2response.md @@ -0,0 +1,9 @@ +# SegmentAnything2Response + + +## Fields + +| Field | Type | Required | Description | +| --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- | +| `HTTPMeta` | [components.HTTPMetadata](../../models/components/httpmetadata.md) | :heavy_check_mark: | N/A | +| `MasksResponse` | [*components.MasksResponse](../../models/components/masksresponse.md) | :heavy_minus_sign: | Successful Response | \ No newline at end of file diff --git a/internal/utils/json.go b/internal/utils/json.go index 4d05968..0eb3953 100644 --- a/internal/utils/json.go +++ b/internal/utils/json.go @@ -487,30 +487,29 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa v.Set(m) return nil case reflect.Slice, reflect.Array: - if bytes.Equal(value, []byte("null")) || !isComplexValueType(dereferenceTypePointer(typ.Elem())) { - if v.CanAddr() { - return json.Unmarshal(value, v.Addr().Interface()) - } else { - return json.Unmarshal(value, v.Interface()) - } - } - - var unmarhsaled []json.RawMessage + var unmarshaled []json.RawMessage - if err := json.Unmarshal(value, &unmarhsaled); err != nil { + if err := json.Unmarshal(value, &unmarshaled); err != nil { return err } - arrVal := v + arrVal := reflect.MakeSlice(typ, len(unmarshaled), len(unmarshaled)) - for _, value := range unmarhsaled { + for index, value := range unmarshaled { itemVal := reflect.New(typ.Elem()) if err := unmarshalValue(value, itemVal, tag, disallowUnknownFields); err != nil { return err } - arrVal = reflect.Append(arrVal, itemVal.Elem()) + arrVal.Index(index).Set(itemVal.Elem()) + } + + if v.Kind() == reflect.Pointer { + if v.IsNil() { + v.Set(reflect.New(typ)) + } + v = v.Elem() } v.Set(arrVal) diff --git a/internal/utils/requestbody.go b/internal/utils/requestbody.go index cee9da2..000226e 100644 --- a/internal/utils/requestbody.go +++ b/internal/utils/requestbody.go @@ -66,15 +66,16 @@ func serializeRequestBody(request interface{}, nullable, optional bool, requestF if tag != nil { // request object (non-flattened) requestVal := requestValType.FieldByName(requestFieldName) + val := reflect.ValueOf(requestVal.Interface()) if isNil(requestField.Type, requestVal) { if !nullable && optional { return nil, "", nil } - return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag)) + return serializeContentType(requestFieldName, tag.MediaType, val, string(requestField.Tag)) } - return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag)) + return serializeContentType(requestFieldName, tag.MediaType, val, string(requestField.Tag)) } } diff --git a/livepeerai.go b/livepeerai.go index 5355a5d..f68a950 100644 --- a/livepeerai.go +++ b/livepeerai.go @@ -50,6 +50,9 @@ func Float32(f float32) *float32 { return &f } // Float64 provides a helper function to return a pointer to a float64 func Float64(f float64) *float64 { return &f } +// Pointer provides a helper function to return a pointer to a type +func Pointer[T any](v T) *T { return &v } + type sdkConfiguration struct { Client HTTPClient Security func(context.Context) (interface{}, error) @@ -151,10 +154,10 @@ func New(opts ...SDKOption) *LivepeerAI { sdk := &LivepeerAI{ sdkConfiguration: sdkConfiguration{ Language: "go", - OpenAPIDocVersion: "v0.1.3", - SDKVersion: "0.1.6", - GenVersion: "2.407.0", - UserAgent: "speakeasy-sdk/go 0.1.6 2.407.0 v0.1.3 github.com/livepeer/livepeer-ai-go", + OpenAPIDocVersion: "v0.2.0", + SDKVersion: "0.2.0", + GenVersion: "2.415.6", + UserAgent: "speakeasy-sdk/go 0.2.0 2.415.6 v0.2.0 github.com/livepeer/livepeer-ai-go", Hooks: hooks.New(), }, } @@ -325,17 +328,25 @@ func (s *LivepeerAI) TextToImage(ctx context.Context, request components.TextToI }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) + getRawBody := func() ([]byte, error) { + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) + return rawBody, nil } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out components.ImageResponse if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -343,6 +354,11 @@ func (s *LivepeerAI) TextToImage(ctx context.Context, request components.TextToI res.ImageResponse = &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 400: @@ -352,6 +368,11 @@ func (s *LivepeerAI) TextToImage(ctx context.Context, request components.TextToI case httpRes.StatusCode == 500: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -359,11 +380,21 @@ func (s *LivepeerAI) TextToImage(ctx context.Context, request components.TextToI return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 422: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPValidationError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -371,13 +402,28 @@ func (s *LivepeerAI) TextToImage(ctx context.Context, request components.TextToI return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -533,17 +579,25 @@ func (s *LivepeerAI) ImageToImage(ctx context.Context, request components.BodyIm }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) + getRawBody := func() ([]byte, error) { + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) + return rawBody, nil } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out components.ImageResponse if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -551,6 +605,11 @@ func (s *LivepeerAI) ImageToImage(ctx context.Context, request components.BodyIm res.ImageResponse = &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 400: @@ -560,6 +619,11 @@ func (s *LivepeerAI) ImageToImage(ctx context.Context, request components.BodyIm case httpRes.StatusCode == 500: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -567,11 +631,21 @@ func (s *LivepeerAI) ImageToImage(ctx context.Context, request components.BodyIm return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 422: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPValidationError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -579,13 +653,28 @@ func (s *LivepeerAI) ImageToImage(ctx context.Context, request components.BodyIm return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -741,17 +830,25 @@ func (s *LivepeerAI) ImageToVideo(ctx context.Context, request components.BodyIm }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) + getRawBody := func() ([]byte, error) { + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) + return rawBody, nil } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out components.VideoResponse if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -759,6 +856,11 @@ func (s *LivepeerAI) ImageToVideo(ctx context.Context, request components.BodyIm res.VideoResponse = &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 400: @@ -768,6 +870,11 @@ func (s *LivepeerAI) ImageToVideo(ctx context.Context, request components.BodyIm case httpRes.StatusCode == 500: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -775,11 +882,21 @@ func (s *LivepeerAI) ImageToVideo(ctx context.Context, request components.BodyIm return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 422: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPValidationError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -787,13 +904,28 @@ func (s *LivepeerAI) ImageToVideo(ctx context.Context, request components.BodyIm return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -949,17 +1081,25 @@ func (s *LivepeerAI) Upscale(ctx context.Context, request components.BodyUpscale }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) + getRawBody := func() ([]byte, error) { + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) + return rawBody, nil } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out components.ImageResponse if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -967,6 +1107,11 @@ func (s *LivepeerAI) Upscale(ctx context.Context, request components.BodyUpscale res.ImageResponse = &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 400: @@ -976,6 +1121,11 @@ func (s *LivepeerAI) Upscale(ctx context.Context, request components.BodyUpscale case httpRes.StatusCode == 500: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -983,11 +1133,21 @@ func (s *LivepeerAI) Upscale(ctx context.Context, request components.BodyUpscale return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 422: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPValidationError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -995,13 +1155,28 @@ func (s *LivepeerAI) Upscale(ctx context.Context, request components.BodyUpscale return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -1157,17 +1332,25 @@ func (s *LivepeerAI) AudioToText(ctx context.Context, request components.BodyAud }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) + getRawBody := func() ([]byte, error) { + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) + return rawBody, nil } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out components.TextResponse if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -1175,6 +1358,11 @@ func (s *LivepeerAI) AudioToText(ctx context.Context, request components.BodyAud res.TextResponse = &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 400: @@ -1186,6 +1374,11 @@ func (s *LivepeerAI) AudioToText(ctx context.Context, request components.BodyAud case httpRes.StatusCode == 500: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -1193,11 +1386,21 @@ func (s *LivepeerAI) AudioToText(ctx context.Context, request components.BodyAud return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 422: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + var out sdkerrors.HTTPValidationError if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -1205,13 +1408,279 @@ func (s *LivepeerAI) AudioToText(ctx context.Context, request components.BodyAud return nil, &out default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + + return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} + +// SegmentAnything2 - Segment Anything 2 +// Segment objects in an image. +func (s *LivepeerAI) SegmentAnything2(ctx context.Context, request components.BodySegmentAnything2SegmentAnything2Post, opts ...operations.Option) (*operations.SegmentAnything2Response, error) { + hookCtx := hooks.HookContext{ + Context: ctx, + OperationID: "segment_anything_2", + OAuth2Scopes: []string{}, + SecuritySource: s.sdkConfiguration.Security, + } + + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionRetries, + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + opURL, err := url.JoinPath(baseURL, "/segment-anything-2") + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "multipart", `request:"mediaType=multipart/form-data"`) + if err != nil { + return nil, err + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + req.Header.Set("Content-Type", reqContentType) + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + globalRetryConfig := s.sdkConfiguration.RetryConfig + retryConfig := o.Retries + if retryConfig == nil { + if globalRetryConfig != nil { + retryConfig = globalRetryConfig + } + } + + var httpRes *http.Response + if retryConfig != nil { + httpRes, err = utils.Retry(ctx, utils.Retries{ + Config: retryConfig, + StatusCodes: []string{ + "429", + "500", + "502", + "503", + "504", + }, + }, func() (*http.Response, error) { + if req.Body != nil { + copyBody, err := req.GetBody() + if err != nil { + return nil, err + } + req.Body = copyBody + } + + req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, backoff.Permanent(err) + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } + return httpRes, err + }) + + if err != nil { + return nil, err + } else { + httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + } else { + req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err = s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{"400", "401", "422", "4XX", "500", "5XX"}, httpRes.StatusCode) { + _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + } + + res := &operations.SegmentAnything2Response{ + HTTPMeta: components.HTTPMetadata{ + Request: req, + Response: httpRes, + }, + } + + getRawBody := func() ([]byte, error) { + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) + return rawBody, nil + } + + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + + var out components.MasksResponse + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.MasksResponse = &out + default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 400: + fallthrough + case httpRes.StatusCode == 401: + fallthrough + case httpRes.StatusCode == 500: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + + var out sdkerrors.HTTPError + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + return nil, &out + default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 422: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + + var out sdkerrors.HTTPValidationError + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + return nil, &out + default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: + fallthrough + case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + + return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) + default: + rawBody, err := getRawBody() + if err != nil { + return nil, err + } + return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } diff --git a/models/components/bodysegmentanything2segmentanything2post.go b/models/components/bodysegmentanything2segmentanything2post.go new file mode 100644 index 0000000..4cfca33 --- /dev/null +++ b/models/components/bodysegmentanything2segmentanything2post.go @@ -0,0 +1,122 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package components + +import ( + "github.com/livepeer/livepeer-ai-go/internal/utils" +) + +type BodySegmentAnything2SegmentAnything2PostImage struct { + FileName string `multipartForm:"name=image"` + // This field accepts []byte data or io.Reader implementations, such as *os.File. + Content any `multipartForm:"content"` +} + +func (o *BodySegmentAnything2SegmentAnything2PostImage) GetFileName() string { + if o == nil { + return "" + } + return o.FileName +} + +func (o *BodySegmentAnything2SegmentAnything2PostImage) GetContent() any { + if o == nil { + return nil + } + return o.Content +} + +type BodySegmentAnything2SegmentAnything2Post struct { + // Image to segment. + Image BodySegmentAnything2SegmentAnything2PostImage `multipartForm:"file"` + // Hugging Face model ID used for image generation. + ModelID *string `default:"" multipartForm:"name=model_id"` + // Nx2 array of point prompts to the model, where each point is in (X,Y) in pixels. + PointCoords *string `multipartForm:"name=point_coords"` + // Labels for the point prompts, where 1 indicates a foreground point and 0 indicates a background point. + PointLabels *string `multipartForm:"name=point_labels"` + // A length 4 array given as a box prompt to the model, in XYXY format. + Box *string `multipartForm:"name=box"` + // A low-resolution mask input to the model, typically from a previous prediction iteration, with the form 1xHxW (H=W=256 for SAM). + MaskInput *string `multipartForm:"name=mask_input"` + // If true, the model will return three masks for ambiguous input prompts, often producing better masks than a single prediction. + MultimaskOutput *bool `default:"true" multipartForm:"name=multimask_output"` + // If true, returns un-thresholded mask logits instead of a binary mask. + ReturnLogits *bool `default:"true" multipartForm:"name=return_logits"` + // If true, the point coordinates will be normalized to the range [0,1], with point_coords expected to be with respect to image dimensions. + NormalizeCoords *bool `default:"true" multipartForm:"name=normalize_coords"` +} + +func (b BodySegmentAnything2SegmentAnything2Post) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(b, "", false) +} + +func (b *BodySegmentAnything2SegmentAnything2Post) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &b, "", false, false); err != nil { + return err + } + return nil +} + +func (o *BodySegmentAnything2SegmentAnything2Post) GetImage() BodySegmentAnything2SegmentAnything2PostImage { + if o == nil { + return BodySegmentAnything2SegmentAnything2PostImage{} + } + return o.Image +} + +func (o *BodySegmentAnything2SegmentAnything2Post) GetModelID() *string { + if o == nil { + return nil + } + return o.ModelID +} + +func (o *BodySegmentAnything2SegmentAnything2Post) GetPointCoords() *string { + if o == nil { + return nil + } + return o.PointCoords +} + +func (o *BodySegmentAnything2SegmentAnything2Post) GetPointLabels() *string { + if o == nil { + return nil + } + return o.PointLabels +} + +func (o *BodySegmentAnything2SegmentAnything2Post) GetBox() *string { + if o == nil { + return nil + } + return o.Box +} + +func (o *BodySegmentAnything2SegmentAnything2Post) GetMaskInput() *string { + if o == nil { + return nil + } + return o.MaskInput +} + +func (o *BodySegmentAnything2SegmentAnything2Post) GetMultimaskOutput() *bool { + if o == nil { + return nil + } + return o.MultimaskOutput +} + +func (o *BodySegmentAnything2SegmentAnything2Post) GetReturnLogits() *bool { + if o == nil { + return nil + } + return o.ReturnLogits +} + +func (o *BodySegmentAnything2SegmentAnything2Post) GetNormalizeCoords() *bool { + if o == nil { + return nil + } + return o.NormalizeCoords +} diff --git a/models/components/masksresponse.go b/models/components/masksresponse.go new file mode 100644 index 0000000..62dc852 --- /dev/null +++ b/models/components/masksresponse.go @@ -0,0 +1,34 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package components + +// MasksResponse - Response model for object segmentation. +type MasksResponse struct { + // The generated masks. + Masks string `json:"masks"` + // The model's confidence scores for each generated mask. + Scores string `json:"scores"` + // The raw, unnormalized predictions (logits) for the masks. + Logits string `json:"logits"` +} + +func (o *MasksResponse) GetMasks() string { + if o == nil { + return "" + } + return o.Masks +} + +func (o *MasksResponse) GetScores() string { + if o == nil { + return "" + } + return o.Scores +} + +func (o *MasksResponse) GetLogits() string { + if o == nil { + return "" + } + return o.Logits +} diff --git a/models/operations/segmentanything2.go b/models/operations/segmentanything2.go new file mode 100644 index 0000000..0f8baee --- /dev/null +++ b/models/operations/segmentanything2.go @@ -0,0 +1,27 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/livepeer/livepeer-ai-go/models/components" +) + +type SegmentAnything2Response struct { + HTTPMeta components.HTTPMetadata `json:"-"` + // Successful Response + MasksResponse *components.MasksResponse +} + +func (o *SegmentAnything2Response) GetHTTPMeta() components.HTTPMetadata { + if o == nil { + return components.HTTPMetadata{} + } + return o.HTTPMeta +} + +func (o *SegmentAnything2Response) GetMasksResponse() *components.MasksResponse { + if o == nil { + return nil + } + return o.MasksResponse +} diff --git a/types/pointers.go b/types/pointers.go index 950d6a3..35c439d 100644 --- a/types/pointers.go +++ b/types/pointers.go @@ -8,3 +8,4 @@ func Int(i int) *int { return &i } func Int64(i int64) *int64 { return &i } func Float32(f float32) *float32 { return &f } func Float64(f float64) *float64 { return &f } +func Pointer[T any](v T) *T { return &v }