Skip to content

okcourse.generators

The generators package includes course generators compatible with AI service provider APIs.

Examples:

    course = Course(title="From AGI to ASI: Paperclips, Gray Goo, and You")
    generator = OpenAIAsyncGenerator(course)
    course = await generator.generate_course(course)  # (1)
  1. Generates a complete course—outline, lectures, audio, and cover image—using the OpenAIAsyncGenerator for the given topic and with default CourseSettings.

Modules:

Name Description
base

Abstract base class for generator subclasses that interact with AI service provider APIs to create course content.

openai

Course generators that use the OpenAI API to produce courses and their assets.

Classes:

Name Description
CourseGenerator

Abstract base class for generating a course outline, its lectures, a cover image, and audio for the course.

OpenAIAsyncGenerator

Uses the OpenAI API to generate course content asynchronously.

CourseGenerator

CourseGenerator(course: Course)

Abstract base class for generating a course outline, its lectures, a cover image, and audio for the course.

Parameters:

Name Type Description Default
course Course

The course to generate content for.

required

Attributes:

Name Type Description
log getLogger

The logger for the generator.

Subclasses must implement the abstract methods to generate the course outline, lectures, image, and audio.

Methods:

Name Description
generate_audio

Uses a text-to-speech (TTS) model to generate audio for the course from its lectures.

generate_image

Uses an image generation model to generate a cover image for the course based on its title.

generate_lectures

Uses a generative pre-trained transformer (GPT) to generate the lectures in the course outline.

generate_outline

Uses a generative pre-trained transformer (GPT) to generate an outline for the course based on its title.

Attributes:

Name Type Description
log getLogger

The logger for the generator.

log instance-attribute

log: getLogger = None

The logger for the generator.

generate_audio abstractmethod

generate_audio(course: Course) -> Course

Uses a text-to-speech (TTS) model to generate audio for the course from its lectures.

This method requires that the course has had its lectures generated with a call to generate_lectures before being passed to this method.

Returns:

Name Type Description
Course Course

The course with the audio_file_path attribute set in its generation_info attribute.

generate_image abstractmethod

generate_image(course: Course) -> Course

Uses an image generation model to generate a cover image for the course based on its title.

Parameters:

Name Type Description Default
course Course

The course to generate an image for.

required

Returns:

Name Type Description
Course Course

The course with the image_file_path attribute set in its generation_info attribute.

generate_lectures abstractmethod

generate_lectures(course: Course) -> Course

Uses a generative pre-trained transformer (GPT) to generate the lectures in the course outline.

This method requires that the course has had its outline generated with a call to generate_outline before being passed to this method.

Parameters:

Name Type Description Default
course Course

The course to generate lectures for. The given course must have had its outline generated and its outline attribute set.

required

Returns:

Name Type Description
Course Course

The course with its lectures attribute set.

generate_outline abstractmethod

generate_outline(course: Course) -> Course

Uses a generative pre-trained transformer (GPT) to generate an outline for the course based on its title.

Modify the Course.settings attribute before calling this method to customize the generation process and its output.

Parameters:

Name Type Description Default
course Course

The course to generate an outline for.

required

Returns:

Name Type Description
Course Course

The course with its outline attribute set.

OpenAIAsyncGenerator

OpenAIAsyncGenerator(course: Course)

Uses the OpenAI API to generate course content asynchronously.

Use the OpenAIAsyncGenerator to generate a course outline, lectures, cover image, and audio file for a course.

Examples: Generate a full course, including its outline, lectures, cover image, and audio file:

import asyncio
from okcourse import Course, OpenAIAsyncGenerator


async def main() -> None:
    """Use the OpenAIAsyncGenerator to generate a complete course."""

    # Create a course, configure its settings, and initialize the generator
    course = Course(title="From AGI to ASI: Paperclips, Gray Goo, and You")
    generator = OpenAIAsyncGenerator(course)

    # Generate all course content with - these call AI provider APIs
    course = await generator.generate_outline(course)
    course = await generator.generate_lectures(course)
    course = await generator.generate_image(course)
    course = await generator.generate_audio(course)

    # A Course is a Pydantic model, as are its nested models
    print(course.model_dump_json(indent=2))


if __name__ == "__main__":
    asyncio.run(main())

Parameters:

Name Type Description Default
course Course

The course to generate content for.

required

Methods:

Name Description
generate_audio

Generates an audio file from the combined text of the lectures in the given course using a TTS AI model.

generate_course

Generates a complete course, including its outline, lectures, a cover image, and audio.

generate_image

Generates cover art for the course with the given outline.

generate_lectures

Generates the text for the lectures in the course outline in the settings.

generate_outline

Generates a course outline based on its title and other settings.

Attributes:

Name Type Description
client

client instance-attribute

client = AsyncOpenAI()

generate_audio async

generate_audio(course: Course) -> Course

Generates an audio file from the combined text of the lectures in the given course using a TTS AI model.

Returns:

Type Description
Course

The course with its audio_file_path attribute set which points to the TTS-generated file.

generate_course async

generate_course(course: Course) -> Course

Generates a complete course, including its outline, lectures, a cover image, and audio.

Parameters:

Name Type Description Default
course Course

The course to generate.

required

Returns:

Name Type Description
Course Course

The course with all attributes populated by the generation process.

generate_image async

generate_image(course: Course) -> Course

Generates cover art for the course with the given outline.

The image is appropriate for use as cover art for the course text or audio.

Returns:

Type Description
Course

The results of the generation process with the image_bytes attribute set.

Raises:

Type Description
OpenAIError

If an error occurs during image generation.

generate_lectures async

generate_lectures(course: Course) -> Course

Generates the text for the lectures in the course outline in the settings.

To generate an audio file for the Course generated by this method, call generate_audio.

Returns:

Type Description
Course

The Course with its course.lectures attribute set.

generate_outline async

generate_outline(course: Course) -> Course

Generates a course outline based on its title and other settings.

Set the course's title attribute before calling this method.

Returns:

Name Type Description
Course Course

The result of the generation process with its course.outline attribute set.

Raises:

Type Description
ValueError

If the course has no title.

Examples:

    course = Course(title="From AGI to ASI: Paperclips, Gray Goo, and You")
    generator = OpenAIAsyncGenerator(course)
    course = await generator.generate_outline(course)