|
|
@ -220,6 +220,7 @@ class RunnableConfigurableFields(DynamicRunnable[Input, Output]):
|
|
|
|
annotation=spec.annotation
|
|
|
|
annotation=spec.annotation
|
|
|
|
or self.default.__fields__[field_name].annotation,
|
|
|
|
or self.default.__fields__[field_name].annotation,
|
|
|
|
default=getattr(self.default, field_name),
|
|
|
|
default=getattr(self.default, field_name),
|
|
|
|
|
|
|
|
is_shared=spec.is_shared,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if isinstance(spec, ConfigurableField)
|
|
|
|
if isinstance(spec, ConfigurableField)
|
|
|
|
else make_options_spec(
|
|
|
|
else make_options_spec(
|
|
|
@ -298,6 +299,12 @@ class RunnableConfigurableAlternatives(DynamicRunnable[Input, Output]):
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
default_key: str = "default"
|
|
|
|
default_key: str = "default"
|
|
|
|
|
|
|
|
"""The enum value to use for the default option. Defaults to "default"."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prefix_keys: bool
|
|
|
|
|
|
|
|
"""Whether to prefix configurable fields of each alternative with a namespace
|
|
|
|
|
|
|
|
of the form <which.id>==<alternative_key>, eg. a key named "temperature" used by
|
|
|
|
|
|
|
|
the alternative named "gpt3" becomes "model==gpt3/temperature"."""
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def config_specs(self) -> List[ConfigurableFieldSpec]:
|
|
|
|
def config_specs(self) -> List[ConfigurableFieldSpec]:
|
|
|
@ -313,21 +320,37 @@ class RunnableConfigurableAlternatives(DynamicRunnable[Input, Output]):
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
_enums_for_spec[self.which] = cast(Type[StrEnum], which_enum)
|
|
|
|
_enums_for_spec[self.which] = cast(Type[StrEnum], which_enum)
|
|
|
|
return [
|
|
|
|
return get_unique_config_specs(
|
|
|
|
|
|
|
|
# which alternative
|
|
|
|
|
|
|
|
[
|
|
|
|
ConfigurableFieldSpec(
|
|
|
|
ConfigurableFieldSpec(
|
|
|
|
id=self.which.id,
|
|
|
|
id=self.which.id,
|
|
|
|
name=self.which.name,
|
|
|
|
name=self.which.name,
|
|
|
|
description=self.which.description,
|
|
|
|
description=self.which.description,
|
|
|
|
annotation=which_enum,
|
|
|
|
annotation=which_enum,
|
|
|
|
default=self.default_key,
|
|
|
|
default=self.default_key,
|
|
|
|
|
|
|
|
is_shared=self.which.is_shared,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
*self.default.config_specs,
|
|
|
|
]
|
|
|
|
] + [
|
|
|
|
# config specs of the default option
|
|
|
|
s
|
|
|
|
+ (
|
|
|
|
for alt in self.alternatives.values()
|
|
|
|
[
|
|
|
|
|
|
|
|
prefix_config_spec(s, f"{self.which.id}=={self.default_key}")
|
|
|
|
|
|
|
|
for s in self.default.config_specs
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
if self.prefix_keys
|
|
|
|
|
|
|
|
else self.default.config_specs
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
# config specs of the alternatives
|
|
|
|
|
|
|
|
+ [
|
|
|
|
|
|
|
|
prefix_config_spec(s, f"{self.which.id}=={alt_key}")
|
|
|
|
|
|
|
|
if self.prefix_keys
|
|
|
|
|
|
|
|
else s
|
|
|
|
|
|
|
|
for alt_key, alt in self.alternatives.items()
|
|
|
|
if isinstance(alt, RunnableSerializable)
|
|
|
|
if isinstance(alt, RunnableSerializable)
|
|
|
|
for s in alt.config_specs
|
|
|
|
for s in alt.config_specs
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def configurable_fields(
|
|
|
|
def configurable_fields(
|
|
|
|
self, **kwargs: AnyConfigurableField
|
|
|
|
self, **kwargs: AnyConfigurableField
|
|
|
@ -355,6 +378,23 @@ class RunnableConfigurableAlternatives(DynamicRunnable[Input, Output]):
|
|
|
|
raise ValueError(f"Unknown alternative: {which}")
|
|
|
|
raise ValueError(f"Unknown alternative: {which}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prefix_config_spec(
|
|
|
|
|
|
|
|
spec: ConfigurableFieldSpec, prefix: str
|
|
|
|
|
|
|
|
) -> ConfigurableFieldSpec:
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
ConfigurableFieldSpec(
|
|
|
|
|
|
|
|
id=f"{prefix}/{spec.id}",
|
|
|
|
|
|
|
|
name=spec.name,
|
|
|
|
|
|
|
|
description=spec.description,
|
|
|
|
|
|
|
|
annotation=spec.annotation,
|
|
|
|
|
|
|
|
default=spec.default,
|
|
|
|
|
|
|
|
is_shared=spec.is_shared,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if not spec.is_shared
|
|
|
|
|
|
|
|
else spec
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_options_spec(
|
|
|
|
def make_options_spec(
|
|
|
|
spec: Union[ConfigurableFieldSingleOption, ConfigurableFieldMultiOption],
|
|
|
|
spec: Union[ConfigurableFieldSingleOption, ConfigurableFieldMultiOption],
|
|
|
|
description: Optional[str],
|
|
|
|
description: Optional[str],
|
|
|
@ -377,6 +417,7 @@ def make_options_spec(
|
|
|
|
description=spec.description or description,
|
|
|
|
description=spec.description or description,
|
|
|
|
annotation=enum,
|
|
|
|
annotation=enum,
|
|
|
|
default=spec.default,
|
|
|
|
default=spec.default,
|
|
|
|
|
|
|
|
is_shared=spec.is_shared,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return ConfigurableFieldSpec(
|
|
|
|
return ConfigurableFieldSpec(
|
|
|
@ -385,4 +426,5 @@ def make_options_spec(
|
|
|
|
description=spec.description or description,
|
|
|
|
description=spec.description or description,
|
|
|
|
annotation=Sequence[enum], # type: ignore[valid-type]
|
|
|
|
annotation=Sequence[enum], # type: ignore[valid-type]
|
|
|
|
default=spec.default,
|
|
|
|
default=spec.default,
|
|
|
|
|
|
|
|
is_shared=spec.is_shared,
|
|
|
|
)
|
|
|
|
)
|
|
|
|