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

feat: add code generator #9051

Merged
merged 9 commits into from
Oct 22, 2024

Conversation

Kota-Yamaguchi
Copy link
Contributor

@Kota-Yamaguchi Kota-Yamaguchi commented Oct 7, 2024

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

- Add generateRuleCode function to handle API request
- Define CodeGenRes type for the response
- Implement POST request to '/rule-code-generate' endpoint
- Create button to trigger code generation
- Implement modal for code generation interface
- Add functionality to display generated code
- Include options for code language selection
- Integrate with existing code generation API
- Adjust button placement for better user experience
- Modify interface to accommodate new button layout
- Add handler for code generation functionality
- Update component props to support new features
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 💪 enhancement New feature or request labels Oct 7, 2024
@Kota-Yamaguchi Kota-Yamaguchi changed the title Feature/add code generator feat : add code generator Oct 7, 2024
@Kota-Yamaguchi Kota-Yamaguchi changed the title feat : add code generator feat: add code generator Oct 7, 2024
crazywoola
crazywoola previously approved these changes Oct 22, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 22, 2024
@crazywoola crazywoola merged commit a7ee51e into langgenius:main Oct 22, 2024
7 checks passed
idonotknow pushed a commit to AceDataCloud/Dify that referenced this pull request Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a "CodeGenerator" to Code Nodes
2 participants