Skip to content

Commit 2038d76

Browse files
committed
Chat prompt tweaks
1 parent b77e958 commit 2038d76

File tree

4 files changed

+4
-92
lines changed

4 files changed

+4
-92
lines changed

assistant-prompts/python_chat.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Note that for Chat applications, you should use Shiny Express syntax by default.
2323

2424
Pay very close attention to the chatlas documentation and Shiny example in it. Where there are differences between the chatlas API and the regular Shiny chat API, use the chatlas API instead, from that example.
2525

26+
If someone asks for a Chat application, use an OpenAI's gpt-4o (not gpt-4, but gpt-4o) model by default.
27+
2628
This is the Shiny Chat documentation:
2729

2830
{{ @includeFile("python_chat_genai_chatbots.md", it)/}}

assistant-prompts/python_chat_genai_chatbots.md

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -229,77 +229,6 @@ async def stream_generator(user_input):
229229
As we'll see later, there a couple other ways to append messages to the chat, like `chat.append_message()` and `with chat.message_stream_context()`.
230230
--->
231231

232-
## Bookmark messages
233-
234-
When a Shiny app reloads, the app returns to it's original state, unless the URL includes [bookmarked](../api/express/session.Session.qmd) state.[^1]
235-
Automatically updating the URL to include a bookmark of the chat state is a great way to help users return to their work if they accidentally refresh the page or unexpectedly lose their connection.
236-
237-
Adding bookmark support to an app generally requires some extra effort.
238-
At the very least, Shiny needs to know where and when to save state, and in some cases, how to save/restore it as well.[^2]
239-
The `.enable_bookmarking()` method makes this all a bit easier for bookmarking both the `chat` and `chat_client` instances.
240-
241-
::: {.panel-tabset .panel-pills}
242-
243-
### Express
244-
245-
```python
246-
from chatlas import ChatOllama
247-
from shiny.express import ui
248-
249-
chat_client = ChatOllama(model="llama3.2")
250-
251-
chat = ui.Chat(id="chat")
252-
chat.ui(messages=["Welcome!"])
253-
254-
chat.enable_bookmarking(
255-
chat_client,
256-
bookmark_store="url", # or "server"
257-
bookmark_on="response", # or None
258-
)
259-
```
260-
261-
### Core
262-
263-
```python
264-
from chatlas import ChatOllama
265-
from shiny import ui, App
266-
267-
app_ui = ui.page_fixed(
268-
ui.chat_ui(id="chat", messages=["Welcome!"])
269-
)
270-
271-
def server(input):
272-
chat_client = ChatOllama(model="llama3.2")
273-
chat = ui.Chat(id="chat")
274-
275-
chat.enable_bookmarking(
276-
chat_client,
277-
bookmark_on="response", # or None
278-
)
279-
280-
app = App(app_ui, server, bookmark_store="url")
281-
```
282-
283-
:::
284-
285-
Adding this `.enable_bookmarking()` call handles the where, when, and how of bookmarking chat state:
286-
287-
1. Where (`store`)
288-
- `"url"` store the state in the URL.
289-
- `"server"` store the state on the server. Consider this over `"url"` if you want to support a large amount of state, or have other bookmark state that can't be serialized to JSON.
290-
2. When (`bookmark_on`)
291-
- `"response"`: triggers a bookmark when an `"assistant"` response is appended.
292-
- `None`: don't trigger a bookmark. This assumes you'll be triggering bookmarks through other means (e.g., a button).
293-
3. How is handled automatically by registering the relevant `on_bookmark` and `on_restore` callbacks.
294-
295-
296-
Also note that when `.enable_bookmarking()` triggers a bookmark for you, it'll also update the URL query string to include the bookmark state.
297-
This way, when the user unexpectedly loses connection, they can load the current URL to restore the chat state, or go back to the original URL to start over.
298-
299-
[^1]: This can be especially frustrating behavior since hosted apps, by default, will close a idle session after a certain ([configurable](https://docs.posit.co/shinyapps.io/guide/applications/#advanced-settings)) amount of time.
300-
301-
[^2]: When server-side state can't be fully determined by the UI's `input` values alone, you'll need to register `on_bookmark` and `on_restore` callbacks to save and restore that server-state.
302-
303232
## Layout
304233

305234
### Fill

assistant-prompts/python_chat_shiny_examples.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ ui.page_opts(
157157
chat = ui.Chat(id="chat")
158158
chat.ui()
159159

160-
# Store chat state in the url when an "assistant" response occurs
161-
chat.enable_bookmarking(chat_client, bookmark_store="url")
162-
163160

164161
# Define a callback to run when the user submits a message
165162
@chat.on_user_submit
@@ -240,9 +237,6 @@ chat = ui.Chat(
240237
)
241238
chat.ui()
242239

243-
# Store chat state in the url when an "assistant" response occurs
244-
chat.enable_bookmarking(chat_client, bookmark_store="url")
245-
246240

247241
# Define a callback to run when the user submits a message
248242
@chat.on_user_submit
@@ -323,9 +317,6 @@ chat = ui.Chat(
323317
)
324318
chat.ui()
325319

326-
# Store chat state in the url when an "assistant" response occurs
327-
chat.enable_bookmarking(chat_client, bookmark_store="url")
328-
329320

330321
# Generate a response when the user submits a message
331322
@chat.on_user_submit
@@ -403,9 +394,6 @@ ui.page_opts(
403394
chat = ui.Chat(id="chat")
404395
chat.ui()
405396

406-
# Store chat state in the url when an "assistant" response occurs
407-
chat.enable_bookmarking(chat_client, bookmark_store="url")
408-
409397

410398
# Generate a response when the user submits a message
411399
@chat.on_user_submit
@@ -487,9 +475,6 @@ chat = ui.Chat(
487475
)
488476
chat.ui()
489477

490-
# Store chat state in the url when an "assistant" response occurs
491-
chat.enable_bookmarking(chat_client, bookmark_store="url")
492-
493478

494479
# Define a callback to run when the user submits a message
495480
@chat.on_user_submit
@@ -537,9 +522,6 @@ chat = ui.Chat(
537522
)
538523
chat.ui()
539524

540-
# Store chat state in the url when an "assistant" response occurs
541-
chat.enable_bookmarking(chat_client, bookmark_store="url")
542-
543525

544526
# Generate a response when the user submits a message
545527
@chat.on_user_submit
@@ -619,9 +601,6 @@ chat = ui.Chat(
619601
)
620602
chat.ui()
621603

622-
# Store chat state in the url when an "assistant" response occurs
623-
chat.enable_bookmarking(chat_client, bookmark_store="url")
624-
625604

626605
# Generate a response when the user submits a message
627606
@chat.on_user_submit

assistant-prompts/r_chat.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ OPENAI_API_KEY=XXXXXXXXXXX
1919
ANTHROPIC_API_KEY=XXXXXXXXXXX
2020
```
2121

22+
If someone asks for a Chat application, use an OpenAI's gpt-4o (not gpt-4, but gpt-4o) model by default.
23+
2224
{{ @includeFile("r_chat_shinychat.md", it)/}}
2325

2426
{{ @includeFile("r_chat_ellmer.md", it)/}}

0 commit comments

Comments
 (0)