Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/instructlab/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
model_validator,
)
from pydantic_core import PydanticUndefined
from ruamel.yaml import YAML, CommentedMap
from ruamel.yaml import YAML, CommentedMap, CommentedSeq
from typing_extensions import deprecated as Deprecated
import click

Expand Down Expand Up @@ -1205,8 +1205,20 @@ def config_to_commented_map(
examples = field.examples
default_factory = field.default_factory

# Recursively handle iterables
if isinstance(value, list | tuple):
# If the value is a list or tuple, handle each item
cm[field_name] = CommentedSeq()
for item in value:
if isinstance(item, BaseModel):
# If the item is a BaseModel, convert it to a CommentedMap
nested_cm = config_to_commented_map(item, indent + 2)
cm[field_name].append(nested_cm)
else:
cm[field_name].append(item)

# Recursively handle nested models
if isinstance(value, BaseModel):
elif isinstance(value, BaseModel):
# If the value is a BaseModel but has Field attributes honor them
set_comment(
cm, field_name, description, default_value, deprecated, examples, indent
Expand Down
Loading