vidnavigator 2.5.0 → 2.7.0
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/README.md +64 -26
- package/dist/index.d.ts +18 -6
- package/dist/index.js +19 -1
- package/dist/models/AsyncJob.d.ts +9 -0
- package/dist/models/AsyncJob.js +2 -0
- package/dist/models/Extraction.d.ts +38 -6
- package/dist/webhooks.d.ts +8 -0
- package/package.json +1 -1
- package/src/index.ts +39 -5
- package/src/models/AsyncJob.ts +11 -0
- package/src/models/Extraction.ts +40 -13
- package/src/webhooks.ts +4 -0
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ The official JavaScript/TypeScript SDK for the [VidNavigator Developer API](http
|
|
|
28
28
|
|
|
29
29
|
| Platform | Transcript | Transcribe (speech-to-text) | Watch (scenes) | Carousel |
|
|
30
30
|
|----------|:----------:|:---------------------------:|:--------------:|:--------:|
|
|
31
|
-
| YouTube | Yes |
|
|
31
|
+
| YouTube | Yes | Yes | Yes | - |
|
|
32
32
|
| Instagram Reels | - | Yes | Yes | Yes |
|
|
33
33
|
| Instagram Posts | - | Yes | Yes | Yes (`all_videos`) |
|
|
34
34
|
| TikTok | Yes | Yes | Yes | - |
|
|
@@ -175,7 +175,7 @@ if (Array.isArray(watched.transcript)) {
|
|
|
175
175
|
console.log(watched.frames_analyzed); // number of frames that were analyzed
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
The transcript comes from the platform's captions when it has them, and from speech-to-text otherwise. A video without speech is not an error: `transcript` is empty, `transcript_error` says why, and the scenes are returned.
|
|
178
|
+
The transcript comes from the platform's captions when it has them, and from speech-to-text otherwise. A YouTube video without captions is transcribed from its audio, like the others. A video without speech is not an error: `transcript` is empty, `transcript_error` says why, and the scenes are returned.
|
|
179
179
|
|
|
180
180
|
```ts
|
|
181
181
|
const watched = await vn.watch(url);
|
|
@@ -258,8 +258,11 @@ results.forEach((r, i) => console.log(urls[i], r.status === 'fulfilled' ? r.valu
|
|
|
258
258
|
const job = await vn.extractVideo.submit({
|
|
259
259
|
video_url: 'https://www.facebook.com/watch/?v=1234567890',
|
|
260
260
|
schema: {
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
type: 'object',
|
|
262
|
+
properties: {
|
|
263
|
+
speakers: { type: 'array', description: 'Names of everyone who speaks', items: { type: 'string' } },
|
|
264
|
+
verdict: { type: 'string', description: 'The final conclusion of the video' },
|
|
265
|
+
},
|
|
263
266
|
},
|
|
264
267
|
});
|
|
265
268
|
|
|
@@ -492,12 +495,15 @@ for (const video of videos) {
|
|
|
492
495
|
const { data } = await vn.extractVideoData({
|
|
493
496
|
video_url: video.url,
|
|
494
497
|
schema: {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
type: '
|
|
499
|
-
|
|
500
|
-
|
|
498
|
+
type: 'object',
|
|
499
|
+
properties: {
|
|
500
|
+
hook: { type: 'string', description: 'The opening hook or premise' },
|
|
501
|
+
products: { type: 'array', description: 'Products or brands mentioned', items: { type: 'string' } },
|
|
502
|
+
sentiment: {
|
|
503
|
+
type: 'string',
|
|
504
|
+
description: 'Overall sentiment',
|
|
505
|
+
enum: ['positive', 'negative', 'neutral', 'mixed'],
|
|
506
|
+
},
|
|
501
507
|
},
|
|
502
508
|
},
|
|
503
509
|
what_to_extract: 'Extract creator messaging and product mentions.',
|
|
@@ -748,7 +754,7 @@ console.log(`${scenes?.length} scenes from ${frames_analyzed} frames`);
|
|
|
748
754
|
|
|
749
755
|
- When the picture cannot be read, the analysis is made from the transcript alone: `scenes` is empty and `scenes_error` says why. A video without a transcript is analyzed from its scenes, and `transcript_error` says why the transcript is missing.
|
|
750
756
|
- With scenes, the segments an answer refers to (`best_segment_index`, `relevant_segments`) are counted among the transcript segments and the scenes together, in chronological order. Use `transcript_analysis.timestamp` to locate the moment.
|
|
751
|
-
- With `include_usage: true`, the frames are the `frame_analysis` charge of the `usage` block: 1 credit per
|
|
757
|
+
- With `include_usage: true`, the frames are the `frame_analysis` charge of the `usage` block: 1 credit per 2,000 frames analyzed, with at least 667 frames per hour of video; for an uploaded file the frames are charged once, when its scenes are analyzed.
|
|
752
758
|
|
|
753
759
|
`analyzeVideo()` waits on a single HTTP request. With `include_scenes` on a video longer than about 10 minutes, use `vn.analyze()`: it runs the same analysis as a [background job](#3-background-jobs-one-call-or-many-at-once) and returns the same result.
|
|
754
760
|
|
|
@@ -766,17 +772,19 @@ const later = await vn.analyze.resume(job.task_id).result();
|
|
|
766
772
|
|
|
767
773
|
### 9. Extract structured data
|
|
768
774
|
|
|
769
|
-
Define a schema and get back clean, structured data extracted from any video or file transcript.
|
|
775
|
+
Define a schema, as a standard JSON Schema, and get back clean, structured data extracted from any video or file transcript. Or skip the schema and say what you want in plain words with `what_to_extract`. Per-call usage tracking included (see [Per-call usage](#per-call-usage)).
|
|
770
776
|
|
|
771
777
|
```ts
|
|
772
778
|
const { data, usage } = await vn.extractVideoData({
|
|
773
779
|
video_url: 'https://youtube.com/watch?v=dQw4w9WgXcQ',
|
|
774
780
|
schema: {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
781
|
+
type: 'object',
|
|
782
|
+
properties: {
|
|
783
|
+
topic: { type: 'string', description: 'Main topic of the video' },
|
|
784
|
+
language: { type: 'string', description: 'Primary spoken language (ISO 639-1)' },
|
|
785
|
+
tone: { type: 'string', description: 'Overall tone', enum: ['positive', 'negative', 'neutral', 'mixed'] },
|
|
786
|
+
key_quotes: { type: 'array', description: 'Top 3 memorable quotes', items: { type: 'string' } },
|
|
787
|
+
},
|
|
780
788
|
},
|
|
781
789
|
what_to_extract: 'Determine the topic, language, tone, and notable quotes.',
|
|
782
790
|
include_usage: true,
|
|
@@ -801,10 +809,12 @@ Also works on uploaded files:
|
|
|
801
809
|
const { data } = await vn.extractFileData({
|
|
802
810
|
file_id: 'your-file-id',
|
|
803
811
|
schema: {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
812
|
+
type: 'object',
|
|
813
|
+
properties: {
|
|
814
|
+
action_items: { type: 'array', description: 'List of action items from the meeting', items: { type: 'string' } },
|
|
815
|
+
next_meeting: { type: 'string', description: 'When is the next meeting scheduled?' },
|
|
816
|
+
sentiment: { type: 'string', description: 'Overall meeting mood', enum: ['productive', 'tense', 'casual', 'urgent'] },
|
|
817
|
+
},
|
|
808
818
|
},
|
|
809
819
|
});
|
|
810
820
|
```
|
|
@@ -825,8 +835,11 @@ Pass `include_scenes: true` to extract from what the video shows as well as what
|
|
|
825
835
|
const { data, frames_analyzed } = await vn.extractVideoData({
|
|
826
836
|
video_url: 'https://www.tiktok.com/@user/video/1234567890',
|
|
827
837
|
schema: {
|
|
828
|
-
|
|
829
|
-
|
|
838
|
+
type: 'object',
|
|
839
|
+
properties: {
|
|
840
|
+
dish: { type: 'string', description: 'Name of the dish' },
|
|
841
|
+
ingredients: { type: 'array', description: 'Every ingredient with its quantity', items: { type: 'string' } },
|
|
842
|
+
},
|
|
830
843
|
},
|
|
831
844
|
include_scenes: true,
|
|
832
845
|
});
|
|
@@ -836,11 +849,21 @@ console.log(data, frames_analyzed); // quantities that are only written on scree
|
|
|
836
849
|
|
|
837
850
|
When the picture cannot be read, the fields are extracted from the transcript alone and the result has a `scenes_error`; a video without a transcript is extracted from its scenes, with a `transcript_error`. The same option works on an uploaded file, `vn.extractFileData({ file_id, schema, include_scenes: true })`, once the file has its scenes (see [Scenes of an uploaded file](#8b-scenes-of-an-uploaded-file)).
|
|
838
851
|
|
|
839
|
-
**
|
|
852
|
+
**Schema format:** a standard JSON Schema whose root is an object, `{ type: 'object', properties: { ... } }`. Property types: `string`, `number`, `integer`, `boolean`, `array` (with `items`, the schema of one element) and `object` (with its own `properties`); `enum` restricts a property to a list of values. Give each property a `description`: it tells what to put in it. At most 10 fields per level and 3 levels of nesting. A Zod schema converted with `zod-to-json-schema` works as it is. `required` and `additionalProperties` change nothing: a field the video does not give comes back as `null`. An invalid schema is rejected with a `BadRequestError` before anything runs.
|
|
840
853
|
|
|
841
|
-
**
|
|
854
|
+
**Without a schema:** pass `what_to_extract` alone. The schema is written for you and comes back as `schema` on the result; pass it as `schema` next time to get the same fields.
|
|
842
855
|
|
|
843
|
-
|
|
856
|
+
```ts
|
|
857
|
+
const { data, schema } = await vn.extractVideoData({
|
|
858
|
+
video_url: 'https://youtube.com/watch?v=dQw4w9WgXcQ',
|
|
859
|
+
what_to_extract: 'The mood of the song and every topic it touches on',
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
console.log(data); // { mood: "upbeat", topics: ["love", "commitment"] }
|
|
863
|
+
console.log(schema); // { type: "object", properties: { mood: {...}, topics: {...} }, ... }
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
> `extractVideoData()` runs as a background job, so videos of any length work. For many extractions at once, use `vn.extractVideo.submit()` (see [Background jobs](#3-background-jobs-one-call-or-many-at-once)). The result has `data` (the extracted fields), `video_info` (the video's metadata), `frames_analyzed` with `include_scenes`, `schema` when it was written from `what_to_extract`, and `usage` when requested.
|
|
844
867
|
|
|
845
868
|
### 10. Semantic search
|
|
846
869
|
|
|
@@ -1173,6 +1196,21 @@ All API responses are parsed into typed classes with static `fromJSON()` constru
|
|
|
1173
1196
|
| `TikTokLiveRoomDetail` | A `TikTokLiveRoom` from `getTikTokLiveRoom`: `status` / `isLive`, `ended_at`, `stats.new_followers`, `author.bio`, `share_url`, `chat_enabled`, `subscribers_only`, `products` |
|
|
1174
1197
|
| `TweetStatement` | Structured X/Twitter claim analysis, topics, entities, tone, intent, and source text |
|
|
1175
1198
|
|
|
1199
|
+
## What's new in 2.7.0
|
|
1200
|
+
|
|
1201
|
+
- **Where each value comes from:** extraction results carry `evidence`: for each field of `data` that has a value, the moments of the video it was taken from (`FieldEvidence`: `start` and `end` in seconds, and `in`: `'speech'`, `'picture'` with `include_scenes`, or `'post'` for the post's own text, without times). On `extractVideoData`, `vn.extractVideo`, `extractFileData`, the async job and the `extract_video.completed` webhook event.
|
|
1202
|
+
- **YouTube speech-to-text:** `transcribe` takes YouTube videos, and a YouTube video without captions is transcribed by `watch` and by extraction (`transcribe: true`).
|
|
1203
|
+
|
|
1204
|
+
```ts
|
|
1205
|
+
const { data, evidence } = await vn.extractVideoData({ video_url, schema });
|
|
1206
|
+
for (const moment of evidence?.people ?? []) console.log(moment.in, moment.start, moment.end);
|
|
1207
|
+
```
|
|
1208
|
+
|
|
1209
|
+
## What's new in 2.6.0
|
|
1210
|
+
|
|
1211
|
+
- **Extraction takes a standard JSON Schema**, the only schema format the API accepts now: `{ type: 'object', properties: { ... } }`, with lowercase types. A Zod schema converted with `zod-to-json-schema` can be passed as it is. The former format (`{ field: { type: 'String', ... } }`) is refused with `invalid_schema`. The `ExtractionSchema` and `ExtractionField` types describe the new format.
|
|
1212
|
+
- **Extraction without a schema:** `extractVideoData`, `vn.extractVideo` and `extractFileData` take `what_to_extract` alone; the schema written for it comes back as `schema` on the result (and on the `extract_video.completed` webhook event).
|
|
1213
|
+
|
|
1176
1214
|
## What's new in 2.5.0
|
|
1177
1215
|
|
|
1178
1216
|
- **Scenes in analysis and extraction:** `include_scenes: true` on `analyzeVideo()`, `analyzeFile()`, `extractVideo()` / `extractVideoData()` and `extractFileData()` makes the analysis or the extraction from what the video shows as well as what it says. Analysis results gain `scenes` and `frames_analyzed`, extraction results gain `frames_analyzed`; `scenes_error` and `transcript_error` say when one of the two could not be had.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { VideoInfo, TranscriptOutput, FileInfo, AnalysisResult, VideoSearchResult, FileSearchResult, UsageData, Namespace, NamespaceRef, ExtractionSchema, UsageBlock, CarouselInfo, CarouselVideoResult, TikTokProfileScrapeRequest, TikTokProfileScrapeSubmission, TikTokProfileTask, TikTokSearchRequest, TikTokSearchSubmission, TikTokSearchTask, TikTokLiveSearchRequest, TikTokLiveSearchSubmission, TikTokLiveSearchTask, TikTokLiveRoomRequest, TikTokLiveRoomResult, TweetStatement, WatchResult, WatchTranscriptError, VideoScene, ScenesError, FileScenesStatus, AsyncJob } from './models';
|
|
2
|
+
import { VideoInfo, TranscriptOutput, FileInfo, AnalysisResult, VideoSearchResult, FileSearchResult, UsageData, Namespace, NamespaceRef, ExtractionEvidence, ExtractionSchema, UsageBlock, CarouselInfo, CarouselVideoResult, TikTokProfileScrapeRequest, TikTokProfileScrapeSubmission, TikTokProfileTask, TikTokSearchRequest, TikTokSearchSubmission, TikTokSearchTask, TikTokLiveSearchRequest, TikTokLiveSearchSubmission, TikTokLiveSearchTask, TikTokLiveRoomRequest, TikTokLiveRoomResult, TweetStatement, WatchResult, WatchTranscriptError, VideoScene, ScenesError, FileScenesStatus, AsyncJob } from './models';
|
|
3
3
|
import { Job, JobOperation, PollOptions, RunOptions, SubmitOptions } from './jobs';
|
|
4
4
|
export * from './models';
|
|
5
5
|
export * from './errors';
|
|
@@ -7,7 +7,7 @@ export * from './webhooks';
|
|
|
7
7
|
export { Job } from './jobs';
|
|
8
8
|
export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
|
|
9
9
|
/** SDK version (keep in sync with package.json) */
|
|
10
|
-
export declare const SDK_VERSION = "2.
|
|
10
|
+
export declare const SDK_VERSION = "2.7.0";
|
|
11
11
|
export interface SDKConfig {
|
|
12
12
|
apiKey: string;
|
|
13
13
|
baseURL?: string;
|
|
@@ -75,10 +75,16 @@ export type AnalyzeVideoInput = {
|
|
|
75
75
|
/** Return the transcript as a single string instead of segments. */
|
|
76
76
|
transcript_text?: boolean;
|
|
77
77
|
} & WebhookOption;
|
|
78
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Input for {@link VidNavigatorClient.extractVideo}: a JSON Schema `schema`, or a JSON/YAML
|
|
80
|
+
* `schemaFilePath`, or neither with `what_to_extract`: the schema is then written from that text
|
|
81
|
+
* and comes back as `schema` on the result.
|
|
82
|
+
*/
|
|
79
83
|
export type ExtractVideoInput = ({
|
|
80
84
|
video_url: string;
|
|
81
|
-
|
|
85
|
+
/** The fields to extract, as a standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
86
|
+
schema?: ExtractionSchema;
|
|
87
|
+
/** What to extract, in plain words. Guides the extraction, or alone, writes the schema. */
|
|
82
88
|
what_to_extract?: string;
|
|
83
89
|
/** Speech-to-text the audio when no platform transcript exists. Default true. */
|
|
84
90
|
transcribe?: boolean;
|
|
@@ -185,6 +191,10 @@ export type GetFileResult = {
|
|
|
185
191
|
};
|
|
186
192
|
export interface ExtractDataResult {
|
|
187
193
|
data: Record<string, unknown>;
|
|
194
|
+
/** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
195
|
+
schema?: ExtractionSchema;
|
|
196
|
+
/** For each field of `data` that has a value, the moments of the video it comes from. */
|
|
197
|
+
evidence?: ExtractionEvidence;
|
|
188
198
|
video_info?: VideoInfo;
|
|
189
199
|
file_info?: FileInfo;
|
|
190
200
|
/** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
|
|
@@ -295,7 +305,8 @@ export type AnalyzeFileResult = {
|
|
|
295
305
|
};
|
|
296
306
|
export type ExtractVideoDataPayload = {
|
|
297
307
|
video_url: string;
|
|
298
|
-
|
|
308
|
+
/** A standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
309
|
+
schema?: ExtractionSchema;
|
|
299
310
|
what_to_extract?: string;
|
|
300
311
|
transcribe?: boolean;
|
|
301
312
|
/**
|
|
@@ -319,7 +330,8 @@ export type TweetStatementPayload = {
|
|
|
319
330
|
} & WebhookOption;
|
|
320
331
|
export type ExtractFileDataPayload = {
|
|
321
332
|
file_id: string;
|
|
322
|
-
|
|
333
|
+
/** A standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
334
|
+
schema?: ExtractionSchema;
|
|
323
335
|
what_to_extract?: string;
|
|
324
336
|
/**
|
|
325
337
|
* Default false. `true` extracts from the transcript of the file and its scenes together. The
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ __exportStar(require("./webhooks"), exports);
|
|
|
31
31
|
var jobs_2 = require("./jobs");
|
|
32
32
|
Object.defineProperty(exports, "Job", { enumerable: true, get: function () { return jobs_2.Job; } });
|
|
33
33
|
/** SDK version (keep in sync with package.json) */
|
|
34
|
-
exports.SDK_VERSION = '2.
|
|
34
|
+
exports.SDK_VERSION = '2.7.0';
|
|
35
35
|
/**
|
|
36
36
|
* A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
|
|
37
37
|
* minutes at worst. A shorter configured axios timeout is raised to this for that call only.
|
|
@@ -53,6 +53,18 @@ function parseTranscribeData(inner, usage) {
|
|
|
53
53
|
usage,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* An extraction needs a schema (`schema` or `schemaFilePath`) or, without one, `what_to_extract`,
|
|
58
|
+
* from which the API writes the schema. Checked before anything is sent.
|
|
59
|
+
*/
|
|
60
|
+
function checkSchemaInput(input) {
|
|
61
|
+
if (input.schema !== undefined && input.schemaFilePath !== undefined) {
|
|
62
|
+
throw new Error('Pass at most one of schema or schemaFilePath.');
|
|
63
|
+
}
|
|
64
|
+
if (input.schema === undefined && input.schemaFilePath === undefined && !input.what_to_extract?.trim()) {
|
|
65
|
+
throw new Error('Pass schema, schemaFilePath or what_to_extract.');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
56
68
|
// The scene fields are set only when the response carries them, so a result asked without
|
|
57
69
|
// `include_scenes` keeps the shape it always had.
|
|
58
70
|
function pickSceneNotes(raw) {
|
|
@@ -178,6 +190,8 @@ class VidNavigatorClient {
|
|
|
178
190
|
data: requireResult(task),
|
|
179
191
|
video_info: task.video_info,
|
|
180
192
|
...pickSceneNotes(task),
|
|
193
|
+
...(task.schema ? { schema: task.schema } : {}),
|
|
194
|
+
...(task.evidence ? { evidence: task.evidence } : {}),
|
|
181
195
|
usage: task.usage,
|
|
182
196
|
}),
|
|
183
197
|
});
|
|
@@ -239,6 +253,7 @@ class VidNavigatorClient {
|
|
|
239
253
|
return { ...accepted, job_type: accepted.job_type ?? url.split('/')[1] };
|
|
240
254
|
}
|
|
241
255
|
submitExtractVideo(input) {
|
|
256
|
+
checkSchemaInput(input);
|
|
242
257
|
if ('schemaFilePath' in input) {
|
|
243
258
|
const form = new form_data_1.default();
|
|
244
259
|
form.append('video_url', input.video_url);
|
|
@@ -578,6 +593,7 @@ class VidNavigatorClient {
|
|
|
578
593
|
* is refused with `ScenesNotAvailableError` (HTTP 409).
|
|
579
594
|
*/
|
|
580
595
|
async extractFileData(payload) {
|
|
596
|
+
checkSchemaInput(payload);
|
|
581
597
|
let body;
|
|
582
598
|
if ('schemaFilePath' in payload) {
|
|
583
599
|
const form = new form_data_1.default();
|
|
@@ -595,6 +611,8 @@ class VidNavigatorClient {
|
|
|
595
611
|
data: body.data,
|
|
596
612
|
file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
|
|
597
613
|
...pickSceneNotes(body),
|
|
614
|
+
...(body.schema ? { schema: body.schema } : {}),
|
|
615
|
+
...(body.evidence ? { evidence: body.evidence } : {}),
|
|
598
616
|
usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
|
|
599
617
|
};
|
|
600
618
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ExtractionEvidence, ExtractionSchema } from './Extraction';
|
|
1
2
|
import { UsageBlock } from './Usage';
|
|
2
3
|
import { VideoInfo, VideoInfoJSON } from './VideoInfo';
|
|
3
4
|
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
@@ -71,6 +72,10 @@ export interface AsyncJobJSON {
|
|
|
71
72
|
frames_analyzed?: number;
|
|
72
73
|
scenes_error?: ScenesError;
|
|
73
74
|
transcript_error?: WatchTranscriptError;
|
|
75
|
+
/** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`. */
|
|
76
|
+
schema?: ExtractionSchema;
|
|
77
|
+
/** `extract_video` jobs, once completed: the moments each value of `result` comes from. */
|
|
78
|
+
evidence?: ExtractionEvidence;
|
|
74
79
|
error?: AsyncJobError | null;
|
|
75
80
|
}
|
|
76
81
|
/**
|
|
@@ -100,6 +105,10 @@ export declare class AsyncJob<TResult> {
|
|
|
100
105
|
scenes_error?: ScenesError;
|
|
101
106
|
/** `extract_video` jobs with `include_scenes`: why there is no transcript. The fields were then extracted from the scenes alone. */
|
|
102
107
|
transcript_error?: WatchTranscriptError;
|
|
108
|
+
/** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
109
|
+
schema?: ExtractionSchema;
|
|
110
|
+
/** `extract_video` jobs, once completed: the moments each value of `result` comes from. */
|
|
111
|
+
evidence?: ExtractionEvidence;
|
|
103
112
|
error: AsyncJobError | null;
|
|
104
113
|
/** Per-call usage, populated only when polled with `include_usage: true` and `task_status === 'completed'`. */
|
|
105
114
|
usage?: UsageBlock;
|
package/dist/models/AsyncJob.js
CHANGED
|
@@ -41,6 +41,8 @@ class AsyncJob {
|
|
|
41
41
|
this.frames_analyzed = data.frames_analyzed;
|
|
42
42
|
this.scenes_error = data.scenes_error;
|
|
43
43
|
this.transcript_error = data.transcript_error;
|
|
44
|
+
this.schema = data.schema;
|
|
45
|
+
this.evidence = data.evidence;
|
|
44
46
|
this.error = data.error ?? null;
|
|
45
47
|
}
|
|
46
48
|
static fromJSON(json, parseResult) {
|
|
@@ -1,21 +1,49 @@
|
|
|
1
1
|
import { FileInfoJSON } from './FileInfo';
|
|
2
2
|
import { VideoInfoJSON } from './VideoInfo';
|
|
3
3
|
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
4
|
-
|
|
4
|
+
/** JSON Schema types a property of an extraction schema can have. */
|
|
5
|
+
export type ExtractionFieldType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
6
|
+
/**
|
|
7
|
+
* One property of an extraction schema, in standard JSON Schema. Give it a `type` and a
|
|
8
|
+
* `description` (what to put in it); `enum` restricts it to a list of values. Other JSON Schema
|
|
9
|
+
* keywords are accepted (`$ref`, `format`, `minimum`, ...).
|
|
10
|
+
*/
|
|
5
11
|
export interface ExtractionField {
|
|
6
|
-
type
|
|
7
|
-
description
|
|
12
|
+
type?: ExtractionFieldType | Array<ExtractionFieldType | 'null'>;
|
|
13
|
+
description?: string;
|
|
8
14
|
properties?: Record<string, ExtractionField>;
|
|
9
15
|
items?: ExtractionField;
|
|
10
|
-
enum?: string
|
|
16
|
+
enum?: Array<string | number | boolean | null>;
|
|
17
|
+
[keyword: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The fields to extract, as a standard JSON Schema whose root is an object, for example what
|
|
21
|
+
* `zod-to-json-schema` or Pydantic's `model_json_schema()` produce. At most 10 fields per level
|
|
22
|
+
* and 3 levels of nesting.
|
|
23
|
+
*/
|
|
24
|
+
export interface ExtractionSchema {
|
|
25
|
+
type: 'object';
|
|
26
|
+
properties: Record<string, ExtractionField>;
|
|
27
|
+
required?: string[];
|
|
28
|
+
[keyword: string]: unknown;
|
|
11
29
|
}
|
|
12
|
-
/** Custom schema: field name -> field definition */
|
|
13
|
-
export type ExtractionSchema = Record<string, ExtractionField>;
|
|
14
30
|
export interface ExtractionTokenUsageJSON {
|
|
15
31
|
prompt_tokens?: number;
|
|
16
32
|
completion_tokens?: number;
|
|
17
33
|
total_tokens?: number;
|
|
18
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* A moment an extracted value was taken from. `in` is `'speech'` (said in the video), `'picture'`
|
|
37
|
+
* (shown or written on screen) or `'post'` (the post's own text: title, channel, description;
|
|
38
|
+
* no `start`/`end` then).
|
|
39
|
+
*/
|
|
40
|
+
export interface FieldEvidence {
|
|
41
|
+
start?: number;
|
|
42
|
+
end?: number;
|
|
43
|
+
in: 'speech' | 'picture' | 'post';
|
|
44
|
+
}
|
|
45
|
+
/** For each field of `data` that has a value, the moments of the video it comes from (at most 5). */
|
|
46
|
+
export type ExtractionEvidence = Record<string, FieldEvidence[]>;
|
|
19
47
|
export interface ExtractionResponseJSON {
|
|
20
48
|
status: 'success';
|
|
21
49
|
data: Record<string, unknown>;
|
|
@@ -25,6 +53,10 @@ export interface ExtractionResponseJSON {
|
|
|
25
53
|
frames_analyzed?: number;
|
|
26
54
|
scenes_error?: ScenesError;
|
|
27
55
|
transcript_error?: WatchTranscriptError;
|
|
56
|
+
/** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
57
|
+
schema?: ExtractionSchema;
|
|
58
|
+
/** Where each value of `data` comes from. */
|
|
59
|
+
evidence?: ExtractionEvidence;
|
|
28
60
|
usage?: ExtractionTokenUsageJSON;
|
|
29
61
|
}
|
|
30
62
|
export declare class ExtractionTokenUsage {
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -31,6 +31,14 @@ export interface WebhookEvent {
|
|
|
31
31
|
result_truncated?: boolean;
|
|
32
32
|
/** `extract_video.completed` only: raw `video_info` of the video. Sent even when `result_truncated` is true. */
|
|
33
33
|
video_info?: Record<string, unknown>;
|
|
34
|
+
/** `extract_video.completed` only, when the request had no schema: the schema written from `what_to_extract`. */
|
|
35
|
+
schema?: Record<string, unknown>;
|
|
36
|
+
/** `extract_video.completed` only: the moments each value of `result` comes from. */
|
|
37
|
+
evidence?: Record<string, Array<{
|
|
38
|
+
start?: number;
|
|
39
|
+
end?: number;
|
|
40
|
+
in: 'speech' | 'picture' | 'post';
|
|
41
|
+
}>>;
|
|
34
42
|
error?: AsyncJobError | null;
|
|
35
43
|
};
|
|
36
44
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
NamespaceJSON,
|
|
22
22
|
NamespaceRef,
|
|
23
23
|
NamespaceRefJSON,
|
|
24
|
+
ExtractionEvidence,
|
|
24
25
|
ExtractionSchema,
|
|
25
26
|
UsageBlock,
|
|
26
27
|
UsageBlockJSON,
|
|
@@ -72,7 +73,7 @@ export { Job } from './jobs';
|
|
|
72
73
|
export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
|
|
73
74
|
|
|
74
75
|
/** SDK version (keep in sync with package.json) */
|
|
75
|
-
export const SDK_VERSION = '2.
|
|
76
|
+
export const SDK_VERSION = '2.7.0';
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
|
|
@@ -159,11 +160,17 @@ export type AnalyzeVideoInput = {
|
|
|
159
160
|
transcript_text?: boolean;
|
|
160
161
|
} & WebhookOption;
|
|
161
162
|
|
|
162
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* Input for {@link VidNavigatorClient.extractVideo}: a JSON Schema `schema`, or a JSON/YAML
|
|
165
|
+
* `schemaFilePath`, or neither with `what_to_extract`: the schema is then written from that text
|
|
166
|
+
* and comes back as `schema` on the result.
|
|
167
|
+
*/
|
|
163
168
|
export type ExtractVideoInput =
|
|
164
169
|
| ({
|
|
165
170
|
video_url: string;
|
|
166
|
-
|
|
171
|
+
/** The fields to extract, as a standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
172
|
+
schema?: ExtractionSchema;
|
|
173
|
+
/** What to extract, in plain words. Guides the extraction, or alone, writes the schema. */
|
|
167
174
|
what_to_extract?: string;
|
|
168
175
|
/** Speech-to-text the audio when no platform transcript exists. Default true. */
|
|
169
176
|
transcribe?: boolean;
|
|
@@ -286,6 +293,10 @@ export type GetFileResult = {
|
|
|
286
293
|
|
|
287
294
|
export interface ExtractDataResult {
|
|
288
295
|
data: Record<string, unknown>;
|
|
296
|
+
/** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
297
|
+
schema?: ExtractionSchema;
|
|
298
|
+
/** For each field of `data` that has a value, the moments of the video it comes from. */
|
|
299
|
+
evidence?: ExtractionEvidence;
|
|
289
300
|
video_info?: VideoInfo;
|
|
290
301
|
file_info?: FileInfo;
|
|
291
302
|
/** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
|
|
@@ -406,7 +417,8 @@ export type AnalyzeFileResult = {
|
|
|
406
417
|
|
|
407
418
|
export type ExtractVideoDataPayload = {
|
|
408
419
|
video_url: string;
|
|
409
|
-
|
|
420
|
+
/** A standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
421
|
+
schema?: ExtractionSchema;
|
|
410
422
|
what_to_extract?: string;
|
|
411
423
|
transcribe?: boolean;
|
|
412
424
|
/**
|
|
@@ -431,7 +443,8 @@ export type TweetStatementPayload = { tweet_id: string } & WebhookOption;
|
|
|
431
443
|
|
|
432
444
|
export type ExtractFileDataPayload = {
|
|
433
445
|
file_id: string;
|
|
434
|
-
|
|
446
|
+
/** A standard JSON Schema. Optional when `what_to_extract` is given. */
|
|
447
|
+
schema?: ExtractionSchema;
|
|
435
448
|
what_to_extract?: string;
|
|
436
449
|
/**
|
|
437
450
|
* Default false. `true` extracts from the transcript of the file and its scenes together. The
|
|
@@ -474,6 +487,19 @@ function parseTranscribeData(
|
|
|
474
487
|
};
|
|
475
488
|
}
|
|
476
489
|
|
|
490
|
+
/**
|
|
491
|
+
* An extraction needs a schema (`schema` or `schemaFilePath`) or, without one, `what_to_extract`,
|
|
492
|
+
* from which the API writes the schema. Checked before anything is sent.
|
|
493
|
+
*/
|
|
494
|
+
function checkSchemaInput(input: { schema?: unknown; schemaFilePath?: string; what_to_extract?: string }): void {
|
|
495
|
+
if (input.schema !== undefined && input.schemaFilePath !== undefined) {
|
|
496
|
+
throw new Error('Pass at most one of schema or schemaFilePath.');
|
|
497
|
+
}
|
|
498
|
+
if (input.schema === undefined && input.schemaFilePath === undefined && !input.what_to_extract?.trim()) {
|
|
499
|
+
throw new Error('Pass schema, schemaFilePath or what_to_extract.');
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
477
503
|
/** What `include_scenes` adds beside the scenes themselves. */
|
|
478
504
|
interface SceneNotes {
|
|
479
505
|
frames_analyzed?: number;
|
|
@@ -722,6 +748,8 @@ export class VidNavigatorClient {
|
|
|
722
748
|
data: requireResult(task),
|
|
723
749
|
video_info: task.video_info,
|
|
724
750
|
...pickSceneNotes(task),
|
|
751
|
+
...(task.schema ? { schema: task.schema } : {}),
|
|
752
|
+
...(task.evidence ? { evidence: task.evidence } : {}),
|
|
725
753
|
usage: task.usage,
|
|
726
754
|
}),
|
|
727
755
|
});
|
|
@@ -820,6 +848,7 @@ export class VidNavigatorClient {
|
|
|
820
848
|
}
|
|
821
849
|
|
|
822
850
|
private submitExtractVideo(input: ExtractVideoInput): Promise<JobInfo> {
|
|
851
|
+
checkSchemaInput(input);
|
|
823
852
|
if ('schemaFilePath' in input) {
|
|
824
853
|
const form = new FormData();
|
|
825
854
|
form.append('video_url', input.video_url);
|
|
@@ -1350,10 +1379,13 @@ export class VidNavigatorClient {
|
|
|
1350
1379
|
async extractFileData(
|
|
1351
1380
|
payload: ExtractFileDataPayload | ExtractFileDataMultipartPayload
|
|
1352
1381
|
): Promise<ExtractDataResult> {
|
|
1382
|
+
checkSchemaInput(payload);
|
|
1353
1383
|
type ExtractFileBody = {
|
|
1354
1384
|
status: 'success';
|
|
1355
1385
|
data: Record<string, unknown>;
|
|
1356
1386
|
file_info?: FileInfoJSON;
|
|
1387
|
+
schema?: ExtractionSchema;
|
|
1388
|
+
evidence?: ExtractionEvidence;
|
|
1357
1389
|
usage?: UsageBlockJSON;
|
|
1358
1390
|
} & SceneNotes;
|
|
1359
1391
|
let body: ExtractFileBody;
|
|
@@ -1374,6 +1406,8 @@ export class VidNavigatorClient {
|
|
|
1374
1406
|
data: body.data,
|
|
1375
1407
|
file_info: body.file_info ? FileInfo.fromJSON(body.file_info) : undefined,
|
|
1376
1408
|
...pickSceneNotes(body),
|
|
1409
|
+
...(body.schema ? { schema: body.schema } : {}),
|
|
1410
|
+
...(body.evidence ? { evidence: body.evidence } : {}),
|
|
1377
1411
|
usage: body.usage ? UsageBlock.fromJSON(body.usage) : undefined,
|
|
1378
1412
|
};
|
|
1379
1413
|
}
|
package/src/models/AsyncJob.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ExtractionEvidence, ExtractionSchema } from './Extraction';
|
|
1
2
|
import { UsageBlock } from './Usage';
|
|
2
3
|
import { VideoInfo, VideoInfoJSON } from './VideoInfo';
|
|
3
4
|
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
@@ -91,6 +92,10 @@ export interface AsyncJobJSON {
|
|
|
91
92
|
frames_analyzed?: number;
|
|
92
93
|
scenes_error?: ScenesError;
|
|
93
94
|
transcript_error?: WatchTranscriptError;
|
|
95
|
+
/** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`. */
|
|
96
|
+
schema?: ExtractionSchema;
|
|
97
|
+
/** `extract_video` jobs, once completed: the moments each value of `result` comes from. */
|
|
98
|
+
evidence?: ExtractionEvidence;
|
|
94
99
|
error?: AsyncJobError | null;
|
|
95
100
|
}
|
|
96
101
|
|
|
@@ -121,6 +126,10 @@ export class AsyncJob<TResult> {
|
|
|
121
126
|
scenes_error?: ScenesError;
|
|
122
127
|
/** `extract_video` jobs with `include_scenes`: why there is no transcript. The fields were then extracted from the scenes alone. */
|
|
123
128
|
transcript_error?: WatchTranscriptError;
|
|
129
|
+
/** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
130
|
+
schema?: ExtractionSchema;
|
|
131
|
+
/** `extract_video` jobs, once completed: the moments each value of `result` comes from. */
|
|
132
|
+
evidence?: ExtractionEvidence;
|
|
124
133
|
error: AsyncJobError | null;
|
|
125
134
|
/** Per-call usage, populated only when polled with `include_usage: true` and `task_status === 'completed'`. */
|
|
126
135
|
usage?: UsageBlock;
|
|
@@ -141,6 +150,8 @@ export class AsyncJob<TResult> {
|
|
|
141
150
|
this.frames_analyzed = data.frames_analyzed;
|
|
142
151
|
this.scenes_error = data.scenes_error;
|
|
143
152
|
this.transcript_error = data.transcript_error;
|
|
153
|
+
this.schema = data.schema;
|
|
154
|
+
this.evidence = data.evidence;
|
|
144
155
|
this.error = data.error ?? null;
|
|
145
156
|
}
|
|
146
157
|
|
package/src/models/Extraction.ts
CHANGED
|
@@ -2,25 +2,34 @@ import { FileInfoJSON } from './FileInfo';
|
|
|
2
2
|
import { VideoInfoJSON } from './VideoInfo';
|
|
3
3
|
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
| 'Number'
|
|
8
|
-
| 'Boolean'
|
|
9
|
-
| 'Integer'
|
|
10
|
-
| 'Object'
|
|
11
|
-
| 'Array'
|
|
12
|
-
| 'Enum';
|
|
5
|
+
/** JSON Schema types a property of an extraction schema can have. */
|
|
6
|
+
export type ExtractionFieldType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
13
7
|
|
|
8
|
+
/**
|
|
9
|
+
* One property of an extraction schema, in standard JSON Schema. Give it a `type` and a
|
|
10
|
+
* `description` (what to put in it); `enum` restricts it to a list of values. Other JSON Schema
|
|
11
|
+
* keywords are accepted (`$ref`, `format`, `minimum`, ...).
|
|
12
|
+
*/
|
|
14
13
|
export interface ExtractionField {
|
|
15
|
-
type
|
|
16
|
-
description
|
|
14
|
+
type?: ExtractionFieldType | Array<ExtractionFieldType | 'null'>;
|
|
15
|
+
description?: string;
|
|
17
16
|
properties?: Record<string, ExtractionField>;
|
|
18
17
|
items?: ExtractionField;
|
|
19
|
-
enum?: string
|
|
18
|
+
enum?: Array<string | number | boolean | null>;
|
|
19
|
+
[keyword: string]: unknown;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The fields to extract, as a standard JSON Schema whose root is an object, for example what
|
|
24
|
+
* `zod-to-json-schema` or Pydantic's `model_json_schema()` produce. At most 10 fields per level
|
|
25
|
+
* and 3 levels of nesting.
|
|
26
|
+
*/
|
|
27
|
+
export interface ExtractionSchema {
|
|
28
|
+
type: 'object';
|
|
29
|
+
properties: Record<string, ExtractionField>;
|
|
30
|
+
required?: string[];
|
|
31
|
+
[keyword: string]: unknown;
|
|
32
|
+
}
|
|
24
33
|
|
|
25
34
|
export interface ExtractionTokenUsageJSON {
|
|
26
35
|
prompt_tokens?: number;
|
|
@@ -28,6 +37,20 @@ export interface ExtractionTokenUsageJSON {
|
|
|
28
37
|
total_tokens?: number;
|
|
29
38
|
}
|
|
30
39
|
|
|
40
|
+
/**
|
|
41
|
+
* A moment an extracted value was taken from. `in` is `'speech'` (said in the video), `'picture'`
|
|
42
|
+
* (shown or written on screen) or `'post'` (the post's own text: title, channel, description;
|
|
43
|
+
* no `start`/`end` then).
|
|
44
|
+
*/
|
|
45
|
+
export interface FieldEvidence {
|
|
46
|
+
start?: number;
|
|
47
|
+
end?: number;
|
|
48
|
+
in: 'speech' | 'picture' | 'post';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** For each field of `data` that has a value, the moments of the video it comes from (at most 5). */
|
|
52
|
+
export type ExtractionEvidence = Record<string, FieldEvidence[]>;
|
|
53
|
+
|
|
31
54
|
export interface ExtractionResponseJSON {
|
|
32
55
|
status: 'success';
|
|
33
56
|
data: Record<string, unknown>;
|
|
@@ -37,6 +60,10 @@ export interface ExtractionResponseJSON {
|
|
|
37
60
|
frames_analyzed?: number;
|
|
38
61
|
scenes_error?: ScenesError;
|
|
39
62
|
transcript_error?: WatchTranscriptError;
|
|
63
|
+
/** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
64
|
+
schema?: ExtractionSchema;
|
|
65
|
+
/** Where each value of `data` comes from. */
|
|
66
|
+
evidence?: ExtractionEvidence;
|
|
40
67
|
usage?: ExtractionTokenUsageJSON;
|
|
41
68
|
}
|
|
42
69
|
|
package/src/webhooks.ts
CHANGED
|
@@ -52,6 +52,10 @@ export interface WebhookEvent {
|
|
|
52
52
|
result_truncated?: boolean;
|
|
53
53
|
/** `extract_video.completed` only: raw `video_info` of the video. Sent even when `result_truncated` is true. */
|
|
54
54
|
video_info?: Record<string, unknown>;
|
|
55
|
+
/** `extract_video.completed` only, when the request had no schema: the schema written from `what_to_extract`. */
|
|
56
|
+
schema?: Record<string, unknown>;
|
|
57
|
+
/** `extract_video.completed` only: the moments each value of `result` comes from. */
|
|
58
|
+
evidence?: Record<string, Array<{ start?: number; end?: number; in: 'speech' | 'picture' | 'post' }>>;
|
|
55
59
|
error?: AsyncJobError | null;
|
|
56
60
|
};
|
|
57
61
|
}
|