[PR #9051] feat: add code generator #26276

Closed
opened 2026-02-21 20:39:14 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/9051

State: closed
Merged: Yes


Checklist:

Important

Please review the checklist below before submitting your pull request.

  • Please open an issue before creating a PR or link to an existing issue
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Description

Background

As a user of Dify, I have personally experienced the challenges of writing code directly on the platform. Unlike in local environments where tools like GitHub Copilot or Cursor can assist me in generating code, Dify currently lacks similar features. This makes it difficult to efficiently implement functionalities, particularly for users like me who may not have advanced programming skills. Writing code from scratch without assistance can be time-consuming and discouraging, which limits productivity and creativity.
My company used to do a Dify course for people who couldn't write code, and they had a very hard time with code blocks. I wish I could get them to face LLM more.
So I suggest adding a code generator to the code node. I made a demo to give you an idea.

Close #9021

Added code

Frontend

  • Add generate button to code node
  • Clicking the button opens a modal (just like the prompt generator)

Backend

  • API for code generation added to controller
  • generateCode added to LLMGenerator class
  • Added prompt for both python and javascript
  • Max token setting added to environment variable (.env.example)

Things not implemented

Considering the minimal functionality, I deemed these features unnecessary for this PR, so I did not implement them.

  • Changing the input and output types or variable names of code nodes
  • Displaying generated examples (like in a prompt generator)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update, included: Dify Document
  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement
  • Dependency upgrade

Testing Instructions

You can verify this functionality by following these steps

At First , Launch Workflow/ChatFlow.
⇨ Create a node code. (You can use python and javascript)
⇨ Click on the Generateicon button in the header
⇨ Tell the modal that comes up what code you want to write.
⇨ Apply.

I will post a demonstration.
https://github.com/user-attachments/assets/abaf890d-7ad4-4192-8f2a-9f7a679d6178

**Original Pull Request:** https://github.com/langgenius/dify/pull/9051 **State:** closed **Merged:** Yes --- # Checklist: > [!IMPORTANT] > Please review the checklist below before submitting your pull request. - [x] Please open an issue before creating a PR or link to an existing issue - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods # Description ## Background As a user of Dify, I have personally experienced the challenges of writing code directly on the platform. Unlike in local environments where tools like GitHub Copilot or Cursor can assist me in generating code, Dify currently lacks similar features. This makes it difficult to efficiently implement functionalities, particularly for users like me who may not have advanced programming skills. Writing code from scratch without assistance can be time-consuming and discouraging, which limits productivity and creativity. My company used to do a Dify course for people who couldn't write code, and they had a very hard time with code blocks. I wish I could get them to face LLM more. So I suggest adding a code generator to the code node. I made a demo to give you an idea. Close #9021 ## Added code Frontend - Add generate button to code node - Clicking the button opens a modal (just like the prompt generator) Backend - API for code generation added to controller - generateCode added to LLMGenerator class - Added prompt for both python and javascript - Max token setting added to environment variable (.env.example) ## Things not implemented Considering the minimal functionality, I deemed these features unnecessary for this PR, so I did not implement them. - Changing the input and output types or variable names of code nodes - Displaying generated examples (like in a prompt generator) ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [ ] Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement - [ ] Dependency upgrade # Testing Instructions You can verify this functionality by following these steps At First , Launch Workflow/ChatFlow. ⇨ Create a node code. (You can use python and javascript) ⇨ Click on the Generateicon button in the header ⇨ Tell the modal that comes up what code you want to write. ⇨ Apply. I will post a demonstration. https://github.com/user-attachments/assets/abaf890d-7ad4-4192-8f2a-9f7a679d6178
yindo added the pull-request label 2026-02-21 20:39:14 -05:00
yindo closed this issue 2026-02-21 20:39:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#26276