Reference
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
podflix
project code.
podflix package.
db
A module for managing database connections and operations.
db_factory
SqlAlchemy database interface factory and implementations.
DBInterfaceFactory
Singleton factory class for creating database interface instances.
create
classmethod
create(db_path='db.sqlite')
Creates and returns appropriate database interface based on environment settings.
Returns the same instance on subsequent calls.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_path
|
str | Path
|
Path to SQLite database file. Only used for SQLite interface. |
'db.sqlite'
|
Returns:
Name | Type | Description |
---|---|---|
SqlAlchemyDBInterface |
SqlAlchemyDBInterface
|
Singleton instance of appropriate database interface. |
Source code in src/podflix/db/db_factory.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
PostgresDBInterface
Bases: SqlAlchemyDBInterface
PostgreSQL database interface implementation.
async_connection
async_connection()
Returns the async PostgreSQL connection string.
Returns:
Type | Description |
---|---|
str
|
A string representing the async PostgreSQL connection URL. |
Source code in src/podflix/db/db_factory.py
106 107 108 109 110 111 112 |
|
get_connection_path
get_connection_path()
Returns the PostgreSQL connection path.
Returns:
Type | Description |
---|---|
str
|
A string containing the PostgreSQL connection details including user, password, host, port and database. |
Source code in src/podflix/db/db_factory.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
sync_connection
sync_connection()
Returns the sync PostgreSQL connection string.
Returns:
Type | Description |
---|---|
str
|
A string representing the sync PostgreSQL connection URL. |
Source code in src/podflix/db/db_factory.py
114 115 116 117 118 119 120 |
|
SQLiteDBInterface
SQLiteDBInterface(db_path='db.sqlite')
Bases: SqlAlchemyDBInterface
SQLite database interface implementation.
Source code in src/podflix/db/db_factory.py
57 58 59 |
|
async_connection
async_connection()
Returns the async SQLite connection string.
Returns:
Type | Description |
---|---|
str
|
A string representing the async SQLite connection URL. |
Source code in src/podflix/db/db_factory.py
69 70 71 72 73 74 75 |
|
get_connection_path
get_connection_path()
Returns the SQLite database file path.
Returns:
Type | Description |
---|---|
str
|
A string representing the path to the SQLite database file. |
Source code in src/podflix/db/db_factory.py
61 62 63 64 65 66 67 |
|
sync_connection
sync_connection()
Returns the sync SQLite connection string.
Returns:
Type | Description |
---|---|
str
|
A string representing the sync SQLite connection URL. |
Source code in src/podflix/db/db_factory.py
77 78 79 80 81 82 83 |
|
SqlAlchemyDBInterface
Bases: ABC
Abstract base class for database interfaces.
async_connection
abstractmethod
async_connection()
Returns the async database connection string.
Returns:
Type | Description |
---|---|
str
|
A string representing the async database connection URL. |
Source code in src/podflix/db/db_factory.py
21 22 23 24 25 26 27 |
|
check_db_connection
check_db_connection()
Checks if database connection is valid.
Raises:
Type | Description |
---|---|
Exception
|
If database connection fails, with details about the error. |
Source code in src/podflix/db/db_factory.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
get_connection_path
abstractmethod
get_connection_path()
Returns the database connection path.
Returns:
Type | Description |
---|---|
str
|
A string representing the database connection path. |
Source code in src/podflix/db/db_factory.py
13 14 15 16 17 18 19 |
|
sync_connection
abstractmethod
sync_connection()
Returns the sync database connection string.
Returns:
Type | Description |
---|---|
str
|
A string representing the sync database connection URL. |
Source code in src/podflix/db/db_factory.py
29 30 31 32 33 34 35 |
|
db_manager
Base database management functionality.
This module provides database management capabilities including initialization, connection handling, and SQL file execution with retry logic.
Examples:
>>> from podflix.db.db_manager import DatabaseManager
>>> db_manager = DatabaseManager()
>>> db_manager.execute_sql_file(Path("init.sql"), True, "Initialize")
The module contains the following class:
DatabaseManager
- Handles database operations with retry logic.
DatabaseManager
DatabaseManager(max_retries=5, retry_delay=2)
Manages database operations with retry logic and error handling.
This class provides functionality to manage database operations including reading SQL files, checking table existence, and executing SQL statements with retry logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_retries
|
int
|
Maximum number of connection retry attempts. Defaults to 5. |
5
|
retry_delay
|
int
|
Initial delay between retries in seconds. Defaults to 2. |
2
|
Examples:
>>> db_manager = DatabaseManager(max_retries=3, retry_delay=1)
>>> db_manager.execute_sql_file(Path("init.sql"), True, "Initialize")
Source code in src/podflix/db/db_manager.py
48 49 50 51 |
|
execute_sql_file
execute_sql_file(sql_file, check_exists, operation_name)
Execute SQL statements from a file with retry logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql_file
|
Path
|
Path to the SQL file to execute. |
required |
check_exists
|
bool
|
If True, checks for existing tables before execution. |
required |
operation_name
|
str
|
Name of the operation for logging purposes. |
required |
Raises:
Type | Description |
---|---|
OperationalError
|
If database connection fails after max retries. |
Exception
|
If SQL statement execution fails. |
Examples:
>>> db_manager = DatabaseManager()
>>> db_manager.execute_sql_file(
... Path("init.sql"),
... check_exists=True,
... operation_name="Initialize"
... )
Source code in src/podflix/db/db_manager.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
read_sql_file
read_sql_file(file_path)
Read and parse SQL statements from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to the SQL file to be read. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
A list of SQL statements parsed from the file. |
Examples:
>>> db_manager = DatabaseManager()
>>> statements = db_manager.read_sql_file("init.sql")
>>> len(statements) > 0
True
Source code in src/podflix/db/db_manager.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
table_exists
table_exists(conn)
Check if users table exists in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conn
|
SQLAlchemy connection object to use for the query. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the users table exists, False otherwise. |
Raises:
Type | Description |
---|---|
OperationalError
|
If there's a problem connecting to the database. |
ProgrammingError
|
If there's a problem executing the SQL query. |
Examples:
>>> db_manager = DatabaseManager()
>>> with db_manager.engine.connect() as conn:
... exists = db_manager.table_exists(conn)
>>> isinstance(exists, bool)
True
Source code in src/podflix/db/db_manager.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
init_db
Initialize the database schema using SQL statements from init_db.sql file.
initialize_db
initialize_db(max_retries=5, retry_delay=2)
Initialize the database using SQL statements from init_db.sql file.
Source code in src/podflix/db/init_db.py
8 9 10 11 12 13 14 15 |
|
env_settings
Application configuration for environment variables.
EnvSettings
Bases: BaseSettings
This class is used to load environment variables.
They are either from environment or from a .env file and store them as class attributes.
Note
- environment variables will always take priority over values loaded from a dotenv file
- environment variable names are case-insensitive
- environment variable type is inferred from the type hint of the class attribute
- For environment variables that are not set, a default value should be provided
For more info, see the related pydantic docs: https://docs.pydantic.dev/latest/concepts/pydantic_settings
validate_model_api_base
validate_model_api_base(value, values)
Validate the model API base URL.
Source code in src/podflix/env_settings.py
105 106 107 108 109 110 111 112 113 |
|
validate_openai_key
validate_openai_key(value, values)
Validate the OpenAI API key.
Source code in src/podflix/env_settings.py
95 96 97 98 99 100 101 102 103 |
|
allowed_values
allowed_values(v, values)
Validate if a value is in a set of allowed values.
Examples:
>>> allowed_values("a", ["a", "b"])
'a'
>>> allowed_values(1, [1, 2, 3])
1
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
The value to validate |
required | |
values
|
A collection of allowed values |
required |
Returns:
Type | Description |
---|---|
The validated value if it exists in the allowed values |
Raises:
Type | Description |
---|---|
AssertionError
|
If the value is not in the allowed values |
Source code in src/podflix/env_settings.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
graph
Module about LLM interaction using Langchain Langgprah nodes.
mock
Define the mock graph for the Podflix agent.
AgentState
Bases: TypedDict
A dictionary representing the state of the agent.
mock_answer
async
mock_answer(state)
Generate a mock response using a random choice from predefined messages.
The function simulates an AI model's response by randomly selecting from a predefined list of messages and returning it as an AIMessage.
Examples:
>>> state = {"messages": [HumanMessage(content="Hello")]}
>>> response = await mock_answer(state)
>>> isinstance(response["messages"][0], AIMessage)
True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
AgentState
|
A dictionary containing the current conversation state, including: - messages: A sequence of BaseMessage objects representing the conversation history. |
required |
Returns:
Type | Description |
---|---|
A dictionary containing: - messages: A list with a single AIMessage containing the random response. |
Source code in src/podflix/graph/mock.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
podcast_rag
Define the RAG-based graph for the Podflix agent.
AgentState
Bases: TypedDict
A dictionary representing the state of the agent.
generate
async
generate(state)
Generate a response using the retrieved context.
Source code in src/podflix/graph/podcast_rag.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
retrieve
async
retrieve(state)
Retrieve relevant context based on the user's question.
Source code in src/podflix/graph/podcast_rag.py
22 23 24 25 26 27 28 29 |
|
gui
Chainlit UI module.
base_chat
settings_update
async
settings_update(settings)
Update settings when changed in UI
Source code in src/podflix/gui/base_chat.py
58 59 60 61 |
|
placeholder
Placeholder file to provide several sample math calculations.
This module allows the user to make mathematical calculations. Adapted from: https://realpython.com/python-project-documentation-with-mkdocs/
Examples:
>>> from podflix import placeholder
>>> placeholder.add(2, 4)
6.0
>>> placeholder.multiply(2.0, 4.0)
8.0
>>> from podflix.placeholder import divide
>>> divide(4.0, 2)
2.0
The module contains the following functions:
add(a, b)
- Returns the sum of two numbers.subtract(a, b)
- Returns the difference of two numbers.multiply(a, b)
- Returns the product of two numbers.divide(a, b)
- Returns the quotient of two numbers.
add
add(a, b)
Compute and return the sum of two numbers.
Examples:
>>> add(4.0, 2.0)
6.0
>>> add(4, 2)
6.0
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
float | int
|
A number representing the first addend in the addition. |
required |
b
|
float | int
|
A number representing the second addend in the addition. |
required |
Returns:
Type | Description |
---|---|
float
|
A number representing the arithmetic sum result of |
Source code in src/podflix/placeholder.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
divide
divide(a, b)
Compute and return the division of two numbers.
Examples:
>>> divide(4.0, 2.0)
2.0
>>> divide(4, 2)
2.0
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
float | int
|
A number representing the first divider in the divide. |
required |
b
|
float | int
|
A number representing the second divider in the divide. |
required |
Returns:
Type | Description |
---|---|
float
|
A number representing the division result of |
Raises:
Type | Description |
---|---|
ZeroDivisionError
|
If |
Source code in src/podflix/placeholder.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
multiply
multiply(a, b)
Compute and return the multiplication of two numbers.
Examples:
>>> multiply(4.0, 2.0)
8.0
>>> multiply(4, 2)
8.0
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
float | int
|
A number representing the first multiplicator in the multiply. |
required |
b
|
float | int
|
A number representing the second multiplicator in the multiply. |
required |
Returns:
Type | Description |
---|---|
float
|
A number representing the multiplied result of |
Source code in src/podflix/placeholder.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
subtract
subtract(a, b)
Compute and return the substaction of two numbers.
Examples:
>>> subtract(4.0, 2.0)
2.0
>>> subtract(4, 2)
2.0
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
float | int
|
A number representing the first substracter in the substract. |
required |
b
|
float | int
|
A number representing the second substracter in the substract. |
required |
Returns:
Type | Description |
---|---|
float
|
A number representing the substract result of |
Source code in src/podflix/placeholder.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
utils
Utility functions.
chainlit_utils
Utility functions.
data_layer
Utility functions for working with ChainLit data layer.
This module provides utility functions for configuring and working with ChainLit's data layer, including S3 storage integration and SQLAlchemy database connections.
apply_sqlite_data_layer_fixes
apply_sqlite_data_layer_fixes()
Apply necessary fixes for SQLite data layer configuration.
This function applies patches and configurations specific to SQLite data layer when it is enabled in the environment settings.
Examples:
>>> apply_sqlite_data_layer_fixes() # Applies fixes if SQLite is enabled
Returns:
Type | Description |
---|---|
None |
Source code in src/podflix/utils/chainlit_utils/data_layer.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
check_s3_credentials
check_s3_credentials(boto_client)
Check if the AWS S3 credentials are valid by attempting to list buckets.
Examples:
>>> s3_client = get_s3_storage_client()
>>> check_s3_credentials(s3_client.client) # No error if credentials are valid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boto_client
|
client
|
A boto3 client instance configured for AWS S3. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
Exception
|
If connection to AWS S3 fails using provided credentials. |
Source code in src/podflix/utils/chainlit_utils/data_layer.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
get_custom_sqlalchemy_data_layer
get_custom_sqlalchemy_data_layer(show_logger=False, enable_s3_storage_provider=False)
Create and configure a custom SQLAlchemy data layer instance.
This function sets up a SQLAlchemy data layer with optional S3 storage integration and logging capabilities.
Examples:
>>> data_layer = get_custom_sqlalchemy_data_layer()
>>> isinstance(data_layer, SQLAlchemyDataLayer)
True
>>> data_layer_with_s3 = get_custom_sqlalchemy_data_layer(enable_s3_storage_provider=True)
>>> data_layer_with_logging = get_custom_sqlalchemy_data_layer(show_logger=True)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_logger
|
bool
|
Whether to enable SQL query logging. Defaults to False. |
False
|
enable_s3_storage_provider
|
bool
|
Whether to enable S3 storage integration. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SQLAlchemyDataLayer |
SQLAlchemyDataLayer
|
A configured data layer instance. |
Raises:
Type | Description |
---|---|
ValueError
|
If S3 storage is enabled but credentials are invalid. |
Source code in src/podflix/utils/chainlit_utils/data_layer.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
get_element_url
async
get_element_url(data_layer, thread_id, element_id)
Retrieve the URL for accessing an element's file content.
Examples:
>>> data_layer = get_custom_sqlalchemy_data_layer()
>>> url = await get_element_url(data_layer, "thread123", "element456")
>>> print(url) # None if not found, URL string if exists
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_layer
|
SQLAlchemyDataLayer
|
The SQLAlchemy data layer instance to use for retrieval. |
required |
thread_id
|
str
|
The unique identifier of the thread containing the element. |
required |
element_id
|
str
|
The unique identifier of the element to retrieve. |
required |
Returns:
Type | Description |
---|---|
str | None
|
str | None: The URL string if the element exists, None otherwise. |
Source code in src/podflix/utils/chainlit_utils/data_layer.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
get_read_url_of_file
async
get_read_url_of_file(thread_id, file_id)
Retrieve the URL for accessing an file in a thread.
Examples:
>>> data_layer = ChainlitDataLayer()
>>> url = await get_read_url_of_file(data_layer, "thread123", "audio.mp3")
>>> print(url) # URL string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thread_id
|
str
|
The unique identifier of the thread containing the file. |
required |
file_id
|
str
|
The file id of the file to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The S3 URL string of the file. |
Raises:
Type | Description |
---|---|
ValueError
|
If S3 storage client is not configured in the data layer. |
Source code in src/podflix/utils/chainlit_utils/data_layer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
get_s3_storage_client
get_s3_storage_client()
Get the S3 storage client configured with environment credentials.
Examples:
>>> client = get_s3_storage_client()
>>> isinstance(client, S3StorageClient)
True
Returns:
Name | Type | Description |
---|---|---|
S3StorageClient |
S3StorageClient
|
An initialized S3 storage client instance. |
Raises:
Type | Description |
---|---|
ValueError
|
If required AWS S3 credentials are not set in environment variables. |
Source code in src/podflix/utils/chainlit_utils/data_layer.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
general
Utilies for chainlit UI.
create_message_history_from_db_thread
create_message_history_from_db_thread(thread)
Create message history from the thread steps.
Examples:
>>> thread = {"steps": [{"type": "user_message", "output": "hello", "createdAt": 1}]}
>>> history = create_message_history_from_db_thread(thread)
>>> len(history.messages)
1
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thread
|
ThreadDict
|
A ThreadDict object containing the conversation thread data. |
required |
Returns:
Type | Description |
---|---|
ChatMessageHistory
|
A ChatMessageHistory object containing the processed message history. |
Source code in src/podflix/utils/chainlit_utils/general.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
get_current_chainlit_thread_id
get_current_chainlit_thread_id()
Get the current Chainlit thread ID.
Source code in src/podflix/utils/chainlit_utils/general.py
131 132 133 |
|
set_extra_user_session_params
set_extra_user_session_params(session_id=None, user_id=None, message_history=None)
Set extra user session parameters for the chainlit session.
Examples:
>>> set_extra_user_session_params(session_id="test123")
>>> cl.user_session.get("session_id")
'test123'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_id
|
str | None
|
Optional string representing the session ID. If None, a new UUID is generated. |
None
|
user_id
|
str | None
|
Optional string representing the user ID. If None, gets from current user session. |
None
|
message_history
|
ChatMessageHistory | None
|
Optional ChatMessageHistory object. If None, creates new empty history. |
None
|
Returns:
Type | Description |
---|---|
None |
Source code in src/podflix/utils/chainlit_utils/general.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
set_mock_elements
async
set_mock_elements()
Set mock elements for the sidebar.
Source code in src/podflix/utils/chainlit_utils/general.py
136 137 138 139 140 141 142 143 144 145 146 147 |
|
simple_auth_callback
simple_auth_callback(username, password)
Authenticate user with simple username and password check.
Examples:
>>> simple_auth_callback("admin", "admin")
User(identifier="admin", metadata={"role": "admin", "provider": "credentials"})
Parameters:
Name | Type | Description | Default |
---|---|---|---|
username
|
str
|
A string representing the username for authentication. |
required |
password
|
str
|
A string representing the password for authentication. |
required |
Returns:
Type | Description |
---|---|
User
|
A User object if authentication is successful. |
Raises:
Type | Description |
---|---|
ValueError
|
If credentials are invalid. |
Source code in src/podflix/utils/chainlit_utils/general.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
patch_chainlit
custom_resume_thread
async
custom_resume_thread(session)
Resume a thread and set the user session parameters.
NOTE: This is a workaround to fix the issue of the chatbot not resuming the thread on sqlite data layer.
Source code in src/podflix/utils/chainlit_utils/patch_chainlit.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
setting_widgets
Utility functions for converting Pydantic models to Chainlit settings.
convert_pydantic_model_to_chainlit_settings
convert_pydantic_model_to_chainlit_settings(model_class, prefix='')
Convert a Pydantic model to Chainlit settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_class
|
Type[BaseModel]
|
Pydantic model class to convert |
required |
prefix
|
str
|
Prefix for widget labels (e.g., 'OpenAI - ') |
''
|
Returns:
Type | Description |
---|---|
ChatSettings
|
cl.ChatSettings instance |
Source code in src/podflix/utils/chainlit_utils/setting_widgets.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
get_openai_chat_settings
get_openai_chat_settings()
Get chat settings for OpenAI chat completion parameters.
Source code in src/podflix/utils/chainlit_utils/setting_widgets.py
94 95 96 97 98 |
|
general
General utility functions.
check_env_vars
check_env_vars(env_vars=None)
Checks if the required environment variables are set.
Examples:
>>> check_env_vars(['API_KEY', 'SECRET_KEY'])
None
>>> check_env_vars(None)
None
>>> check_env_vars(['NONEXISTENT_VAR'])
Traceback (most recent call last):
ValueError: Please set NONEXISTENT_VAR env var.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env_vars
|
list[str] | None
|
List of environment variables to check. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ValueError
|
If any of the environment variables are not set. |
Source code in src/podflix/utils/general.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
check_lf_credentials
check_lf_credentials()
Check if the Langfuse credentials are correct by attempting authentication.
Examples:
>>> check_lf_credentials()
None
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ValueError
|
If authentication fails with provided Langfuse credentials |
Exception
|
If Langfuse authentication check fails for any other reason |
Source code in src/podflix/utils/general.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
get_lf_project_id
get_lf_project_id()
Retrieve the Langfuse project ID from the first available project.
Examples:
>>> get_lf_project_id()
'cm5a4jaff0006r8yk44cvas5a'
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The unique identifier of the first Langfuse project. |
Raises:
Type | Description |
---|---|
Exception
|
If no projects are found or if there's an error accessing Langfuse API |
Source code in src/podflix/utils/general.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
get_lf_session_url
get_lf_session_url(session_id)
Construct the full URL for a Langfuse session.
Examples:
>>> get_lf_session_url("123")
'https://YOUR_LANFUSE_HOST/project/YOUR_PROJECT_ID/sessions/123'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_id
|
str
|
The unique identifier of the Langfuse session. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The complete URL to access the session in Langfuse UI. |
Raises:
Type | Description |
---|---|
Exception
|
If there's an error retrieving the project ID |
Source code in src/podflix/utils/general.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
get_lf_traces_url
get_lf_traces_url(langchain_run_id)
Construct the full URL for a Langfuse trace.
Examples:
>>> get_lf_traces_url("123")
'https://YOUR_LANFUSE_HOST/project/YOUR_PROJECT_ID/traces/123'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
langchain_run_id
|
str
|
The unique identifier of the Langchain run. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The complete URL to access the trace in Langfuse UI. |
Raises:
Type | Description |
---|---|
ValueError
|
If langchain_run_id is None |
Exception
|
If there's an error retrieving the project ID |
Source code in src/podflix/utils/general.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
is_module_installed
is_module_installed(module_name, throw_error=False)
Check if the module is installed or not.
Examples:
>>> is_module_installed(module_name="yaml", throw_error=False)
True
>>> is_module_installed(module_name="numpy", throw_error=False)
False
>>> is_module_installed(module_name="numpy", throw_error=True)
Traceback (most recent call last):
ImportError: Module numpy is not installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name
|
str
|
Name of the module to be checked. |
required |
throw_error
|
bool
|
If True, raises ImportError if module is not installed. |
False
|
Returns:
Type | Description |
---|---|
bool
|
Returns True if module is installed, False otherwise. |
Raises:
Type | Description |
---|---|
ImportError
|
If throw_error is True and module is not installed. |
Source code in src/podflix/utils/general.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
graph_runner
Helper class for running the graph.
GraphRunner
GraphRunner(
graph,
graph_inputs,
graph_streamable_node_names,
lf_cb_handler,
session_id,
assistant_message,
)
Helper class for on_message callback.
Initialize the GraphRunner class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
CompiledStateGraph
|
A CompiledStateGraph instance representing the graph to be executed. |
required |
graph_inputs
|
dict
|
A dictionary containing the inputs for the graph. |
required |
graph_streamable_node_names
|
list[str]
|
A list of node names that can be streamed. |
required |
lf_cb_handler
|
CallbackHandler
|
A LangfuseCallbackHandler instance for tracking. |
required |
session_id
|
str
|
A string representing the unique session identifier. |
required |
assistant_message
|
Message
|
A chainlit Message instance for displaying responses. |
required |
Source code in src/podflix/utils/graph_runner.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
run_graph
async
run_graph()
Execute the graph asynchronously with the configured inputs.
This method sets up the runnable configuration with callbacks and streams the graph events to process the LLM responses.
Examples:
>>> runner = GraphRunner(graph, inputs, nodes, handler, "session1", message)
>>> await runner.run_graph()
Returns:
Type | Description |
---|---|
None |
Source code in src/podflix/utils/graph_runner.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
stream_llm_response
async
stream_llm_response(event)
Stream the LLM response to the assistant message.
Process the event data and stream tokens to the assistant message if the event comes from a streamable node.
Examples:
>>> event = {"event": "on_chat_model_stream", "data": {"chunk": chunk}}
>>> await runner.stream_llm_response(event)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
dict
|
A dictionary containing the event data with the following structure: - event: The type of event (str) - metadata: Dictionary with event metadata - data: The event payload |
required |
Returns:
Type | Description |
---|---|
None |
Notes
The method updates the assistant_message.content when streaming tokens. It also captures the run_id for Langfuse tracking when the chain ends.
Source code in src/podflix/utils/graph_runner.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
hf_related
Hugginface related utilities.
download_gguf_hf
download_gguf_hf(repo_id, filename, revision='main')
Download a specific GGUF file from Hugging Face hub.
Examples:
>>> download_gguf_hf("Qwen/Qwen2-0.5B-Instruct-GGUF", "qwen2-0_5b-instruct-fp16.gguf")
'/path/to/downloaded/file.gguf'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_id
|
str
|
A string representing the Hugging Face repository ID. |
required |
filename
|
str
|
A string representing the name of the GGUF file to download. |
required |
revision
|
str
|
A string representing the specific model version to use. |
'main'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Local path to the downloaded file. |
Source code in src/podflix/utils/hf_related.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
download_model_snapshot_hf
download_model_snapshot_hf(
repo_id="Qwen/Qwen2.5-0.5B-Instruct", revision="main", ignore_patterns=None
)
Download a complete model snapshot from Hugging Face hub.
Examples:
>>> download_model_snapshot_hf("Qwen/Qwen2.5-0.5B-Instruct")
>>> download_model_snapshot_hf("Qwen/Qwen2.5-0.5B-Instruct", ignore_patterns=["*.pt"])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_id
|
str
|
A string representing the Hugging Face repository ID. |
'Qwen/Qwen2.5-0.5B-Instruct'
|
revision
|
str
|
A string representing the specific model version to use. |
'main'
|
ignore_patterns
|
list[str] | None
|
A list of patterns to ignore during download. |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in src/podflix/utils/hf_related.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
model
Model utilities.
get_chat_model
get_chat_model(model_name=None, chat_model_kwargs=None)
Create and configure a ChatOpenAI model instance.
Examples:
>>> model = get_chat_model()
>>> isinstance(model, ChatOpenAI)
True
>>> model = get_chat_model("gpt-4o-mini", {"temperature": 0.7})
>>> isinstance(model, ChatOpenAI)
True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str | None
|
The name of the model to use. If None, uses the default from env_settings. |
None
|
chat_model_kwargs
|
dict[Any] | None
|
Additional keyword arguments to pass to ChatOpenAI. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
ChatOpenAI
|
A configured ChatOpenAI model instance ready for use. |
Source code in src/podflix/utils/model.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
get_mock_model
get_mock_model(message='MOCK MESSAGE')
Create a mock language model for testing purposes.
Examples:
>>> model = get_mock_model("Test response")
>>> isinstance(model, (FakeListChatModel, StrOutputParser))
True
>>> model = get_mock_model()
>>> isinstance(model, (FakeListChatModel, StrOutputParser))
True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The message to be returned by the mock model. Defaults to "MOCK MESSAGE". |
'MOCK MESSAGE'
|
Returns:
Type | Description |
---|---|
FakeListChatModel | StrOutputParser
|
A chain of FakeListChatModel and StrOutputParser that returns the specified message. |
Source code in src/podflix/utils/model.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
transcribe_audio_file
transcribe_audio_file(file, model_name=None, response_format='verbose_json')
Transcribe an audio file using OpenAI's Whisper model.
When using the verbose_json response format, the function returns the transcribed text with optional timestamps. Otherwise, it returns only the transcribed text.
Examples:
>>> with open('audio.mp3', 'rb') as f:
... transcription = transcribe_audio_file(f)
>>> isinstance(transcription.text, str)
True
>>> transcription = transcribe_audio_file(Path('audio.mp3'))
>>> isinstance(transcription.text, str)
True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
BinaryIO | Path
|
The audio file to transcribe. Can be a file object or Path. |
required |
model_name
|
str | None
|
The name of the Whisper model to use. If None, uses the default from env_settings. |
None
|
response_format
|
AudioResponseFormat
|
The format of the response to return. Defaults to "verbose_json". |
'verbose_json'
|
Returns:
Type | Description |
---|---|
Transcription | TranscriptionVerbose
|
The transcribed text with optional timestamps from the audio file. |
Source code in src/podflix/utils/model.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
pydantic_models
Pydantic models for Podflix.
OpenAIChatGenerationSettings
Bases: BaseModel
Pydantic model for OpenAI chat settings.
get_available_models
get_available_models()
Return available models based on environment settings.
Source code in src/podflix/utils/pydantic_models.py
8 9 10 11 12 |
|
get_default_model
get_default_model()
Return the default model based on environment settings.
Source code in src/podflix/utils/pydantic_models.py
15 16 17 18 19 |
|