The resources.Generate class provides methods to generate various types of text content from videos.

Related quickstart notebook: Open In Colab.

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:

def gist(
    self,
    video_id: str,
    types: List[Union[str, Literal["topic", "hashtag", "title"]]],
    **kwargs
) -> models.GenerateGistResult

result = client.generate.gist(
    video_id="<YOUR_VIDEO_ID",
    types=["title", "topic", "hashtag"]
)

print("Result ID:", result.id)

if result.title is not None:
    print("Title:", result.title)

if result.topics is not None:
    print("Topics:")
    for topic in result.topics:
        print(f"  - {topic}")

if result.hashtags is not None:
    print("Hashtags:")
    for hashtag in result.hashtags:
        print(f"  - {hashtag}")

Parameters:

NameTypeRequiredDescription
video_idstrYesThe unique identifier of the video for which you want to generate text.
typesList[Union[str, Literal["topic", "hashtag", "title"]]]YesThe types of text you want to generate. Available values: topics, titles, hashtags.
**kwargsdictNoAdditional keyword arguments for the request.

Return value: Returns a models.GenerateGistResult object containing the generated gist elements.

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:

def summarize(
    self,
    video_id: str,
    type: Union[str, Literal["summary", "chapter", "highlight"]],
    *,
    prompt: Optional[str] = None,
    temperature: Optional[float] = None,
    **kwargs
) -> models.GenerateSummarizeResult
result = client.generate.summarize(
    video_id="<YOUR_VIDEO_ID>",
    prompt="<YOUR_PROMPT>",
    temperature=0.7,
    type="summary"
)

print(f"Result ID: {result.id}")

if result.summary is not None:
    print(f"Summary: {result.summary}")

if result.chapters is not None:
    print("Chapters:")
    for chapter in result.chapters:
        print(f"  Chapter {chapter.chapter_number}:")
        print(f"    Start: {chapter.start}")
        print(f"    End: {chapter.end}")
        print(f"    Title: {chapter.chapter_title}")
        print(f"    Summary: {chapter.chapter_summary}")

if result.highlights is not None:
    print("Highlights:")
    for highlight in result.highlights:
        print(f"  Start: {highlight.start}")
        print(f"  End: {highlight.end}")
        print(f"  Highlight: {highlight.highlight}")

Parameters:

NameTypeRequiredDescription
video_idstringYesThe unique identifier of the video for which you want to generate text.
typeUnion[str, Literal["summary", "chapter", "highlight"]YesThe type of text you want to generate. Available values: summaries, chapters, highlights.
promptOptional[str]NoThe prompt to customize the output.
temperatureOptional[float]NoThe temperature to use in the generation.
**kwargsRequestOptionsNoAdditional keyword arguments for the request.

Return value: Returns a models.GenerateSummarizeResult object containing the generated content.

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:

def text(
    self,
    video_id: str,
    prompt: str,
    *,
    temperature: Optional[float] = None,
    **kwargs
) -> models.GenerateOpenEndedTextResult
result = client.generate.text(
  video_id="<YOUR_VIDEO_ID>",
  prompt="<YOUR_PROMPT>",
  temperature=0.7
)

print("Result ID:", result.id)
print(f"Generated Text: {result.data}")

Parameters:

NameTypeRequiredDescription
video_idstrYesThe unique identifier of the video for which you want to generate text.
promptstrYesThe prompt to customize the output.
temperatureOptional[float]NoThe temperature to use in the generation.
**kwargsdictNoAdditional keyword arguments for the request.

Return value: Returns a models.GenerateOpenEndedTextResult object containing the generated text.

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:

def text_stream(
    self,
    video_id: str,
    prompt: str,
    *,
    temperature: Optional[float] = None,
    **kwargs
) -> models.GenerateOpenEndedTextStreamResult
result = client.generate.text_stream(
    video_id="<YOUR_VIDEO_ID>",
    prompt="<YOUR_PROMPT>",
    temperature=0.7
)
for text in result:
    print(text)

print(f"Aggregated text: {result.aggregated_text}")

Parameters:

NameTypeRequiredDescription
video_idstrYesThe unique identifier of the video for which you want to generate text.
promptstrNoThe prompt to customize the output.
temperatureOptional[float]NoThe temperature to use in the generation.
**kwargsdictNoAdditional keyword arguments for the request.

Return value: Returns a models.GenerateOpenEndedTextStreamResult object.

API Reference: For a description of each field in the request and response, see the Open-ended text page.

Related guide: Streaming responses .