-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init updated code from posit-dev/posit-sdk-py#375
- Loading branch information
Showing
15 changed files
with
6,319 additions
and
0 deletions.
There are no files selected for viewing
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,3 +1,9 @@ | ||
/.quarto/ | ||
_site/ | ||
.Rproj.user | ||
|
||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class |
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,4 @@ | ||
chatlas/ | ||
rsconnect-python/ | ||
_swagger.json | ||
_swagger_prompt.md |
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,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 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,58 @@ | ||
# 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. | ||
* ![Access Granted](readme_access_granted.png) | ||
* 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.