Skip to content

Commit

Permalink
More commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yje-arch committed Jul 26, 2023
1 parent 9a430fd commit 06e5d03
Show file tree
Hide file tree
Showing 15 changed files with 426 additions and 38 deletions.
38 changes: 19 additions & 19 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@

custom_function: module.test
dataset:
config:
file_path: demo/data/hello_yival.csv
reader: csv_reader
reader_config:
chunk_size: 100
expected_result_column: null
use_first_column_as_id: false
reader: csv_reader
source_type: dataset
description: Generated experiment config
evaluators:
- evaluator_type: individual
matching_technique: includes
metric_calculators: []
name: string_expected_result
wrapper_configs:
- config: {}
name: string_wrapper
- evaluator_type: individual
matching_technique: includes
metric_calculators: []
name: string_expected_result

# wrapper_configs: []

# Variations allow for dynamic content during experiments.
# They are identified by a globally unique name. For example, in your code,
# you might reference a variation by its name, like:
# variation = StringWrapper("hello", 'test_experiment')
# In this config, you would define the variations associated with that name, e.g.
variations:
- name: key1
variations:
- instantiated_value: value1
value: value1
value_type: str
variation_id: null
- instantiated_value: value2
value: value2
value_type: str
variation_id: null
- name: key1
variations:
- instantiated_value: value1
value: value1
value_type: str
variation_id: null
- instantiated_value: value2
value: value2
value_type: str
variation_id: null
3 changes: 3 additions & 0 deletions demo/data/hello_yival.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user_input
"Hello, YiVal"
"It is nice to meet you"
Empty file added demo/simple_custom_function.py
Empty file.
141 changes: 140 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fuzzywuzzy = "^0.18.0"
types-pyyaml = "^6.0.12.11"
python-levenshtein = "^0.21.1"
pydantic = "^2.1.1"
textual = "^0.30.0"


[tool.poetry.group.test.dependencies]
Expand Down
54 changes: 53 additions & 1 deletion src/yival/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ def add_arguments_to(subparser):
nargs='+',
help="Variations in 'key=value_type:value1,value2,...' format."
)
parser.add_argument(
"--custom_reader",
type=str,
help=
"Specify custom readers in 'name:class_path:config_cls_path' format."
)
parser.add_argument(
"--custom_wrappers",
type=str,
nargs='+',
help=
"Specify custom wrappers in 'name:class_path:config_cls_path' format."
)
parser.add_argument(
"--custom_evaluators",
type=str,
nargs='+',
help=
"Specify custom evaluators in 'name:class_path:config_cls_path' format."
)


def init(args: Namespace):
Expand All @@ -98,6 +118,35 @@ def init(args: Namespace):
name=list(wc_dict.keys())[0], variations=list(wc_dict.values())[0]
) for wc_dict in args.variations
]
custom_reader = {}
if args.custom_reader:
reader_name, reader_class_path, reader_config_cls_path = args.custom_reader.split(
":"
)
custom_reader[reader_name] = {
"class_path": reader_class_path,
"config_path": reader_config_cls_path
}
custom_wrappers = {}
if args.custom_wrappers:
for custom_wrapper in args.custom_wrappers:
wrapper_name, wrapper_class_path, wrapper_config_cls_path = custom_wrapper.split(
":"
)
custom_wrappers[wrapper_name] = {
"class_path": wrapper_class_path,
"config_path": wrapper_config_cls_path
}
custom_evaluators = {}
if args.custom_evaluators:
for custom_evaluator in args.custom_evaluators:
evaluator_name, evaluator_class_path, evaluator_config_cls_path = custom_evaluator(
":"
)
custom_evaluators[evaluator_name] = {
"class_path": evaluator_class_path,
"config_path": evaluator_config_cls_path
}

# Generate the configuration template dynamically
yaml_template = generate_experiment_config_yaml(
Expand All @@ -106,7 +155,10 @@ def init(args: Namespace):
evaluator_names=args.evaluator_names,
reader_name=args.reader_name,
wrapper_names=args.wrapper_names,
wrapper_configs=wrapper_config_objects
wrapper_configs=wrapper_config_objects,
custom_reader=custom_reader,
custom_wrappers=custom_wrappers,
custom_evaluators=custom_evaluators
)

# Save the generated template to the specified config path
Expand Down
18 changes: 16 additions & 2 deletions src/yival/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def generate_experiment_config_yaml(
evaluator_names: Optional[List[str]] = None,
reader_name: Optional[str] = None,
wrapper_names: Optional[List[str]] = None,
wrapper_configs: Optional[List[WrapperConfig]] = None
wrapper_configs: Optional[List[WrapperConfig]] = None,
custom_reader: Optional[Dict[str, Dict[str, Any]]] = None,
custom_wrappers: Optional[Dict[str, Dict[str, Any]]] = None,
custom_evaluators: Optional[Dict[str, Dict[str, Any]]] = None
) -> str:

def get_default_config(
Expand All @@ -43,18 +46,29 @@ def get_default_config(
dataset_section: Dict[str, Any] = {
"source_type": source_type,
}
if source_type == "dataset":
dataset_section["file_path"] = "/path/to/file_path"
if reader_name:
dataset_section["reader"] = reader_name
reader_cls = BaseReader.get_reader(reader_name)
if reader_cls:
default_config = get_default_config(reader_cls)
if default_config:
dataset_section["config"] = default_config
dataset_section["reader_config"] = default_config
experiment_config: Dict[Any, Any] = {
"description": "Generated experiment config",
"dataset": dataset_section,
}

if custom_reader:
experiment_config["custom_reader"] = custom_reader

if custom_wrappers:
experiment_config["custom_wrappers"] = custom_wrappers

if custom_evaluators:
experiment_config["custom_evaluators"] = custom_evaluators

evaluators_section = []
if evaluator_names:
for name in evaluator_names:
Expand Down
Loading

0 comments on commit 06e5d03

Please sign in to comment.