Texera / texera

Collaborative Machine-Learning-Centric Data Analytics Using Workflows
https://texera.github.io
Apache License 2.0
161 stars 68 forks source link

Add AI-Assistant flag and features #2801

Closed IamtherealBrian closed 2 weeks ago

IamtherealBrian commented 3 weeks ago

This PR adds a flag to allow the user to use the AI assistant (currently only OpenAI) and introduces some AI features that enhance the user experience of the Python UDF after integrating with the Pyright language server. You can refer to the PR for the Pyright language server here: https://github.com/Texera/texera/pull/2797.

Key change:

  1. Added an AI assistant flag to allow users to switch between "none" (no AI assistant) and "openai" (using OpenAI as the AI assistant).
  2. Added two Monaco actions in the frontend Python UDF editor to allow users to automatically add type annotations to their arguments. The first action is called "Add Type Annotation," and the second action is called "Add All Type Annotations."

Flag: If the user chooses the 'none' flag, all AI features will be hidden and not available to the user. Otherwise, the AI features will be accessible in the Python UDF editor.

Add Type Annotation: This action requires the user to select a single argument in their Python UDF code. A UI with a suggestion for the selected argument will pop up. The user can choose to accept or decline the suggestion from OpenAI. If they accept the suggestion, it will be added to their code; otherwise, the code will remain unchanged. The suggestion is provided by OpenAI. After the backend receives the response from OpenAI, it will be forwarded to the frontend via a RESTful API.

Example:

https://github.com/user-attachments/assets/29cee6c8-c793-4d83-8b27-db64bcc636ae

Add All Type Annotation: This action requires the user to select a code block in their Python UDF code. The action will automatically identify all arguments without type annotations and provide type annotation suggestions for each argument sequentially. The selected code block will be sent to the backend for Python Abstract Syntax Tree (AST) analysis to locate arguments without type annotations, and the result will be sent back to the frontend via a RESTful API. If the user selects a code block that has no arguments or where all the arguments already have type annotations, the code will remain unchanged. Example:

https://github.com/user-attachments/assets/d70c1b02-b309-4359-a267-0a5eef831316

Summary: With these two AI features, users can easily add type annotations to their code. This will enable the Pyright language server to perform better at detecting semantic errors after the type annotations are added.