twelvelabs-js 0.1.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/LICENSE +183 -0
- package/README.md +278 -0
- package/dist/README.md +278 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +4 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core.d.ts +23 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +145 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +114 -0
- package/dist/core.mjs.map +1 -0
- package/dist/error.d.ts +34 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +55 -0
- package/dist/error.js.map +1 -0
- package/dist/error.mjs +40 -0
- package/dist/error.mjs.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +23 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interfaces.d.ts +7 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/interfaces.js +3 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/interfaces.mjs +2 -0
- package/dist/interfaces.mjs.map +1 -0
- package/dist/models/engine/index.d.ts +16 -0
- package/dist/models/engine/index.d.ts.map +1 -0
- package/dist/models/engine/index.js +14 -0
- package/dist/models/engine/index.js.map +1 -0
- package/dist/models/engine/index.mjs +10 -0
- package/dist/models/engine/index.mjs.map +1 -0
- package/dist/models/generate/index.d.ts +29 -0
- package/dist/models/generate/index.d.ts.map +1 -0
- package/dist/models/generate/index.js +3 -0
- package/dist/models/generate/index.js.map +1 -0
- package/dist/models/generate/index.mjs +2 -0
- package/dist/models/generate/index.mjs.map +1 -0
- package/dist/models/index/index.d.ts +57 -0
- package/dist/models/index/index.d.ts.map +1 -0
- package/dist/models/index/index.js +72 -0
- package/dist/models/index/index.js.map +1 -0
- package/dist/models/index/index.mjs +67 -0
- package/dist/models/index/index.mjs.map +1 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +24 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/index.mjs +8 -0
- package/dist/models/index.mjs.map +1 -0
- package/dist/models/interfaces.d.ts +7 -0
- package/dist/models/interfaces.d.ts.map +1 -0
- package/dist/models/interfaces.js +3 -0
- package/dist/models/interfaces.js.map +1 -0
- package/dist/models/interfaces.mjs +2 -0
- package/dist/models/interfaces.mjs.map +1 -0
- package/dist/models/search/index.d.ts +47 -0
- package/dist/models/search/index.d.ts.map +1 -0
- package/dist/models/search/index.js +22 -0
- package/dist/models/search/index.js.map +1 -0
- package/dist/models/search/index.mjs +18 -0
- package/dist/models/search/index.mjs.map +1 -0
- package/dist/models/task/index.d.ts +59 -0
- package/dist/models/task/index.d.ts.map +1 -0
- package/dist/models/task/index.js +67 -0
- package/dist/models/task/index.js.map +1 -0
- package/dist/models/task/index.mjs +62 -0
- package/dist/models/task/index.mjs.map +1 -0
- package/dist/models/video/index.d.ts +52 -0
- package/dist/models/video/index.d.ts.map +1 -0
- package/dist/models/video/index.js +64 -0
- package/dist/models/video/index.js.map +1 -0
- package/dist/models/video/index.mjs +59 -0
- package/dist/models/video/index.mjs.map +1 -0
- package/dist/package.json +37 -0
- package/dist/resource.d.ts +12 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +17 -0
- package/dist/resource.js.map +1 -0
- package/dist/resource.mjs +13 -0
- package/dist/resource.mjs.map +1 -0
- package/dist/resources/engine/index.d.ts +8 -0
- package/dist/resources/engine/index.d.ts.map +1 -0
- package/dist/resources/engine/index.js +42 -0
- package/dist/resources/engine/index.js.map +1 -0
- package/dist/resources/engine/index.mjs +15 -0
- package/dist/resources/engine/index.mjs.map +1 -0
- package/dist/resources/generate/index.d.ts +10 -0
- package/dist/resources/generate/index.d.ts.map +1 -0
- package/dist/resources/generate/index.js +36 -0
- package/dist/resources/generate/index.js.map +1 -0
- package/dist/resources/generate/index.mjs +32 -0
- package/dist/resources/generate/index.mjs.map +1 -0
- package/dist/resources/generate/interfaces.d.ts +3 -0
- package/dist/resources/generate/interfaces.d.ts.map +1 -0
- package/dist/resources/generate/interfaces.js +3 -0
- package/dist/resources/generate/interfaces.js.map +1 -0
- package/dist/resources/generate/interfaces.mjs +2 -0
- package/dist/resources/generate/interfaces.mjs.map +1 -0
- package/dist/resources/index/index.d.ts +17 -0
- package/dist/resources/index/index.d.ts.map +1 -0
- package/dist/resources/index/index.js +82 -0
- package/dist/resources/index/index.js.map +1 -0
- package/dist/resources/index/index.mjs +55 -0
- package/dist/resources/index/index.mjs.map +1 -0
- package/dist/resources/index/interfaces.d.ts +18 -0
- package/dist/resources/index/interfaces.d.ts.map +1 -0
- package/dist/resources/index/interfaces.js +3 -0
- package/dist/resources/index/interfaces.js.map +1 -0
- package/dist/resources/index/interfaces.mjs +2 -0
- package/dist/resources/index/interfaces.mjs.map +1 -0
- package/dist/resources/index.d.ts +12 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +28 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/index.mjs +12 -0
- package/dist/resources/index.mjs.map +1 -0
- package/dist/resources/search/index.d.ts +9 -0
- package/dist/resources/search/index.d.ts.map +1 -0
- package/dist/resources/search/index.js +45 -0
- package/dist/resources/search/index.js.map +1 -0
- package/dist/resources/search/index.mjs +18 -0
- package/dist/resources/search/index.mjs.map +1 -0
- package/dist/resources/search/interfaces.d.ts +13 -0
- package/dist/resources/search/interfaces.d.ts.map +1 -0
- package/dist/resources/search/interfaces.js +3 -0
- package/dist/resources/search/interfaces.js.map +1 -0
- package/dist/resources/search/interfaces.mjs +2 -0
- package/dist/resources/search/interfaces.mjs.map +1 -0
- package/dist/resources/task/index.d.ts +23 -0
- package/dist/resources/task/index.d.ts.map +1 -0
- package/dist/resources/task/index.js +147 -0
- package/dist/resources/task/index.js.map +1 -0
- package/dist/resources/task/index.mjs +117 -0
- package/dist/resources/task/index.mjs.map +1 -0
- package/dist/resources/task/interfaces.d.ts +24 -0
- package/dist/resources/task/interfaces.d.ts.map +1 -0
- package/dist/resources/task/interfaces.js +3 -0
- package/dist/resources/task/interfaces.js.map +1 -0
- package/dist/resources/task/interfaces.mjs +2 -0
- package/dist/resources/task/interfaces.mjs.map +1 -0
- package/dist/resources/video/index.d.ts +16 -0
- package/dist/resources/video/index.d.ts.map +1 -0
- package/dist/resources/video/index.js +92 -0
- package/dist/resources/video/index.js.map +1 -0
- package/dist/resources/video/index.mjs +65 -0
- package/dist/resources/video/index.mjs.map +1 -0
- package/dist/resources/video/interfaces.d.ts +23 -0
- package/dist/resources/video/interfaces.d.ts.map +1 -0
- package/dist/resources/video/interfaces.js +3 -0
- package/dist/resources/video/interfaces.js.map +1 -0
- package/dist/resources/video/interfaces.mjs +2 -0
- package/dist/resources/video/interfaces.mjs.map +1 -0
- package/dist/src/constants.ts +3 -0
- package/dist/src/core.ts +138 -0
- package/dist/src/error.ts +40 -0
- package/dist/src/index.ts +86 -0
- package/dist/src/interfaces.ts +6 -0
- package/dist/src/models/engine/index.ts +23 -0
- package/dist/src/models/generate/index.ts +32 -0
- package/dist/src/models/index/index.ts +135 -0
- package/dist/src/models/index.ts +7 -0
- package/dist/src/models/interfaces.ts +6 -0
- package/dist/src/models/search/index.ts +66 -0
- package/dist/src/models/task/index.ts +132 -0
- package/dist/src/models/video/index.ts +135 -0
- package/dist/src/resource.ts +21 -0
- package/dist/src/resources/engine/index.ts +17 -0
- package/dist/src/resources/generate/index.ts +56 -0
- package/dist/src/resources/generate/interfaces.ts +2 -0
- package/dist/src/resources/index/index.ts +91 -0
- package/dist/src/resources/index/interfaces.ts +16 -0
- package/dist/src/resources/index.ts +12 -0
- package/dist/src/resources/search/index.ts +28 -0
- package/dist/src/resources/search/interfaces.ts +12 -0
- package/dist/src/resources/task/index.ts +161 -0
- package/dist/src/resources/task/interfaces.ts +23 -0
- package/dist/src/resources/video/index.ts +157 -0
- package/dist/src/resources/video/interfaces.ts +25 -0
- package/dist/src/util.ts +94 -0
- package/dist/util.d.ts +5 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +94 -0
- package/dist/util.js.map +1 -0
- package/dist/util.mjs +87 -0
- package/dist/util.mjs.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# TwelveLabs JavaScript SDK
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# Prerequisites
|
|
7
|
+
|
|
8
|
+
Ensure that the following prerequisites are met before using the SDK:
|
|
9
|
+
|
|
10
|
+
- [Node.js](https://nodejs.org/) 14 or newer must be installed on your machine.
|
|
11
|
+
- 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.
|
|
12
|
+
|
|
13
|
+
# Install the SDK
|
|
14
|
+
|
|
15
|
+
Install the `twelvelabs-js` package:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
yarn add twelvelabs-js # or npm i twelvelabs-js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
# Initialize the SDK
|
|
22
|
+
|
|
23
|
+
1. Import the required packages into your application:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { TwelveLabs, SearchData, Task } from 'twelvelabs-js';
|
|
27
|
+
import { promises as fsPromises } from 'fs';
|
|
28
|
+
import * as path from 'path';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
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`:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>' });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
# Use the SDK
|
|
38
|
+
|
|
39
|
+
To get started with the SDK, follow these basic steps:
|
|
40
|
+
|
|
41
|
+
1. Create an index.
|
|
42
|
+
2. Upload videos.
|
|
43
|
+
3. Perform downstream tasks, such as searching or generating text from video.
|
|
44
|
+
|
|
45
|
+
## Create an index
|
|
46
|
+
|
|
47
|
+
To create an index, use the example code below, replacing '<YOUR_INDEX_NAME>' with the desired name for your index:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
let index = await client.index.create({
|
|
51
|
+
name: '<YOUR_INDEX_NAME>',
|
|
52
|
+
engines: [
|
|
53
|
+
{
|
|
54
|
+
name: 'marengo2.6',
|
|
55
|
+
options: ['visual', 'conversation', 'text_in_video'],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'pegasus1',
|
|
59
|
+
options: ['visual', 'conversation'],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
console.log(`Created index: id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)}`);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Note the following about this example:
|
|
68
|
+
- The platform provides two distinct engine types - embedding and generative, each serving unique purposes in multimodal video understanding.
|
|
69
|
+
- **Embedding engines (Marengo)**: These engines are proficient at performing tasks such as search and classification, enabling enhanced video understanding.
|
|
70
|
+
- **Generative engines (Pegasus)**: These engines generate text based on your videos.
|
|
71
|
+
For your index, both Marengo and Pegasus are enabled.
|
|
72
|
+
- 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.
|
|
73
|
+
- 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.
|
|
74
|
+
|
|
75
|
+
The output should look similar to the following:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
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"]}]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Note that the API returns, among other information, a field named `id`, representing the unique identifier of your new index.
|
|
82
|
+
|
|
83
|
+
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.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## Upload videos
|
|
87
|
+
|
|
88
|
+
Before you upload a video to the platform, ensure that it meets the following requirements:
|
|
89
|
+
|
|
90
|
+
- **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.
|
|
91
|
+
- **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).
|
|
92
|
+
- **File size**: Must not exceed 2 GB. If you require different options, send us an email at support@twelvelabs.io.
|
|
93
|
+
- **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.
|
|
94
|
+
|
|
95
|
+
To upload videos, use the example code below, replacing the following:
|
|
96
|
+
|
|
97
|
+
- **`<YOUR_VIDEO_PATH>`**: with a string representing the path to the directory containing the video files you wish to upload.
|
|
98
|
+
- **`<YOUR_INDEX_ID>`**: with a string representing the unique identifier of the index to which you want to upload your video.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
const files = await fsPromises.readdir('YOUR_VIDEO_PATH');
|
|
103
|
+
for (const file of files) {
|
|
104
|
+
const filePath = path.join(__dirname, file);
|
|
105
|
+
console.log(`Uploading ${filePath}`);
|
|
106
|
+
const task = await client.task.create({
|
|
107
|
+
indexId: '<YOUR_INDEX_ID>'
|
|
108
|
+
file: filePath,
|
|
109
|
+
});
|
|
110
|
+
console.log(`Created task: id=${task.id}`);
|
|
111
|
+
await task.waitForDone(50, (task: Task) => {
|
|
112
|
+
console.log(` Status=${task.status}`);
|
|
113
|
+
});
|
|
114
|
+
if (task.status !== 'ready') {
|
|
115
|
+
throw new Error(`Indexing failed with status ${task.status}`);
|
|
116
|
+
}
|
|
117
|
+
console.log(`Uploaded ${videoPath}. The unique identifer of your video is ${task.videoId}`);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Note that once a video has been successfully uploaded and indexed, the response will contain a field named `videoId`, representing the unique identifier of your video.
|
|
122
|
+
|
|
123
|
+
For a description of each field in the request and response, see the [Create a video indexing task](https://docs.twelvelabs.io/reference/create-video-indexing-task) page.
|
|
124
|
+
|
|
125
|
+
## Perform downstream tasks
|
|
126
|
+
|
|
127
|
+
The sections below show how you can perform the most common downstream tasks. See [our documentation](https://docs.twelvelabs.io/docs) for a complete list of all the features the Twelve Labs Understanding Platform provides.
|
|
128
|
+
|
|
129
|
+
### Search
|
|
130
|
+
|
|
131
|
+
To perform a search request, use the example code below, replacing the following:
|
|
132
|
+
|
|
133
|
+
- **`<YOUR_INDEX_ID>`**: with a string representing the unique identifier of your index.
|
|
134
|
+
- **`<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."
|
|
135
|
+
- **`[<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 and conversation cues, use `["visual", "conversation"]`. 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.
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
let searchResults = await client.search.query({
|
|
139
|
+
indexId: '<YOUR_INDEX_ID>'
|
|
140
|
+
query: '<YOUR_QUERY>',
|
|
141
|
+
options: ['<YOUR_SEARCH_OPTIONS>'],
|
|
142
|
+
});
|
|
143
|
+
printPage(searchResults.data);
|
|
144
|
+
while (true) {
|
|
145
|
+
const page = await searchResults.next();
|
|
146
|
+
if (page === null) break;
|
|
147
|
+
else printPage(page);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Utility function to print a specific page
|
|
151
|
+
function printPage(searchData) {
|
|
152
|
+
(searchData as SearchData[]).forEach((clip) => {
|
|
153
|
+
console.log(
|
|
154
|
+
`video_id= ${clip.videoId} score=${clip.score} start=${clip.start} end=${clip.end} confidence=${clip.confidence}`,
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
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`.
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
video_id=65ca2bce48db9fa780cb3fa4 score=84.9 start=104.9375 end=111.90625 confidence=high
|
|
164
|
+
video_id=65ca2bce48db9fa780cb3fa4 score=84.82 start=160.46875 end=172.75 confidence=high
|
|
165
|
+
video_id=65ca2bce48db9fa780cb3fa4 score=84.77 start=55.375 end=72.46875 confidence=high
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
Note that the response contains, among other information, the following fields:
|
|
170
|
+
- `videoId`: The unique identifier of the video that matched your search terms.
|
|
171
|
+
- `score`: A quantitative value determined by the AI engine representing the level of confidence that the results match your search terms.
|
|
172
|
+
- `start`: The start time of the matching video clip, expressed in seconds.
|
|
173
|
+
- `end`: The end time of the matching video clip, expressed in seconds.
|
|
174
|
+
- `confidence`: A qualitative indicator based on the value of the score field. This field can take one of the following values:
|
|
175
|
+
- `high`
|
|
176
|
+
- `medium`
|
|
177
|
+
- `low`
|
|
178
|
+
- `extremely low`
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
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.
|
|
182
|
+
|
|
183
|
+
### Generate text from video
|
|
184
|
+
|
|
185
|
+
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.
|
|
186
|
+
|
|
187
|
+
Note the following about using these endpoints:
|
|
188
|
+
- The Pegasus video understanding engine must be enabled for the index to which your video has been uploaded.
|
|
189
|
+
- Your prompts must be instructive or descriptive, and you should not phrase them as questions.
|
|
190
|
+
- The maximum length of a prompt is 300 characters.
|
|
191
|
+
|
|
192
|
+
#### Topics, titles, and hashtags
|
|
193
|
+
|
|
194
|
+
To generate topics, titles, and hashtags, use the example code below, replacing the following:
|
|
195
|
+
|
|
196
|
+
- **`<YOUR_VIDEO_ID>`**: with a string representing the unique identifier of your video.
|
|
197
|
+
- **`[<TYPES>]`**: with an array of strings representing the type of text the platform should generate. Example: `["title", "topic", "hashtag"]`.
|
|
198
|
+
|
|
199
|
+
```py
|
|
200
|
+
const gist = await client.generate.gist('<YOUR_VIDEO_ID>', ['<TYPES>']);
|
|
201
|
+
console.log(`Title: ${gist.title}\nTopics=${gist.topics}\nHashtags=${gist.hashtags}`);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
For a description of each field in the request and response, see the [Titles, topics, or hashtags](https://docs.twelvelabs.io/v1.2/reference/generate-gist) page.
|
|
205
|
+
|
|
206
|
+
#### Summaries, chapters, and highlights
|
|
207
|
+
|
|
208
|
+
To generate summaries, chapters, and highlights, use the example code below, replacing the following:
|
|
209
|
+
|
|
210
|
+
- **`<YOUR_VIDEO_ID>`**: with a string representing the unique identifier of your video.
|
|
211
|
+
- **`<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".
|
|
212
|
+
- _(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."
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
```js
|
|
216
|
+
const summary = await client.generate.summarize('<YOUR_VIDEO_ID>', '<TYPE>');
|
|
217
|
+
console.log(`Summary: ${summary.summary}`);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
For a description of each field in the request and response, see the [Summaries, chapters, or highlights](https://docs.twelvelabs.io/v1.2/docs/generate-summaries-chapters-highlights) page.
|
|
221
|
+
|
|
222
|
+
#### Open-ended texts
|
|
223
|
+
|
|
224
|
+
To generate open-ended texts, use the example code below, replacing the following:
|
|
225
|
+
- **`<YOUR_VIDEO_ID>`**: with a string representing the unique identifier of your video.
|
|
226
|
+
- **`<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."
|
|
227
|
+
|
|
228
|
+
```py
|
|
229
|
+
const text = await client.generate.text('<YOUR_VIDEO_ID>', '<YOUR_PROMPT>');
|
|
230
|
+
console.log(`Open-ended Text: ${text.data}`);
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Error Handling
|
|
234
|
+
|
|
235
|
+
The SDK includes a set of exceptions that are mapped to specific HTTP status codes, as shown in the table below:
|
|
236
|
+
|
|
237
|
+
| Exception | HTTP Status Code |
|
|
238
|
+
|----------|----------|
|
|
239
|
+
| BadRequestError| 400 |
|
|
240
|
+
| AuthenticationError | 401 |
|
|
241
|
+
| PermissionDeniedError | 403 |
|
|
242
|
+
| NotFoundError | 404 |
|
|
243
|
+
| ConflictError | 409 |
|
|
244
|
+
| UnprocessableEntityError | 422 |
|
|
245
|
+
| RateLimitError | 429 |
|
|
246
|
+
| InternalServerError | 5xx |
|
|
247
|
+
|
|
248
|
+
The following example shows how you can handle specific HTTP errors in your application:
|
|
249
|
+
|
|
250
|
+
```js
|
|
251
|
+
try {
|
|
252
|
+
let index = await client.index.create({
|
|
253
|
+
name: '<YOUR_INDEX_NAME>',
|
|
254
|
+
engines: [
|
|
255
|
+
{
|
|
256
|
+
name: 'marengo2.6',
|
|
257
|
+
options: ['visual', 'conversation'],
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
});
|
|
261
|
+
console.log(`Created index: id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)}`);
|
|
262
|
+
} catch (e) {
|
|
263
|
+
console.log(e);
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
# License
|
|
268
|
+
|
|
269
|
+
We use the Developer Certificate of Origin (DCO) in lieu of a Contributor License Agreement for all contributions to Twelve Labs' open-source projects. We request that contributors agree to the terms of the DCO and indicate that agreement by signing all commits made to Twelve Labs' projects by adding a line with your name and email address to every Git commit message contributed, as shown in the example below:
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
Signed-off-by: Jane Doe <jane.doe@example.com>
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
You can sign your commit automatically with Git by using `git commit -s` if you have your `user.name` and `user.email` set as part of your Git configuration.
|
|
276
|
+
We ask that you use your real name (please, no anonymous contributions or pseudonyms). By signing your commitment, you are certifying that you have the right have the right to submit it under the open-source license used by that particular project. You must use your real name (no pseudonyms or anonymous contributions are allowed.)
|
|
277
|
+
We use the Probot DCO GitHub app to check for DCO signoffs of every commit.
|
|
278
|
+
If you forget to sign your commits, the DCO bot will remind you and give you detailed instructions for how to amend your commits to add a signature.
|