mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 15:22:37 +00:00
fix: update interpolate_only to handle None inputs and remove duplicate attribute
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -431,8 +431,6 @@ class Task(BaseModel):
|
|||||||
tasks_slices = [self.description, output]
|
tasks_slices = [self.description, output]
|
||||||
return "\n".join(tasks_slices)
|
return "\n".join(tasks_slices)
|
||||||
|
|
||||||
_original_output_file: Optional[str] = None
|
|
||||||
|
|
||||||
def interpolate_inputs(self, inputs: Dict[str, Union[str, int, float]]) -> None:
|
def interpolate_inputs(self, inputs: Dict[str, Union[str, int, float]]) -> 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.
|
||||||
|
|
||||||
@@ -475,23 +473,27 @@ class Task(BaseModel):
|
|||||||
except (KeyError, ValueError) as e:
|
except (KeyError, ValueError) as e:
|
||||||
raise ValueError(f"Error interpolating output_file path: {str(e)}") from e
|
raise ValueError(f"Error interpolating output_file path: {str(e)}") from e
|
||||||
|
|
||||||
def interpolate_only(self, input_string: str, inputs: Dict[str, Union[str, int, float]]) -> str:
|
def interpolate_only(self, input_string: Optional[str], inputs: Dict[str, Union[str, int, float]]) -> str:
|
||||||
"""Interpolate placeholders (e.g., {key}) in a string while leaving JSON untouched.
|
"""Interpolate placeholders (e.g., {key}) in a string while leaving JSON untouched.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
input_string: The string containing template variables to interpolate.
|
input_string: The string containing template variables to interpolate.
|
||||||
|
Can be None, 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, and floats.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The interpolated string with all template variables replaced with their values.
|
The interpolated string with all template variables replaced with their values.
|
||||||
|
Empty string if input_string is None.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If a required template variable is missing from inputs.
|
ValueError: If a required template variable is missing from inputs.
|
||||||
KeyError: If a template variable is not found in the inputs dictionary.
|
KeyError: If a template variable is not found in the inputs dictionary.
|
||||||
"""
|
"""
|
||||||
|
if input_string is None:
|
||||||
|
return ""
|
||||||
if not input_string:
|
if not input_string:
|
||||||
raise ValueError("Input string cannot be empty")
|
raise ValueError("Input string cannot be empty when provided")
|
||||||
if not inputs:
|
if not inputs:
|
||||||
raise ValueError("Inputs dictionary cannot be empty")
|
raise ValueError("Inputs dictionary cannot be empty")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user