The Resources.Generate class provides methods to generate various types of text content from videos.
Titles, topics, and hashtags
Description: This method generates titles, topics, and hashtags for a specific video. It uses predefined formats and doesn't require a custom prompt, and it's best for generating immediate and straightforward text representations without specific customization.
Function signature and example:
async gist(
videoId: string,
types: GenerateGistType[],
options: RequestOptions = {},
): Promise<Models.GenerateGistResult> const result = await client.generate.gist(
"<YOUR_VIDEO_ID>",
["title", "topic", "hashtag"]
);
console.log("Result ID:", result.id);
if (result.title !== undefined) {
console.log("Title:", result.title);
}
if (result.topics !== undefined) {
console.log("Topics:");
result.topics.forEach(topic => {
console.log(` - ${topic}`);
});
}
if (result.hashtags !== undefined) {
console.log("Hashtags:");
result.hashtags.forEach(hashtag => {
console.log(` - ${hashtag}`);
});
}Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
videoId | string | Yes | The unique identifier of the video for which you want to generate text. |
types | GenerateGistType[] | Yes | The types of text you want to generate. Available values: topics, titles, hashtags. |
options | RequestOptions | No | Additional options for the request. Defaults to {}. |
Return value: Returns a Promise that resolves to a Models.GenerateGistResult instance.
API Reference: For a description of each field in the request and response, see the Generate topics, titles, and hashtags page.
Related guide: Titles, topics, and hashtags.
Summaries, chapters, and highlights
Description: This method generates summaries, chapters, or highlights for your videos. Optionally, you can provide a prompt to customize the output.
Function signature and example:
async summarize(
videoId: string,
type: GenerateSummarizeType,
prompt?: string,
temperature?: number,
options: RequestOptions = {},
): Promise<Models.GenerateSummarizeResult>const result = await client.generate.summarize(
"<YOUR_VIDEO_ID>",
"summary",
"<YOUR_PROMPT>",
0.7
)
console.log(`Result ID: ${result.id}`);
if (result.summary !== undefined) {
console.log(`Summary: ${result.summary}`);
}
if (result.chapters !== undefined && result.chapters.length > 0) {
console.log("Chapters:");
result.chapters.forEach(chapter => {
console.log(` Chapter ${chapter.chapterNumber}:`);
console.log(` Start: ${chapter.start}`);
console.log(` End: ${chapter.end}`);
console.log(` Title: ${chapter.chapterTitle}`);
console.log(` Summary: ${chapter.chapterSummary}`);
});
}
if (result.highlights !== undefined && result.highlights.length > 0) {
console.log("Highlights:");
result.highlights.forEach(highlight => {
console.log(` Start: ${highlight.start}`);
console.log(` End: ${highlight.end}`);
console.log(` Highlight: ${highlight.highlight}`);
});
}Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
videoId | string | Yes | The unique identifier of the video for which you want to generate text. |
type | string | Yes | The type of text you want to generate. Available values: summaries, chapters, highlights. |
prompt | string | No | The prompt to customize the output. |
temperature | number | No | The temperature to use in the generation. |
options | RequestOptions | No | Additional options for the request. Defaults to {}. |
Return value: Returns a Promise that resolves to a Models.GenerateSummarizeResult instance.
API Reference: For a description of each field in the request and response, see the Generate summaries, chapters, and highlights page.
Related guide: Summaries, chapters, and highlights.
Open-ended text
Description: This method generates open-ended texts based on your videos.
Function signature and example:
async text(
videoId: string,
prompt: string,
temperature?: number,
options: RequestOptions = {},
): Promise<Models.GenerateOpenEndedTextResult>const result = await client.generate.text(
"<YOUR_VIDEO_ID>",
"Be concise"
0.7,
);
console.log(`Result ID: ${result.id}`);
console.log(`Generated text: ${result.data}`);Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
videoId | string | Yes | The unique identifier of the video for which you want to generate text. |
prompt | string | Yes | The prompt to customize the output. |
temperature | number | No | The temperature to use in the generation. |
options | RequestOptions | No | Additional options for the request. Defaults to {}. |
Return value: Returns a Promise that resolves to a Models.GenerateOpenEndedTextResult instance.
API Reference: For a description of each field in the request and response, see the Open-ended text page.
Related guide: Open-ended text .
Open-ended text with streaming responses
Description: This method generates open-ended texts and supports streaming responses.
Function signature and example:
async textStream(
{ videoId, prompt, temperature }: GenerateTextStreamParams,
options: RequestOptions = {},
): Promise<Models.GenerateTextStreamResult> const textStream = await client.generate.textStream({
videoId: "<YOUR_VIDEO_ID>",
prompt: '<YOUR_PROMPT>',
temperature: 0.7
});
for await (const text of textStream) {
console.log(text);
}
console.log(`Aggregated text: ${textStream.aggregatedText}`);
})();Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
params | GenerateTextStreamParams | Yes | Parameters for generating open-ended text. |
options | RequestOptions | No | Additional options for the request. Defaults to {}. |
The GenerateTextStreamParams interface defines the parameters for streaming text generated based on video content:
| Name | Type | Required | Description |
|---|---|---|---|
videoId | string | Yes | The unique identifier of the video for which you want to generate text. |
prompt | string | Yes | The prompt to customize the output. |
temperature | number | No | The temperature to use in the generation. |
API Reference: For a description of each field in the request and response, see the Open-ended text page.
Related guide: Streaming responses.