improvements with type hints, doc fixes and rm print statements

This commit is contained in:
Lorenze Jay
2025-01-28 10:09:57 -08:00
parent 25fc5073dd
commit fedb91fae3

View File

@@ -454,7 +454,7 @@ class Task(BaseModel):
return "\n".join(tasks_slices) return "\n".join(tasks_slices)
def interpolate_inputs_and_add_conversation_history( def interpolate_inputs_and_add_conversation_history(
self, inputs: Dict[str, Union[str, int, float, dict, list]] self, inputs: Dict[str, Union[str, int, float, Dict[str, Any], List[Any]]]
) -> None: ) -> None:
"""Interpolate inputs into the task description, expected output, and output file path. """Interpolate inputs into the task description, expected output, and output file path.
Add conversation history if present. Add conversation history if present.
@@ -536,7 +536,7 @@ class Task(BaseModel):
input_string: The string containing template variables to interpolate. input_string: The string containing template variables to interpolate.
Can be None or empty, in which case an empty string is returned. Can be None or empty, in which case an empty string is returned.
inputs: Dictionary mapping template variables to their values. inputs: Dictionary mapping template variables to their values.
Supported value types are strings, integers, and floats. Supported value types are strings, integers, floats, dicts, and lists.
If input_string is empty or has no placeholders, inputs can be empty. If input_string is empty or has no placeholders, inputs can be empty.
Returns: Returns:
@@ -558,13 +558,17 @@ class Task(BaseModel):
try: try:
# Validate input types # Validate input types
for key, value in inputs.items(): for key, value in inputs.items():
print("key", key, value)
if not isinstance(value, (str, int, float, dict, list)): if not isinstance(value, (str, int, float, dict, list)):
raise ValueError( raise ValueError(
f"Value for key '{key}' must be a string, integer, float, dict, or list, got {type(value).__name__}" f"Value for key '{key}' must be a string, integer, float, dict, or list, got {type(value).__name__}"
) )
if isinstance(value, (dict, list)): if isinstance(value, (dict, list)):
inputs[key] = json.dumps(value, ensure_ascii=False) try:
inputs[key] = json.dumps(value, ensure_ascii=False)
except Exception as e:
raise ValueError(
f"Failed to serialize value for key: {key} with value: {value} due to error: {str(e)}"
) from e
escaped_string = input_string.replace("{", "{{").replace("}", "}}") escaped_string = input_string.replace("{", "{{").replace("}", "}}")