-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consistent config load_config (#1065)
* Consistent config load_config - Provide a consistent way to load configuration - Resolve potential timestamp directories upfront upon config object creation - Add unit tests for resolving timestamp directories - Resolves #599 - Resolves #1049 * fix formatting issues * remove unnecessary path resolution * fix smoke tests * update prompts to use load_config * Update none checks * Update none checks * Update searching for config method signature * Update unit tests * fix formatting issues
- Loading branch information
Showing
17 changed files
with
169 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "patch", | ||
"description": "Consistent config loading. Resolves #99 and Resolves #1049" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. | ||
# Licensed under the MIT License | ||
|
||
"""Default method for loading config.""" | ||
|
||
from pathlib import Path | ||
|
||
from .config_file_loader import load_config_from_file, search_for_config_in_root_dir | ||
from .create_graphrag_config import create_graphrag_config | ||
from .models.graph_rag_config import GraphRagConfig | ||
from .resolve_timestamp_path import resolve_timestamp_path | ||
|
||
|
||
def load_config( | ||
root_dir: str | Path, | ||
config_filepath: str | Path | None = None, | ||
run_id: str | None = None, | ||
) -> GraphRagConfig: | ||
"""Load configuration from a file or create a default configuration. | ||
If a config file is not found the default configuration is created. | ||
Parameters | ||
---------- | ||
root_dir : str | Path | ||
The root directory of the project. Will search for the config file in this directory. | ||
config_filepath : str | Path | None | ||
The path to the config file. | ||
If None, searches for config file in root and | ||
if not found creates a default configuration. | ||
run_id : str | None | ||
The run id to use for resolving timestamp_paths. | ||
""" | ||
root = Path(root_dir).resolve() | ||
|
||
# If user specified a config file path then it is required | ||
if config_filepath: | ||
config_path = (root / config_filepath).resolve() | ||
if not config_path.exists(): | ||
msg = f"Specified Config file not found: {config_path}" | ||
raise FileNotFoundError(msg) | ||
|
||
# Else optional resolve the config path from the root directory if it exists | ||
config_path = search_for_config_in_root_dir(root) | ||
if config_path: | ||
config = load_config_from_file(config_path) | ||
else: | ||
config = create_graphrag_config(root_dir=str(root)) | ||
|
||
if run_id: | ||
config.storage.base_dir = str( | ||
resolve_timestamp_path((root / config.storage.base_dir).resolve(), run_id) | ||
) | ||
config.reporting.base_dir = str( | ||
resolve_timestamp_path((root / config.reporting.base_dir).resolve(), run_id) | ||
) | ||
else: | ||
config.storage.base_dir = str( | ||
resolve_timestamp_path((root / config.storage.base_dir).resolve()) | ||
) | ||
config.reporting.base_dir = str( | ||
resolve_timestamp_path((root / config.reporting.base_dir).resolve()) | ||
) | ||
|
||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.