Skip to content

Conversation

@IamtherealBrian
Copy link
Contributor

@IamtherealBrian IamtherealBrian commented Aug 29, 2024

This is the first PR of the "Add AI Assistant Service" series, which will consist of 3 PRs in total.
-PR for the "[2/3] Add AI Assistant Service - add the "Add Type Annotation" Python UDF action" : #2811
-PR for the "[3/3] Add AI Assistant Service - add the "Add All Type Annotation" Python UDF action" : #2812

This PR introduces an AI Assistant flag that allows users to switch between "none" (disabling the AI assistant) and "openai" (using OpenAI as the AI assistant). If the 'none' flag is selected, all AI features will be hidden and unavailable to the user. If the 'openai' flag is selected, AI features will be enabled and accessible in the Python UDF editor. (The implementation of these AI features will be covered in PR2 of 3 and PR3 of 3).

Key idea of each new file:
(1) AiAssistantManager.scala:
Handling results corresponding to the two cases obtained from the flag.
(2) AiAssistantResource.scala:
Implement three RESTful API endpoints to manage AI flag.

Notice:
Since the AI features are in the second and third PRs, the RESTful API functionality in this PR cannot be tested yet, as it will only be used in the second and third PRs. However, if you just want to test the result, you can print the result of the boolean for the testing purpose by calling the frontend method checkAiAssistantEnabled().

@IamtherealBrian IamtherealBrian requested a review from yunyad August 29, 2024 07:12
@IamtherealBrian IamtherealBrian self-assigned this Aug 29, 2024
@IamtherealBrian IamtherealBrian changed the title Add AI Assistant Service (PR1 of 3) [1/3] Add AI Assistant Service - Ai Flag Aug 29, 2024
Copy link
Contributor

@yunyad yunyad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check my comments and add the links in the description. Thank you!

Copy link
Contributor

@yunyad yunyad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 small issues.

Copy link
Contributor

@yunyad yunyad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM please format before merge.

Copy link
Contributor

@chenlica chenlica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check my comments

@chenlica chenlica changed the title [1/3] Add AI Assistant Service - Ai Flag [1/3] Add AI Assistant Service - AI Flag Sep 2, 2024
Copy link
Contributor

@chenlica chenlica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it looks good after those changes.

@IamtherealBrian IamtherealBrian merged commit 02f658f into master Sep 2, 2024
@IamtherealBrian IamtherealBrian deleted the minchongWu-flag-pr branch September 2, 2024 18:55
xudongwu-0 added a commit that referenced this pull request Sep 5, 2024
)

This PR enhances the AI flag by allowing ai-assistant-server to be
missing.
The previous PR:#2808

**Optional AI Assistant Configuration:**

The new version allows the ai-assistant-server configuration to be
missing. In this case, its behavior corresponds to the case of
"NoAiAssistant".
xudongwu-0 added a commit that referenced this pull request Sep 18, 2024
This PR enhances the report generation functionality by adding animation
during the process. This PR is a continuation and enhancement of the
previous PR:

Adding a button to generate a report for a workflow:
#2770
Enhancing Report Generation by adding Operator Results:
#2792
Enhancing Report Generation by Adding Operator Json and Comments Section
: #2807
Ai Flag: #2818 and
#2808

Key Changes:

**menu.component.ts:** 
At the start, notification.blank is called to display a message, and
notification.remove is used to remove it at the end. Upon successful
generation, this.notificationService.success is invoked.

**notification.service.ts:** 
notification.blank and notification.remove have been added.

Screenshot of the notification:

![image](https://github.com/user-attachments/assets/76f01cfd-dd52-4ba5-8f87-d2703473e82e)

![image](https://github.com/user-attachments/assets/a0a06876-275d-4062-a62a-0b423488107c)
IamtherealBrian added a commit that referenced this pull request Sep 20, 2024
… UDF action (#2811)

This PR introduces a new AI-based feature called "Add Type Annotation"
that enhances the user experience of the Python UDF on top of the
Pyright language server. The following are related PR's:
-PR for the "Add the pyright language server" :
#2797.
-PR for the "[1/3] Add AI Assistant Service - Ai Flag" :
#2808
-PR for the "[3/3] Add AI Assistant Service - add the "Add All Type
Annotation" Python UDF action" :
#2812

**Key changes:**
Added a Monaco action in the frontend Python UDF editor to allow users
to automatically add type annotations for an argument each time they
select a single argument in their code.

**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

---------

Co-authored-by: Yicong Huang <17627829+Yicong-Huang@users.noreply.github.com>
Co-authored-by: Yicong Huang <yicong.huang@observeinc.com>
IamtherealBrian added a commit that referenced this pull request Oct 2, 2024
…thon UDF action (#2857)

This PR introduces another AI feature call "Add All Type Annotation"
that enhance the user experience of the Python UDF after integrating
with the Pyright language server. You can refer to the related PR here:
-PR for the "Add the pyright language server" :
#2797.
-PR for the "[1/3] Add AI Assistant Service - Ai Flag" :
#2808
-PR for the "[2/3] Add AI Assistant Service - add the "Add Type
Annotation" Python UDF action" :
#2811

**Key change:**
Added another Monaco action in the frontend Python UDF editor to allow
users to automatically add all type annotations for the arguments within
their selected code block.

**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
xudongwu-0 added a commit that referenced this pull request Oct 15, 2024
#2816)

This PR enhances the report generation functionality by
addingStory-teller Ai based on Ai flag. This PR is a continuation and
enhancement of the previous PR:
Adding a button to generate a report for a workflow: #2770 
Enhancing Report Generation by adding Operator Results: #2792 
Enhancing Report Generation by Adding Operator Json and Comments Section
: #2807
Ai Flag: #2818 and
#2808

**New Methods:**
checkAiAssistantEnabled():
Validates whether the AI Assistant feature is enabled by checking the
availability of the required API key. This function ensures that
subsequent AI-based functionalities are executed only when the AI
Assistant is available.

generateComment(operatorInfo: any):
Generates insightful comments for each operator using OpenAI’s GPT
model, tailored for a highly educated audience but one that might not
have deep statistical knowledge. The comments are plain text, enhancing
the overall readability and value of the report.

generateSummaryComment(operatorInfo: any):
Produces a concise, insightful summary comment that highlights key
findings, trends, and areas of improvement across the workflow, focusing
particularly on UDFs. This function is crucial for providing a
comprehensive understanding of the workflow to users.

**Enhanced Methods:**
retrieveOperatorInfoReport(operatorId: string, allResults: { operatorId:
string; html: string }[]):
Implements the checkAiAssistantEnabled, generateComment, and
generateSummaryComment functions to enrich the operator information
section in the generated reports. The function now adds a "Toggle
Detail" button beneath each operator, allowing users to expand and view
the operator’s corresponding JSON, formatted using a JSON viewer.
Additionally, a comments section is added below each operator, enabling
users to leave or view AI-generated comments.

generateReportAsHtml(workflowSnapshot: string, allResults: string[],
workflowName: string):
Generates a comprehensive HTML file containing the workflow snapshot,
all operator results, operator details, and comments. This method
integrates AI-generated comments and a summary section at the end of the
report. It also introduces a "Download Workflow JSON" button, allowing
users to download the entire workflow JSON file directly from the
report.

**Operation Process:** 
Click the button below to generate the report with detailed operator
results and the workflow snapshot.

![image](https://github.com/user-attachments/assets/4c2fccf7-c931-4e9c-a2d2-a6bcc9d640a1)

To turn on the ai feature, you need to modify the following sections in
application.udf

![image](https://github.com/user-attachments/assets/d88755af-c86e-4eb3-a717-59a69b74200e)

For example, to turn on the openai:

![image](https://github.com/user-attachments/assets/588de609-806e-46f8-abea-6a08030243fb)


Here is a part of the example report.

![image](https://github.com/user-attachments/assets/3911a558-497f-45bc-a948-1a7a3a671a85)

![image](https://github.com/user-attachments/assets/f8fa5284-5a5b-4d70-a18b-283a2b3c612f)
PurelyBlank pushed a commit that referenced this pull request Dec 4, 2024
This is the first PR of the "Add AI Assistant Service" series, which
will consist of 3 PRs in total.
-PR for the "[2/3] Add AI Assistant Service - add the "Add Type
Annotation" Python UDF action" :
#2811
-PR for the "[3/3] Add AI Assistant Service - add the "Add All Type
Annotation" Python UDF action" :
#2812

This PR introduces an AI Assistant flag that allows users to switch
between "none" (disabling the AI assistant) and "openai" (using OpenAI
as the AI assistant). If the 'none' flag is selected, all AI features
will be hidden and unavailable to the user. If the 'openai' flag is
selected, AI features will be enabled and accessible in the Python UDF
editor. (The implementation of these AI features will be covered in PR2
of 3 and PR3 of 3).

**Key idea of each new file:**
(1) AiAssistantManager.scala:   
Handling results corresponding to the two cases obtained from the flag.
(2) AiAssistantResource.scala:
Implement three RESTful API endpoints to manage AI flag.

**Notice:**
Since the AI features are in the second and third PRs, the RESTful API
functionality in this PR cannot be tested yet, as it will only be used
in the second and third PRs. However, if you just want to test the
result, you can print the result of the boolean for the testing purpose
by calling the frontend method `checkAiAssistantEnabled()`.

---------

Co-authored-by: Xudong Wu <2373025856w@gmail.com>
PurelyBlank pushed a commit that referenced this pull request Dec 4, 2024
)

This PR enhances the AI flag by allowing ai-assistant-server to be
missing.
The previous PR:#2808

**Optional AI Assistant Configuration:**

The new version allows the ai-assistant-server configuration to be
missing. In this case, its behavior corresponds to the case of
"NoAiAssistant".
PurelyBlank pushed a commit that referenced this pull request Dec 4, 2024
This PR enhances the report generation functionality by adding animation
during the process. This PR is a continuation and enhancement of the
previous PR:

Adding a button to generate a report for a workflow:
#2770
Enhancing Report Generation by adding Operator Results:
#2792
Enhancing Report Generation by Adding Operator Json and Comments Section
: #2807
Ai Flag: #2818 and
#2808

Key Changes:

**menu.component.ts:** 
At the start, notification.blank is called to display a message, and
notification.remove is used to remove it at the end. Upon successful
generation, this.notificationService.success is invoked.

**notification.service.ts:** 
notification.blank and notification.remove have been added.

Screenshot of the notification:

![image](https://github.com/user-attachments/assets/76f01cfd-dd52-4ba5-8f87-d2703473e82e)

![image](https://github.com/user-attachments/assets/a0a06876-275d-4062-a62a-0b423488107c)
PurelyBlank pushed a commit that referenced this pull request Dec 4, 2024
… UDF action (#2811)

This PR introduces a new AI-based feature called "Add Type Annotation"
that enhances the user experience of the Python UDF on top of the
Pyright language server. The following are related PR's:
-PR for the "Add the pyright language server" :
#2797.
-PR for the "[1/3] Add AI Assistant Service - Ai Flag" :
#2808
-PR for the "[3/3] Add AI Assistant Service - add the "Add All Type
Annotation" Python UDF action" :
#2812

**Key changes:**
Added a Monaco action in the frontend Python UDF editor to allow users
to automatically add type annotations for an argument each time they
select a single argument in their code.

**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

---------

Co-authored-by: Yicong Huang <17627829+Yicong-Huang@users.noreply.github.com>
Co-authored-by: Yicong Huang <yicong.huang@observeinc.com>
PurelyBlank pushed a commit that referenced this pull request Dec 4, 2024
…thon UDF action (#2857)

This PR introduces another AI feature call "Add All Type Annotation"
that enhance the user experience of the Python UDF after integrating
with the Pyright language server. You can refer to the related PR here:
-PR for the "Add the pyright language server" :
#2797.
-PR for the "[1/3] Add AI Assistant Service - Ai Flag" :
#2808
-PR for the "[2/3] Add AI Assistant Service - add the "Add Type
Annotation" Python UDF action" :
#2811

**Key change:**
Added another Monaco action in the frontend Python UDF editor to allow
users to automatically add all type annotations for the arguments within
their selected code block.

**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
PurelyBlank pushed a commit that referenced this pull request Dec 4, 2024
#2816)

This PR enhances the report generation functionality by
addingStory-teller Ai based on Ai flag. This PR is a continuation and
enhancement of the previous PR:
Adding a button to generate a report for a workflow: #2770 
Enhancing Report Generation by adding Operator Results: #2792 
Enhancing Report Generation by Adding Operator Json and Comments Section
: #2807
Ai Flag: #2818 and
#2808

**New Methods:**
checkAiAssistantEnabled():
Validates whether the AI Assistant feature is enabled by checking the
availability of the required API key. This function ensures that
subsequent AI-based functionalities are executed only when the AI
Assistant is available.

generateComment(operatorInfo: any):
Generates insightful comments for each operator using OpenAI’s GPT
model, tailored for a highly educated audience but one that might not
have deep statistical knowledge. The comments are plain text, enhancing
the overall readability and value of the report.

generateSummaryComment(operatorInfo: any):
Produces a concise, insightful summary comment that highlights key
findings, trends, and areas of improvement across the workflow, focusing
particularly on UDFs. This function is crucial for providing a
comprehensive understanding of the workflow to users.

**Enhanced Methods:**
retrieveOperatorInfoReport(operatorId: string, allResults: { operatorId:
string; html: string }[]):
Implements the checkAiAssistantEnabled, generateComment, and
generateSummaryComment functions to enrich the operator information
section in the generated reports. The function now adds a "Toggle
Detail" button beneath each operator, allowing users to expand and view
the operator’s corresponding JSON, formatted using a JSON viewer.
Additionally, a comments section is added below each operator, enabling
users to leave or view AI-generated comments.

generateReportAsHtml(workflowSnapshot: string, allResults: string[],
workflowName: string):
Generates a comprehensive HTML file containing the workflow snapshot,
all operator results, operator details, and comments. This method
integrates AI-generated comments and a summary section at the end of the
report. It also introduces a "Download Workflow JSON" button, allowing
users to download the entire workflow JSON file directly from the
report.

**Operation Process:** 
Click the button below to generate the report with detailed operator
results and the workflow snapshot.

![image](https://github.com/user-attachments/assets/4c2fccf7-c931-4e9c-a2d2-a6bcc9d640a1)

To turn on the ai feature, you need to modify the following sections in
application.udf

![image](https://github.com/user-attachments/assets/d88755af-c86e-4eb3-a717-59a69b74200e)

For example, to turn on the openai:

![image](https://github.com/user-attachments/assets/588de609-806e-46f8-abea-6a08030243fb)


Here is a part of the example report.

![image](https://github.com/user-attachments/assets/3911a558-497f-45bc-a948-1a7a3a671a85)

![image](https://github.com/user-attachments/assets/f8fa5284-5a5b-4d70-a18b-283a2b3c612f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants