From a2e15c2c5c69a3b8783a0549b0b3216ec8b33203 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:53:55 +0200 Subject: [PATCH] ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.421.2 (#19) Co-authored-by: speakeasybot --- .speakeasy/gen.lock | 31 +++- .speakeasy/gen.yaml | 3 +- .speakeasy/workflow.lock | 12 +- README.md | 17 +- RELEASES.md | 12 +- codeSamples.yaml | 23 +++ docs/models/components/bodygenimagetotext.md | 17 ++ .../components/bodygenimagetotextimage.md | 16 ++ docs/models/components/imageresponse.md | 4 +- docs/models/components/imagetotextresponse.md | 19 +++ docs/models/components/llmresponse.md | 2 +- docs/models/components/loc.md | 2 +- docs/models/components/media.md | 4 +- docs/models/components/validationerror.md | 2 +- docs/models/components/videoresponse.md | 4 +- .../operations/genimagetotextresponse.md | 24 +++ docs/sdks/generate/README.md | 83 +++++++++- jsr.json | 2 +- package-lock.json | 4 +- package.json | 2 +- src/funcs/generateAudioToText.ts | 8 +- src/funcs/generateImageToImage.ts | 4 +- src/funcs/generateImageToText.ts | 155 ++++++++++++++++++ src/funcs/generateImageToVideo.ts | 4 +- src/funcs/generateLlm.ts | 4 +- src/funcs/generateSegmentAnything2.ts | 4 +- src/funcs/generateTextToImage.ts | 4 +- src/funcs/generateUpscale.ts | 4 +- src/lib/config.ts | 8 +- src/models/components/bodygenimagetotext.ts | 128 +++++++++++++++ src/models/components/imagetotextresponse.ts | 51 ++++++ src/models/components/index.ts | 2 + src/models/operations/genimagetotext.ts | 87 ++++++++++ src/models/operations/index.ts | 1 + src/sdk/generate.ts | 18 ++ 35 files changed, 702 insertions(+), 63 deletions(-) create mode 100644 docs/models/components/bodygenimagetotext.md create mode 100644 docs/models/components/bodygenimagetotextimage.md create mode 100644 docs/models/components/imagetotextresponse.md create mode 100644 docs/models/operations/genimagetotextresponse.md create mode 100644 src/funcs/generateImageToText.ts create mode 100644 src/models/components/bodygenimagetotext.ts create mode 100644 src/models/components/imagetotextresponse.ts create mode 100644 src/models/operations/genimagetotext.ts diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 7325c2d..02b2cc3 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,11 +1,12 @@ lockVersion: 2.0.0 id: 8bd6d3b6-cae6-4e55-b72f-6fdc1dbce9a1 management: - docChecksum: 21334b8071b6c8e28a5dda229ceafd7e - speakeasyVersion: 1.405.6 - generationVersion: 2.428.1 - releaseVersion: 0.4.0 - configChecksum: afd3c6579111409ef5d5b0b954be5634 + docChecksum: a140881cbcff74961991f5dfff13f0a0 + docVersion: 0.0.0 + speakeasyVersion: 1.421.2 + generationVersion: 2.438.15 + releaseVersion: 0.4.1 + configChecksum: 2d2321dd652b40627a863461eab6e343 repoURL: https://github.com/livepeer/livepeer-ai-js.git installationURL: https://github.com/livepeer/livepeer-ai-js published: true @@ -13,7 +14,7 @@ features: typescript: additionalDependencies: 0.1.0 constsAndDefaults: 0.1.11 - core: 3.18.1 + core: 3.18.2 defaultEnabledRetries: 0.1.0 envVarSecurityUsage: 0.1.1 globalSecurity: 2.82.11 @@ -38,6 +39,8 @@ generatedFiles: - docs/models/components/audio.md - docs/models/components/bodygenaudiototext.md - docs/models/components/bodygenimagetoimage.md + - docs/models/components/bodygenimagetotext.md + - docs/models/components/bodygenimagetotextimage.md - docs/models/components/bodygenimagetovideo.md - docs/models/components/bodygenimagetovideoimage.md - docs/models/components/bodygenllm.md @@ -48,6 +51,7 @@ generatedFiles: - docs/models/components/chunk.md - docs/models/components/image.md - docs/models/components/imageresponse.md + - docs/models/components/imagetotextresponse.md - docs/models/components/llmresponse.md - docs/models/components/loc.md - docs/models/components/masksresponse.md @@ -61,6 +65,7 @@ generatedFiles: - docs/models/errors/httpvalidationerror.md - docs/models/operations/genaudiototextresponse.md - docs/models/operations/genimagetoimageresponse.md + - docs/models/operations/genimagetotextresponse.md - docs/models/operations/genimagetovideoresponse.md - docs/models/operations/genllmresponse.md - docs/models/operations/gensegmentanything2response.md @@ -73,6 +78,7 @@ generatedFiles: - src/core.ts - src/funcs/generateAudioToText.ts - src/funcs/generateImageToImage.ts + - src/funcs/generateImageToText.ts - src/funcs/generateImageToVideo.ts - src/funcs/generateLlm.ts - src/funcs/generateSegmentAnything2.ts @@ -100,12 +106,14 @@ generatedFiles: - src/models/components/apierror.ts - src/models/components/bodygenaudiototext.ts - src/models/components/bodygenimagetoimage.ts + - src/models/components/bodygenimagetotext.ts - src/models/components/bodygenimagetovideo.ts - src/models/components/bodygenllm.ts - src/models/components/bodygensegmentanything2.ts - src/models/components/bodygenupscale.ts - src/models/components/chunk.ts - src/models/components/imageresponse.ts + - src/models/components/imagetotextresponse.ts - src/models/components/index.ts - src/models/components/llmresponse.ts - src/models/components/masksresponse.ts @@ -123,6 +131,7 @@ generatedFiles: - src/models/errors/sdkvalidationerror.ts - src/models/operations/genaudiototext.ts - src/models/operations/genimagetoimage.ts + - src/models/operations/genimagetotext.ts - src/models/operations/genimagetovideo.ts - src/models/operations/genllm.ts - src/models/operations/gensegmentanything2.ts @@ -212,3 +221,13 @@ examples: "400": application/json: {"detail": {"msg": ""}} "422": {} + genImageToText: + speakeasy-default-gen-image-to-text: + requestBody: + multipart/form-data: {"image": {}} + responses: + "200": + application/json: {"text": ""} + "400": + application/json: {"detail": {"msg": ""}} + "422": {} diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 10094d5..4d88e33 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -11,7 +11,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: false typescript: - version: 0.4.0 + version: 0.4.1 additionalDependencies: dependencies: jest: ^29.7.0 @@ -25,6 +25,7 @@ typescript: clientServerStatusCodesAsErrors: true enumFormat: enum flattenGlobalSecurity: true + flatteningOrder: body-first imports: option: openapi paths: diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index b8dc8c7..635d027 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,9 +1,9 @@ -speakeasyVersion: 1.405.6 +speakeasyVersion: 1.421.2 sources: livepeer-ai-OAS: sourceNamespace: livepeer-ai-oas - sourceRevisionDigest: sha256:28d29014d26e0617906dcc16a4ceef1e093bd486b956a13eba844f8653004fca - sourceBlobDigest: sha256:1381f76cad0ec28b51d5559fdf87a0b14f39e2946fe25e0c21c0b8b0fe42cf99 + sourceRevisionDigest: sha256:5354d8a69a4e1db3706c645db7becd62271bfc93572f1a65dc1df1fc8575ed1a + sourceBlobDigest: sha256:ad0b2e92bea306b60b1929309669cb1c3ca574325bb0ab4a2e44949fc8249a9f tags: - latest - main @@ -11,10 +11,10 @@ targets: livepeer-ai-ts: source: livepeer-ai-OAS sourceNamespace: livepeer-ai-oas - sourceRevisionDigest: sha256:28d29014d26e0617906dcc16a4ceef1e093bd486b956a13eba844f8653004fca - sourceBlobDigest: sha256:1381f76cad0ec28b51d5559fdf87a0b14f39e2946fe25e0c21c0b8b0fe42cf99 + sourceRevisionDigest: sha256:5354d8a69a4e1db3706c645db7becd62271bfc93572f1a65dc1df1fc8575ed1a + sourceBlobDigest: sha256:ad0b2e92bea306b60b1929309669cb1c3ca574325bb0ab4a2e44949fc8249a9f codeSamplesNamespace: code-samples-typescript-livepeer-ts - codeSamplesRevisionDigest: sha256:dbf36c79c6b1c0a0c034081e1b0b210571b9f155e26c0f5bdf524ae4f3d05214 + codeSamplesRevisionDigest: sha256:18cc5cd255be78c6bec9835dcfab751472a892f985bc172cb82f5cb6dadd6cb1 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/README.md b/README.md index da9895e..ead047d 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ run(); * [audioToText](docs/sdks/generate/README.md#audiototext) - Audio To Text * [segmentAnything2](docs/sdks/generate/README.md#segmentanything2) - Segment Anything 2 * [llm](docs/sdks/generate/README.md#llm) - LLM +* [imageToText](docs/sdks/generate/README.md#imagetotext) - Image To Text @@ -109,14 +110,14 @@ To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md). Available standalone functions -- [generateAudioToText](docs/sdks/generate/README.md#audiototext) -- [generateImageToImage](docs/sdks/generate/README.md#imagetoimage) -- [generateImageToVideo](docs/sdks/generate/README.md#imagetovideo) -- [generateLlm](docs/sdks/generate/README.md#llm) -- [generateSegmentAnything2](docs/sdks/generate/README.md#segmentanything2) -- [generateTextToImage](docs/sdks/generate/README.md#texttoimage) -- [generateUpscale](docs/sdks/generate/README.md#upscale) - +- [`generateAudioToText`](docs/sdks/generate/README.md#audiototext) - Audio To Text +- [`generateImageToImage`](docs/sdks/generate/README.md#imagetoimage) - Image To Image +- [`generateImageToText`](docs/sdks/generate/README.md#imagetotext) - Image To Text +- [`generateImageToVideo`](docs/sdks/generate/README.md#imagetovideo) - Image To Video +- [`generateLlm`](docs/sdks/generate/README.md#llm) - LLM +- [`generateSegmentAnything2`](docs/sdks/generate/README.md#segmentanything2) - Segment Anything 2 +- [`generateTextToImage`](docs/sdks/generate/README.md#texttoimage) - Text To Image +- [`generateUpscale`](docs/sdks/generate/README.md#upscale) - Upscale diff --git a/RELEASES.md b/RELEASES.md index 36ded32..e94012f 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -90,4 +90,14 @@ Based on: ### Generated - [typescript v0.4.0] . ### Releases -- [NPM v0.4.0] https://www.npmjs.com/package/@livepeer/ai/v/0.4.0 - . \ No newline at end of file +- [NPM v0.4.0] https://www.npmjs.com/package/@livepeer/ai/v/0.4.0 - . + +## 2024-10-25 00:01:21 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.421.2 (2.438.15) https://github.com/speakeasy-api/speakeasy +### Generated +- [typescript v0.4.1] . +### Releases +- [NPM v0.4.1] https://www.npmjs.com/package/@livepeer/ai/v/0.4.1 - . \ No newline at end of file diff --git a/codeSamples.yaml b/codeSamples.yaml index 8f16837..51e1b9a 100644 --- a/codeSamples.yaml +++ b/codeSamples.yaml @@ -49,6 +49,29 @@ actions: console.log(result); } + run(); + - target: $["paths"]["/image-to-text"]["post"] + update: + x-codeSamples: + - lang: typescript + label: genImageToText + source: |- + import { Livepeer } from "@livepeer/ai"; + import { openAsBlob } from "node:fs"; + + const livepeer = new Livepeer({ + httpBearer: "", + }); + + async function run() { + const result = await livepeer.generate.imageToText({ + image: await openAsBlob("example.file"), + }); + + // Handle the result + console.log(result); + } + run(); - target: $["paths"]["/image-to-video"]["post"] update: diff --git a/docs/models/components/bodygenimagetotext.md b/docs/models/components/bodygenimagetotext.md new file mode 100644 index 0000000..5eec08d --- /dev/null +++ b/docs/models/components/bodygenimagetotext.md @@ -0,0 +1,17 @@ +# BodyGenImageToText + +## Example Usage + +```typescript +import { BodyGenImageToText } from "@livepeer/ai/models/components"; + +// No examples available for this model +``` + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `image` | [File](https://developer.mozilla.org/en-US/docs/Web/API/File) \| [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) \| [components.BodyGenImageToTextImage](../../models/components/bodygenimagetotextimage.md) | :heavy_check_mark: | Uploaded image to transform with the pipeline. | +| `modelId` | *string* | :heavy_minus_sign: | Hugging Face model ID used for transformation. | +| `prompt` | *string* | :heavy_minus_sign: | Text prompt(s) to guide transformation. | \ No newline at end of file diff --git a/docs/models/components/bodygenimagetotextimage.md b/docs/models/components/bodygenimagetotextimage.md new file mode 100644 index 0000000..436433c --- /dev/null +++ b/docs/models/components/bodygenimagetotextimage.md @@ -0,0 +1,16 @@ +# BodyGenImageToTextImage + +## Example Usage + +```typescript +import { BodyGenImageToTextImage } from "@livepeer/ai/models/components"; + +// No examples available for this model +``` + +## Fields + +| Field | Type | Required | Description | +| ---------------------------- | ---------------------------- | ---------------------------- | ---------------------------- | +| `fileName` | *string* | :heavy_check_mark: | N/A | +| `content` | *ReadableStream* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/models/components/imageresponse.md b/docs/models/components/imageresponse.md index 7daa14b..458da10 100644 --- a/docs/models/components/imageresponse.md +++ b/docs/models/components/imageresponse.md @@ -10,8 +10,8 @@ import { ImageResponse } from "@livepeer/ai/models/components"; let value: ImageResponse = { images: [ { - url: "https://bright-agreement.net/", - seed: 778157, + url: "https://talkative-sauerkraut.org/", + seed: 978619, nsfw: false, }, ], diff --git a/docs/models/components/imagetotextresponse.md b/docs/models/components/imagetotextresponse.md new file mode 100644 index 0000000..adb93cf --- /dev/null +++ b/docs/models/components/imagetotextresponse.md @@ -0,0 +1,19 @@ +# ImageToTextResponse + +Response model for text generation. + +## Example Usage + +```typescript +import { ImageToTextResponse } from "@livepeer/ai/models/components"; + +let value: ImageToTextResponse = { + text: "", +}; +``` + +## Fields + +| Field | Type | Required | Description | +| ------------------- | ------------------- | ------------------- | ------------------- | +| `text` | *string* | :heavy_check_mark: | The generated text. | \ No newline at end of file diff --git a/docs/models/components/llmresponse.md b/docs/models/components/llmresponse.md index 2f85d22..b07f1df 100644 --- a/docs/models/components/llmresponse.md +++ b/docs/models/components/llmresponse.md @@ -7,7 +7,7 @@ import { LLMResponse } from "@livepeer/ai/models/components"; let value: LLMResponse = { response: "", - tokensUsed: 456150, + tokensUsed: 18789, }; ``` diff --git a/docs/models/components/loc.md b/docs/models/components/loc.md index 0b19f16..161afed 100644 --- a/docs/models/components/loc.md +++ b/docs/models/components/loc.md @@ -12,6 +12,6 @@ const value: string = ""; ### `number` ```typescript -const value: number = 118274; +const value: number = 143353; ``` diff --git a/docs/models/components/media.md b/docs/models/components/media.md index ed93a3d..24daf7b 100644 --- a/docs/models/components/media.md +++ b/docs/models/components/media.md @@ -8,8 +8,8 @@ A media object containing information about the generated media. import { Media } from "@livepeer/ai/models/components"; let value: Media = { - url: "https://wonderful-sediment.info", - seed: 780529, + url: "https://leading-scaffold.com", + seed: 639921, nsfw: false, }; ``` diff --git a/docs/models/components/validationerror.md b/docs/models/components/validationerror.md index 9f6a4ea..8f58658 100644 --- a/docs/models/components/validationerror.md +++ b/docs/models/components/validationerror.md @@ -7,7 +7,7 @@ import { ValidationError } from "@livepeer/ai/models/components"; let value: ValidationError = { loc: [ - 143353, + 521848, ], msg: "", type: "", diff --git a/docs/models/components/videoresponse.md b/docs/models/components/videoresponse.md index fe858ae..5ed83e8 100644 --- a/docs/models/components/videoresponse.md +++ b/docs/models/components/videoresponse.md @@ -10,8 +10,8 @@ import { VideoResponse } from "@livepeer/ai/models/components"; let value: VideoResponse = { images: [ { - url: "https://misguided-hawk.biz", - seed: 774234, + url: "https://favorable-sand.info/", + seed: 568434, nsfw: false, }, ], diff --git a/docs/models/operations/genimagetotextresponse.md b/docs/models/operations/genimagetotextresponse.md new file mode 100644 index 0000000..ce3040d --- /dev/null +++ b/docs/models/operations/genimagetotextresponse.md @@ -0,0 +1,24 @@ +# GenImageToTextResponse + +## Example Usage + +```typescript +import { GenImageToTextResponse } from "@livepeer/ai/models/operations"; + +let value: GenImageToTextResponse = { + contentType: "", + statusCode: 100, + rawResponse: new Response("{\"message\": \"hello world\"}", { + headers: { "Content-Type": "application/json" }, + }), +}; +``` + +## Fields + +| Field | Type | Required | Description | +| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | +| `contentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `statusCode` | *number* | :heavy_check_mark: | HTTP response status code for this operation | +| `rawResponse` | [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing | +| `imageToTextResponse` | [components.ImageToTextResponse](../../models/components/imagetotextresponse.md) | :heavy_minus_sign: | Successful Response | \ No newline at end of file diff --git a/docs/sdks/generate/README.md b/docs/sdks/generate/README.md index d30856f..4be3023 100644 --- a/docs/sdks/generate/README.md +++ b/docs/sdks/generate/README.md @@ -12,6 +12,7 @@ * [audioToText](#audiototext) - Audio To Text * [segmentAnything2](#segmentanything2) - Segment Anything 2 * [llm](#llm) - LLM +* [imageToText](#imagetotext) - Image To Text ## textToImage @@ -411,7 +412,7 @@ run(); | Error Type | Status Code | Content Type | | -------------------------- | -------------------------- | -------------------------- | -| errors.HTTPError | 400, 401, 413, 500 | application/json | +| errors.HTTPError | 400, 401, 413, 415, 500 | application/json | | errors.HTTPValidationError | 422 | application/json | | errors.SDKError | 4XX, 5XX | \*/\* | @@ -571,4 +572,84 @@ run(); | -------------------------- | -------------------------- | -------------------------- | | errors.HTTPError | 400, 401, 500 | application/json | | errors.HTTPValidationError | 422 | application/json | +| errors.SDKError | 4XX, 5XX | \*/\* | + +## imageToText + +Transform image files to text. + +### Example Usage + +```typescript +import { Livepeer } from "@livepeer/ai"; +import { openAsBlob } from "node:fs"; + +const livepeer = new Livepeer({ + httpBearer: "", +}); + +async function run() { + const result = await livepeer.generate.imageToText({ + image: await openAsBlob("example.file"), + }); + + // Handle the result + console.log(result); +} + +run(); +``` + +### Standalone function + +The standalone function version of this method: + +```typescript +import { LivepeerCore } from "@livepeer/ai/core.js"; +import { generateImageToText } from "@livepeer/ai/funcs/generateImageToText.js"; +import { openAsBlob } from "node:fs"; + +// Use `LivepeerCore` for best tree-shaking performance. +// You can create one instance of it to use across an application. +const livepeer = new LivepeerCore({ + httpBearer: "", +}); + +async function run() { + const res = await generateImageToText(livepeer, { + image: await openAsBlob("example.file"), + }); + + if (!res.ok) { + throw res.error; + } + + const { value: result } = res; + + // Handle the result + console.log(result); +} + +run(); +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `request` | [components.BodyGenImageToText](../../models/components/bodygenimagetotext.md) | :heavy_check_mark: | The request object to use for the request. | +| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | +| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | +| `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | + +### Response + +**Promise\<[operations.GenImageToTextResponse](../../models/operations/genimagetotextresponse.md)\>** + +### Errors + +| Error Type | Status Code | Content Type | +| -------------------------- | -------------------------- | -------------------------- | +| errors.HTTPError | 400, 401, 413, 500 | application/json | +| errors.HTTPValidationError | 422 | application/json | | errors.SDKError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/jsr.json b/jsr.json index 65dbea1..bb0aad6 100644 --- a/jsr.json +++ b/jsr.json @@ -2,7 +2,7 @@ { "name": "@livepeer/ai", - "version": "0.4.0", + "version": "0.4.1", "exports": { ".": "./src/index.ts", "./models/errors": "./src/models/errors/index.ts", diff --git a/package-lock.json b/package-lock.json index 390f54f..d3dc5f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@livepeer/ai", - "version": "0.4.0", + "version": "0.4.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@livepeer/ai", - "version": "0.4.0", + "version": "0.4.1", "dependencies": { "jest": "^29.7.0", "jest-junit": "^16.0.0", diff --git a/package.json b/package.json index faec81c..59f6d21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@livepeer/ai", - "version": "0.4.0", + "version": "0.4.1", "author": "Livepeer", "main": "./index.js", "sideEffects": false, diff --git a/src/funcs/generateAudioToText.ts b/src/funcs/generateAudioToText.ts index 6791ca5..89614c4 100644 --- a/src/funcs/generateAudioToText.ts +++ b/src/funcs/generateAudioToText.ts @@ -49,10 +49,8 @@ export async function generateAudioToText( | ConnectionError > > { - const input = request; - const parsed = safeParse( - input, + request, (value) => components.BodyGenAudioToText$outboundSchema.parse(value), "Input validation failed", ); @@ -109,7 +107,7 @@ export async function generateAudioToText( const doResult = await client._do(req, { context, - errorCodes: ["400", "401", "413", "422", "4XX", "500", "5XX"], + errorCodes: ["400", "401", "413", "415", "422", "4XX", "500", "5XX"], retryConfig: options?.retries || client._options.retryConfig, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], @@ -142,7 +140,7 @@ export async function generateAudioToText( M.json(200, operations.GenAudioToTextResponse$inboundSchema, { key: "TextResponse", }), - M.jsonErr([400, 401, 413, 500], errors.HTTPError$inboundSchema), + M.jsonErr([400, 401, 413, 415, 500], errors.HTTPError$inboundSchema), M.jsonErr(422, errors.HTTPValidationError$inboundSchema), M.fail(["4XX", "5XX"]), )(response, { extraFields: responseFields }); diff --git a/src/funcs/generateImageToImage.ts b/src/funcs/generateImageToImage.ts index 489903a..eace91f 100644 --- a/src/funcs/generateImageToImage.ts +++ b/src/funcs/generateImageToImage.ts @@ -49,10 +49,8 @@ export async function generateImageToImage( | ConnectionError > > { - const input = request; - const parsed = safeParse( - input, + request, (value) => components.BodyGenImageToImage$outboundSchema.parse(value), "Input validation failed", ); diff --git a/src/funcs/generateImageToText.ts b/src/funcs/generateImageToText.ts new file mode 100644 index 0000000..430d3fb --- /dev/null +++ b/src/funcs/generateImageToText.ts @@ -0,0 +1,155 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { LivepeerCore } from "../core.js"; +import { readableStreamToArrayBuffer } from "../lib/files.js"; +import * as M from "../lib/matchers.js"; +import { safeParse } from "../lib/schemas.js"; +import { RequestOptions } from "../lib/sdks.js"; +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; +import { pathToFunc } from "../lib/url.js"; +import * as components from "../models/components/index.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../models/errors/httpclienterrors.js"; +import * as errors from "../models/errors/index.js"; +import { SDKError } from "../models/errors/sdkerror.js"; +import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; +import * as operations from "../models/operations/index.js"; +import { isBlobLike } from "../types/blobs.js"; +import { Result } from "../types/fp.js"; +import { isReadableStream } from "../types/streams.js"; + +/** + * Image To Text + * + * @remarks + * Transform image files to text. + */ +export async function generateImageToText( + client: LivepeerCore, + request: components.BodyGenImageToText, + options?: RequestOptions, +): Promise< + Result< + operations.GenImageToTextResponse, + | errors.HTTPError + | errors.HTTPValidationError + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const parsed = safeParse( + request, + (value) => components.BodyGenImageToText$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return parsed; + } + const payload = parsed.value; + const body = new FormData(); + + if (isBlobLike(payload.image)) { + body.append("image", payload.image); + } else if (isReadableStream(payload.image.content)) { + const buffer = await readableStreamToArrayBuffer(payload.image.content); + const blob = new Blob([buffer], { type: "application/octet-stream" }); + body.append("image", blob); + } else { + body.append( + "image", + new Blob([payload.image.content], { type: "application/octet-stream" }), + payload.image.fileName, + ); + } + if (payload.model_id !== undefined) { + body.append("model_id", payload.model_id); + } + if (payload.prompt !== undefined) { + body.append("prompt", payload.prompt); + } + + const path = pathToFunc("/image-to-text")(); + + const headers = new Headers({ + Accept: "application/json", + }); + + const secConfig = await extractSecurity(client._options.httpBearer); + const securityInput = secConfig == null ? {} : { httpBearer: secConfig }; + const context = { + operationID: "genImageToText", + oAuth2Scopes: [], + securitySource: client._options.httpBearer, + }; + const requestSecurity = resolveGlobalSecurity(securityInput); + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "POST", + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "413", "422", "4XX", "500", "5XX"], + retryConfig: options?.retries + || client._options.retryConfig, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") + ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GenImageToTextResponse, + | errors.HTTPError + | errors.HTTPValidationError + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json(200, operations.GenImageToTextResponse$inboundSchema, { + key: "ImageToTextResponse", + }), + M.jsonErr([400, 401, 413, 500], errors.HTTPError$inboundSchema), + M.jsonErr(422, errors.HTTPValidationError$inboundSchema), + M.fail(["4XX", "5XX"]), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/src/funcs/generateImageToVideo.ts b/src/funcs/generateImageToVideo.ts index c56bc8f..a3e83dc 100644 --- a/src/funcs/generateImageToVideo.ts +++ b/src/funcs/generateImageToVideo.ts @@ -49,10 +49,8 @@ export async function generateImageToVideo( | ConnectionError > > { - const input = request; - const parsed = safeParse( - input, + request, (value) => components.BodyGenImageToVideo$outboundSchema.parse(value), "Input validation failed", ); diff --git a/src/funcs/generateLlm.ts b/src/funcs/generateLlm.ts index a2db66c..26c6dbc 100644 --- a/src/funcs/generateLlm.ts +++ b/src/funcs/generateLlm.ts @@ -47,10 +47,8 @@ export async function generateLlm( | ConnectionError > > { - const input = request; - const parsed = safeParse( - input, + request, (value) => components.BodyGenLLM$outboundSchema.parse(value), "Input validation failed", ); diff --git a/src/funcs/generateSegmentAnything2.ts b/src/funcs/generateSegmentAnything2.ts index 57d88fd..ee79ed2 100644 --- a/src/funcs/generateSegmentAnything2.ts +++ b/src/funcs/generateSegmentAnything2.ts @@ -49,10 +49,8 @@ export async function generateSegmentAnything2( | ConnectionError > > { - const input = request; - const parsed = safeParse( - input, + request, (value) => components.BodyGenSegmentAnything2$outboundSchema.parse(value), "Input validation failed", ); diff --git a/src/funcs/generateTextToImage.ts b/src/funcs/generateTextToImage.ts index e2390b3..f32260e 100644 --- a/src/funcs/generateTextToImage.ts +++ b/src/funcs/generateTextToImage.ts @@ -47,10 +47,8 @@ export async function generateTextToImage( | ConnectionError > > { - const input = request; - const parsed = safeParse( - input, + request, (value) => components.TextToImageParams$outboundSchema.parse(value), "Input validation failed", ); diff --git a/src/funcs/generateUpscale.ts b/src/funcs/generateUpscale.ts index e8c23cc..003e424 100644 --- a/src/funcs/generateUpscale.ts +++ b/src/funcs/generateUpscale.ts @@ -49,10 +49,8 @@ export async function generateUpscale( | ConnectionError > > { - const input = request; - const parsed = safeParse( - input, + request, (value) => components.BodyGenUpscale$outboundSchema.parse(value), "Input validation failed", ); diff --git a/src/lib/config.ts b/src/lib/config.ts index dbd7fef..224bafe 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -60,8 +60,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", - openapiDocVersion: "", - sdkVersion: "0.4.0", - genVersion: "2.428.1", - userAgent: "speakeasy-sdk/typescript 0.4.0 2.428.1 @livepeer/ai", + openapiDocVersion: "0.0.0", + sdkVersion: "0.4.1", + genVersion: "2.438.15", + userAgent: "speakeasy-sdk/typescript 0.4.1 2.438.15 0.0.0 @livepeer/ai", } as const; diff --git a/src/models/components/bodygenimagetotext.ts b/src/models/components/bodygenimagetotext.ts new file mode 100644 index 0000000..039e93d --- /dev/null +++ b/src/models/components/bodygenimagetotext.ts @@ -0,0 +1,128 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { blobLikeSchema } from "../../types/blobs.js"; + +export type BodyGenImageToTextImage = { + fileName: string; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; +}; + +export type BodyGenImageToText = { + /** + * Uploaded image to transform with the pipeline. + */ + image: BodyGenImageToTextImage | Blob; + /** + * Hugging Face model ID used for transformation. + */ + modelId?: string | undefined; + /** + * Text prompt(s) to guide transformation. + */ + prompt?: string | undefined; +}; + +/** @internal */ +export const BodyGenImageToTextImage$inboundSchema: z.ZodType< + BodyGenImageToTextImage, + z.ZodTypeDef, + unknown +> = z.object({ + fileName: z.string(), + content: z.union([ + z.instanceof(ReadableStream), + z.instanceof(Blob), + z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), + ]), +}); + +/** @internal */ +export type BodyGenImageToTextImage$Outbound = { + fileName: string; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; +}; + +/** @internal */ +export const BodyGenImageToTextImage$outboundSchema: z.ZodType< + BodyGenImageToTextImage$Outbound, + z.ZodTypeDef, + BodyGenImageToTextImage +> = z.object({ + fileName: z.string(), + content: z.union([ + z.instanceof(ReadableStream), + z.instanceof(Blob), + z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), + ]), +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace BodyGenImageToTextImage$ { + /** @deprecated use `BodyGenImageToTextImage$inboundSchema` instead. */ + export const inboundSchema = BodyGenImageToTextImage$inboundSchema; + /** @deprecated use `BodyGenImageToTextImage$outboundSchema` instead. */ + export const outboundSchema = BodyGenImageToTextImage$outboundSchema; + /** @deprecated use `BodyGenImageToTextImage$Outbound` instead. */ + export type Outbound = BodyGenImageToTextImage$Outbound; +} + +/** @internal */ +export const BodyGenImageToText$inboundSchema: z.ZodType< + BodyGenImageToText, + z.ZodTypeDef, + unknown +> = z.object({ + image: z.lazy(() => BodyGenImageToTextImage$inboundSchema), + model_id: z.string().default(""), + prompt: z.string().default(""), +}).transform((v) => { + return remap$(v, { + "model_id": "modelId", + }); +}); + +/** @internal */ +export type BodyGenImageToText$Outbound = { + image: BodyGenImageToTextImage$Outbound | Blob; + model_id: string; + prompt: string; +}; + +/** @internal */ +export const BodyGenImageToText$outboundSchema: z.ZodType< + BodyGenImageToText$Outbound, + z.ZodTypeDef, + BodyGenImageToText +> = z.object({ + image: z.lazy(() => BodyGenImageToTextImage$outboundSchema).or( + blobLikeSchema, + ), + modelId: z.string().default(""), + prompt: z.string().default(""), +}).transform((v) => { + return remap$(v, { + modelId: "model_id", + }); +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace BodyGenImageToText$ { + /** @deprecated use `BodyGenImageToText$inboundSchema` instead. */ + export const inboundSchema = BodyGenImageToText$inboundSchema; + /** @deprecated use `BodyGenImageToText$outboundSchema` instead. */ + export const outboundSchema = BodyGenImageToText$outboundSchema; + /** @deprecated use `BodyGenImageToText$Outbound` instead. */ + export type Outbound = BodyGenImageToText$Outbound; +} diff --git a/src/models/components/imagetotextresponse.ts b/src/models/components/imagetotextresponse.ts new file mode 100644 index 0000000..f06ae2e --- /dev/null +++ b/src/models/components/imagetotextresponse.ts @@ -0,0 +1,51 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod"; + +/** + * Response model for text generation. + */ +export type ImageToTextResponse = { + /** + * The generated text. + */ + text: string; +}; + +/** @internal */ +export const ImageToTextResponse$inboundSchema: z.ZodType< + ImageToTextResponse, + z.ZodTypeDef, + unknown +> = z.object({ + text: z.string(), +}); + +/** @internal */ +export type ImageToTextResponse$Outbound = { + text: string; +}; + +/** @internal */ +export const ImageToTextResponse$outboundSchema: z.ZodType< + ImageToTextResponse$Outbound, + z.ZodTypeDef, + ImageToTextResponse +> = z.object({ + text: z.string(), +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ImageToTextResponse$ { + /** @deprecated use `ImageToTextResponse$inboundSchema` instead. */ + export const inboundSchema = ImageToTextResponse$inboundSchema; + /** @deprecated use `ImageToTextResponse$outboundSchema` instead. */ + export const outboundSchema = ImageToTextResponse$outboundSchema; + /** @deprecated use `ImageToTextResponse$Outbound` instead. */ + export type Outbound = ImageToTextResponse$Outbound; +} diff --git a/src/models/components/index.ts b/src/models/components/index.ts index 144d8ee..b97d8f0 100644 --- a/src/models/components/index.ts +++ b/src/models/components/index.ts @@ -5,12 +5,14 @@ export * from "./apierror.js"; export * from "./bodygenaudiototext.js"; export * from "./bodygenimagetoimage.js"; +export * from "./bodygenimagetotext.js"; export * from "./bodygenimagetovideo.js"; export * from "./bodygenllm.js"; export * from "./bodygensegmentanything2.js"; export * from "./bodygenupscale.js"; export * from "./chunk.js"; export * from "./imageresponse.js"; +export * from "./imagetotextresponse.js"; export * from "./llmresponse.js"; export * from "./masksresponse.js"; export * from "./media.js"; diff --git a/src/models/operations/genimagetotext.ts b/src/models/operations/genimagetotext.ts new file mode 100644 index 0000000..a6ee290 --- /dev/null +++ b/src/models/operations/genimagetotext.ts @@ -0,0 +1,87 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod"; +import { remap as remap$ } from "../../lib/primitives.js"; +import * as components from "../components/index.js"; + +export type GenImageToTextResponse = { + /** + * HTTP response content type for this operation + */ + contentType: string; + /** + * HTTP response status code for this operation + */ + statusCode: number; + /** + * Raw HTTP response; suitable for custom response parsing + */ + rawResponse: Response; + /** + * Successful Response + */ + imageToTextResponse?: components.ImageToTextResponse | undefined; +}; + +/** @internal */ +export const GenImageToTextResponse$inboundSchema: z.ZodType< + GenImageToTextResponse, + z.ZodTypeDef, + unknown +> = z.object({ + ContentType: z.string(), + StatusCode: z.number().int(), + RawResponse: z.instanceof(Response), + ImageToTextResponse: components.ImageToTextResponse$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "ContentType": "contentType", + "StatusCode": "statusCode", + "RawResponse": "rawResponse", + "ImageToTextResponse": "imageToTextResponse", + }); +}); + +/** @internal */ +export type GenImageToTextResponse$Outbound = { + ContentType: string; + StatusCode: number; + RawResponse: never; + ImageToTextResponse?: components.ImageToTextResponse$Outbound | undefined; +}; + +/** @internal */ +export const GenImageToTextResponse$outboundSchema: z.ZodType< + GenImageToTextResponse$Outbound, + z.ZodTypeDef, + GenImageToTextResponse +> = z.object({ + contentType: z.string(), + statusCode: z.number().int(), + rawResponse: z.instanceof(Response).transform(() => { + throw new Error("Response cannot be serialized"); + }), + imageToTextResponse: components.ImageToTextResponse$outboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + contentType: "ContentType", + statusCode: "StatusCode", + rawResponse: "RawResponse", + imageToTextResponse: "ImageToTextResponse", + }); +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace GenImageToTextResponse$ { + /** @deprecated use `GenImageToTextResponse$inboundSchema` instead. */ + export const inboundSchema = GenImageToTextResponse$inboundSchema; + /** @deprecated use `GenImageToTextResponse$outboundSchema` instead. */ + export const outboundSchema = GenImageToTextResponse$outboundSchema; + /** @deprecated use `GenImageToTextResponse$Outbound` instead. */ + export type Outbound = GenImageToTextResponse$Outbound; +} diff --git a/src/models/operations/index.ts b/src/models/operations/index.ts index 63357bc..657fe24 100644 --- a/src/models/operations/index.ts +++ b/src/models/operations/index.ts @@ -4,6 +4,7 @@ export * from "./genaudiototext.js"; export * from "./genimagetoimage.js"; +export * from "./genimagetotext.js"; export * from "./genimagetovideo.js"; export * from "./genllm.js"; export * from "./gensegmentanything2.js"; diff --git a/src/sdk/generate.ts b/src/sdk/generate.ts index 1d868ea..4fac35a 100644 --- a/src/sdk/generate.ts +++ b/src/sdk/generate.ts @@ -4,6 +4,7 @@ import { generateAudioToText } from "../funcs/generateAudioToText.js"; import { generateImageToImage } from "../funcs/generateImageToImage.js"; +import { generateImageToText } from "../funcs/generateImageToText.js"; import { generateImageToVideo } from "../funcs/generateImageToVideo.js"; import { generateLlm } from "../funcs/generateLlm.js"; import { generateSegmentAnything2 } from "../funcs/generateSegmentAnything2.js"; @@ -133,4 +134,21 @@ export class Generate extends ClientSDK { options, )); } + + /** + * Image To Text + * + * @remarks + * Transform image files to text. + */ + async imageToText( + request: components.BodyGenImageToText, + options?: RequestOptions, + ): Promise { + return unwrapAsync(generateImageToText( + this, + request, + options, + )); + } }