twelvelabs-js 0.2.2 → 0.2.4

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.
Files changed (62) hide show
  1. package/README.md +67 -40
  2. package/dist/README.md +67 -40
  3. package/dist/core.d.ts +0 -1
  4. package/dist/core.d.ts.map +1 -1
  5. package/dist/core.js +13 -11
  6. package/dist/core.js.map +1 -1
  7. package/dist/core.mjs +12 -10
  8. package/dist/core.mjs.map +1 -1
  9. package/dist/error.d.ts +0 -2
  10. package/dist/error.d.ts.map +1 -1
  11. package/dist/error.js.map +1 -1
  12. package/dist/error.mjs.map +1 -1
  13. package/dist/models/embed/index.d.ts +2 -2
  14. package/dist/models/embed/index.d.ts.map +1 -1
  15. package/dist/models/embed/index.js +11 -6
  16. package/dist/models/embed/index.js.map +1 -1
  17. package/dist/models/embed/index.mjs +11 -6
  18. package/dist/models/embed/index.mjs.map +1 -1
  19. package/dist/models/generate/index.d.ts +8 -0
  20. package/dist/models/generate/index.d.ts.map +1 -1
  21. package/dist/models/generate/index.js +56 -0
  22. package/dist/models/generate/index.js.map +1 -1
  23. package/dist/models/generate/index.mjs +54 -1
  24. package/dist/models/generate/index.mjs.map +1 -1
  25. package/dist/models/task/index.d.ts.map +1 -1
  26. package/dist/models/task/index.js +11 -5
  27. package/dist/models/task/index.js.map +1 -1
  28. package/dist/models/task/index.mjs +11 -5
  29. package/dist/models/task/index.mjs.map +1 -1
  30. package/dist/resources/generate/index.d.ts +2 -1
  31. package/dist/resources/generate/index.d.ts.map +1 -1
  32. package/dist/resources/generate/index.js +35 -1
  33. package/dist/resources/generate/index.js.map +1 -1
  34. package/dist/resources/generate/index.mjs +13 -2
  35. package/dist/resources/generate/index.mjs.map +1 -1
  36. package/dist/resources/generate/interfaces.d.ts +5 -0
  37. package/dist/resources/generate/interfaces.d.ts.map +1 -1
  38. package/dist/resources/search/index.d.ts +1 -1
  39. package/dist/resources/search/index.d.ts.map +1 -1
  40. package/dist/resources/search/index.js +4 -1
  41. package/dist/resources/search/index.js.map +1 -1
  42. package/dist/resources/search/index.mjs +4 -1
  43. package/dist/resources/search/index.mjs.map +1 -1
  44. package/dist/resources/search/interfaces.d.ts +1 -0
  45. package/dist/resources/search/interfaces.d.ts.map +1 -1
  46. package/dist/src/core.ts +11 -9
  47. package/dist/src/error.ts +0 -1
  48. package/dist/src/models/embed/index.ts +11 -7
  49. package/dist/src/models/generate/index.ts +61 -0
  50. package/dist/src/models/task/index.ts +10 -6
  51. package/dist/src/resources/generate/index.ts +25 -3
  52. package/dist/src/resources/generate/interfaces.ts +6 -0
  53. package/dist/src/resources/search/index.ts +3 -0
  54. package/dist/src/resources/search/interfaces.ts +1 -0
  55. package/dist/src/util.ts +49 -0
  56. package/dist/util.d.ts +1 -0
  57. package/dist/util.d.ts.map +1 -1
  58. package/dist/util.js +43 -1
  59. package/dist/util.js.map +1 -1
  60. package/dist/util.mjs +41 -0
  61. package/dist/util.mjs.map +1 -1
  62. package/package.json +3 -4
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # TwelveLabs JavaScript SDK
2
+
2
3
  [![NPM version](https://img.shields.io/npm/v/twelvelabs-js.svg)](https://npmjs.org/package/twelvelabs-js)
3
4
 
4
5
  This SDK provides a convenient way to interact with the Twelve Labs Video Understanding Platform from an application written in JavaScript or TypeScript language. The SDK equips you with a set of intuitive methods that streamline the process of interacting with the platform, minimizing the need for boilerplate code.
5
6
 
6
-
7
7
  # Prerequisites
8
8
 
9
9
  Ensure that the following prerequisites are met before using the SDK:
10
10
 
11
- - [Node.js](https://nodejs.org/) 14 or newer must be installed on your machine.
12
- - You have an API key. If you don't have an account, please [sign up](https://api.twelvelabs.io/) for a free account. Then, to retrieve your API key, go to the [Dashboard](https://api.twelvelabs.io/dashboard) page, and select the **Copy** icon to the right of the key to copy it to your clipboard.
11
+ - [Node.js](https://nodejs.org/) 14 or newer must be installed on your machine.
12
+ - You have an API key. If you don't have an account, please [sign up](https://api.twelvelabs.io/) for a free account. Then, to retrieve your API key, go to the [Dashboard](https://api.twelvelabs.io/dashboard) page, and select the **Copy** icon to the right of the key to copy it to your clipboard.
13
13
 
14
14
  # Install the SDK
15
15
 
@@ -23,17 +23,17 @@ yarn add twelvelabs-js # or npm i twelvelabs-js
23
23
 
24
24
  1. Import the required packages into your application:
25
25
 
26
- ```js
27
- import { TwelveLabs, SearchData, Task } from 'twelvelabs-js';
28
- import { promises as fsPromises } from 'fs';
29
- import * as path from 'path';
30
- ```
26
+ ```js
27
+ import { TwelveLabs, SearchData, Task } from 'twelvelabs-js';
28
+ import { promises as fsPromises } from 'fs';
29
+ import * as path from 'path';
30
+ ```
31
31
 
32
32
  2. Instantiate the SDK client with your API key. This example code assumes that your API key is stored in an environment variable named `TL_API_KEY`:
33
33
 
34
- ```js
35
- const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>' });
36
- ```
34
+ ```js
35
+ const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>' });
36
+ ```
37
37
 
38
38
  # Use the SDK
39
39
 
@@ -56,7 +56,7 @@ let index = await client.index.create({
56
56
  options: ['visual', 'conversation', 'text_in_video'],
57
57
  },
58
58
  {
59
- name: 'pegasus1',
59
+ name: 'pegasus1.1',
60
60
  options: ['visual', 'conversation'],
61
61
  },
62
62
  ],
@@ -66,31 +66,31 @@ console.log(`Created index: id=${index.id} name=${index.name} engines=${JSON.str
66
66
  ```
67
67
 
68
68
  Note the following about this example:
69
+
69
70
  - The platform provides two distinct engine types - embedding and generative, each serving unique purposes in multimodal video understanding.
70
71
  - **Embedding engines (Marengo)**: These engines are proficient at performing tasks such as search and classification, enabling enhanced video understanding.
71
72
  - **Generative engines (Pegasus)**: These engines generate text based on your videos.
72
- For your index, both Marengo and Pegasus are enabled.
73
+ For your index, both Marengo and Pegasus are enabled.
73
74
  - The `engines.options` fields specify the types of information each video understanding engine will process. For details, see the [Engine options](https://docs.twelvelabs.io/v1.2/docs/engine-options) page.
74
75
  - The engines and the engine options specified when you create an index apply to all the videos you upload to that index and cannot be changed. For details, see the [Engine options](https://docs.twelvelabs.io/v1.2/docs/engine-options) page.
75
76
 
76
77
  The output should look similar to the following:
77
78
 
78
79
  ```
79
- Created index: id=65e71802bb29f13bdd6f38d8 name=2024-03-05T13:02:57.938Z engines=[{"name":"pegasus1","options":["visual","conversation"]},{"name":"marengo2.6","options":["visual","conversation","text_in_video"]}]
80
+ Created index: id=65e71802bb29f13bdd6f38d8 name=2024-03-05T13:02:57.938Z engines=[{"name":"pegasus1.1","options":["visual","conversation"]},{"name":"marengo2.6","options":["visual","conversation","text_in_video"]}]
80
81
  ```
81
82
 
82
83
  Note that the API returns, among other information, a field named `id`, representing the unique identifier of your new index.
83
84
 
84
85
  For a description of each field in the request and response, see the [Create an index](https://docs.twelvelabs.io/v1.2/reference/create-index) page.
85
86
 
86
-
87
87
  ## Upload videos
88
88
 
89
89
  Before you upload a video to the platform, ensure that it meets the following requirements:
90
90
 
91
- - **Video resolution**: Must be greater or equal than 360p and less or equal than 4K. For consistent search results, Twelve Labs recommends you upload 360p videos.
92
- - **Video and audio formats**: The video files you wish to upload must be encoded in the video and audio formats listed on the [FFmpeg Formats Documentation](https://ffmpeg.org/ffmpeg-formats.html) page. For videos in other formats, contact us at [support@twelvelabs.io](mailto:support@twelvelabs.io).
93
- - **Duration**: For Marengo, it must be between 4 seconds and 2 hours (7,200s). For Pegasus, it must be between 4 seconds and 20 minutes (1200s).
91
+ - **Video resolution**: Must be greater or equal than 360p and less or equal than 4K.
92
+ - **Video and audio formats**: The video files you wish to upload must be encoded in the video and audio formats listed on the [FFmpeg Formats Documentation](https://ffmpeg.org/ffmpeg-formats.html) page. For videos in other formats, contact us at [support@twelvelabs.io](mailto:support@twelvelabs.io).
93
+ - **Duration**: For Marengo, it must be between 4 seconds and 2 hours (7,200s). For Pegasus, it must be between 4 seconds and 30 minutes (1,800s).
94
94
  - **File size**: Must not exceed 2 GB. If you require different options, send us an email at support@twelvelabs.io.
95
95
  - **Audio track**: If the `conversation` [engine option](https://docs.twelvelabs.io/v1.2/docs/engine-options) is selected, the video you're uploading must contain an audio track.
96
96
 
@@ -99,7 +99,6 @@ To upload videos, use the example code below, replacing the following:
99
99
  - **`<YOUR_VIDEO_PATH>`**: with a string representing the path to the directory containing the video files you wish to upload.
100
100
  - **`<YOUR_INDEX_ID>`**: with a string representing the unique identifier of the index to which you want to upload your video.
101
101
 
102
-
103
102
  ```js
104
103
  const files = await fsPromises.readdir('YOUR_VIDEO_PATH');
105
104
  for (const file of files) {
@@ -130,7 +129,14 @@ The sections below show how you can perform the most common downstream tasks. Se
130
129
 
131
130
  ### Search
132
131
 
133
- To perform a search request, use the example code below, replacing the following:
132
+ To search for relevant video content, you can use either text or images as queries:
133
+
134
+ - **Text queries**: Use natural language to find video segments matching specific keywords or phrases.
135
+ - **Image queries**: Use images to find video segments that are semantically similar to the provided images.
136
+
137
+ **Search using text queries**
138
+
139
+ To perform search requests using text queries, use the example code below, replacing the following:
134
140
 
135
141
  - **`<YOUR_INDEX_ID>`**: with a string representing the unique identifier of your index.
136
142
  - **`<YOUR_QUERY>`**: with a string representing your search query. Note that the API supports full natural language-based search. The following examples are valid queries: "birds flying near a castle," "sun shining on water," and "an officer holding a child's hand."
@@ -159,7 +165,7 @@ function printPage(searchData) {
159
165
  }
160
166
  ```
161
167
 
162
- The results are returned one page at a time, with a default limit of 10 results on each page. The `next ` method returns the next page of results. When you've reached the end of the dataset, the response is `null`.
168
+ The results are returned one page at a time, with a default limit of 10 results on each page. The `next` method returns the next page of results. When you've reached the end of the dataset, the response is `null`.
163
169
 
164
170
  ```
165
171
  video_id=65ca2bce48db9fa780cb3fa4 score=84.9 start=104.9375 end=111.90625 confidence=high
@@ -167,8 +173,8 @@ The results are returned one page at a time, with a default limit of 10 results
167
173
  video_id=65ca2bce48db9fa780cb3fa4 score=84.77 start=55.375 end=72.46875 confidence=high
168
174
  ```
169
175
 
170
-
171
176
  Note that the response contains, among other information, the following fields:
177
+
172
178
  - `videoId`: The unique identifier of the video that matched your search terms.
173
179
  - `score`: A quantitative value determined by the AI engine representing the level of confidence that the results match your search terms.
174
180
  - `start`: The start time of the matching video clip, expressed in seconds.
@@ -179,17 +185,38 @@ Note that the response contains, among other information, the following fields:
179
185
  - `low`
180
186
  - `extremely low`
181
187
 
182
-
183
188
  For a description of each field in the request and response, see the [Make a search request](https://docs.twelvelabs.io/v1.2/reference/make-search-request) page.
184
189
 
190
+ **Search using image queries**
191
+
192
+ You can provide images as local files or publicly accessible URLs. Use the `queryMediaFile` parameter for local image files and the `queryMediaUrl` parameter for publicly accessible URLs.
193
+
194
+ To perform a search request using image queries, use the example code below, replacing the following:
195
+
196
+ - **`<YOUR_INDEX_ID>`**: with a string representing the unique identifier of your index.
197
+ - **`<YOUR_FILE_PATH>`**: with a string representing the path of the image file you wish to provide.
198
+ - **`[<YOUR_SEARCH_OPTIONS>]`**: with an array of strings that specifies the sources of information the platform uses when performing a search. For example, to search based on visual cues, use `["visual"]`. Note that the search options you specify must be a subset of the engine options used when you created the index. For more details, see the [Search options](https://docs.twelvelabs.io/docs/search-options) page.
199
+
200
+ ```js
201
+ let searchResults = await client.search.query({
202
+ indexId: '<YOUR_INDEX_ID>',
203
+ queryMediaType: 'image',
204
+ queryMediaFile: '<YOUR_FILE_PATH>', // Use queryMediaUrl instead to provide a file from a publicly accessible URL.
205
+ options: ['visual'],
206
+ });
207
+ ```
208
+
209
+ The response is similar to that received when using text queries.
210
+
185
211
  ### Generate text from video
186
212
 
187
213
  The Twelve Labs Video Understanding Platform offers three distinct endpoints tailored to meet various requirements. Each endpoint has been designed with specific levels of flexibility and customization to accommodate different needs.
188
214
 
189
215
  Note the following about using these endpoints:
216
+
190
217
  - The Pegasus video understanding engine must be enabled for the index to which your video has been uploaded.
191
- - Your prompts must be instructive or descriptive, and you should not phrase them as questions.
192
- - The maximum length of a prompt is 300 characters.
218
+ - Your prompts must be instructive or descriptive, and you can also phrase them as questions.
219
+ - The maximum length of a prompt is 1500 characters.
193
220
 
194
221
  #### Topics, titles, and hashtags
195
222
 
@@ -198,7 +225,7 @@ To generate topics, titles, and hashtags, use the example code below, replacing
198
225
  - **`<YOUR_VIDEO_ID>`**: with a string representing the unique identifier of your video.
199
226
  - **`[<TYPES>]`**: with an array of strings representing the type of text the platform should generate. Example: `["title", "topic", "hashtag"]`.
200
227
 
201
- ```py
228
+ ```js
202
229
  const gist = await client.generate.gist('<YOUR_VIDEO_ID>', ['<TYPES>']);
203
230
  console.log(`Title: ${gist.title}\nTopics=${gist.topics}\nHashtags=${gist.hashtags}`);
204
231
  ```
@@ -211,8 +238,7 @@ To generate summaries, chapters, and highlights, use the example code below, rep
211
238
 
212
239
  - **`<YOUR_VIDEO_ID>`**: with a string representing the unique identifier of your video.
213
240
  - **`<TYPE>`**: with a string representing the type of text the platform should generate. This parameter can take one of the following values: "summary", "chapter", or "highlight".
214
- - _(Optional)_ **`<YOUR_PROMPT>`**: with a string that provides context for the summarization task, such as the target audience, style, tone of voice, and purpose. Example: "Generate a summary in no more than 5 bullet points."
215
-
241
+ - _(Optional)_ **`<YOUR_PROMPT>`**: with a string that provides context for the summarization task, such as the target audience, style, tone of voice, and purpose. Example: "Generate a summary in no more than 5 bullet points."
216
242
 
217
243
  ```js
218
244
  const summary = await client.generate.summarize('<YOUR_VIDEO_ID>', '<TYPE>');
@@ -224,10 +250,11 @@ For a description of each field in the request and response, see the [Summaries,
224
250
  #### Open-ended texts
225
251
 
226
252
  To generate open-ended texts, use the example code below, replacing the following:
253
+
227
254
  - **`<YOUR_VIDEO_ID>`**: with a string representing the unique identifier of your video.
228
- - **`<YOUR_PROMPT>`**: with a string that guides the model on the desired format or content. The maximum length of the prompt is 500 tokens or roughly 350 words. Example: "I want to generate a description for my video with the following format: Title of the video, followed by a summary in 2-3 sentences, highlighting the main topic, key events, and concluding remarks."
255
+ - **`<YOUR_PROMPT>`**: with a string that guides the model on the desired format or content. The maximum length of the prompt is 1500 characters. Example: "I want to generate a description for my video with the following format: Title of the video, followed by a summary in 2-3 sentences, highlighting the main topic, key events, and concluding remarks."
229
256
 
230
- ```py
257
+ ```js
231
258
  const text = await client.generate.text('<YOUR_VIDEO_ID>', '<YOUR_PROMPT>');
232
259
  console.log(`Open-ended Text: ${text.data}`);
233
260
  ```
@@ -236,16 +263,16 @@ console.log(`Open-ended Text: ${text.data}`);
236
263
 
237
264
  The SDK includes a set of exceptions that are mapped to specific HTTP status codes, as shown in the table below:
238
265
 
239
- | Exception | HTTP Status Code |
240
- |----------|----------|
241
- | BadRequestError| 400 |
242
- | AuthenticationError | 401 |
243
- | PermissionDeniedError | 403 |
244
- | NotFoundError | 404 |
245
- | ConflictError | 409 |
246
- | UnprocessableEntityError | 422 |
247
- | RateLimitError | 429 |
248
- | InternalServerError | 5xx |
266
+ | Exception | HTTP Status Code |
267
+ | ------------------------ | ---------------- |
268
+ | BadRequestError | 400 |
269
+ | AuthenticationError | 401 |
270
+ | PermissionDeniedError | 403 |
271
+ | NotFoundError | 404 |
272
+ | ConflictError | 409 |
273
+ | UnprocessableEntityError | 422 |
274
+ | RateLimitError | 429 |
275
+ | InternalServerError | 5xx |
249
276
 
250
277
  The following example shows how you can handle specific HTTP errors in your application:
251
278
 
package/dist/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # TwelveLabs JavaScript SDK
2
+
2
3
  [![NPM version](https://img.shields.io/npm/v/twelvelabs-js.svg)](https://npmjs.org/package/twelvelabs-js)
3
4
 
4
5
  This SDK provides a convenient way to interact with the Twelve Labs Video Understanding Platform from an application written in JavaScript or TypeScript language. The SDK equips you with a set of intuitive methods that streamline the process of interacting with the platform, minimizing the need for boilerplate code.
5
6
 
6
-
7
7
  # Prerequisites
8
8
 
9
9
  Ensure that the following prerequisites are met before using the SDK:
10
10
 
11
- - [Node.js](https://nodejs.org/) 14 or newer must be installed on your machine.
12
- - You have an API key. If you don't have an account, please [sign up](https://api.twelvelabs.io/) for a free account. Then, to retrieve your API key, go to the [Dashboard](https://api.twelvelabs.io/dashboard) page, and select the **Copy** icon to the right of the key to copy it to your clipboard.
11
+ - [Node.js](https://nodejs.org/) 14 or newer must be installed on your machine.
12
+ - You have an API key. If you don't have an account, please [sign up](https://api.twelvelabs.io/) for a free account. Then, to retrieve your API key, go to the [Dashboard](https://api.twelvelabs.io/dashboard) page, and select the **Copy** icon to the right of the key to copy it to your clipboard.
13
13
 
14
14
  # Install the SDK
15
15
 
@@ -23,17 +23,17 @@ yarn add twelvelabs-js # or npm i twelvelabs-js
23
23
 
24
24
  1. Import the required packages into your application:
25
25
 
26
- ```js
27
- import { TwelveLabs, SearchData, Task } from 'twelvelabs-js';
28
- import { promises as fsPromises } from 'fs';
29
- import * as path from 'path';
30
- ```
26
+ ```js
27
+ import { TwelveLabs, SearchData, Task } from 'twelvelabs-js';
28
+ import { promises as fsPromises } from 'fs';
29
+ import * as path from 'path';
30
+ ```
31
31
 
32
32
  2. Instantiate the SDK client with your API key. This example code assumes that your API key is stored in an environment variable named `TL_API_KEY`:
33
33
 
34
- ```js
35
- const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>' });
36
- ```
34
+ ```js
35
+ const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>' });
36
+ ```
37
37
 
38
38
  # Use the SDK
39
39
 
@@ -56,7 +56,7 @@ let index = await client.index.create({
56
56
  options: ['visual', 'conversation', 'text_in_video'],
57
57
  },
58
58
  {
59
- name: 'pegasus1',
59
+ name: 'pegasus1.1',
60
60
  options: ['visual', 'conversation'],
61
61
  },
62
62
  ],
@@ -66,31 +66,31 @@ console.log(`Created index: id=${index.id} name=${index.name} engines=${JSON.str
66
66
  ```
67
67
 
68
68
  Note the following about this example:
69
+
69
70
  - The platform provides two distinct engine types - embedding and generative, each serving unique purposes in multimodal video understanding.
70
71
  - **Embedding engines (Marengo)**: These engines are proficient at performing tasks such as search and classification, enabling enhanced video understanding.
71
72
  - **Generative engines (Pegasus)**: These engines generate text based on your videos.
72
- For your index, both Marengo and Pegasus are enabled.
73
+ For your index, both Marengo and Pegasus are enabled.
73
74
  - The `engines.options` fields specify the types of information each video understanding engine will process. For details, see the [Engine options](https://docs.twelvelabs.io/v1.2/docs/engine-options) page.
74
75
  - The engines and the engine options specified when you create an index apply to all the videos you upload to that index and cannot be changed. For details, see the [Engine options](https://docs.twelvelabs.io/v1.2/docs/engine-options) page.
75
76
 
76
77
  The output should look similar to the following:
77
78
 
78
79
  ```
79
- Created index: id=65e71802bb29f13bdd6f38d8 name=2024-03-05T13:02:57.938Z engines=[{"name":"pegasus1","options":["visual","conversation"]},{"name":"marengo2.6","options":["visual","conversation","text_in_video"]}]
80
+ Created index: id=65e71802bb29f13bdd6f38d8 name=2024-03-05T13:02:57.938Z engines=[{"name":"pegasus1.1","options":["visual","conversation"]},{"name":"marengo2.6","options":["visual","conversation","text_in_video"]}]
80
81
  ```
81
82
 
82
83
  Note that the API returns, among other information, a field named `id`, representing the unique identifier of your new index.
83
84
 
84
85
  For a description of each field in the request and response, see the [Create an index](https://docs.twelvelabs.io/v1.2/reference/create-index) page.
85
86
 
86
-
87
87
  ## Upload videos
88
88
 
89
89
  Before you upload a video to the platform, ensure that it meets the following requirements:
90
90
 
91
- - **Video resolution**: Must be greater or equal than 360p and less or equal than 4K. For consistent search results, Twelve Labs recommends you upload 360p videos.
92
- - **Video and audio formats**: The video files you wish to upload must be encoded in the video and audio formats listed on the [FFmpeg Formats Documentation](https://ffmpeg.org/ffmpeg-formats.html) page. For videos in other formats, contact us at [support@twelvelabs.io](mailto:support@twelvelabs.io).
93
- - **Duration**: For Marengo, it must be between 4 seconds and 2 hours (7,200s). For Pegasus, it must be between 4 seconds and 20 minutes (1200s).
91
+ - **Video resolution**: Must be greater or equal than 360p and less or equal than 4K.
92
+ - **Video and audio formats**: The video files you wish to upload must be encoded in the video and audio formats listed on the [FFmpeg Formats Documentation](https://ffmpeg.org/ffmpeg-formats.html) page. For videos in other formats, contact us at [support@twelvelabs.io](mailto:support@twelvelabs.io).
93
+ - **Duration**: For Marengo, it must be between 4 seconds and 2 hours (7,200s). For Pegasus, it must be between 4 seconds and 30 minutes (1,800s).
94
94
  - **File size**: Must not exceed 2 GB. If you require different options, send us an email at support@twelvelabs.io.
95
95
  - **Audio track**: If the `conversation` [engine option](https://docs.twelvelabs.io/v1.2/docs/engine-options) is selected, the video you're uploading must contain an audio track.
96
96
 
@@ -99,7 +99,6 @@ To upload videos, use the example code below, replacing the following:
99
99
  - **`<YOUR_VIDEO_PATH>`**: with a string representing the path to the directory containing the video files you wish to upload.
100
100
  - **`<YOUR_INDEX_ID>`**: with a string representing the unique identifier of the index to which you want to upload your video.
101
101
 
102
-
103
102
  ```js
104
103
  const files = await fsPromises.readdir('YOUR_VIDEO_PATH');
105
104
  for (const file of files) {
@@ -130,7 +129,14 @@ The sections below show how you can perform the most common downstream tasks. Se
130
129
 
131
130
  ### Search
132
131
 
133
- To perform a search request, use the example code below, replacing the following:
132
+ To search for relevant video content, you can use either text or images as queries:
133
+
134
+ - **Text queries**: Use natural language to find video segments matching specific keywords or phrases.
135
+ - **Image queries**: Use images to find video segments that are semantically similar to the provided images.
136
+
137
+ **Search using text queries**
138
+
139
+ To perform search requests using text queries, use the example code below, replacing the following:
134
140
 
135
141
  - **`<YOUR_INDEX_ID>`**: with a string representing the unique identifier of your index.
136
142
  - **`<YOUR_QUERY>`**: with a string representing your search query. Note that the API supports full natural language-based search. The following examples are valid queries: "birds flying near a castle," "sun shining on water," and "an officer holding a child's hand."
@@ -159,7 +165,7 @@ function printPage(searchData) {
159
165
  }
160
166
  ```
161
167
 
162
- The results are returned one page at a time, with a default limit of 10 results on each page. The `next ` method returns the next page of results. When you've reached the end of the dataset, the response is `null`.
168
+ The results are returned one page at a time, with a default limit of 10 results on each page. The `next` method returns the next page of results. When you've reached the end of the dataset, the response is `null`.
163
169
 
164
170
  ```
165
171
  video_id=65ca2bce48db9fa780cb3fa4 score=84.9 start=104.9375 end=111.90625 confidence=high
@@ -167,8 +173,8 @@ The results are returned one page at a time, with a default limit of 10 results
167
173
  video_id=65ca2bce48db9fa780cb3fa4 score=84.77 start=55.375 end=72.46875 confidence=high
168
174
  ```
169
175
 
170
-
171
176
  Note that the response contains, among other information, the following fields:
177
+
172
178
  - `videoId`: The unique identifier of the video that matched your search terms.
173
179
  - `score`: A quantitative value determined by the AI engine representing the level of confidence that the results match your search terms.
174
180
  - `start`: The start time of the matching video clip, expressed in seconds.
@@ -179,17 +185,38 @@ Note that the response contains, among other information, the following fields:
179
185
  - `low`
180
186
  - `extremely low`
181
187
 
182
-
183
188
  For a description of each field in the request and response, see the [Make a search request](https://docs.twelvelabs.io/v1.2/reference/make-search-request) page.
184
189
 
190
+ **Search using image queries**
191
+
192
+ You can provide images as local files or publicly accessible URLs. Use the `queryMediaFile` parameter for local image files and the `queryMediaUrl` parameter for publicly accessible URLs.
193
+
194
+ To perform a search request using image queries, use the example code below, replacing the following:
195
+
196
+ - **`<YOUR_INDEX_ID>`**: with a string representing the unique identifier of your index.
197
+ - **`<YOUR_FILE_PATH>`**: with a string representing the path of the image file you wish to provide.
198
+ - **`[<YOUR_SEARCH_OPTIONS>]`**: with an array of strings that specifies the sources of information the platform uses when performing a search. For example, to search based on visual cues, use `["visual"]`. Note that the search options you specify must be a subset of the engine options used when you created the index. For more details, see the [Search options](https://docs.twelvelabs.io/docs/search-options) page.
199
+
200
+ ```js
201
+ let searchResults = await client.search.query({
202
+ indexId: '<YOUR_INDEX_ID>',
203
+ queryMediaType: 'image',
204
+ queryMediaFile: '<YOUR_FILE_PATH>', // Use queryMediaUrl instead to provide a file from a publicly accessible URL.
205
+ options: ['visual'],
206
+ });
207
+ ```
208
+
209
+ The response is similar to that received when using text queries.
210
+
185
211
  ### Generate text from video
186
212
 
187
213
  The Twelve Labs Video Understanding Platform offers three distinct endpoints tailored to meet various requirements. Each endpoint has been designed with specific levels of flexibility and customization to accommodate different needs.
188
214
 
189
215
  Note the following about using these endpoints:
216
+
190
217
  - The Pegasus video understanding engine must be enabled for the index to which your video has been uploaded.
191
- - Your prompts must be instructive or descriptive, and you should not phrase them as questions.
192
- - The maximum length of a prompt is 300 characters.
218
+ - Your prompts must be instructive or descriptive, and you can also phrase them as questions.
219
+ - The maximum length of a prompt is 1500 characters.
193
220
 
194
221
  #### Topics, titles, and hashtags
195
222
 
@@ -198,7 +225,7 @@ To generate topics, titles, and hashtags, use the example code below, replacing
198
225
  - **`<YOUR_VIDEO_ID>`**: with a string representing the unique identifier of your video.
199
226
  - **`[<TYPES>]`**: with an array of strings representing the type of text the platform should generate. Example: `["title", "topic", "hashtag"]`.
200
227
 
201
- ```py
228
+ ```js
202
229
  const gist = await client.generate.gist('<YOUR_VIDEO_ID>', ['<TYPES>']);
203
230
  console.log(`Title: ${gist.title}\nTopics=${gist.topics}\nHashtags=${gist.hashtags}`);
204
231
  ```
@@ -211,8 +238,7 @@ To generate summaries, chapters, and highlights, use the example code below, rep
211
238
 
212
239
  - **`<YOUR_VIDEO_ID>`**: with a string representing the unique identifier of your video.
213
240
  - **`<TYPE>`**: with a string representing the type of text the platform should generate. This parameter can take one of the following values: "summary", "chapter", or "highlight".
214
- - _(Optional)_ **`<YOUR_PROMPT>`**: with a string that provides context for the summarization task, such as the target audience, style, tone of voice, and purpose. Example: "Generate a summary in no more than 5 bullet points."
215
-
241
+ - _(Optional)_ **`<YOUR_PROMPT>`**: with a string that provides context for the summarization task, such as the target audience, style, tone of voice, and purpose. Example: "Generate a summary in no more than 5 bullet points."
216
242
 
217
243
  ```js
218
244
  const summary = await client.generate.summarize('<YOUR_VIDEO_ID>', '<TYPE>');
@@ -224,10 +250,11 @@ For a description of each field in the request and response, see the [Summaries,
224
250
  #### Open-ended texts
225
251
 
226
252
  To generate open-ended texts, use the example code below, replacing the following:
253
+
227
254
  - **`<YOUR_VIDEO_ID>`**: with a string representing the unique identifier of your video.
228
- - **`<YOUR_PROMPT>`**: with a string that guides the model on the desired format or content. The maximum length of the prompt is 500 tokens or roughly 350 words. Example: "I want to generate a description for my video with the following format: Title of the video, followed by a summary in 2-3 sentences, highlighting the main topic, key events, and concluding remarks."
255
+ - **`<YOUR_PROMPT>`**: with a string that guides the model on the desired format or content. The maximum length of the prompt is 1500 characters. Example: "I want to generate a description for my video with the following format: Title of the video, followed by a summary in 2-3 sentences, highlighting the main topic, key events, and concluding remarks."
229
256
 
230
- ```py
257
+ ```js
231
258
  const text = await client.generate.text('<YOUR_VIDEO_ID>', '<YOUR_PROMPT>');
232
259
  console.log(`Open-ended Text: ${text.data}`);
233
260
  ```
@@ -236,16 +263,16 @@ console.log(`Open-ended Text: ${text.data}`);
236
263
 
237
264
  The SDK includes a set of exceptions that are mapped to specific HTTP status codes, as shown in the table below:
238
265
 
239
- | Exception | HTTP Status Code |
240
- |----------|----------|
241
- | BadRequestError| 400 |
242
- | AuthenticationError | 401 |
243
- | PermissionDeniedError | 403 |
244
- | NotFoundError | 404 |
245
- | ConflictError | 409 |
246
- | UnprocessableEntityError | 422 |
247
- | RateLimitError | 429 |
248
- | InternalServerError | 5xx |
266
+ | Exception | HTTP Status Code |
267
+ | ------------------------ | ---------------- |
268
+ | BadRequestError | 400 |
269
+ | AuthenticationError | 401 |
270
+ | PermissionDeniedError | 403 |
271
+ | NotFoundError | 404 |
272
+ | ConflictError | 409 |
273
+ | UnprocessableEntityError | 422 |
274
+ | RateLimitError | 429 |
275
+ | InternalServerError | 5xx |
249
276
 
250
277
  The following example shows how you can handle specific HTTP errors in your application:
251
278
 
package/dist/core.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { RequestInit, Response } from 'node-fetch';
2
1
  export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
3
2
  export type RequestOptions = RequestInit & {
4
3
  params?: Record<string, any>;
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["src/core.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAM1D,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GA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QAAQ,GAAG,OAAO,CAAC;AACrE,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEtG,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,SAAS;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;gBAEH,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,gBAAgB;YAKnC,QAAQ;IAmEhB,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAE,cAAmB;IAIpF,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,GAAE,cAAmB;IAInE,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,GAAE,cAAmB;IAIpE,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,GAAE,cAAmB;IAIlE,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;CAGhE;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CA4BzF"}
package/dist/core.js CHANGED
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.handleResponse = exports.APIClient = void 0;
30
- const node_fetch_1 = __importDefault(require("node-fetch"));
30
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
31
31
  const form_data_1 = __importDefault(require("form-data"));
32
32
  const constants_1 = require("./constants.js");
33
33
  const Errors = __importStar(require("./error.js"));
@@ -54,6 +54,7 @@ class APIClient {
54
54
  };
55
55
  }
56
56
  const config = {
57
+ ...options,
57
58
  method,
58
59
  headers,
59
60
  body: body ?
@@ -61,13 +62,16 @@ class APIClient {
61
62
  body
62
63
  : JSON.stringify(body)
63
64
  : undefined,
64
- ...options,
65
65
  };
66
66
  try {
67
- const response = await (0, node_fetch_1.default)(url, config);
67
+ const response = await (0, cross_fetch_1.default)(url, config);
68
68
  const contentType = response.headers.get('Content-Type');
69
+ const transferEncoding = response.headers.get('Transfer-Encoding');
69
70
  let body = null;
70
- if (contentType && contentType.includes('application/json')) {
71
+ if (transferEncoding === 'chunked') {
72
+ body = response.body;
73
+ }
74
+ else if (contentType && contentType.includes('application/json')) {
71
75
  const rawBody = await response.json();
72
76
  body = (0, util_1.convertKeysToCamelCase)(rawBody, skipCamelKeys);
73
77
  }
@@ -78,13 +82,11 @@ class APIClient {
78
82
  return body;
79
83
  }
80
84
  catch (error) {
81
- if (error instanceof node_fetch_1.default.FetchError) {
82
- if (error.code === 'ENOTFOUND') {
83
- throw new Errors.APIConnectionError('API Connection Error', error);
84
- }
85
- else if (error.type === 'request-timeout') {
86
- throw new Errors.APITimeoutError('API Timeout Error', error);
87
- }
85
+ if (error.code === 'ENOTFOUND') {
86
+ throw new Errors.APIConnectionError('API Connection Error', error);
87
+ }
88
+ if (error.type === 'request-timeout') {
89
+ throw new Errors.APITimeoutError('API Timeout Error', error);
88
90
  }
89
91
  if (error instanceof Error) {
90
92
  throw error;
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA0D;AAC1D,0DAAi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G;oBACN,MAAM,IAAI,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;gBACnF,KAAK,GAAG;oBACN,MAAM,IAAI,MAAM,CAAC,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC1F;oBACE,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;aAC/E;SACF;aAAM,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE;YACjC,MAAM,IAAI,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;SACxF;QACD,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;KAC7E;AACH,CAAC;AA5BD,wCA4BC"}
package/dist/core.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import fetch from 'node-fetch';
1
+ import fetch from 'cross-fetch';
2
2
  import FormData from 'form-data';
3
3
  import { API_KEY_HEADER } from "./constants.mjs";
4
4
  import * as Errors from "./error.mjs";
@@ -25,6 +25,7 @@ export class APIClient {
25
25
  };
26
26
  }
27
27
  const config = {
28
+ ...options,
28
29
  method,
29
30
  headers,
30
31
  body: body ?
@@ -32,13 +33,16 @@ export class APIClient {
32
33
  body
33
34
  : JSON.stringify(body)
34
35
  : undefined,
35
- ...options,
36
36
  };
37
37
  try {
38
38
  const response = await fetch(url, config);
39
39
  const contentType = response.headers.get('Content-Type');
40
+ const transferEncoding = response.headers.get('Transfer-Encoding');
40
41
  let body = null;
41
- if (contentType && contentType.includes('application/json')) {
42
+ if (transferEncoding === 'chunked') {
43
+ body = response.body;
44
+ }
45
+ else if (contentType && contentType.includes('application/json')) {
42
46
  const rawBody = await response.json();
43
47
  body = convertKeysToCamelCase(rawBody, skipCamelKeys);
44
48
  }
@@ -49,13 +53,11 @@ export class APIClient {
49
53
  return body;
50
54
  }
51
55
  catch (error) {
52
- if (error instanceof fetch.FetchError) {
53
- if (error.code === 'ENOTFOUND') {
54
- throw new Errors.APIConnectionError('API Connection Error', error);
55
- }
56
- else if (error.type === 'request-timeout') {
57
- throw new Errors.APITimeoutError('API Timeout Error', error);
58
- }
56
+ if (error.code === 'ENOTFOUND') {
57
+ throw new Errors.APIConnectionError('API Connection Error', error);
58
+ }
59
+ if (error.type === 'request-timeout') {
60
+ throw new Errors.APITimeoutError('API Timeout Error', error);
59
61
  }
60
62
  if (error instanceof Error) {
61
63
  throw error;