/easychart

Dify Plugin: Generate matplotlib code from natural language using a chosen model.

Primary LanguagePython

easychart

Author: lysonober
Version: 0.0.1
Type: tool Repo: https://github.com/LogicOber/easychart Example Chatflow: https://github.com/LogicOber/easychart/blob/main/Natural%20Language%20Data%20Visualization.yml

Description

Generate matplotlib code from natural language using a chosen model, optionally execute it, and return a PNG image blob.

Tools

  • generate_matplotlib: accepts instruction, optional data_context, and a model (model-selector). Returns JSON with code and a Text output containing only the code for easy reference. If return_image is enabled, executes the code and outputs a PNG blob named by output_filename.

Inputs and outputs

  • Inputs

    • model (model-selector, required, form=form): choose the LLM in Dify
    • instruction (string, required, form=llm): chart description (axes/marks/titles)
    • data_context (string, optional, form=llm): variable names/shapes available
    • result_format (select, optional, form=form): text|json
    • return_image (boolean, optional, default true, form=form): execute and emit PNG
    • output_filename (string, optional, default chart.png, form=llm): PNG filename
  • Outputs (Dual Output Pattern)

    • JSON: { code, instruction, data_context }
    • Text: bare Python code only
    • Blob (optional): PNG image (mime image/png, file name from output_filename)

Example usage

  1. Pick a model (e.g., gpt-4o-mini) and set:

    • instruction: "Line plot of y = sin(x) from 0 to 10"
    • return_image: true (default)
    • output_filename: chart.png
  2. Outputs:

    • Text: raw matplotlib code
    • JSON: full details including code
    • Blob: chart.png (PNG)

Notes

  • The tool runs matplotlib headlessly (Agg backend) and never writes to disk; images are returned as blobs per Dify patterns.