Skip to content

Commit

Permalink
docs[patch],community[minor]: Update AssemblyAI SDK, add user agent, …
Browse files Browse the repository at this point in the history
…update AssemblyAI URLs (#6084)

* Update AssemblyAI SDK, loader, and docs

* Update AssemblyAI SDK to 4.6.0

* Apply suggestions from code review

---------

Co-authored-by: Brace Sproul <braceasproul@gmail.com>
  • Loading branch information
Swimburger and bracesproul authored Jul 16, 2024
1 parent f624793 commit 795ca0b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CodeBlock from "@theme/CodeBlock";

# AssemblyAI Audio Transcript

This covers how to load audio (and video) transcripts as document objects from a file using the [AssemblyAI API](https://www.assemblyai.com/docs/api-reference/transcript).
This covers how to load audio (and video) transcripts as document objects from a file using the [AssemblyAI API](https://www.assemblyai.com/docs/api-reference/transcripts/submit?utm_source=langchainjs).

## Usage

Expand All @@ -16,8 +16,8 @@ First, you'll need to install the official AssemblyAI package:
npm install assemblyai
```

To use the loaders you need an [AssemblyAI account](https://www.assemblyai.com/dashboard/signup) and
[get your AssemblyAI API key from the dashboard](https://www.assemblyai.com/app/account).
To use the loaders you need an [AssemblyAI account](https://www.assemblyai.com/dashboard/signup?utm_source=langchainjs) and
[get your AssemblyAI API key from the dashboard](https://www.assemblyai.com/app/account?utm_source=langchainjs).

Then, configure the API key as the `ASSEMBLYAI_API_KEY` environment variable or the `apiKey` options parameter.

Expand All @@ -29,9 +29,9 @@ import TranscriptExample from "@examples/document_loaders/assemblyai_audio_trans
>
> - You can use the `AudioTranscriptParagraphsLoader` or `AudioTranscriptSentencesLoader` to split the transcript into paragraphs or sentences.
> - The `audio` parameter can be a URL, a local file path, a buffer, or a stream.
> - The `audio` can also be a video file. See the [list of supported file types in the FAQ doc](https://www.assemblyai.com/docs/concepts/faq#:~:text=file%20types%20are%20supported).
> - The `audio` can also be a video file. See the [list of supported file types in the FAQ doc](https://www.assemblyai.com/docs/concepts/faq?utm_source=langchainjs#:~:text=file%20types%20are%20supported).
> - If you don't pass in the `apiKey` option, the loader will use the `ASSEMBLYAI_API_KEY` environment variable.
> - You can add more properties in addition to `audio`. Find the full list of request parameters in the [AssemblyAI API docs](https://www.assemblyai.com/docs/api-reference/transcript#create-a-transcript).
> - You can add more properties in addition to `audio`. Find the full list of request parameters in the [AssemblyAI API docs](https://www.assemblyai.com/docs/api-reference/transcripts/submit?utm_source=langchainjs#create-a-transcript).
You can also use the `AudioSubtitleLoader` to get `srt` or `vtt` subtitles as a document.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const audioUrl = "https://storage.googleapis.com/aai-docs-samples/espn.m4a";
const loader = new AudioTranscriptLoader(
{
audio: audioUrl,
// any other parameters as documented here: https://www.assemblyai.com/docs/api-reference/transcript#create-a-transcript
// any other parameters as documented here: https://www.assemblyai.com/docs/api-reference/transcripts/submit
},
{
apiKey: "<ASSEMBLYAI_API_KEY>", // or set the `ASSEMBLYAI_API_KEY` env variable
Expand Down
2 changes: 1 addition & 1 deletion examples/src/document_loaders/assemblyai_subtitles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const audioUrl = "https://storage.googleapis.com/aai-docs-samples/espn.m4a";
const loader = new AudioSubtitleLoader(
{
audio: audioUrl,
// any other parameters as documented here: https://www.assemblyai.com/docs/api-reference/transcript#create-a-transcript
// any other parameters as documented here: https://www.assemblyai.com/docs/api-reference/transcripts/submit
},
"srt", // srt or vtt
{
Expand Down
4 changes: 2 additions & 2 deletions langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@
"@vercel/kv": "^0.2.3",
"@xata.io/client": "^0.28.0",
"apify-client": "^2.7.1",
"assemblyai": "^4.0.0",
"assemblyai": "^4.6.0",
"axios": "^0.26.0",
"cheerio": "^1.0.0-rc.12",
"chromadb": "^1.5.3",
Expand Down Expand Up @@ -701,7 +701,7 @@
"@vercel/kv": "^0.2.3",
"@xata.io/client": "^0.28.0",
"apify-client": "^2.7.1",
"assemblyai": "^4.0.0",
"assemblyai": "^4.6.0",
"axios": "*",
"cheerio": "^1.0.0-rc.12",
"chromadb": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from "../web/assemblyai.js";

const transcriptId = process.env.ASSEMBLYAI_TRANSCRIPT_ID!;
console.log(transcriptId);

describe.skip("AssemblyAI", () => {
test("Invalid API key", async () => {
Expand Down
11 changes: 10 additions & 1 deletion langchain/src/document_loaders/web/assemblyai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import { logVersion020MigrationWarning } from "../../util/entrypoint_deprecation

export type * from "../../types/assemblyai-types.js";

const defaultOptions = {
userAgent: {
integration: { name: "LangChainJS", version: "1.0.1" },
},
};

/**
* @deprecated
* Base class for AssemblyAI loaders.
Expand All @@ -46,7 +52,10 @@ abstract class AssemblyAILoader extends BaseDocumentLoader {
throw new Error("No AssemblyAI API key provided");
}

this.client = new AssemblyAI(options as BaseServiceParams);
this.client = new AssemblyAI({
...defaultOptions,
...options,
} as BaseServiceParams);
}
}

Expand Down
4 changes: 2 additions & 2 deletions libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"@xenova/transformers": "^2.17.2",
"@zilliz/milvus2-sdk-node": ">=2.3.5",
"apify-client": "^2.7.1",
"assemblyai": "^4.0.0",
"assemblyai": "^4.6.0",
"better-sqlite3": ">=9.4.0 <12.0.0",
"cassandra-driver": "^4.7.2",
"cborg": "^4.1.1",
Expand Down Expand Up @@ -274,7 +274,7 @@
"@xenova/transformers": "^2.17.2",
"@zilliz/milvus2-sdk-node": ">=2.3.5",
"apify-client": "^2.7.1",
"assemblyai": "^4.0.0",
"assemblyai": "^4.6.0",
"better-sqlite3": ">=9.4.0 <12.0.0",
"cassandra-driver": "^4.7.2",
"cborg": "^4.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from "../web/assemblyai.js";

const transcriptId = process.env.ASSEMBLYAI_TRANSCRIPT_ID!;
console.log(transcriptId);

describe.skip("AssemblyAI", () => {
test("Invalid API key", async () => {
Expand Down
11 changes: 10 additions & 1 deletion libs/langchain-community/src/document_loaders/web/assemblyai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import { AssemblyAIOptions } from "../../types/assemblyai-types.js";

export type * from "../../types/assemblyai-types.js";

const defaultOptions = {
userAgent: {
integration: { name: "LangChainJS", version: "1.0.1" },
},
};

/**
* Base class for AssemblyAI loaders.
*/
Expand All @@ -39,7 +45,10 @@ abstract class AssemblyAILoader extends BaseDocumentLoader {
throw new Error("No AssemblyAI API key provided");
}

this.client = new AssemblyAI(options as BaseServiceParams);
this.client = new AssemblyAI({
...defaultOptions,
...options,
} as BaseServiceParams);
}
}

Expand Down
33 changes: 24 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10551,7 +10551,7 @@ __metadata:
"@xenova/transformers": ^2.17.2
"@zilliz/milvus2-sdk-node": ">=2.3.5"
apify-client: ^2.7.1
assemblyai: ^4.0.0
assemblyai: ^4.6.0
better-sqlite3: ">=9.4.0 <12.0.0"
binary-extensions: ^2.2.0
cassandra-driver: ^4.7.2
Expand Down Expand Up @@ -10700,7 +10700,7 @@ __metadata:
"@xenova/transformers": ^2.17.2
"@zilliz/milvus2-sdk-node": ">=2.3.5"
apify-client: ^2.7.1
assemblyai: ^4.0.0
assemblyai: ^4.6.0
better-sqlite3: ">=9.4.0 <12.0.0"
cassandra-driver: ^4.7.2
cborg: ^4.1.1
Expand Down Expand Up @@ -19431,12 +19431,12 @@ __metadata:
languageName: node
linkType: hard

"assemblyai@npm:^4.0.0":
version: 4.0.0
resolution: "assemblyai@npm:4.0.0"
"assemblyai@npm:^4.6.0":
version: 4.6.0
resolution: "assemblyai@npm:4.6.0"
dependencies:
ws: ^8.13.0
checksum: 09a2b2ed4c7269b5ef64dbc81a7c83cdcdfff6ec68f9600c702a416f91858b67c76a047f17c3c86701f0157ea64e51a00e77a1beaf790e6212eacc4e4ae3bd44
ws: ^8.17.1
checksum: de6da06c7a86939033ef9272691eb7f767712cd4ccb6dea84c492df80f510aadcd806081da876948c23dd87b27d3c04e6dfc841dbb403e7ddd52917a591ef142
languageName: node
linkType: hard

Expand Down Expand Up @@ -30286,7 +30286,7 @@ __metadata:
"@vercel/kv": ^0.2.3
"@xata.io/client": ^0.28.0
apify-client: ^2.7.1
assemblyai: ^4.0.0
assemblyai: ^4.6.0
axios: ^0.26.0
binary-extensions: ^2.2.0
cheerio: ^1.0.0-rc.12
Expand Down Expand Up @@ -30367,7 +30367,7 @@ __metadata:
"@vercel/kv": ^0.2.3
"@xata.io/client": ^0.28.0
apify-client: ^2.7.1
assemblyai: ^4.0.0
assemblyai: ^4.6.0
axios: "*"
cheerio: ^1.0.0-rc.12
chromadb: "*"
Expand Down Expand Up @@ -40812,6 +40812,21 @@ __metadata:
languageName: node
linkType: hard

"ws@npm:^8.17.1":
version: 8.18.0
resolution: "ws@npm:8.18.0"
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: ">=5.0.2"
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
checksum: 91d4d35bc99ff6df483bdf029b9ea4bfd7af1f16fc91231a96777a63d263e1eabf486e13a2353970efc534f9faa43bdbf9ee76525af22f4752cbc5ebda333975
languageName: node
linkType: hard

"xdg-basedir@npm:^4.0.0":
version: 4.0.0
resolution: "xdg-basedir@npm:4.0.0"
Expand Down

0 comments on commit 795ca0b

Please sign in to comment.