From 62346af8befaec7ea06b86161fe0100f8b9f701c Mon Sep 17 00:00:00 2001 From: CODER Date: Wed, 22 Jul 2026 20:13:45 +0000 Subject: [PATCH] feat: implement task --- generated_code.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 generated_code.py diff --git a/generated_code.py b/generated_code.py new file mode 100644 index 0000000..ec0f47f --- /dev/null +++ b/generated_code.py @@ -0,0 +1,48 @@ +{ + "files": { + "ai-core/utils/conversion.py": """import sys + +def convert_temperature(value, units): + """ + Convert temperature between Celsius, Fahrenheit, and Kelvin. + + Args: + value (float): The temperature value to be converted. + units (str): The units of the input value ('Celsius', 'Fahrenheit', 'Kelvin'). + + Returns: + float: The converted temperature value. + + Raises: + ValueError: If an invalid unit is provided or if the input value cannot be parsed as a number. + """ + + try: + value = float(value) + except ValueError: + raise ValueError("Input value must be a numeric type.") + + if units == 'Celsius': + # Convert to Fahrenheit + return (value * 9/5) + 32 + + elif units == 'Fahrenheit': + # Convert to Celsius + return (value - 32) * 5/9 + + elif units == 'Kelvin': + # Convert to Celsius + return value - 273.15 + + else: + raise ValueError("Invalid unit provided. Choose from 'Celsius', 'Fahrenheit', or 'Kelvin'.") + +# Example usage and testing +if __name__ == "__main__": + print(convert_temperature(0, "Celsius")) # Output: 32.0 (Freezing point of water in Fahrenheit) + print(convert_temperature(32, "Fahrenheit")) # Output: 0.0 (Freezing point of water in Celsius) + print(convert_temperature(273.15, "Kelvin")) # Output: 0.0 (Freezing point of water in Celsius) +""" + }, + "commit_message": "feat: add temperature conversion utility function" +} \ No newline at end of file -- 2.43.0