Skip to content

Commit

Permalink
add other assistant config files with !include
Browse files Browse the repository at this point in the history
  • Loading branch information
samleeney committed Nov 17, 2024
1 parent 5f686f9 commit 25ae99f
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions gptcli/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
from typing import Dict, List, Optional
from attr import dataclass

import yaml
from attr import dataclass

from gptcli.assistant import AssistantConfig
from gptcli.providers.llama import LLaMAModelConfig


CONFIG_FILE_PATHS = [
os.path.join(os.path.expanduser("~"), ".config", "gpt-cli", "gpt.yml"),
os.path.join(os.path.expanduser("~"), ".gptrc"),
Expand Down Expand Up @@ -38,9 +38,24 @@ def choose_config_file(paths: List[str]) -> str:
return ""


# Custom YAML Loader with !include support
class CustomLoader(yaml.SafeLoader):
pass


def include_constructor(loader, node):
# Get the file path from the node
file_path = loader.construct_scalar(node)
# Read and return the content of the included file
with open(file_path, "r") as include_file:
return include_file.read()


# Register the !include constructor
CustomLoader.add_constructor("!include", include_constructor)


def read_yaml_config(file_path: str) -> GptCliConfig:
with open(file_path, "r") as file:
config = yaml.safe_load(file)
return GptCliConfig(
**config,
)
config = yaml.load(file, Loader=CustomLoader)
return GptCliConfig(**config)

0 comments on commit 25ae99f

Please sign in to comment.