async_openai
The async_openai
module contains the OpenAIAsyncGenerator
class.
Classes:
Name | Description |
---|---|
OpenAIAsyncGenerator |
Uses the OpenAI API to generate course content asynchronously. |
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: