From ac5fcc5c4200f98feb824d3a4797949c70a84753 Mon Sep 17 00:00:00 2001 From: Arjun Bingly Date: Tue, 30 Apr 2024 14:04:54 -0400 Subject: [PATCH 1/2] add create_config script --- src/grag/components/create_config.py | 43 ++++++++++++++++++ src/grag/resources/__init__.py | 0 src/grag/resources/default_config.ini | 64 +++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 src/grag/components/create_config.py create mode 100644 src/grag/resources/__init__.py create mode 100644 src/grag/resources/default_config.ini diff --git a/src/grag/components/create_config.py b/src/grag/components/create_config.py new file mode 100644 index 0000000..9708a18 --- /dev/null +++ b/src/grag/components/create_config.py @@ -0,0 +1,43 @@ +"""Runnable file for creating a default config.ini file.""" + +import shutil +from pathlib import Path +from typing import Union + +import grag.resources +from importlib_resources import files + + +def create_config(path: Union[str, Path] = '.') -> None: + """Create a configuration file if it doesn't exist. + + This function checks for the existence of a 'config.ini' file at the given path. + If the file does not exist, it copies a default configuration file from the package's + resources to the specified location. If the file already exists, it notifies the user + and does not overwrite the existing file. + + Args: + path (Union[str, Path]): The directory path where the 'config.ini' should be + located. If not specified, defaults to the current + directory ('.'). + + Returns: + None + + Raises: + FileNotFoundError: If the default configuration file does not exist. + PermissionError: If the process does not have permission to write to the specified + directory. + """ + default_config_path = files(grag.resources).joinpath('default_config.ini') + path = Path(path) / 'config.ini' + path = path.resolve() + if path.exists(): + print('Config file already exists') + else: + shutil.copyfile(default_config_path, path, follow_symlinks=True) + print(f"Created config file at {path}") + + +if __name__ == '__main__': + create_config() diff --git a/src/grag/resources/__init__.py b/src/grag/resources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/grag/resources/default_config.ini b/src/grag/resources/default_config.ini new file mode 100644 index 0000000..7e8add1 --- /dev/null +++ b/src/grag/resources/default_config.ini @@ -0,0 +1,64 @@ +; This is the default config.ini file generated by GRAG +; All values are same as package defaults +; Values that do not have a default value are commented out + +; Make sure to fill in the path configs under data, env, quantize and root (whatever applies) + +[llm] +;model_name : Llama-2-13b-chat +;quantization : Q5_K_M +;pipeline : llama_cpp +device_map : auto +task : text-generation +max_new_tokens : 1024 +temperature : 0.1 +n_batch : 1024 +n_ctx : 6000 +n_gpu_layers : -1 +std_out : True +base_dir : ${root:root_path}/models + +[chroma_client] +host : localhost +port : 8000 +collection_name : grag +embedding_type : instructor-embedding +embedding_model : hkunlp/instructor-xl + +[deeplake_client] +collection_name : grag +embedding_type : instructor-embedding +embedding_model : hkunlp/instructor-xl +store_path : ${data:data_path}/vectordb + +[text_splitter] +chunk_size : 2000 +chunk_overlap : 400 + +[multivec_retriever] +store_path : ${data:data_path}/doc_store +top_k : 3 +id_key : doc_id +namespace : 71e4b558187b270922923569301f1039 + +[parse_pdf] +single_text_out : True +strategy : hi_res +infer_table_structure : True +extract_images : True +image_output_dir : None +add_captions_to_text : True +add_captions_to_blocks : True +table_as_html : False + +;[data] +;data_path : ${root:root_path}/data +; +;[env] +;env_path : ${root:root_path}/.env +; +;[quantize] +;llama_cpp_path : ${root:root_path} +; +;[root] +;root_path : ~/Capstone_5 From 2a4e77ced1fe8f00af421355b6b05642a0125968 Mon Sep 17 00:00:00 2001 From: Arjun Bingly Date: Tue, 30 Apr 2024 14:05:14 -0400 Subject: [PATCH 2/2] Add doc for create_config --- src/docs/get_started.config.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/docs/get_started.config.rst b/src/docs/get_started.config.rst index e9f0c0f..3c82967 100644 --- a/src/docs/get_started.config.rst +++ b/src/docs/get_started.config.rst @@ -4,6 +4,14 @@ Configuration GRAG gives the user an option to use a config file, in the form of a ``config.ini``. The use of a config file streamlines the process of passing arguments to the various components in the code. +Generate Config file +********************** +To generate a starters config file with default values, run the below command at the location you want the config file. + +`` +python -m grag.components.create_config +`` + File Resolution **************** GRAG takes the closest ``config.ini`` to the file you run. This enables users to have multiple config files per project,