-
Notifications
You must be signed in to change notification settings - Fork 3
feat: posit SDK Assistant
#17
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c4d3c02
Init updated code from https://github.com/posit-dev/posit-sdk-py/pull…
schloerke 45eae3c
Add gif
schloerke ca30066
Use `@reactive.event()` on chat_ui.messages
schloerke 1d55940
Remove comment
schloerke f35a845
Remove link to private demo
schloerke f73fe9d
Remove commented line
schloerke 7382a3f
Use `pathlib` methods over `os`
schloerke ba6bb95
Remove unnecessary methods from swagger processing; Fix path errors.
schloerke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,3 +1,9 @@ | ||
| /.quarto/ | ||
| _site/ | ||
| .Rproj.user | ||
|
|
||
|
|
||
| # Byte-compiled / optimized / DLL files | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class |
This file contains hidden or 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,4 @@ | ||
| chatlas/ | ||
| rsconnect-python/ | ||
| _swagger.json | ||
| _swagger_prompt.md |
This file contains hidden or 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,94 @@ | ||
| PYTHON ?= $(shell command -v python || command -v python3) | ||
| .DEFAULT_GOAL := help | ||
|
|
||
| .PHONY=FORCE | ||
| FORCE: | ||
|
|
||
| all: _prompt.xml manifest.json FORCE ## [py] Lazily update the prompt and manifest | ||
|
|
||
| install: ensure-uv FORCE ## [py] Install the assistant | ||
| uv pip install --python 3.12 -r requirements.txt | ||
|
|
||
| PORT=7000 | ||
| AUTORELOAD_PORT=7001 | ||
| shiny: _prompt.xml FORCE ## [py] Run the shiny app | ||
| @$(MAKE) install 1>/dev/null | ||
| uv run --python 3.12 python -m \ | ||
| shiny run \ | ||
| --port $(PORT) \ | ||
| --reload --autoreload-port $(AUTORELOAD_PORT) \ | ||
| --launch-browser \ | ||
| app.py | ||
|
|
||
| app.py: | ||
| requirements.txt: | ||
| manifest.json: app.py requirements.txt _prompt.xml | ||
| @$(MAKE) manifest | ||
| manifest: ensure-uv FORCE ## [py] Write the manifest file for GitHub | ||
| uv run --python 3.12 \ | ||
| --with "rsconnect-python >= 1.21.0" \ | ||
| rsconnect write-manifest shiny \ | ||
| -x "_swagger_prompt.md" \ | ||
| -x "custom-prompt-instructions.md" \ | ||
| -x "uv_*.py" \ | ||
| -x "requirements.txt" \ | ||
| -x "Makefile" \ | ||
| -x "README.md" \ | ||
| -x ".DS_Store" \ | ||
| -x "repomix.config.json" \ | ||
| -x ".gitignore" \ | ||
| -x "chatlas/*" \ | ||
| -x "_swagger.json" \ | ||
| --overwrite \ | ||
| . | ||
|
|
||
| prompt: ensure-uv FORCE ## [py] Update the assistant's system prompt | ||
| uv run --python 3.12 uv_update_prompt.py | ||
|
|
||
| test: ensure-uv FORCE ## [py] Test the assistant locally | ||
| uv run --python 3.12 uv_test_chat.py | ||
|
|
||
| _prompt.xml: custom-prompt-instructions.md _swagger_prompt.md | ||
| @$(MAKE) prompt | ||
|
|
||
| _swagger_prompt.md: | ||
| @$(MAKE) swagger | ||
|
|
||
| swagger: ensure-uv FORCE ## [py] Update the Swagger file | ||
| uv run uv_update_swagger.py | ||
|
|
||
| deploy: ensure-uv FORCE ## [py] Deploy the assistant | ||
| uv run --python 3.12 \ | ||
| --with "rsconnect-python >= 1.21.0" \ | ||
| rsconnect deploy shiny \ | ||
| --server https://connect.posit.it/ \ | ||
| --app-id 21ac1399-b840-4356-a35c-bc37d10ef1d8 \ | ||
| . | ||
|
|
||
| # Do not add a dep on `ensure-uv` to avoid recursive depencencies | ||
| .venv: | ||
| uv venv | ||
| ensure-uv: FORCE | ||
| @if ! command -v uv >/dev/null; then \ | ||
| $(PYTHON) -m ensurepip && $(PYTHON) -m pip install "uv >= 0.5.22"; \ | ||
| fi | ||
| @# Install virtual environment (before calling `uv pip install ...`) | ||
| @$(MAKE) .venv 1>/dev/null | ||
| @# Be sure recent uv is installed | ||
| @uv pip install "uv >= 0.4.27" --quiet | ||
|
|
||
| help: FORCE ## Show help messages for make targets | ||
| @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; { \ | ||
| printf "\033[32m%-18s\033[0m", $$1; \ | ||
| if ($$2 ~ /^\[docs\]/) { \ | ||
| printf "\033[34m[docs]\033[0m%s\n", substr($$2, 7); \ | ||
| } else if ($$2 ~ /^\[py\]/) { \ | ||
| printf " \033[33m[py]\033[0m%s\n", substr($$2, 5); \ | ||
| } else if ($$2 ~ /^\[ext\]/) { \ | ||
| printf " \033[35m[ext]\033[0m%s\n", substr($$2, 6); \ | ||
| } else if ($$2 ~ /^\[r\]/) { \ | ||
| printf " \033[31m[r]\033[0m%s\n", substr($$2, 4); \ | ||
| } else { \ | ||
| printf " %s\n", $$2; \ | ||
| } \ | ||
| }' |
This file contains hidden or 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,60 @@ | ||
| # Posit Connect SDK Assistant | ||
|
|
||
|  | ||
|
|
||
| This is a tool to help developers understand how to use the [Posit Connect SDK python package](https://github.com/posit-dev/posit-sdk-py). | ||
|
|
||
| Currently, it does not execute any code. | ||
|
|
||
| ## Usage | ||
|
|
||
| To view the live application, visit [this link](https://connect.posit.it/sdk-assistant/). | ||
|
|
||
| To run the assistant, simply run the following command: | ||
|
|
||
| ```bash | ||
| make shiny | ||
| ``` | ||
|
|
||
| ## LLM | ||
|
|
||
| The assistant uses AWS Bedrock to run the Anthropic model. The model is a Claude model that is trained on the Posit Connect SDK. The model is trained on the custom prompt and the Posit Connect SDK documentation and function signatures. | ||
|
|
||
| **Requirements:** | ||
| * Model must be enabled. | ||
| *  | ||
| * You must have access to the model. ("Access Granted" in green in image) | ||
| * The model must be enabled in the region you are running the assistant. This app uses `us-east-1`. ("N. Virginia" in image) | ||
| * Model ID must be the "Cross-region Interference" > "Inference profile ID" value. Ex: `"us.anthropic.claude-3-sonnet-20240229-v1:0"` | ||
| * For local development, you must be logged into the AWS CLI within your terminal's session. | ||
| * To log into the AWS Browser Console console within the browser, call `aws-console` in a termainal with an active AWS session. Install `aws-console` by running `brew install aws-console`. | ||
|
|
||
| ## Development | ||
|
|
||
| To update the custom prompt, edit the `custom-prompt-instructions.md` file. | ||
|
|
||
| To compile the whole prompt, run `make prompt`. This will extract the typings from [posit-sdk](https://github.com/posit-dev/posit-sdk-py), download the latest [Connect swagger json file](https://docs.posit.co/connect/api/swagger.json), and compile the typings/swagger/custom-prompt into a single file: `_prompt.xml`. | ||
|
|
||
| `_prompt.xml` is an output file from `repomix`. [Repomix](https://github.com/yamadashy/repomix) outputs the content in XML format which is preferred by the Claude model. | ||
|
|
||
|
|
||
| ### Future | ||
|
|
||
| Possible default prompts: | ||
| * [Current default prompt] What are the pieces of Posit connect and how do they fit together? | ||
| * Can you create a sequence diagram for the typical workflow? | ||
|
|
||
|
|
||
| ### Possible TODOs | ||
|
|
||
| * Provide common workflow examples for different User types: | ||
| * How to publish content (publisher) | ||
| * How to add a user to a group (admin) | ||
|
|
||
| ### Deployment | ||
|
|
||
| To deploy the assistant, run the following command: | ||
|
|
||
| ```bash | ||
| make deploy | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.