-
Notifications
You must be signed in to change notification settings - Fork 37
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
Tcoz openai assist #1138
Tcoz openai assist #1138
Conversation
Some notes for people that might want to run full-on native, with detail about how Mac hijacks port 7000 and how to get around it.
This reverts commit 096887c.
Some details for user that might be running Python3, Mac, and want to run everything locally/natively.
Uses MUI tooltip, as it behaves more predictably with existing styling, and enables top-level theme config. Top-level configuration for all MUI components can be controlled via overriding the existing theme. See index.tsx. This could be done per user for customization, etc. Enabling JSON module imports in tsconfig.json seemed to fix the error in ReactDiagramEditor
A working starting point.
Along with route and function, api config, etc.
If it is, loads the related UI, otherwise it doesn't appear.
Had to find all the places permissions are enabled, etc.
Finishing touches for the most part. REQUIRES TWO ENV VARS BE SET. SPIFFWORKFLOW_SCRIPT_ASSIST_ENABLED=["True" | "true" | 1] (anything else is false) SECRET_KEY_OPENAI_API=[thekey] The are retrieved in default.py. I run the app locally, so I just set them in the terminal. NEW INSTALL: @carbon/colors (so we consistently use carbon palette etc.)
Finishing it off.
Complete UX stuff
Remove log
Add this tweak to avoid TMI.
…into tcoz-dev-branch
Should (but I don't know how to tell yet) call the change handler that wasn't firing before.
WalkthroughThe recent update integrates AI-driven script assistance into the SpiffWorkflow platform, enhancing both the backend and frontend. It introduces new API endpoints for script processing, configures the backend for AI tool support, and adds necessary dependencies. On the frontend, it implements UI components and hooks to interact with the AI services, enabling dynamic script generation and processing. This update significantly boosts the platform's capabilities in automating and assisting users with script creation. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 9
Configuration used: .coderabbit.yaml
Files selected for processing (14)
- spiffworkflow-backend/pyproject.toml (2 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/init.py (1 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/api.yml (2 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/config/default.py (2 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/config/permissions/local_development.yml (1 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py (1 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.py (1 hunks)
- spiffworkflow-frontend/package-lock.json (4 hunks)
- spiffworkflow-frontend/package.json (2 hunks)
- spiffworkflow-frontend/src/components/SpiffTooltip.tsx (1 hunks)
- spiffworkflow-frontend/src/hooks/useProcessScriptAssistQuery.tsx (1 hunks)
- spiffworkflow-frontend/src/hooks/useScriptAssistEnabled.tsx (1 hunks)
- spiffworkflow-frontend/src/index.css (1 hunks)
- spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx (6 hunks)
Files skipped from review due to trivial changes (1)
- spiffworkflow-backend/src/spiffworkflow_backend/config/permissions/local_development.yml
Additional comments: 17
spiffworkflow-frontend/src/components/SpiffTooltip.tsx (1)
- 14-18: The addition of
PopperProps
with azIndex
style to theTooltip
component ensures that the tooltip will be displayed above other UI elements. This is a good practice for improving UI visibility and user experience. However, ensure that thezIndex
value of9999
does not conflict with other elements in your application that might also use highzIndex
values.spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py (3)
- 10-13: The TODO comments provide useful context about potential future improvements, such as testing for the existence of the API key to determine if script assist is enabled and considering the use of the async version of the OpenAI library. These comments are helpful for maintaining and evolving the codebase.
- 14-15: The
enabled
function correctly checks the configuration to determine if script assistance is enabled and returns the status. This is a straightforward and effective implementation.- 18-56: The
process_message
function is well-structured and includes important checks, such as verifying the presence of the OpenAI API key and the script query. The use of a prepend and append string to guide the OpenAI model's response is a clever approach to ensure more relevant and secure outputs. However, the static analysis tool's hint about SQL injection is a false positive in this context, as the code is constructing a query for the OpenAI API, not a SQL database. Nonetheless, ensure that the content returned from OpenAI is handled securely, especially since it's dynamically generated code that could be executed.spiffworkflow-frontend/package.json (2)
- 9-9: Adding
@carbon/colors
as a dependency is a good choice for enhancing UI styling with a consistent color palette. Ensure that the version^11.20.0
is compatible with other UI components and libraries you are using.- 99-99: The addition of
@types/carbon__colors
as a dev dependency is appropriate for TypeScript projects, providing type definitions for@carbon/colors
. This facilitates better development experience and type checking.spiffworkflow-backend/pyproject.toml (2)
- 36-37: The addition of
pymysql
andopenai
dependencies is aligned with the PR's objectives to enhance the project with AI and script assistance features. Ensure that these versions are compatible with the project's Python version and other dependencies.- 79-79: Updating
mysqlclient
to version^2.2.3
is a good practice to keep dependencies up-to-date. Verify that this version is compatible with the project's database version and SQLAlchemy.spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx (7)
- 20-22: The addition of
Stack
,TextArea
, andInlineLoading
components from@carbon/react
is appropriate for the new UI elements related to script assistance. Ensure these components are used in a way that aligns with the Carbon Design System guidelines.- 30-30: The addition of the
Information
icon from@carbon/icons-react
is suitable for providing informational tooltips or guidance within the UI. It's a good practice to use such visual cues to enhance user experience.- 32-32: Importing
gray
from@carbon/colors
is a good practice for maintaining consistency in UI color schemes. Ensure that thegray
color variable is used appropriately across the UI components to maintain a cohesive design.- 57-58: The introduction of custom hooks
useScriptAssistEnabled
anduseProcessScriptAssistMessage
is a good practice for encapsulating the logic related to fetching script assistance settings and processing script assistance messages. This enhances modularity and maintainability of the code.- 99-103: The addition of new state variables
scriptAssistValue
,scriptAssistError
, and the destructuring ofscriptAssistEnabled
,setScriptAssistQuery
,scriptAssistLoading
,scriptAssistResult
from custom hooks indicates a significant enhancement in handling script assistance functionality. Ensure that these state variables and hook results are used correctly throughout the component to manage the script assistance feature effectively.- 522-526: The use of
useEffect
to manually triggerhandleEditorScriptChange
whenscriptAssistResult
is updated is a practical workaround for the issue where dynamic updates to the editor's value do not trigger anonChange
event. This ensures that the script editor's content is kept in sync with the script assistance results.- 978-978: The conditional rendering of the
Script Assist
tab based onscriptAssistEnabled
is a good practice, ensuring that UI elements are only shown when the relevant feature is enabled. This enhances the user experience by avoiding confusion with unavailable features.spiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.py (1)
- 555-556: The addition of the permission
read
for/script-assist/enabled
andcreate
for/script-assist/process-message
is correctly implemented. These permissions align with the intended functionality of checking if script assistance is enabled and processing messages through the script assistance feature, respectively. However, ensure that the broader security implications of these permissions are considered, especially for thecreate
permission on/script-assist/process-message
, which allows for data submission. It's crucial to validate and sanitize inputs to prevent potential security vulnerabilities.spiffworkflow-backend/src/spiffworkflow_backend/api.yml (1)
- 177-189: The new API endpoint
/script-assist/enabled
is well-defined, with a clear operationId, summary, and response schema. It adheres to RESTful principles by using the appropriate HTTP method (GET
) for retrieving information. The summary and description provide clear information about the endpoint's purpose, which is to return the value ofSCRIPT_ASSIST_ENABLED
, indicating whether AI script assistance should be enabled in the UI.
spiffworkflow-backend/src/spiffworkflow_backend/config/default.py
Outdated
Show resolved
Hide resolved
spiffworkflow-backend/src/spiffworkflow_backend/config/default.py
Outdated
Show resolved
Hide resolved
spiffworkflow-frontend/src/hooks/useProcessScriptAssistQuery.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 3
Configuration used: .coderabbit.yaml
Files selected for processing (6)
- spiffworkflow-backend/src/spiffworkflow_backend/init.py (1 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/config/default.py (2 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/models/reference_cache.py (2 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py (1 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/services/authentication_service.py (3 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_service.py (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- spiffworkflow-backend/src/spiffworkflow_backend/init.py
- spiffworkflow-backend/src/spiffworkflow_backend/config/default.py
Additional comments: 3
spiffworkflow-backend/src/spiffworkflow_backend/models/reference_cache.py (2)
- 5-5: Removing the
type: ignore
comment for theflask_marshmallow.Schema
import indicates an improvement in type checking compliance. It's good practice to ensure that the codebase adheres to static type checking as much as possible, as it enhances code quality and maintainability.- 145-145: Similarly, removing the
type: ignore
comment for theReferenceSchema
class declaration is a positive change, suggesting that the type checking issues have been resolved. Continue to ensure that the codebase remains compliant with static type checking to maintain high code quality.spiffworkflow-backend/src/spiffworkflow_backend/services/authentication_service.py (1)
- 206-219: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [183-216]
The changes made to the
parse_jwt_token
method, including assigning the result ofjwt.decode
toparsed_token
and usingcast
to ensure the return type isdict
, are commendable. These improvements enhance code clarity and type safety, making the method more robust and easier to understand. Good job on making these enhancements.
spiffworkflow-backend/src/spiffworkflow_backend/services/workflow_service.py
Show resolved
Hide resolved
spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py
Outdated
Show resolved
Hide resolved
spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py
Outdated
Show resolved
Hide resolved
…l update spiff in a later pr w/ burnettk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yaml
Files selected for processing (2)
- spiffworkflow-backend/pyproject.toml (2 hunks)
- spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_authorization_service.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- spiffworkflow-backend/pyproject.toml
Additional comments: 1
spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_authorization_service.py (1)
- 461-462: The addition of permissions for
/script-assist/enabled
(read) and/script-assist/process-message
(create) aligns with the PR objectives to enhance the project with AI and script assistance features. These permissions seem appropriate for enabling script assistance functionality and processing messages through the script assist feature. Ensure that the access control for these endpoints is thoroughly tested, especially considering the potential sensitivity of processing messages through script assistance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 3
Configuration used: .coderabbit.yaml
Files selected for processing (5)
- spiffworkflow-backend/src/spiffworkflow_backend/api.yml (2 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/config/default.py (1 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py (1 hunks)
- spiffworkflow-frontend/src/hooks/useProcessScriptAssistQuery.tsx (1 hunks)
- spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx (6 hunks)
Files skipped from review as they are similar to previous changes (4)
- spiffworkflow-backend/src/spiffworkflow_backend/api.yml
- spiffworkflow-backend/src/spiffworkflow_backend/config/default.py
- spiffworkflow-frontend/src/hooks/useProcessScriptAssistQuery.tsx
- spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx
Additional comments: 5
spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py (5)
- 12-14: The
enabled()
function correctly checks the configuration to determine if script assistance is enabled and returns the status. This is a straightforward and effective implementation.- 18-20: Properly handling the case where the OpenAI API key is not set by returning a response indicating the issue. This is good practice for error handling and user feedback.
- 22-24: Checking if the script query is provided and returning an appropriate message if not. This is a good practice for validating input and providing clear feedback to the user.
- 36-53: The construction of the query and the use of the OpenAI API to process the script assistance request are implemented correctly. However, the static analysis tool's warning about SQL injection is a false positive in this context, as the query is for the OpenAI API, not a SQL database. Still, it's crucial to ensure that user input is sanitized and safely handled.
However, it's worth noting the static analysis tool's warning and ensuring that all user inputs are sanitized and validated to prevent any potential security vulnerabilities.
- 55-55: The function correctly processes the message, interacts with the OpenAI API, and returns the response. This implementation effectively achieves the desired functionality.
spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py
Show resolved
Hide resolved
spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py
Show resolved
Hide resolved
spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py
Show resolved
Hide resolved
… other errors and some ui tweaks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yaml
Files selected for processing (4)
- spiffworkflow-backend/src/spiffworkflow_backend/api.yml (2 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py (1 hunks)
- spiffworkflow-frontend/src/hooks/useProcessScriptAssistQuery.tsx (1 hunks)
- spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx (6 hunks)
Files skipped from review as they are similar to previous changes (4)
- spiffworkflow-backend/src/spiffworkflow_backend/api.yml
- spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py
- spiffworkflow-frontend/src/hooks/useProcessScriptAssistQuery.tsx
- spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yaml
Files selected for processing (2)
- spiffworkflow-backend/pyproject.toml (2 hunks)
- spiffworkflow-backend/src/spiffworkflow_backend/init.py (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- spiffworkflow-backend/pyproject.toml
- spiffworkflow-backend/src/spiffworkflow_backend/init.py
Created from @tcoz branch in PR #1134 but in the sartography project instead of a fork.
Summary by CodeRabbit
New Features
Enhancements
@carbon/colors
for improved color management in the frontend.Library Updates
Style