okcourse.generators.openai
Course generators that use the OpenAI API to produce courses and their assets.
Modules:
Name | Description |
---|---|
async_openai |
The |
openai_utils |
Shared utilities for interacting with the OpenAI API. |
Classes:
Name | Description |
---|---|
AIModels |
|
OpenAIAsyncGenerator |
Uses the OpenAI API to generate course content asynchronously. |
Functions:
Name | Description |
---|---|
get_usable_models_async |
Asynchronously get the usable models, fetching them if not already cached. |
get_usable_models_sync |
Synchronously get the usable models using asyncio.run(). |
AIModels
dataclass
AIModels(
image_models: list[str],
speech_models: list[str],
text_models: list[str],
other_models: list[str] | None,
)
Attributes:
Name | Type | Description |
---|---|---|
image_models |
list[str]
|
|
other_models |
list[str] | None
|
|
speech_models |
list[str]
|
|
text_models |
list[str]
|
|
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:
get_usable_models_async
async
get_usable_models_async() -> AIModels
Asynchronously get the usable models, fetching them if not already cached.
get_usable_models_sync
get_usable_models_sync() -> AIModels
Synchronously get the usable models using asyncio.run().