generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f247994
commit f465816
Showing
8 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
type Model = { | ||
name: string; | ||
canonical_name: string; | ||
architecture: string; | ||
languages?: string[]; | ||
language?: string; | ||
version: string; | ||
uuid: string; | ||
batch?: boolean; | ||
streaming?: boolean; | ||
formatted_output?: boolean; | ||
metadata?: { | ||
accent: string; | ||
color: string; | ||
gender: string; | ||
image: string; | ||
sample: string; | ||
}; | ||
}; | ||
|
||
export type GetModelResponse = Model; | ||
|
||
export type GetModelsResponse = { | ||
stt: Model[]; | ||
tts: Model[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { isDeepgramError } from "../lib/errors"; | ||
import { DeepgramResponse, GetModelResponse, GetModelsResponse } from "../lib/types"; | ||
import { AbstractRestClient } from "./AbstractRestClient"; | ||
|
||
/** | ||
* Represents a REST client for interacting with the Deepgram API. | ||
* | ||
* The `ModelsRestClient` class provides methods for interacting with the Deepgram API to retrieve information about available models. | ||
* @extends AbstractRestClient | ||
*/ | ||
export class ModelsRestClient extends AbstractRestClient { | ||
public namespace: string = "models"; | ||
|
||
/** | ||
* Retrieves a list of all available models. | ||
* | ||
* @param endpoint - (optional) The endpoint to request. | ||
* @returns A promise that resolves with the response from the Deepgram API. | ||
* @example | ||
* ```typescript | ||
* import { createClient } from "@deepgram/sdk"; | ||
* | ||
* const deepgram = createClient(DEEPGRAM_API_KEY); | ||
* const { result: models, error } = deepgram.models.getAll(); | ||
* | ||
* if (error) { | ||
* console.error(error); | ||
* } else { | ||
* console.log(models); | ||
* } | ||
* ``` | ||
*/ | ||
async getAll(endpoint = ":version/models"): Promise<DeepgramResponse<GetModelsResponse>> { | ||
try { | ||
const requestUrl = this.getRequestUrl(endpoint); | ||
const result: GetModelsResponse = await this.get(requestUrl).then((result) => result.json()); | ||
|
||
return { result, error: null }; | ||
} catch (error) { | ||
if (isDeepgramError(error)) { | ||
return { result: null, error }; | ||
} | ||
|
||
throw error; | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves information about a specific model. | ||
* | ||
* @param modelId - The UUID of the model to retrieve. | ||
* @param endpoint - (optional) The endpoint to request. | ||
* @returns A promise that resolves with the response from the Deepgram API. | ||
* @example | ||
* ```typescript | ||
* import { createClient } from "@deepgram/sdk"; | ||
* | ||
* const deepgram = createClient(DEEPGRAM_API_KEY); | ||
* const { result: model, error } = deepgram.models.getModel("modelId"); | ||
* | ||
* if (error) { | ||
* console.error(error); | ||
* } else { | ||
* console.log(model); | ||
* } | ||
* ``` | ||
*/ | ||
async getModel( | ||
modelId: string, | ||
endpoint = ":version/models/:modelId" | ||
): Promise<DeepgramResponse<GetModelResponse>> { | ||
try { | ||
const requestUrl = this.getRequestUrl(endpoint, { modelId }); | ||
const result: GetModelResponse = await this.get(requestUrl).then((result) => result.json()); | ||
|
||
return { result, error: null }; | ||
} catch (error) { | ||
if (isDeepgramError(error)) { | ||
return { result: null, error }; | ||
} | ||
|
||
throw error; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { assert } from "chai"; | ||
import { createClient } from "../src"; | ||
import { faker } from "@faker-js/faker"; | ||
import { ModelsRestClient } from "../src/packages"; | ||
|
||
describe("ModelsRestClient", () => { | ||
let modelsRestClient: ModelsRestClient; | ||
|
||
beforeEach(() => { | ||
modelsRestClient = createClient(faker.string.alphanumeric(40)).models; | ||
}); | ||
|
||
it("should retrieve a list of models", async () => { | ||
const { result, error } = await modelsRestClient.getAll(); | ||
|
||
assert.isNull(error); | ||
assert.isNotNull(result); | ||
}); | ||
|
||
it("should retrieve a models", async () => { | ||
const { result, error } = await modelsRestClient.getModel(faker.string.uuid()); | ||
|
||
assert.isNull(error); | ||
assert.isNotNull(result); | ||
}); | ||
}); |