-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update README.md 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. * Revert "Update README.md" This reverts commit 096887c. * README update and native code patch Some details for user that might be running Python3, Mac, and want to run everything locally/natively. * Implement basic tooltips 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 * Naive AI code editor implementation A working starting point. * Implement API to return if script assist should be enabled Along with route and function, api config, etc. * UI calls backend to see if script assist is enabled. If it is, loads the related UI, otherwise it doesn't appear. * Moving forward with service for message processing. * Services scaffolded * Open API called, prompt-engineered to get script only. * Little cleanup work * Enabled + process message working. Had to find all the places permissions are enabled, etc. * Cleanup, comments, etc. * Env vars, styling, error cases, conditional display of script assist 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.) * Fix tooltips, clean up some styling. Finishing it off. * Add loader and error message Complete UX stuff * Update useScriptAssistEnabled.tsx Remove log * Update script_assist_controller.py Add this tweak to avoid TMI. * Some reasonable changes suggested by the build process * Comments from PR. * Update ProcessModelEditDiagram.tsx Should (but I don't know how to tell yet) call the change handler that wasn't firing before. * updated the permissions setting in authorization service w/ burnettk * precommit now passes. tests are failing w/ burnettk * pinned SpiffWorkflow to known working version and fixed tests. we will update spiff in a later pr w/ burnettk * made changes based on coderabbi suggestions * updated the error handling to be more inline with how we have handled other errors and some ui tweaks * removed pymysql package w/ burnettk * forgot to remove pymysql from lock file w/ burnettk --------- Co-authored-by: Tim Consolazio <[email protected]> Co-authored-by: Kevin Burnett <[email protected]> Co-authored-by: jasquat <[email protected]>
- Loading branch information
1 parent
c154c0a
commit a71af6e
Showing
19 changed files
with
1,695 additions
and
993 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
spiffworkflow-backend/src/spiffworkflow_backend/config/permissions/local_development.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
users: | ||
admin: | ||
service: local_open_id | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
spiffworkflow-backend/src/spiffworkflow_backend/routes/script_assist_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from flask import current_app | ||
from flask import jsonify | ||
from flask import make_response | ||
from flask.wrappers import Response | ||
from openai import OpenAI | ||
|
||
from spiffworkflow_backend.exceptions.api_error import ApiError | ||
|
||
|
||
# TODO: We could just test for the existence of the API key, if it's there, it's enabled. | ||
# Leaving them separate now for clarity. | ||
# Note there is an async version in the openai lib if that's preferable. | ||
def enabled() -> Response: | ||
assist_enabled = current_app.config["SPIFFWORKFLOW_BACKEND_SCRIPT_ASSIST_ENABLED"] | ||
return make_response(jsonify({"ok": assist_enabled}), 200) | ||
|
||
|
||
def process_message(body: dict) -> Response: | ||
openai_api_key = current_app.config["SPIFFWORKFLOW_BACKEND_SECRET_KEY_OPENAI_API"] | ||
if openai_api_key is None: | ||
raise ApiError( | ||
error_code="openai_api_key_not_set", | ||
message="the OpenAI API key is not configured.", | ||
) | ||
|
||
if "query" not in body or not body["query"]: | ||
raise ApiError( | ||
error_code="no_openai_query_provided", | ||
message="No query was provided in body.", | ||
) | ||
|
||
# Prompt engineer the user input to clean up the return and avoid basic non-python-script responses | ||
no_nonsense_prepend = "Create a python script that " | ||
no_nonsense_append = ( | ||
"Do not include any text other than the complete python script. " | ||
"Do not include any lines with comments. " | ||
"Reject any request that does not appear to be for a python script." | ||
"Do not include the word 'OpenAI' in any responses." | ||
) | ||
|
||
# Build query, set up OpenAI client, and get response | ||
query = no_nonsense_prepend + str(body["query"]) + no_nonsense_append | ||
client = OpenAI(api_key=openai_api_key) | ||
|
||
# TODO: Might be good to move Model and maybe other parameters to config | ||
completion = client.chat.completions.create( | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": query, | ||
} | ||
], | ||
model="gpt-3.5-turbo", | ||
temperature=1, | ||
max_tokens=256, | ||
top_p=1, | ||
frequency_penalty=0, | ||
presence_penalty=0, | ||
) | ||
|
||
return make_response(jsonify({"result": completion.choices[0].message.content}), 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
spiffworkflow-frontend/src/hooks/useProcessScriptAssistQuery.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useEffect, useState } from 'react'; | ||
import HttpService from '../services/HttpService'; | ||
|
||
/** | ||
* When scriptAssistQuery is set, trigger the call to the AI service | ||
* and set the result to update any watchers. | ||
*/ | ||
const useProcessScriptAssistMessage = () => { | ||
const [scriptAssistQuery, setScriptAssistQuery] = useState<string>(''); | ||
const [scriptAssistResult, setScriptAssistResult] = useState<Record< | ||
string, | ||
any | ||
> | null>(null); | ||
const [scriptAssistLoading, setScriptAssistLoading] = | ||
useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
const handleResponse = (response: Record<string, any>) => { | ||
setScriptAssistResult(response); | ||
setScriptAssistQuery(''); | ||
setScriptAssistLoading(false); | ||
}; | ||
|
||
/** Possibly make this check more robust, depending on what we see in use. */ | ||
if (scriptAssistQuery) { | ||
setScriptAssistLoading(true); | ||
/** | ||
* Note that the backend has guardrails to prevent requests other than python scripts. | ||
* See script_assist_controller.py | ||
*/ | ||
HttpService.makeCallToBackend({ | ||
httpMethod: 'POST', | ||
path: `/script-assist/process-message`, | ||
postBody: { query: scriptAssistQuery.trim() }, | ||
successCallback: handleResponse, | ||
failureCallback: (error: any) => { | ||
setScriptAssistResult(error); | ||
setScriptAssistQuery(''); | ||
setScriptAssistLoading(false); | ||
}, | ||
}); | ||
} | ||
}, [scriptAssistQuery, setScriptAssistQuery, scriptAssistResult]); | ||
|
||
return { | ||
setScriptAssistQuery, | ||
scriptAssistLoading, | ||
scriptAssistResult, | ||
}; | ||
}; | ||
|
||
export default useProcessScriptAssistMessage; |
26 changes: 26 additions & 0 deletions
26
spiffworkflow-frontend/src/hooks/useScriptAssistEnabled.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useEffect, useState } from 'react'; | ||
import HttpService from '../services/HttpService'; | ||
|
||
/** Basic fetcher for the env value from the backend */ | ||
const useScriptAssistEnabled = () => { | ||
const [scriptAssistEnabled, setScriptAssistEnabled] = useState(null); | ||
|
||
useEffect(() => { | ||
if (scriptAssistEnabled === null) { | ||
const handleResponse = (response: any) => { | ||
setScriptAssistEnabled(response.ok); | ||
}; | ||
|
||
HttpService.makeCallToBackend({ | ||
path: `/script-assist/enabled`, | ||
successCallback: handleResponse, | ||
}); | ||
} | ||
}, [scriptAssistEnabled]); | ||
|
||
return { | ||
scriptAssistEnabled, | ||
}; | ||
}; | ||
|
||
export default useScriptAssistEnabled; |
Oops, something went wrong.