langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
50.5k stars 7.24k forks source link

Code Execution python print or any log visible in the frontend #7511

Closed FrancisVarga closed 3 weeks ago

FrancisVarga commented 2 months ago

Self Checks

1. Is this request related to a challenge you're experiencing? Tell me about your story.

Debugging code is hard, possible to have the print or anything returned to the frontend or any form of logging.

2. Additional context or comments

No response

3. Can you help us with this feature?

alterxyz commented 2 months ago

Currently you can use Python Try Except, the return format only in dict with few format.

def main():
    try:
        x = 1 / 0
    except Exception as e:
        x = 0
        error_message = str(e)

    return{
        "number": x,
        "debug": error_message
    }

I hope this helps. Please let me know if you have any other questions.

Regarding the sandbox(the engine for Code Execution), please refer to this: https://github.com/langgenius/dify-sandbox