Skip to content

Commit

Permalink
refactor: rename SDK class
Browse files Browse the repository at this point in the history
This commit renames the SDK class so that it adheres to naming
conventions.
  • Loading branch information
rickstaa committed Aug 21, 2024
1 parent 5225b51 commit 4bc1d57
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ EOL
echo "$TS_CONFIG_CONTENT" > samples/tsconfig.json

# Generate starter usage sample with speakeasy
speakeasy generate usage -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.json -l typescript -o samples/root.ts
speakeasy generate usage -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.json -l typescript -o samples/root.ts
16 changes: 8 additions & 8 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
lockVersion: 2.0.0
id: 8766970f-4397-4dff-8082-81333329536d
management:
docChecksum: 510cfa2da9f90c7685f770ff2ba4eca6
docVersion: 0.1.0
speakeasyVersion: 1.372.0
generationVersion: 2.399.0
releaseVersion: 0.0.2
configChecksum: 8822ace0e62551968845376ac95e6eec
docChecksum: c222ffbf28e5f62770dc8cbd99010f96
docVersion: v0.1.2
speakeasyVersion: 1.376.1
generationVersion: 2.402.5
releaseVersion: 0.1.2
configChecksum: b0d2f710722fbf4899c5f3e77fcbd33f
repoURL: https://github.com/livepeer/livepeer-ai-js.git
installationURL: https://github.com/livepeer/livepeer-ai-js
features:
typescript:
additionalDependencies: 0.1.0
constsAndDefaults: 0.1.8
core: 3.13.2
constsAndDefaults: 0.1.10
core: 3.14.1
defaultEnabledRetries: 0.1.0
devContainers: 2.90.0
envVarSecurityUsage: 0.1.1
Expand Down
4 changes: 2 additions & 2 deletions .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ generation:
devContainers:
enabled: true
schemaPath: https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.json
sdkClassName: LivepeerAi
sdkClassName: LivepeerAI
maintainOpenAPIOrder: true
usageSnippets:
optionalPropertyRendering: withExample
Expand All @@ -15,7 +15,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
typescript:
version: 0.0.2
version: 0.1.2
additionalDependencies:
dependencies: {}
devDependencies: {}
Expand Down
15 changes: 7 additions & 8 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
speakeasyVersion: 1.372.0
speakeasyVersion: 1.376.1
sources:
livepeer-ai-OAS:
sourceNamespace: livepeer-ai-oas
sourceRevisionDigest: sha256:38afa7f1861a22fb18d400f362331305d3d261805959e73bf3ab6eb0cb4845a7
sourceBlobDigest: sha256:33f4138b25cfe97858b17c1966a1559000e32e20e588fa2298902060da23900c
sourceRevisionDigest: sha256:c3a8dccb8a3f822b82931d3d9e3cb7f4eb6d164d3f289a3c0c7b3dd98de913d3
sourceBlobDigest: sha256:e2549433c2d09c42e52916d511a18269d4ce6e728cd487f043ab8e82991b4d36
tags:
- latest
- main
targets:
livepeer-ai:
source: livepeer-ai-OAS
Expand All @@ -17,11 +16,11 @@ targets:
livepeer-ts:
source: livepeer-ai-OAS
sourceNamespace: livepeer-ai-oas
sourceRevisionDigest: sha256:38afa7f1861a22fb18d400f362331305d3d261805959e73bf3ab6eb0cb4845a7
sourceBlobDigest: sha256:33f4138b25cfe97858b17c1966a1559000e32e20e588fa2298902060da23900c
sourceRevisionDigest: sha256:c3a8dccb8a3f822b82931d3d9e3cb7f4eb6d164d3f289a3c0c7b3dd98de913d3
sourceBlobDigest: sha256:e2549433c2d09c42e52916d511a18269d4ce6e728cd487f043ab8e82991b4d36
codeSamplesNamespace: code-samples-typescript-livepeer-ts
codeSamplesRevisionDigest: sha256:a4cf6a478083c4c544e2193d4ee083013ee403df4eadd4c184a66a66b8cfe7f1
outLocation: /github/workspace/repo
codeSamplesRevisionDigest: sha256:f5f04f8efc644b6e81cd50641403c143e83a31d4136e8a7b99d62473c78ce7fb
outLocation: /home/ricks/development/livepeer/ai/livepeer-ai-js
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand Down
8 changes: 4 additions & 4 deletions FUNCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ specific category of applications.
## Example

```typescript
import { LivepeerAiCore } from "livepeer-ai/core.js";
import { LivepeerAICore } from "livepeer-ai/core.js";
import { textToImage } from "livepeer-ai/funcs/textToImage.js";
import { SDKValidationError } from "livepeer-ai/models/errors/sdkvalidationerror.js";

// Use `LivepeerAiCore` for best tree-shaking performance.
// Use `LivepeerAICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeerAi = new LivepeerAiCore({
const livepeerAI = new LivepeerAICore({
httpBearer: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
const res = await textToImage(livepeerAi, {
const res = await textToImage(livepeerAI, {
prompt: "<value>",
});

Expand Down
62 changes: 32 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
### Example

```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";

const livepeerAi = new LivepeerAi({
const livepeerAI = new LivepeerAI({
httpBearer: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
const result = await livepeerAi.textToImage({
const result = await livepeerAI.textToImage({
prompt: "<value>",
});

Expand All @@ -75,7 +75,7 @@ run();
<!-- Start Available Resources and Operations [operations] -->
## Available Resources and Operations

### [LivepeerAi SDK](docs/sdks/livepeerai/README.md)
### [LivepeerAI SDK](docs/sdks/livepeerai/README.md)

* [textToImage](docs/sdks/livepeerai/README.md#texttoimage) - Text To Image
* [imageToImage](docs/sdks/livepeerai/README.md#imagetoimage) - Image To Image
Expand Down Expand Up @@ -124,15 +124,15 @@ Certain SDK methods accept files as part of a multi-part request. It is possible
> - **Node.js v18:** A file stream can be created using the `fileFrom` helper from [`fetch-blob/from.js`](https://www.npmjs.com/package/fetch-blob).
```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";
import { openAsBlob } from "node:fs";

const livepeerAi = new LivepeerAi({
const livepeerAI = new LivepeerAI({
httpBearer: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
const result = await livepeerAi.imageToImage({
const result = await livepeerAI.imageToImage({
image: await openAsBlob("./sample-file"),
prompt: "<value>",
});
Expand All @@ -153,14 +153,14 @@ Some of the endpoints in this SDK support retries. If you use the SDK without a

To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";

const livepeerAi = new LivepeerAi({
const livepeerAI = new LivepeerAI({
httpBearer: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
const result = await livepeerAi.textToImage(
const result = await livepeerAI.textToImage(
{
prompt: "<value>",
},
Expand Down Expand Up @@ -188,9 +188,9 @@ run();

If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";

const livepeerAi = new LivepeerAi({
const livepeerAI = new LivepeerAI({
retryConfig: {
strategy: "backoff",
backoff: {
Expand All @@ -205,7 +205,7 @@ const livepeerAi = new LivepeerAi({
});

async function run() {
const result = await livepeerAi.textToImage({
const result = await livepeerAI.textToImage({
prompt: "<value>",
});

Expand Down Expand Up @@ -233,17 +233,17 @@ Validation errors can also occur when either method arguments or data returned f


```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";
import { SDKValidationError } from "livepeer-ai/models/errors";

const livepeerAi = new LivepeerAi({
const livepeerAI = new LivepeerAI({
httpBearer: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
let result;
try {
result = await livepeerAi.textToImage({
result = await livepeerAI.textToImage({
prompt: "<value>",
});
} catch (err) {
Expand Down Expand Up @@ -290,15 +290,15 @@ You can override the default server globally by passing a server index to the `s
| 0 | `https://dream-gateway.livepeer.cloud` | None |

```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";

const livepeerAi = new LivepeerAi({
const livepeerAI = new LivepeerAI({
serverIdx: 0,
httpBearer: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
const result = await livepeerAi.textToImage({
const result = await livepeerAI.textToImage({
prompt: "<value>",
});

Expand All @@ -316,15 +316,15 @@ run();
The default server can also be overridden globally by passing a URL to the `serverURL` optional parameter when initializing the SDK client instance. For example:

```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";

const livepeerAi = new LivepeerAi({
const livepeerAI = new LivepeerAI({
serverURL: "https://dream-gateway.livepeer.cloud",
httpBearer: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
const result = await livepeerAi.textToImage({
const result = await livepeerAI.textToImage({
prompt: "<value>",
});

Expand Down Expand Up @@ -355,7 +355,7 @@ custom header and a timeout to requests and how to use the `"requestError"` hook
to log errors:

```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";
import { HTTPClient } from "livepeer-ai/lib/http";

const httpClient = new HTTPClient({
Expand All @@ -382,7 +382,7 @@ httpClient.addHook("requestError", (error, request) => {
console.groupEnd();
});

const sdk = new LivepeerAi({ httpClient });
const sdk = new LivepeerAI({ httpClient });
```
<!-- End Custom HTTP Client [http-client] -->

Expand All @@ -399,14 +399,14 @@ This SDK supports the following security scheme globally:

To authenticate with the API the `httpBearer` parameter must be set when initializing the SDK client instance. For example:
```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";

const livepeerAi = new LivepeerAi({
const livepeerAI = new LivepeerAI({
httpBearer: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
const result = await livepeerAi.textToImage({
const result = await livepeerAI.textToImage({
prompt: "<value>",
});

Expand All @@ -422,15 +422,17 @@ run();
<!-- Start Debugging [debug] -->
## Debugging

To log HTTP requests and responses, you can pass a logger that matches `console`'s interface as an SDK option.
You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass a logger that matches `console`'s interface as an SDK option.

> [!WARNING]
> Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";

const sdk = new LivepeerAi({ debugLogger: console });
const sdk = new LivepeerAI({ debugLogger: console });
```
<!-- End Debugging [debug] -->

Expand Down
6 changes: 3 additions & 3 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!-- Start SDK Example Usage [usage] -->
```typescript
import { LivepeerAi } from "livepeer-ai";
import { LivepeerAI } from "livepeer-ai";

const livepeerAi = new LivepeerAi({
const livepeerAI = new LivepeerAI({
httpBearer: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
const result = await livepeerAi.textToImage({
const result = await livepeerAI.textToImage({
prompt: "<value>",
});

Expand Down
20 changes: 10 additions & 10 deletions codeSamples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ info:
title: CodeSamples overlay for typescript target
version: 0.0.0
actions:
- target: $["paths"]["/audio-to-text"]["post"]
update:
"x-codeSamples":
- "lang": "typescript"
"label": "audio_to_text"
"source": "import { LivepeerAi } from \"livepeer-ai\";\nimport { openAsBlob } from \"node:fs\";\n\nconst livepeerAi = new LivepeerAi({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAi.audioToText({\n audio: await openAsBlob(\"./sample-file\"),\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
- target: $["paths"]["/text-to-image"]["post"]
update:
"x-codeSamples":
- "lang": "typescript"
"label": "text_to_image"
"source": "import { LivepeerAi } from \"livepeer-ai\";\n\nconst livepeerAi = new LivepeerAi({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAi.textToImage({\n prompt: \"<value>\",\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
"source": "import { LivepeerAI } from \"livepeer-ai\";\n\nconst livepeerAI = new LivepeerAI({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAI.textToImage({\n prompt: \"<value>\",\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
- target: $["paths"]["/image-to-image"]["post"]
update:
"x-codeSamples":
- "lang": "typescript"
"label": "image_to_image"
"source": "import { LivepeerAi } from \"livepeer-ai\";\nimport { openAsBlob } from \"node:fs\";\n\nconst livepeerAi = new LivepeerAi({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAi.imageToImage({\n prompt: \"<value>\",\n image: await openAsBlob(\"./sample-file\"),\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
"source": "import { LivepeerAI } from \"livepeer-ai\";\nimport { openAsBlob } from \"node:fs\";\n\nconst livepeerAI = new LivepeerAI({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAI.imageToImage({\n prompt: \"<value>\",\n image: await openAsBlob(\"./sample-file\"),\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
- target: $["paths"]["/image-to-video"]["post"]
update:
"x-codeSamples":
- "lang": "typescript"
"label": "image_to_video"
"source": "import { LivepeerAi } from \"livepeer-ai\";\nimport { openAsBlob } from \"node:fs\";\n\nconst livepeerAi = new LivepeerAi({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAi.imageToVideo({\n image: await openAsBlob(\"./sample-file\"),\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
"source": "import { LivepeerAI } from \"livepeer-ai\";\nimport { openAsBlob } from \"node:fs\";\n\nconst livepeerAI = new LivepeerAI({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAI.imageToVideo({\n image: await openAsBlob(\"./sample-file\"),\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
- target: $["paths"]["/upscale"]["post"]
update:
"x-codeSamples":
- "lang": "typescript"
"label": "upscale"
"source": "import { LivepeerAi } from \"livepeer-ai\";\nimport { openAsBlob } from \"node:fs\";\n\nconst livepeerAi = new LivepeerAi({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAi.upscale({\n prompt: \"<value>\",\n image: await openAsBlob(\"./sample-file\"),\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
"source": "import { LivepeerAI } from \"livepeer-ai\";\nimport { openAsBlob } from \"node:fs\";\n\nconst livepeerAI = new LivepeerAI({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAI.upscale({\n prompt: \"<value>\",\n image: await openAsBlob(\"./sample-file\"),\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
- target: $["paths"]["/audio-to-text"]["post"]
update:
"x-codeSamples":
- "lang": "typescript"
"label": "audio_to_text"
"source": "import { LivepeerAI } from \"livepeer-ai\";\nimport { openAsBlob } from \"node:fs\";\n\nconst livepeerAI = new LivepeerAI({\n httpBearer: \"<YOUR_BEARER_TOKEN_HERE>\",\n});\n\nasync function run() {\n const result = await livepeerAI.audioToText({\n audio: await openAsBlob(\"./sample-file\"),\n });\n\n // Handle the result\n console.log(result)\n}\n\nrun();"
Loading

0 comments on commit 4bc1d57

Please sign in to comment.