assemblyai 1.0.0 → 2.0.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +79 -66
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +378 -0
- package/dist/index.js +380 -0
- package/dist/services/base.d.ts +15 -0
- package/dist/services/files/index.d.ts +9 -0
- package/dist/services/index.d.ts +31 -0
- package/dist/services/lemur/index.d.ts +8 -0
- package/dist/services/realtime/index.d.ts +16 -0
- package/dist/services/transcripts/index.d.ts +42 -0
- package/dist/services/transcripts/redactions.d.ts +14 -0
- package/dist/services/transcripts/subtitles.d.ts +12 -0
- package/dist/types/core/index.d.ts +2 -0
- package/dist/types/core/params.d.ts +2 -0
- package/dist/types/core/segments.d.ts +28 -0
- package/dist/types/core/transcript.d.ts +113 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/lemur/index.d.ts +79 -0
- package/dist/types/models/auto_chapter.d.ts +8 -0
- package/dist/types/models/auto_highlights.d.ts +11 -0
- package/dist/types/models/content_safety.d.ts +25 -0
- package/dist/types/models/entity_detection.d.ts +7 -0
- package/dist/types/models/index.d.ts +8 -0
- package/dist/types/models/pii.d.ts +3 -0
- package/dist/types/models/sentiment_analysis.d.ts +9 -0
- package/dist/types/models/shared.d.ts +3 -0
- package/dist/types/models/summarization.d.ts +3 -0
- package/dist/types/models/topic_detection.d.ts +17 -0
- package/dist/types/realtime/index.d.ts +17 -0
- package/dist/types/services/abstractions.d.ts +80 -0
- package/dist/types/services/index.d.ts +9 -0
- package/dist/types/shared/index.d.ts +2 -0
- package/dist/types/shared/pagination.d.ts +7 -0
- package/dist/types/shared/timestamp.d.ts +5 -0
- package/dist/utils/errors/index.d.ts +1 -0
- package/dist/utils/errors/realtime.d.ts +26 -0
- package/package.json +55 -21
- package/src/index.ts +2 -0
- package/src/services/base.ts +16 -0
- package/src/services/files/index.ts +22 -0
- package/src/services/index.ts +66 -0
- package/src/services/lemur/index.ts +45 -0
- package/src/services/realtime/index.ts +106 -0
- package/src/services/transcripts/index.ts +156 -0
- package/src/services/transcripts/redactions.ts +27 -0
- package/src/services/transcripts/subtitles.ts +26 -0
- package/src/types/core/index.ts +2 -0
- package/src/types/core/params.ts +3 -0
- package/src/types/core/segments.ts +29 -0
- package/src/types/core/transcript.ts +159 -0
- package/src/types/index.ts +6 -0
- package/src/types/lemur/index.ts +97 -0
- package/src/types/models/auto_chapter.ts +9 -0
- package/src/types/models/auto_highlights.ts +14 -0
- package/src/types/models/content_safety.ts +34 -0
- package/src/types/models/entity_detection.ts +8 -0
- package/src/types/models/index.ts +8 -0
- package/src/types/models/pii.ts +32 -0
- package/src/types/models/sentiment_analysis.ts +11 -0
- package/src/types/models/shared.ts +4 -0
- package/src/types/models/summarization.ts +10 -0
- package/src/types/models/topic_detection.ts +21 -0
- package/src/types/realtime/index.ts +28 -0
- package/src/types/services/abstractions.ts +88 -0
- package/src/types/services/index.ts +11 -0
- package/src/types/shared/index.ts +2 -0
- package/src/types/shared/pagination.ts +8 -0
- package/src/types/shared/timestamp.ts +6 -0
- package/src/utils/.gitkeep +0 -0
- package/src/utils/errors/index.ts +5 -0
- package/src/utils/errors/realtime.ts +58 -0
- package/.eslintrc.json +0 -3
- package/index.js +0 -15
- package/src/Client.js +0 -28
- package/src/api/Http/Request.js +0 -108
- package/src/api/Http/Response.js +0 -23
- package/src/api/Model.js +0 -17
- package/src/api/Transcript.js +0 -16
- package/src/api/Upload.js +0 -41
- package/src/api/util.js +0 -44
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
type LeMURModel = "default" | "basic";
|
|
2
|
+
type LeMURContext = string | object | LeMURContext[];
|
|
3
|
+
type LeMURBaseServiceParams = {
|
|
4
|
+
/**
|
|
5
|
+
* A list of completed transcripts with text. Up to 100 files max, or 100 hours max. Whichever is lower.
|
|
6
|
+
*/
|
|
7
|
+
transcript_ids: string[];
|
|
8
|
+
/**
|
|
9
|
+
* The model that is used for the final prompt after compression is performed (options: "basic" and "default").
|
|
10
|
+
*/
|
|
11
|
+
final_model?: LeMURModel;
|
|
12
|
+
/**
|
|
13
|
+
* Max output size in tokens. Up to 4000 allowed.
|
|
14
|
+
*/
|
|
15
|
+
max_output_size?: number;
|
|
16
|
+
};
|
|
17
|
+
type SummaryParams = LeMURBaseServiceParams & {
|
|
18
|
+
/**
|
|
19
|
+
* How you want the summary to be returned. This can be any text. Examples: "TLDR", "bullet points"
|
|
20
|
+
*/
|
|
21
|
+
answer_format?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Any context about the transcripts you wish to provide. This can be a string, or free-form JSON.
|
|
24
|
+
*/
|
|
25
|
+
context?: LeMURContext;
|
|
26
|
+
};
|
|
27
|
+
type Question = {
|
|
28
|
+
/**
|
|
29
|
+
* The question you wish to ask. For more complex questions use default model.
|
|
30
|
+
*/
|
|
31
|
+
question: string;
|
|
32
|
+
/**
|
|
33
|
+
* Any context about the transcripts you wish to provide. This can be a string, or free-form JSON.
|
|
34
|
+
*/
|
|
35
|
+
context?: LeMURContext;
|
|
36
|
+
/**
|
|
37
|
+
* How you want the answer to be returned. This can be any text. Cannot be used with answer_options. Examples: "short sentence", "bullet points"
|
|
38
|
+
*/
|
|
39
|
+
answer_format?: string;
|
|
40
|
+
/**
|
|
41
|
+
* What discrete options to return. Useful for precise responses. Cannot be used with answer_format. Example: ["Yes", "No"]
|
|
42
|
+
*/
|
|
43
|
+
answer_options?: string[];
|
|
44
|
+
};
|
|
45
|
+
type QuestionAnswerParams = LeMURBaseServiceParams & {
|
|
46
|
+
/**
|
|
47
|
+
* Any context about the transcripts you wish to provide. This can be a string, or free-form JSON.
|
|
48
|
+
*/
|
|
49
|
+
context?: LeMURContext;
|
|
50
|
+
/**
|
|
51
|
+
* A list of questions to ask. Question format listed below.
|
|
52
|
+
*/
|
|
53
|
+
questions: Question[];
|
|
54
|
+
};
|
|
55
|
+
type ActionItemsParams = LeMURBaseServiceParams & {
|
|
56
|
+
/**
|
|
57
|
+
* Any context about the transcripts you wish to provide. This can be a string, or free-form JSON.
|
|
58
|
+
*/
|
|
59
|
+
context?: LeMURContext;
|
|
60
|
+
};
|
|
61
|
+
type TaskParams = LeMURBaseServiceParams & {
|
|
62
|
+
/**
|
|
63
|
+
* Your text to prompt the model to produce a desired output, including any context you want to pass into the model.
|
|
64
|
+
*/
|
|
65
|
+
prompt: string;
|
|
66
|
+
};
|
|
67
|
+
type LeMURResponse = {
|
|
68
|
+
response: string;
|
|
69
|
+
request_id: string;
|
|
70
|
+
};
|
|
71
|
+
type QuestionAnswer = {
|
|
72
|
+
question: string;
|
|
73
|
+
answer: string;
|
|
74
|
+
};
|
|
75
|
+
type LeMURQuestionAnswerResponse = {
|
|
76
|
+
response: QuestionAnswer[];
|
|
77
|
+
request_id: string;
|
|
78
|
+
};
|
|
79
|
+
export type { SummaryParams, QuestionAnswerParams, ActionItemsParams, TaskParams, LeMURResponse, LeMURQuestionAnswerResponse, LeMURBaseServiceParams, };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModelResultStatus } from "./shared";
|
|
2
|
+
type AutoHighlightsResult = {
|
|
3
|
+
text: string;
|
|
4
|
+
count: number;
|
|
5
|
+
rank: number;
|
|
6
|
+
};
|
|
7
|
+
type AutoHighlights = {
|
|
8
|
+
status: ModelResultStatus;
|
|
9
|
+
results: AutoHighlightsResult[];
|
|
10
|
+
};
|
|
11
|
+
export type { AutoHighlights };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ModelResultStatus, ModelSummary } from "./shared";
|
|
2
|
+
import { Timestamp } from "@/types/shared";
|
|
3
|
+
type ContentSafetyLabel = {
|
|
4
|
+
label: string;
|
|
5
|
+
confidence: number;
|
|
6
|
+
severity: number | null;
|
|
7
|
+
};
|
|
8
|
+
type ContentSafetyResult = {
|
|
9
|
+
text: string;
|
|
10
|
+
labels: ContentSafetyLabel[];
|
|
11
|
+
timestamp: Timestamp;
|
|
12
|
+
};
|
|
13
|
+
type ContentSafetySeverityScore = {
|
|
14
|
+
low: number;
|
|
15
|
+
medium: number;
|
|
16
|
+
high: number;
|
|
17
|
+
};
|
|
18
|
+
type ContentSafetySeverityScoreSummary = Record<string, ContentSafetySeverityScore>;
|
|
19
|
+
type ContentSafetyLabels = {
|
|
20
|
+
status: ModelResultStatus;
|
|
21
|
+
results: ContentSafetyResult[];
|
|
22
|
+
summary: ModelSummary;
|
|
23
|
+
severity_score_summary: ContentSafetySeverityScoreSummary;
|
|
24
|
+
};
|
|
25
|
+
export type { ContentSafetyLabels };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type * from "./auto_chapter";
|
|
2
|
+
export type * from "./auto_highlights";
|
|
3
|
+
export type * from "./content_safety";
|
|
4
|
+
export type * from "./entity_detection";
|
|
5
|
+
export type * from "./pii";
|
|
6
|
+
export type * from "./sentiment_analysis";
|
|
7
|
+
export type * from "./summarization";
|
|
8
|
+
export type * from "./topic_detection";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
type PIIRedactionPolicies = "medical_process" | "medical_condition" | "blood_type" | "drug" | "injury" | "number_sequence" | "email_address" | "date_of_birth" | "phone_number" | "us_social_security_number" | "credit_card_number" | "credit_card_expiration" | "credit_card_cvv" | "date" | "nationality" | "event" | "language" | "location" | "money_amount" | "person_name" | "person_age" | "organization" | "political_affiliation" | "occupation" | "religion" | "drivers_license" | "banking_information";
|
|
2
|
+
type PIIAudioQuality = "mp3" | "wav";
|
|
3
|
+
export type { PIIRedactionPolicies, PIIAudioQuality };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModelResultStatus, ModelSummary } from "./shared";
|
|
2
|
+
import { Timestamp } from "@/types/shared";
|
|
3
|
+
type TopicDetectionLabel = {
|
|
4
|
+
relevance: number;
|
|
5
|
+
label: string;
|
|
6
|
+
};
|
|
7
|
+
type TopicDetectionResults = {
|
|
8
|
+
text: string;
|
|
9
|
+
labels: TopicDetectionLabel[];
|
|
10
|
+
timestamp: Timestamp;
|
|
11
|
+
};
|
|
12
|
+
type TopicDetection = {
|
|
13
|
+
status: ModelResultStatus;
|
|
14
|
+
results: TopicDetectionResults[];
|
|
15
|
+
summary: ModelSummary;
|
|
16
|
+
};
|
|
17
|
+
export type { TopicDetection };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type RealtimeConnectionParams = {
|
|
2
|
+
sampleRate?: number;
|
|
3
|
+
wordBoost?: string[];
|
|
4
|
+
};
|
|
5
|
+
type RealtimeListener = "data" | "error" | "open" | "close";
|
|
6
|
+
type RealtimeTranscriptType = "PartialTranscript" | "FinalTranscript";
|
|
7
|
+
type RealtimeTranscript = {
|
|
8
|
+
text: string;
|
|
9
|
+
message_type: RealtimeTranscriptType;
|
|
10
|
+
};
|
|
11
|
+
type RealtimeListeners = {
|
|
12
|
+
data?: (transcript: RealtimeTranscript) => void;
|
|
13
|
+
error?: (error: Error) => void;
|
|
14
|
+
open?: () => void;
|
|
15
|
+
close?: (code: number, reason: string) => void;
|
|
16
|
+
};
|
|
17
|
+
export type { RealtimeConnectionParams, RealtimeListener, RealtimeTranscript, RealtimeTranscriptType, RealtimeListeners, };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for classes that can create resources.
|
|
3
|
+
* @template T The type of the resource.
|
|
4
|
+
* @template Props The type of the properties required to create the resource.
|
|
5
|
+
*/
|
|
6
|
+
interface Createable<T, Props, Settings = Record<string, any>> {
|
|
7
|
+
/**
|
|
8
|
+
* Create a new resource.
|
|
9
|
+
* @param data The properties of the new resource.
|
|
10
|
+
* @param settings The settings used for creating the new resource.
|
|
11
|
+
* @return A promise that resolves to the newly created resource.
|
|
12
|
+
*/
|
|
13
|
+
create(params: Props, settings?: Settings | null): Promise<T>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Interface for classes that can retrieve resources.
|
|
17
|
+
* @template T The type of the resource.
|
|
18
|
+
* @template Id The type of the resource's identifier. Defaults to string.
|
|
19
|
+
*/
|
|
20
|
+
interface Retrieveable<T, Id = string> {
|
|
21
|
+
/**
|
|
22
|
+
* Retrieve a resource.
|
|
23
|
+
* @param id The identifier of the resource to retrieve.
|
|
24
|
+
* @return A promise that resolves to the retrieved resource.
|
|
25
|
+
*/
|
|
26
|
+
retrieve(id: Id): Promise<T>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Interface for classes that can delete resources.
|
|
30
|
+
* @template T The type of the resource.
|
|
31
|
+
* @template Id The type of the resource's identifier. Defaults to string.
|
|
32
|
+
*/
|
|
33
|
+
interface Deletable<T, Id = string> {
|
|
34
|
+
/**
|
|
35
|
+
* Delete a resource.
|
|
36
|
+
* @param id The identifier of the resource to delete.
|
|
37
|
+
* @return A promise that resolves to a boolean indicating whether the deletion was successful.
|
|
38
|
+
*/
|
|
39
|
+
delete(id: Id): Promise<T>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Interface for classes that can list resources.
|
|
43
|
+
* @template T The type of the resource.
|
|
44
|
+
*/
|
|
45
|
+
interface Listable<T, Page = string> {
|
|
46
|
+
/**
|
|
47
|
+
* List all resources.
|
|
48
|
+
* @return A promise that resolves to an array of resources.
|
|
49
|
+
*/
|
|
50
|
+
list(page?: Page): Promise<T>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Interface for classes that can connect to resources.
|
|
54
|
+
* @template T The type of the resource's data.
|
|
55
|
+
*/
|
|
56
|
+
interface Connectable<T, Params> {
|
|
57
|
+
/**
|
|
58
|
+
* Connect to a resource.
|
|
59
|
+
* @param event The event to listen for.
|
|
60
|
+
* @param listener The listener for the event.
|
|
61
|
+
*/
|
|
62
|
+
on(event: "data", listener: (data: T) => void): void;
|
|
63
|
+
on(event: "error", listener: (error: Error) => void): void;
|
|
64
|
+
on(event: "open", listener: () => void): void;
|
|
65
|
+
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
66
|
+
/**
|
|
67
|
+
* Send data to the resource.
|
|
68
|
+
* @param data The data to send.
|
|
69
|
+
*/
|
|
70
|
+
send(data: ArrayBuffer): void;
|
|
71
|
+
/**
|
|
72
|
+
* Connect to the resource.
|
|
73
|
+
*/
|
|
74
|
+
connect(params: Params): void;
|
|
75
|
+
/**
|
|
76
|
+
* Disconnect from the resource.
|
|
77
|
+
*/
|
|
78
|
+
disconnect(): void;
|
|
79
|
+
}
|
|
80
|
+
export type { Createable, Retrieveable, Deletable, Listable, Connectable };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as RealtimeError, RealtimeErrorType, RealtimeErrorMessages, } from "./realtime";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare enum RealtimeErrorType {
|
|
2
|
+
BadSampleRate = 4000,
|
|
3
|
+
AuthFailed = 4001,
|
|
4
|
+
InsufficientFunds = 4002,
|
|
5
|
+
FreeAccount = 4003,
|
|
6
|
+
NonexistentSessionId = 4004,
|
|
7
|
+
SessionExpired = 4008,
|
|
8
|
+
ClosedSession = 4010,
|
|
9
|
+
RateLimited = 4029,
|
|
10
|
+
UniqueSessionViolation = 4030,
|
|
11
|
+
SessionTimeout = 4031,
|
|
12
|
+
AudioTooShort = 4032,
|
|
13
|
+
AudioTooLong = 4033,
|
|
14
|
+
BadJson = 4100,
|
|
15
|
+
BadSchema = 4101,
|
|
16
|
+
TooManyStreams = 4102,
|
|
17
|
+
Reconnected = 4103,
|
|
18
|
+
ReconnectAttemptsExhausted = 1013
|
|
19
|
+
}
|
|
20
|
+
declare const RealtimeErrorMessages: Record<RealtimeErrorType, string>;
|
|
21
|
+
declare class RealtimeError extends Error {
|
|
22
|
+
code: RealtimeErrorType;
|
|
23
|
+
constructor(code: RealtimeErrorType);
|
|
24
|
+
}
|
|
25
|
+
export { RealtimeErrorType, RealtimeErrorMessages };
|
|
26
|
+
export default RealtimeError;
|
package/package.json
CHANGED
|
@@ -1,31 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
"version": "2.0.0-beta",
|
|
4
|
+
"description": "The AssemblyAI Node.js SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"typings": "dist/index.d.ts",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/AssemblyAI/assemblyai-
|
|
11
|
+
"url": "git+https://github.com/AssemblyAI/assemblyai-typescript-sdk.git"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"url": "https://github.com/AssemblyAI/assemblyai-node-sdk/issues"
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"tag": "beta",
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
17
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "pnpm clean && pnpm rollup -c",
|
|
20
|
+
"clean": "rimraf dist",
|
|
21
|
+
"lint": "tslint -p tsconfig.json",
|
|
22
|
+
"test": "pnpm lint && pnpm test:unit",
|
|
23
|
+
"test:unit": "jest --config jest.config.rollup.ts",
|
|
24
|
+
"prettier": "prettier --write 'src/**/*.ts'"
|
|
22
25
|
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"AssemblyAI",
|
|
28
|
+
"Speech-to-text"
|
|
29
|
+
],
|
|
30
|
+
"author": "AssemblyAI (https://www.assemblyai.com)",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"homepage": "https://www.assemblyai.com/docs",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"src",
|
|
36
|
+
"types"
|
|
37
|
+
],
|
|
23
38
|
"devDependencies": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"eslint
|
|
28
|
-
"
|
|
29
|
-
"
|
|
39
|
+
"@types/jest": "^29.5.2",
|
|
40
|
+
"@types/node": "^20.5.7",
|
|
41
|
+
"@types/ws": "^8.5.5",
|
|
42
|
+
"eslint": "^8.43.0",
|
|
43
|
+
"i": "^0.3.7",
|
|
44
|
+
"jest": "^29.5.0",
|
|
45
|
+
"jest-cli": "^29.5.0",
|
|
46
|
+
"jest-junit": "^16.0.0",
|
|
47
|
+
"jest-mock-extended": "^3.0.4",
|
|
48
|
+
"mock-socket": "^9.2.1",
|
|
49
|
+
"npm": "^9.7.1",
|
|
50
|
+
"prettier": "^2.8.8",
|
|
51
|
+
"rimraf": "^5.0.1",
|
|
52
|
+
"rollup": "^3.25.1",
|
|
53
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
54
|
+
"ts-jest": "^29.1.0",
|
|
55
|
+
"ts-node": "^10.9.1",
|
|
56
|
+
"tslib": "^2.5.3",
|
|
57
|
+
"tslint": "^6.1.3",
|
|
58
|
+
"typescript": "^5.1.3",
|
|
59
|
+
"jest-websocket-mock": "^2.4.1"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"axios": "^1.4.0",
|
|
63
|
+
"ws": "^8.13.0"
|
|
30
64
|
}
|
|
31
65
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import axios, { AxiosInstance } from "axios";
|
|
2
|
+
import { BaseServiceParams } from "@/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Base class for services that communicate with the API.
|
|
6
|
+
*/
|
|
7
|
+
abstract class BaseService {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new service.
|
|
10
|
+
* @param params The AxiosInstance to send HTTP requests to the API.
|
|
11
|
+
*/
|
|
12
|
+
constructor(protected client: AxiosInstance) {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type { BaseServiceParams };
|
|
16
|
+
export default BaseService;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import BaseService from "@/services/base";
|
|
3
|
+
import { Upload } from "@/types";
|
|
4
|
+
|
|
5
|
+
export default class FileService extends BaseService {
|
|
6
|
+
/**
|
|
7
|
+
* Upload a local file to AssemblyAI.
|
|
8
|
+
* @param path The local file to upload.
|
|
9
|
+
* @return A promise that resolves to the uploaded file URL.
|
|
10
|
+
*/
|
|
11
|
+
async upload(path: string): Promise<string> {
|
|
12
|
+
const file = await fs.readFile(path);
|
|
13
|
+
|
|
14
|
+
const { data } = await this.client.post<Upload>("/v2/upload", file, {
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Type": "application/octet-stream",
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return data.upload_url;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import axios, { isAxiosError } from "axios";
|
|
2
|
+
import { BaseServiceParams } from "./base";
|
|
3
|
+
import LeMURService from "./lemur";
|
|
4
|
+
import RealtimeService from "./realtime";
|
|
5
|
+
import TranscriptService from "./transcripts";
|
|
6
|
+
import FileService from "./files";
|
|
7
|
+
|
|
8
|
+
export default class AssemblyAI {
|
|
9
|
+
/**
|
|
10
|
+
* The files service.
|
|
11
|
+
*/
|
|
12
|
+
public files: FileService;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The transcripts service.
|
|
16
|
+
*/
|
|
17
|
+
public transcripts: TranscriptService;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The LeMUR service.
|
|
21
|
+
*/
|
|
22
|
+
public lemur: LeMURService;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The realtime service.
|
|
26
|
+
*/
|
|
27
|
+
public realtime: (params?: { baseUrl: string }) => RealtimeService;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a new AssemblyAI client.
|
|
31
|
+
* @param params The parameters for the service, including the API token and base URL, if any.
|
|
32
|
+
*/
|
|
33
|
+
constructor(params: BaseServiceParams) {
|
|
34
|
+
params.baseUrl = params.baseUrl || "https://api.assemblyai.com";
|
|
35
|
+
const client = this.createClient(params);
|
|
36
|
+
this.files = new FileService(client);
|
|
37
|
+
this.transcripts = new TranscriptService(client, this.files);
|
|
38
|
+
this.lemur = new LeMURService(client);
|
|
39
|
+
this.realtime = ({ baseUrl } = { baseUrl: "" }) => {
|
|
40
|
+
if (!baseUrl) {
|
|
41
|
+
const url = new URL(params.baseUrl as string);
|
|
42
|
+
url.protocol = "wss:";
|
|
43
|
+
baseUrl = url.toString();
|
|
44
|
+
}
|
|
45
|
+
return new RealtimeService({
|
|
46
|
+
token: params.token,
|
|
47
|
+
baseUrl,
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private createClient(params: BaseServiceParams) {
|
|
53
|
+
const client = axios.create({
|
|
54
|
+
baseURL: params.baseUrl,
|
|
55
|
+
headers: { Authorization: params.token },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
client.interceptors.response.use(null, (error) => {
|
|
59
|
+
if (isAxiosError(error) && error.response?.data?.error) {
|
|
60
|
+
return Promise.reject(new Error(error.response.data.error));
|
|
61
|
+
}
|
|
62
|
+
return Promise.reject(error);
|
|
63
|
+
});
|
|
64
|
+
return client;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LeMURResponse,
|
|
3
|
+
SummaryParams,
|
|
4
|
+
QuestionAnswerParams,
|
|
5
|
+
ActionItemsParams,
|
|
6
|
+
TaskParams,
|
|
7
|
+
LeMURQuestionAnswerResponse,
|
|
8
|
+
} from "@/types";
|
|
9
|
+
import BaseService from "@/services/base";
|
|
10
|
+
|
|
11
|
+
export default class LeMURService extends BaseService {
|
|
12
|
+
async summary(params: SummaryParams): Promise<LeMURResponse> {
|
|
13
|
+
const { data } = await this.client.post<LeMURResponse>(
|
|
14
|
+
"/lemur/v3/generate/summary",
|
|
15
|
+
params
|
|
16
|
+
);
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async questionAnswer(
|
|
21
|
+
params: QuestionAnswerParams
|
|
22
|
+
): Promise<LeMURQuestionAnswerResponse> {
|
|
23
|
+
const { data } = await this.client.post<LeMURQuestionAnswerResponse>(
|
|
24
|
+
"/lemur/v3/generate/question-answer",
|
|
25
|
+
params
|
|
26
|
+
);
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async actionItems(params: ActionItemsParams): Promise<LeMURResponse> {
|
|
31
|
+
const { data } = await this.client.post<LeMURResponse>(
|
|
32
|
+
"/lemur/v3/generate/action-items",
|
|
33
|
+
params
|
|
34
|
+
);
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async task(params: TaskParams): Promise<LeMURResponse> {
|
|
39
|
+
const { data } = await this.client.post<LeMURResponse>(
|
|
40
|
+
"/lemur/v3/generate/task",
|
|
41
|
+
params
|
|
42
|
+
);
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
}
|