Skip to content

Commit 4662abe

Browse files
authored
feat: posit SDK Assistant (#17)
1 parent 2406959 commit 4662abe

16 files changed

+6186
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
/.quarto/
22
_site/
33
.Rproj.user
4+
5+
6+
# Byte-compiled / optimized / DLL files
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
chatlas/
2+
rsconnect-python/
3+
_swagger.json
4+
_swagger_prompt.md

extensions/sdk-assistant/Makefile

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
PYTHON ?= $(shell command -v python || command -v python3)
2+
.DEFAULT_GOAL := help
3+
4+
.PHONY=FORCE
5+
FORCE:
6+
7+
all: _prompt.xml manifest.json FORCE ## [py] Lazily update the prompt and manifest
8+
9+
install: ensure-uv FORCE ## [py] Install the assistant
10+
uv pip install --python 3.12 -r requirements.txt
11+
12+
PORT=7000
13+
AUTORELOAD_PORT=7001
14+
shiny: _prompt.xml FORCE ## [py] Run the shiny app
15+
@$(MAKE) install 1>/dev/null
16+
uv run --python 3.12 python -m \
17+
shiny run \
18+
--port $(PORT) \
19+
--reload --autoreload-port $(AUTORELOAD_PORT) \
20+
--launch-browser \
21+
app.py
22+
23+
app.py:
24+
requirements.txt:
25+
manifest.json: app.py requirements.txt _prompt.xml
26+
@$(MAKE) manifest
27+
manifest: ensure-uv FORCE ## [py] Write the manifest file for GitHub
28+
uv run --python 3.12 \
29+
--with "rsconnect-python >= 1.21.0" \
30+
rsconnect write-manifest shiny \
31+
-x "_swagger_prompt.md" \
32+
-x "custom-prompt-instructions.md" \
33+
-x "uv_*.py" \
34+
-x "requirements.txt" \
35+
-x "Makefile" \
36+
-x "README.md" \
37+
-x ".DS_Store" \
38+
-x "repomix.config.json" \
39+
-x ".gitignore" \
40+
-x "chatlas/*" \
41+
-x "_swagger.json" \
42+
--overwrite \
43+
.
44+
45+
prompt: ensure-uv FORCE ## [py] Update the assistant's system prompt
46+
uv run --python 3.12 uv_update_prompt.py
47+
48+
test: ensure-uv FORCE ## [py] Test the assistant locally
49+
uv run --python 3.12 uv_test_chat.py
50+
51+
_prompt.xml: custom-prompt-instructions.md _swagger_prompt.md
52+
@$(MAKE) prompt
53+
54+
_swagger_prompt.md:
55+
@$(MAKE) swagger
56+
57+
swagger: ensure-uv FORCE ## [py] Update the Swagger file
58+
uv run uv_update_swagger.py
59+
60+
deploy: ensure-uv FORCE ## [py] Deploy the assistant
61+
uv run --python 3.12 \
62+
--with "rsconnect-python >= 1.21.0" \
63+
rsconnect deploy shiny \
64+
--server https://connect.posit.it/ \
65+
--app-id 21ac1399-b840-4356-a35c-bc37d10ef1d8 \
66+
.
67+
68+
# Do not add a dep on `ensure-uv` to avoid recursive depencencies
69+
.venv:
70+
uv venv
71+
ensure-uv: FORCE
72+
@if ! command -v uv >/dev/null; then \
73+
$(PYTHON) -m ensurepip && $(PYTHON) -m pip install "uv >= 0.5.22"; \
74+
fi
75+
@# Install virtual environment (before calling `uv pip install ...`)
76+
@$(MAKE) .venv 1>/dev/null
77+
@# Be sure recent uv is installed
78+
@uv pip install "uv >= 0.4.27" --quiet
79+
80+
help: FORCE ## Show help messages for make targets
81+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; { \
82+
printf "\033[32m%-18s\033[0m", $$1; \
83+
if ($$2 ~ /^\[docs\]/) { \
84+
printf "\033[34m[docs]\033[0m%s\n", substr($$2, 7); \
85+
} else if ($$2 ~ /^\[py\]/) { \
86+
printf " \033[33m[py]\033[0m%s\n", substr($$2, 5); \
87+
} else if ($$2 ~ /^\[ext\]/) { \
88+
printf " \033[35m[ext]\033[0m%s\n", substr($$2, 6); \
89+
} else if ($$2 ~ /^\[r\]/) { \
90+
printf " \033[31m[r]\033[0m%s\n", substr($$2, 4); \
91+
} else { \
92+
printf " %s\n", $$2; \
93+
} \
94+
}'

extensions/sdk-assistant/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Posit Connect SDK Assistant
2+
3+
![SDK Assistant](sdk-assistant.gif)
4+
5+
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).
6+
7+
Currently, it does not execute any code.
8+
9+
## Usage
10+
11+
To run the assistant, simply run the following command:
12+
13+
```bash
14+
make shiny
15+
```
16+
17+
## LLM
18+
19+
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.
20+
21+
**Requirements:**
22+
* Model must be enabled.
23+
* ![Access Granted](readme_access_granted.png)
24+
* You must have access to the model. ("Access Granted" in green in image)
25+
* The model must be enabled in the region you are running the assistant. This app uses `us-east-1`. ("N. Virginia" in image)
26+
* Model ID must be the "Cross-region Interference" > "Inference profile ID" value. Ex: `"us.anthropic.claude-3-sonnet-20240229-v1:0"`
27+
* For local development, you must be logged into the AWS CLI within your terminal's session.
28+
* 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`.
29+
30+
## Development
31+
32+
To update the custom prompt, edit the `custom-prompt-instructions.md` file.
33+
34+
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`.
35+
36+
`_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.
37+
38+
39+
### Future
40+
41+
Possible default prompts:
42+
* [Current default prompt] What are the pieces of Posit connect and how do they fit together?
43+
* Can you create a sequence diagram for the typical workflow?
44+
45+
46+
### Possible TODOs
47+
48+
* Provide common workflow examples for different User types:
49+
* How to publish content (publisher)
50+
* How to add a user to a group (admin)
51+
52+
### Deployment
53+
54+
To deploy the assistant, run the following command:
55+
56+
```bash
57+
make deploy
58+
```

0 commit comments

Comments
 (0)