Upload formats.py with huggingface_hub
Browse files- formats.py +5 -0
formats.py
CHANGED
|
@@ -5,6 +5,7 @@ from typing import (
|
|
| 5 |
Optional,
|
| 6 |
)
|
| 7 |
|
|
|
|
| 8 |
from .operator import StreamInstanceOperator
|
| 9 |
from .type_utils import isoftype
|
| 10 |
|
|
@@ -34,6 +35,7 @@ class SystemFormat(Format):
|
|
| 34 |
demo_format (str): formatting string for a single demo, combining fields "source" and "target"
|
| 35 |
model_input_format (str) overall product format, combining instruction and source (as read from fields "instruction"
|
| 36 |
and "source" of the input instance), together with demos (as formatted into one string)
|
|
|
|
| 37 |
|
| 38 |
Example:
|
| 39 |
when input instance:
|
|
@@ -73,6 +75,7 @@ class SystemFormat(Format):
|
|
| 73 |
model_input_format: str = (
|
| 74 |
"{system_prompt}{instruction}{demos}{source}\n{target_prefix}"
|
| 75 |
)
|
|
|
|
| 76 |
|
| 77 |
@staticmethod
|
| 78 |
def _retrieve_field_and_assert_not_none(instance, field_name) -> str:
|
|
@@ -128,6 +131,7 @@ class SystemFormat(Format):
|
|
| 128 |
target_prefix=target_prefix,
|
| 129 |
source=demo_instance["source"],
|
| 130 |
target=demo_instance["target"],
|
|
|
|
| 131 |
)
|
| 132 |
demos_string += demo_str
|
| 133 |
|
|
@@ -137,6 +141,7 @@ class SystemFormat(Format):
|
|
| 137 |
demos=demos_string,
|
| 138 |
source=source,
|
| 139 |
target_prefix=target_prefix,
|
|
|
|
| 140 |
)
|
| 141 |
instance["source"] = output
|
| 142 |
return instance
|
|
|
|
| 5 |
Optional,
|
| 6 |
)
|
| 7 |
|
| 8 |
+
from .dataclass import OptionalField
|
| 9 |
from .operator import StreamInstanceOperator
|
| 10 |
from .type_utils import isoftype
|
| 11 |
|
|
|
|
| 35 |
demo_format (str): formatting string for a single demo, combining fields "source" and "target"
|
| 36 |
model_input_format (str) overall product format, combining instruction and source (as read from fields "instruction"
|
| 37 |
and "source" of the input instance), together with demos (as formatted into one string)
|
| 38 |
+
format_args: Dict[str,str]: additional format args to be used when formatting the different format strings
|
| 39 |
|
| 40 |
Example:
|
| 41 |
when input instance:
|
|
|
|
| 75 |
model_input_format: str = (
|
| 76 |
"{system_prompt}{instruction}{demos}{source}\n{target_prefix}"
|
| 77 |
)
|
| 78 |
+
format_args: Dict[str, str] = OptionalField(default_factory=dict)
|
| 79 |
|
| 80 |
@staticmethod
|
| 81 |
def _retrieve_field_and_assert_not_none(instance, field_name) -> str:
|
|
|
|
| 131 |
target_prefix=target_prefix,
|
| 132 |
source=demo_instance["source"],
|
| 133 |
target=demo_instance["target"],
|
| 134 |
+
**self.format_args,
|
| 135 |
)
|
| 136 |
demos_string += demo_str
|
| 137 |
|
|
|
|
| 141 |
demos=demos_string,
|
| 142 |
source=source,
|
| 143 |
target_prefix=target_prefix,
|
| 144 |
+
**self.format_args,
|
| 145 |
)
|
| 146 |
instance["source"] = output
|
| 147 |
return instance
|