@ai-sdk/deepgram 3.0.0-beta.3 → 3.0.0-beta.31
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/CHANGELOG.md +242 -4
- package/README.md +2 -0
- package/dist/index.d.ts +63 -44
- package/dist/index.js +131 -115
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/deepgram-config.ts +2 -2
- package/src/deepgram-provider.ts +11 -11
- package/src/deepgram-speech-model-options.ts +25 -0
- package/src/deepgram-speech-model.ts +28 -35
- package/src/deepgram-transcription-model-options.ts +45 -0
- package/src/deepgram-transcription-model.ts +29 -55
- package/src/index.ts +2 -2
- package/dist/index.d.mts +0 -128
- package/dist/index.mjs +0 -650
- package/dist/index.mjs.map +0 -1
|
@@ -1,59 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SharedV4Warning, TranscriptionModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
combineHeaders,
|
|
4
4
|
createJsonResponseHandler,
|
|
5
5
|
parseProviderOptions,
|
|
6
6
|
postToApi,
|
|
7
|
+
serializeModelOptions,
|
|
8
|
+
WORKFLOW_SERIALIZE,
|
|
9
|
+
WORKFLOW_DESERIALIZE,
|
|
7
10
|
} from '@ai-sdk/provider-utils';
|
|
8
11
|
import { z } from 'zod/v4';
|
|
9
|
-
import { DeepgramTranscriptionAPITypes } from './deepgram-api-types';
|
|
10
|
-
import { DeepgramConfig } from './deepgram-config';
|
|
12
|
+
import type { DeepgramTranscriptionAPITypes } from './deepgram-api-types';
|
|
13
|
+
import type { DeepgramConfig } from './deepgram-config';
|
|
11
14
|
import { deepgramFailedResponseHandler } from './deepgram-error';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
// https://developers.deepgram.com/docs/pre-recorded-audio#results
|
|
15
|
-
const deepgramTranscriptionModelOptionsSchema = z.object({
|
|
16
|
-
/** Language to use for transcription. If not specified, Deepgram defaults to English. Use `detectLanguage: true` to enable automatic language detection. */
|
|
17
|
-
language: z.string().nullish(),
|
|
18
|
-
/** Whether to enable automatic language detection. When true, Deepgram will detect the language of the audio. */
|
|
19
|
-
detectLanguage: z.boolean().nullish(),
|
|
20
|
-
/** Whether to use smart formatting, which formats written-out numbers, dates, times, etc. */
|
|
21
|
-
smartFormat: z.boolean().nullish(),
|
|
22
|
-
/** Whether to add punctuation to the transcript. */
|
|
23
|
-
punctuate: z.boolean().nullish(),
|
|
24
|
-
/** Whether to format the transcript into paragraphs. */
|
|
25
|
-
paragraphs: z.boolean().nullish(),
|
|
26
|
-
/** Whether to generate a summary of the transcript. Use 'v2' for the latest version or false to disable. */
|
|
27
|
-
summarize: z.union([z.literal('v2'), z.literal(false)]).nullish(),
|
|
28
|
-
/** Whether to identify topics in the transcript. */
|
|
29
|
-
topics: z.boolean().nullish(),
|
|
30
|
-
/** Whether to identify intents in the transcript. */
|
|
31
|
-
intents: z.boolean().nullish(),
|
|
32
|
-
/** Whether to analyze sentiment in the transcript. */
|
|
33
|
-
sentiment: z.boolean().nullish(),
|
|
34
|
-
/** Whether to detect and tag named entities in the transcript. */
|
|
35
|
-
detectEntities: z.boolean().nullish(),
|
|
36
|
-
/** Specify terms or patterns to redact from the transcript. Can be a string or array of strings. */
|
|
37
|
-
redact: z.union([z.string(), z.array(z.string())]).nullish(),
|
|
38
|
-
/** String to replace redacted content with. */
|
|
39
|
-
replace: z.string().nullish(),
|
|
40
|
-
/** Term or phrase to search for in the transcript. */
|
|
41
|
-
search: z.string().nullish(),
|
|
42
|
-
/** Key term to identify in the transcript. */
|
|
43
|
-
keyterm: z.string().nullish(),
|
|
44
|
-
/** Whether to identify different speakers in the audio. */
|
|
45
|
-
diarize: z.boolean().nullish(),
|
|
46
|
-
/** Whether to segment the transcript into utterances. */
|
|
47
|
-
utterances: z.boolean().nullish(),
|
|
48
|
-
/** Minimum duration of silence (in seconds) to trigger a new utterance. */
|
|
49
|
-
uttSplit: z.number().nullish(),
|
|
50
|
-
/** Whether to include filler words (um, uh, etc.) in the transcript. */
|
|
51
|
-
fillerWords: z.boolean().nullish(),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
export type DeepgramTranscriptionModelOptions = z.infer<
|
|
55
|
-
typeof deepgramTranscriptionModelOptionsSchema
|
|
56
|
-
>;
|
|
15
|
+
import { deepgramTranscriptionModelOptionsSchema } from './deepgram-transcription-model-options';
|
|
16
|
+
import type { DeepgramTranscriptionModelId } from './deepgram-transcription-options';
|
|
57
17
|
|
|
58
18
|
interface DeepgramTranscriptionModelConfig extends DeepgramConfig {
|
|
59
19
|
_internal?: {
|
|
@@ -61,13 +21,27 @@ interface DeepgramTranscriptionModelConfig extends DeepgramConfig {
|
|
|
61
21
|
};
|
|
62
22
|
}
|
|
63
23
|
|
|
64
|
-
export class DeepgramTranscriptionModel implements
|
|
65
|
-
readonly specificationVersion = '
|
|
24
|
+
export class DeepgramTranscriptionModel implements TranscriptionModelV4 {
|
|
25
|
+
readonly specificationVersion = 'v4';
|
|
66
26
|
|
|
67
27
|
get provider(): string {
|
|
68
28
|
return this.config.provider;
|
|
69
29
|
}
|
|
70
30
|
|
|
31
|
+
static [WORKFLOW_SERIALIZE](model: DeepgramTranscriptionModel) {
|
|
32
|
+
return serializeModelOptions({
|
|
33
|
+
modelId: model.modelId,
|
|
34
|
+
config: model.config,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
39
|
+
modelId: DeepgramTranscriptionModelId;
|
|
40
|
+
config: DeepgramTranscriptionModelConfig;
|
|
41
|
+
}) {
|
|
42
|
+
return new DeepgramTranscriptionModel(options.modelId, options.config);
|
|
43
|
+
}
|
|
44
|
+
|
|
71
45
|
constructor(
|
|
72
46
|
readonly modelId: DeepgramTranscriptionModelId,
|
|
73
47
|
private readonly config: DeepgramTranscriptionModelConfig,
|
|
@@ -75,8 +49,8 @@ export class DeepgramTranscriptionModel implements TranscriptionModelV3 {
|
|
|
75
49
|
|
|
76
50
|
private async getArgs({
|
|
77
51
|
providerOptions,
|
|
78
|
-
}: Parameters<
|
|
79
|
-
const warnings:
|
|
52
|
+
}: Parameters<TranscriptionModelV4['doGenerate']>[0]) {
|
|
53
|
+
const warnings: SharedV4Warning[] = [];
|
|
80
54
|
|
|
81
55
|
// Parse provider options
|
|
82
56
|
const deepgramOptions = await parseProviderOptions({
|
|
@@ -125,8 +99,8 @@ export class DeepgramTranscriptionModel implements TranscriptionModelV3 {
|
|
|
125
99
|
}
|
|
126
100
|
|
|
127
101
|
async doGenerate(
|
|
128
|
-
options: Parameters<
|
|
129
|
-
): Promise<Awaited<ReturnType<
|
|
102
|
+
options: Parameters<TranscriptionModelV4['doGenerate']>[0],
|
|
103
|
+
): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {
|
|
130
104
|
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
131
105
|
const { queryParams, warnings } = await this.getArgs(options);
|
|
132
106
|
|
|
@@ -143,7 +117,7 @@ export class DeepgramTranscriptionModel implements TranscriptionModelV3 {
|
|
|
143
117
|
'?' +
|
|
144
118
|
queryParams.toString(),
|
|
145
119
|
headers: {
|
|
146
|
-
...combineHeaders(this.config.headers(), options.headers),
|
|
120
|
+
...combineHeaders(this.config.headers?.(), options.headers),
|
|
147
121
|
'Content-Type': options.mediaType,
|
|
148
122
|
},
|
|
149
123
|
body: {
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type {
|
|
|
8
8
|
DeepgramSpeechModelOptions,
|
|
9
9
|
/** @deprecated Use `DeepgramSpeechModelOptions` instead. */
|
|
10
10
|
DeepgramSpeechModelOptions as DeepgramSpeechCallOptions,
|
|
11
|
-
} from './deepgram-speech-model';
|
|
11
|
+
} from './deepgram-speech-model-options';
|
|
12
12
|
export type { DeepgramSpeechModelId } from './deepgram-speech-options';
|
|
13
|
-
export type { DeepgramTranscriptionModelOptions } from './deepgram-transcription-model';
|
|
13
|
+
export type { DeepgramTranscriptionModelOptions } from './deepgram-transcription-model-options';
|
|
14
14
|
export { VERSION } from './version';
|
package/dist/index.d.mts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { TranscriptionModelV3, ProviderV3, SpeechModelV3 } from '@ai-sdk/provider';
|
|
2
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { z } from 'zod/v4';
|
|
4
|
-
|
|
5
|
-
type DeepgramConfig = {
|
|
6
|
-
provider: string;
|
|
7
|
-
url: (options: {
|
|
8
|
-
modelId: string;
|
|
9
|
-
path: string;
|
|
10
|
-
}) => string;
|
|
11
|
-
headers: () => Record<string, string | undefined>;
|
|
12
|
-
fetch?: FetchFunction;
|
|
13
|
-
generateId?: () => string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type DeepgramTranscriptionModelId = 'base' | 'base-general' | 'base-meeting' | 'base-phonecall' | 'base-finance' | 'base-conversationalai' | 'base-voicemail' | 'base-video' | 'enhanced' | 'enhanced-general' | 'enhanced-meeting' | 'enhanced-phonecall' | 'enhanced-finance' | 'nova' | 'nova-general' | 'nova-phonecall' | 'nova-medical' | 'nova-2' | 'nova-2-general' | 'nova-2-meeting' | 'nova-2-phonecall' | 'nova-2-finance' | 'nova-2-conversationalai' | 'nova-2-voicemail' | 'nova-2-video' | 'nova-2-medical' | 'nova-2-drivethru' | 'nova-2-automotive' | 'nova-2-atc' | 'nova-3' | 'nova-3-general' | 'nova-3-medical' | (string & {});
|
|
17
|
-
|
|
18
|
-
declare const deepgramTranscriptionModelOptionsSchema: z.ZodObject<{
|
|
19
|
-
language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
-
detectLanguage: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
21
|
-
smartFormat: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
22
|
-
punctuate: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
23
|
-
paragraphs: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
24
|
-
summarize: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodLiteral<"v2">, z.ZodLiteral<false>]>>>;
|
|
25
|
-
topics: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
26
|
-
intents: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
27
|
-
sentiment: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
28
|
-
detectEntities: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
29
|
-
redact: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
|
|
30
|
-
replace: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
31
|
-
search: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
32
|
-
keyterm: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
33
|
-
diarize: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
34
|
-
utterances: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
35
|
-
uttSplit: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
36
|
-
fillerWords: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
37
|
-
}, z.core.$strip>;
|
|
38
|
-
type DeepgramTranscriptionModelOptions = z.infer<typeof deepgramTranscriptionModelOptionsSchema>;
|
|
39
|
-
interface DeepgramTranscriptionModelConfig extends DeepgramConfig {
|
|
40
|
-
_internal?: {
|
|
41
|
-
currentDate?: () => Date;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
declare class DeepgramTranscriptionModel implements TranscriptionModelV3 {
|
|
45
|
-
readonly modelId: DeepgramTranscriptionModelId;
|
|
46
|
-
private readonly config;
|
|
47
|
-
readonly specificationVersion = "v3";
|
|
48
|
-
get provider(): string;
|
|
49
|
-
constructor(modelId: DeepgramTranscriptionModelId, config: DeepgramTranscriptionModelConfig);
|
|
50
|
-
private getArgs;
|
|
51
|
-
doGenerate(options: Parameters<TranscriptionModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<TranscriptionModelV3['doGenerate']>>>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
type DeepgramSpeechModelId = 'aura-asteria-en' | 'aura-2-asteria-en' | 'aura-2-thalia-en' | 'aura-2-helena-en' | 'aura-2-orpheus-en' | 'aura-2-zeus-en' | 'aura-luna-en' | 'aura-stella-en' | (string & {});
|
|
55
|
-
|
|
56
|
-
interface DeepgramProvider extends ProviderV3 {
|
|
57
|
-
(modelId: 'nova-3', settings?: {}): {
|
|
58
|
-
transcription: DeepgramTranscriptionModel;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Creates a model for transcription.
|
|
62
|
-
*/
|
|
63
|
-
transcription(modelId: DeepgramTranscriptionModelId): TranscriptionModelV3;
|
|
64
|
-
/**
|
|
65
|
-
* Creates a model for speech generation.
|
|
66
|
-
*/
|
|
67
|
-
speech(modelId: DeepgramSpeechModelId): SpeechModelV3;
|
|
68
|
-
/**
|
|
69
|
-
* @deprecated Use `embeddingModel` instead.
|
|
70
|
-
*/
|
|
71
|
-
textEmbeddingModel(modelId: string): never;
|
|
72
|
-
}
|
|
73
|
-
interface DeepgramProviderSettings {
|
|
74
|
-
/**
|
|
75
|
-
* API key for authenticating requests.
|
|
76
|
-
*/
|
|
77
|
-
apiKey?: string;
|
|
78
|
-
/**
|
|
79
|
-
* Custom headers to include in the requests.
|
|
80
|
-
*/
|
|
81
|
-
headers?: Record<string, string>;
|
|
82
|
-
/**
|
|
83
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
84
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
85
|
-
*/
|
|
86
|
-
fetch?: FetchFunction;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Create an Deepgram provider instance.
|
|
90
|
-
*/
|
|
91
|
-
declare function createDeepgram(options?: DeepgramProviderSettings): DeepgramProvider;
|
|
92
|
-
/**
|
|
93
|
-
* Default Deepgram provider instance.
|
|
94
|
-
*/
|
|
95
|
-
declare const deepgram: DeepgramProvider;
|
|
96
|
-
|
|
97
|
-
declare const deepgramSpeechModelOptionsSchema: z.ZodObject<{
|
|
98
|
-
bitRate: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
|
|
99
|
-
container: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
100
|
-
encoding: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
101
|
-
sampleRate: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
102
|
-
callback: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
103
|
-
callbackMethod: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
104
|
-
POST: "POST";
|
|
105
|
-
PUT: "PUT";
|
|
106
|
-
}>>>;
|
|
107
|
-
mipOptOut: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
108
|
-
tag: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
|
|
109
|
-
}, z.core.$strip>;
|
|
110
|
-
type DeepgramSpeechModelOptions = z.infer<typeof deepgramSpeechModelOptionsSchema>;
|
|
111
|
-
interface DeepgramSpeechModelConfig extends DeepgramConfig {
|
|
112
|
-
_internal?: {
|
|
113
|
-
currentDate?: () => Date;
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
declare class DeepgramSpeechModel implements SpeechModelV3 {
|
|
117
|
-
readonly modelId: DeepgramSpeechModelId;
|
|
118
|
-
private readonly config;
|
|
119
|
-
readonly specificationVersion = "v3";
|
|
120
|
-
get provider(): string;
|
|
121
|
-
constructor(modelId: DeepgramSpeechModelId, config: DeepgramSpeechModelConfig);
|
|
122
|
-
private getArgs;
|
|
123
|
-
doGenerate(options: Parameters<SpeechModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV3['doGenerate']>>>;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
declare const VERSION: string;
|
|
127
|
-
|
|
128
|
-
export { type DeepgramProvider, type DeepgramProviderSettings, type DeepgramSpeechModelOptions as DeepgramSpeechCallOptions, DeepgramSpeechModel, type DeepgramSpeechModelId, type DeepgramSpeechModelOptions, type DeepgramTranscriptionModelOptions, VERSION, createDeepgram, deepgram };
|