Tool
analyst
A toolkit for data science with llms
Tool ID
analyst
Creator
@sworddai
Downloads
260+

Tool Content
python
class Tools:
    def __init__(self):
        self.citation = True

    def code_interpreter(self, code_str: str) -> str:
        """
        Execute Python code and return the result.
        :param code_str: The Python code to execute.
        :return: The result of the code execution.
        """
        try:
            # Create a local namespace for execution
            local_vars = {}
            exec(code_str, globals(), local_vars)
            return local_vars
        except Exception as e:
            return f"An error occurred: {e}"

# Παράδειγμα χρήσης
tools = Tools()
code = '''
def add(a, b):
    return a + b

result = add(3, 5)
'''
output = tools.code_interpreter(code)
print(output.get('result'))  # Εκτυπώνει: 8