Skip to content

Commit 00d72db

Browse files
authored
refactor: Update to shiny v1.4.0 (#54)
1 parent 8252f39 commit 00d72db

File tree

6 files changed

+476
-92
lines changed

6 files changed

+476
-92
lines changed

extensions/sdk-assistant/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ _swagger_prompt.md:
5757
swagger: ensure-uv FORCE ## [py] Update the Swagger file
5858
uv run uv_update_swagger.py
5959

60+
# --server https://pub.demo.posit.team/ \
6061
deploy: ensure-uv FORCE ## [py] Deploy the assistant
6162
uv run --python 3.12 \
6263
--with "rsconnect-python >= 1.21.0" \

extensions/sdk-assistant/_prompt.xml

Lines changed: 441 additions & 27 deletions
Large diffs are not rendered by default.

extensions/sdk-assistant/app.py

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import chatlas
77
import faicons
88

9-
from shiny import App, Inputs, reactive, render, session, ui
9+
from shiny import App, Inputs, reactive, render, ui
1010

1111
app_ui = ui.page_fillable(
1212
ui.h1(
@@ -30,9 +30,7 @@
3030
font-size: medium;
3131
vertical-align: middle;
3232
}
33-
.sdk_suggested_prompt {
34-
cursor: pointer;
35-
border-radius: 0.5em;
33+
.suggestion {
3634
display: list-item;
3735
}
3836
.external-link {
@@ -46,31 +44,6 @@
4644
}
4745
"""
4846
),
49-
ui.tags.script(
50-
"""
51-
$(() => {
52-
$("body").click(function(e) {
53-
if (!$(e.target).hasClass("sdk_suggested_prompt")) {
54-
return;
55-
}
56-
window.Shiny.setInputValue("new_sdk_prompt", $(e.target).text());
57-
});
58-
})
59-
window.Shiny.addCustomMessageHandler("submit-chat", function(message) {
60-
const enterEvent = new KeyboardEvent('keydown', {
61-
key: 'Enter',
62-
code: 'Enter',
63-
keyCode: 13,
64-
which: 13,
65-
});
66-
67-
// Dispatch the 'Enter' event on the input element
68-
console.log("Dispatching Enter event", message);
69-
document.querySelector("#" + message['id'] + " textarea#chat_user_input").dispatchEvent(enterEvent);
70-
});
71-
72-
"""
73-
),
7447
fillable_mobile=True,
7548
)
7649

@@ -90,12 +63,6 @@ def server(input: Inputs): # noqa: A002
9063

9164
chat_ui = ui.Chat("chat")
9265

93-
async def submit_chat(new_value: str):
94-
chat_ui.update_user_input(value=new_value)
95-
96-
local_session = session.require_active_session(None)
97-
await local_session.send_custom_message("submit-chat", {"id": "chat"})
98-
9966
@render.text
10067
@reactive.event(chat_ui.messages)
10168
def cost():
@@ -116,6 +83,22 @@ def cost():
11683
ans = ans + "0"
11784
return ans
11885

86+
@reactive.effect
87+
@reactive.event(input.info_link)
88+
async def _():
89+
modal = ui.modal(
90+
ui.h1("Information"),
91+
ui.h3("Model"),
92+
ui.pre(
93+
f"Model: {aws_model}\nRegion: {aws_region}",
94+
),
95+
ui.h3("System prompt"),
96+
ui.pre(chat.system_prompt),
97+
easy_close=True,
98+
size="xl",
99+
)
100+
ui.modal_show(modal)
101+
119102
@render.ui
120103
def new_gh_issue():
121104
messages = chat_ui.messages()
@@ -130,7 +113,7 @@ def new_gh_issue():
130113

131114
with tempfile.TemporaryDirectory() as tmpdirname:
132115
export_path = pathlib.Path(tmpdirname) / "chat_export.md"
133-
chat.export(export_path, include="all", include_system_prompt=False)
116+
chat.export(export_path, content="all", include_system_prompt=False)
134117

135118
exported_content = export_path.read_text()
136119

@@ -203,36 +186,16 @@ async def _():
203186
)
204187
)
205188

206-
@reactive.effect
207-
@reactive.event(input.new_sdk_prompt)
208-
async def _():
209-
await submit_chat(input.new_sdk_prompt())
210-
211189
@reactive.effect
212190
async def _init_chat_on_load():
213-
await submit_chat(
214-
"What are the pieces of Posit connect and how do they fit together?"
191+
chat_ui.update_user_input(
192+
value="What are the pieces of Posit connect and how do they fit together?",
193+
submit=True,
215194
)
216195

217196
# Remove the effect after the first run
218197
_init_chat_on_load.destroy()
219198

220-
@reactive.effect
221-
@reactive.event(input.info_link)
222-
async def _():
223-
modal = ui.modal(
224-
ui.h1("Information"),
225-
ui.h3("Model"),
226-
ui.pre(
227-
f"Model: {aws_model}\nRegion: {aws_region}",
228-
),
229-
ui.h3("System prompt"),
230-
ui.pre(chat.system_prompt),
231-
easy_close=True,
232-
size="xl",
233-
)
234-
ui.modal_show(modal)
235-
236199

237200
app = App(
238201
app_ui,

extensions/sdk-assistant/custom-prompt-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ This is a serious exercise. Please provide evidence for each answer and double c
66

77
If a question is unclear, please ask for clarification.
88

9-
If you feel there is an opportunity for further exploration, please suggest the prompts. Wrap each suggested prompt within a <a class="sdk_suggested_prompt"></a> tag.
9+
If you feel there is an opportunity for further exploration, please suggest the prompts. Wrap each suggested prompt within a <a class="suggestion submit"></a> tag.

extensions/sdk-assistant/manifest.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,25 @@
99
"version": "3.12.7",
1010
"package_manager": {
1111
"name": "pip",
12-
"version": "24.3.1",
12+
"version": "25.0.1",
1313
"package_file": "requirements.txt"
1414
}
1515
},
1616
"files": {
1717
"requirements.txt": {
18-
"checksum": "f5f6e6c263f93a4c1c8e6f040af97a52"
18+
"checksum": "31f19ff2394253c464d65b5a590cc6f6"
1919
},
2020
"_prompt.xml": {
21-
"checksum": "11b53de6fe16486696042838d0a64f86"
21+
"checksum": "a650dd564e1613b20e170953f0cc5c2a"
2222
},
2323
"app.py": {
24-
"checksum": "0780643a8b9af200326f582a6f8b8be4"
24+
"checksum": "4f0d50d6b540f03b73311e0dac0cfe9f"
25+
},
26+
"readme_access_granted.png": {
27+
"checksum": "7c995c651d8346bfd2616c7e93331520"
28+
},
29+
"sdk-assistant.gif": {
30+
"checksum": "cd81de01a9df80afe635cb48eb4f0880"
2531
},
2632
"www/new_gh_issue.svg": {
2733
"checksum": "0e700e135c5062d209ea19fb20725ea3"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
anthropic[bedrock]
22
chatlas @ git+https://github.com/posit-dev/chatlas@main
33
faicons
4-
shiny
4+
shiny>=1.4.0

0 commit comments

Comments
 (0)