Skip to content

Commit

Permalink
Merge pull request #114 from arjbingly/make-config
Browse files Browse the repository at this point in the history
Ability to create a defaults config file
  • Loading branch information
sanchitvj authored Apr 30, 2024
2 parents 0dd6f5f + 2a4e77c commit b4ffbed
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/docs/get_started.config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
43 changes: 43 additions & 0 deletions src/grag/components/create_config.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file added src/grag/resources/__init__.py
Empty file.
64 changes: 64 additions & 0 deletions src/grag/resources/default_config.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b4ffbed

Please sign in to comment.