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)
- Generates a complete course—outline, lectures, audio, and cover image—using the
OpenAIAsyncGenerator
for the given topic and with defaultCourseSettings
.
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. |
generate_audio
abstractmethod
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 |
generate_image
abstractmethod
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 |
generate_lectures
abstractmethod
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
|
required |
Returns:
Name | Type | Description |
---|---|---|
Course |
Course
|
The course with its |
generate_outline
abstractmethod
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 |
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 |
Attributes:
Name | Type | Description |
---|---|---|
client |
|
generate_audio
async
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 |
generate_course
async
generate_image
async
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 |
Raises:
Type | Description |
---|---|
OpenAIError
|
If an error occurs during image generation. |
generate_lectures
async
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 |
generate_outline
async
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 |
Raises:
Type | Description |
---|---|
ValueError
|
If the course has no title. |
Examples: