Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "complex" in python executor #78

Closed
joaopauloschuler opened this issue Jan 6, 2025 · 3 comments
Closed

Support for "complex" in python executor #78

joaopauloschuler opened this issue Jan 6, 2025 · 3 comments

Comments

@joaopauloschuler
Copy link
Contributor

joaopauloschuler commented Jan 6, 2025

The following code produced by DeepSeek fails:

def generate_mandelbrot(width, height, x_min, x_max, y_min, y_max, max_iter):                                      
    image = np.zeros((height, width))                                                                              
    for row in range(height):                                                                                      
        for col in range(width):                                                                                   
            x = x_min + (x_max - x_min) * col / width                                                              
            y = y_min + (y_max - y_min) * row / height                                                             
            c = complex(x, y)                                                                                      
            m = mandelbrot(c, max_iter)                                                                            
            color = 1 - m / max_iter                                                                               
            image[row, col] = color                                                                                
    return image 
@batrlatom
Copy link

what is the fail message? I think that in this line :

        m = mandelbrot(c, max_iter)                                                                            

mandelbrot is not defined. And if there is some import needs to be done, you can add it to the additional imports like this:

manager_agent = CodeAgent(
tools=[],
model=model,
additional_authorized_imports=["time", "numpy", "pandas"],
)

Also, this is not secure, but you can add specific function names in the local_python_executor here:

BASE_PYTHON_TOOLS = {
"print": custom_print,
"isinstance": isinstance,
"range": range,
"float": float,
"int": int,
"bool": bool,
"str": str,
"set": set,
"list": list,
"dict": dict,
"tuple": tuple,
"round": round,
"ceil": math.ceil,
"floor": math.floor,
"log": math.log,
"exp": math.exp,
"sin": math.sin,
"cos": math.cos,
"tan": math.tan,
"asin": math.asin,
"acos": math.acos,
"atan": math.atan,
"atan2": math.atan2,
"degrees": math.degrees,
"radians": math.radians,
"pow": math.pow,
"sqrt": math.sqrt,
"len": len,
"sum": sum,
"max": max,
"min": min,
"abs": abs,
"enumerate": enumerate,
"zip": zip,
"reversed": reversed,
"sorted": sorted,
"all": all,
"any": any,
"map": map,
"filter": filter,
"ord": ord,
"chr": chr,
"next": next,
"iter": iter,
"divmod": divmod,
"callable": callable,
"getattr": getattr,
"hasattr": hasattr,
"setattr": setattr,
"issubclass": issubclass,
"type": type,
}

I, for example added "open": open, for executor to open files natively

@joaopauloschuler
Copy link
Contributor Author

joaopauloschuler commented Jan 6, 2025

The problem happens at: c = complex(x, y). Adding complex to BASE_PYTHON_TOOLS fixes the problem. This is the fix: #79 .

@aymeric-roucher
Copy link
Collaborator

Closed by merging #79! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants