utils¶
Utility functions for Direktor.
direktor.core.utils
¶
Utility functions for Direktor.
This module contains helper functions for file operations, API calls, and text processing.
create_temp_dir(input_file)
¶
Create a temporary directory based on the input file's hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
Path to the input file |
required |
Returns:
| Type | Description |
|---|---|
|
Path to the created temporary directory |
Source code in direktor/core/utils.py
download_file(url, local_filename)
¶
Download a file from a URL with progress tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
The URL to download from |
required | |
local_filename
|
Local path to save the file |
required |
Returns:
| Type | Description |
|---|---|
|
The local filename |
Source code in direktor/core/utils.py
group_sentences(sentences, max_chars=100)
¶
Group sentences into chunks with a maximum character count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sentences
|
List of sentences to group |
required | |
max_chars
|
Maximum characters per chunk |
100
|
Returns:
| Type | Description |
|---|---|
|
List of grouped text chunks |
Source code in direktor/core/utils.py
run_replicate_model(model, input_data)
¶
Run a Replicate model with the given input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
The Replicate model identifier |
required | |
input_data
|
Dictionary of input parameters |
required |
Returns:
| Type | Description |
|---|---|
|
The model output |
Raises:
| Type | Description |
|---|---|
Exception
|
If the prediction fails |
Source code in direktor/core/utils.py
split_into_sentences(text)
¶
Split text into sentences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
The text to split |
required |
Returns:
| Type | Description |
|---|---|
|
List of sentences |
split_text(text, max_tokens)
¶
Split text into chunks based on token count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
The text to split |
required | |
max_tokens
|
Maximum tokens per chunk |
required |
Returns:
| Type | Description |
|---|---|
|
List of text chunks |
Source code in direktor/core/utils.py
upload_to_r2(file_path, object_name)
¶
Upload a file to S3-compatible storage (Cloudflare R2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path to the local file |
required | |
object_name
|
Object name in the bucket |
required |
Returns:
| Type | Description |
|---|---|
|
Presigned URL for the uploaded file, or None on failure |