Skip to content

Commit 0afca1c

Browse files
JasonWeillpre-commit-ci[bot]3coinsandrii-i
authored
Chat help message on load (#277)
* Shortens text box placeholder * Adds help command * Adds link to docs * Simplifies help handler * Initial help message on load * Reverts changes to default.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Copy edit: send -> ask * Update packages/jupyter-ai/jupyter_ai/chat_handlers/help.py Co-authored-by: Piyush Jain <[email protected]> * Simplifies reply logic * Tightens spacing for bulleted lists in markdown * Slash commands, mentions magic commands * Plural notebooks * Update packages/jupyter-ai/jupyter_ai/chat_handlers/help.py Co-authored-by: Andrii Ieroshenko <[email protected]> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Piyush Jain <[email protected]> Co-authored-by: Andrii Ieroshenko <[email protected]>
1 parent b0dd34f commit 0afca1c

File tree

6 files changed

+49
-4
lines changed

6 files changed

+49
-4
lines changed

packages/jupyter-ai/jupyter_ai/chat_handlers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
from .clear import ClearChatHandler
44
from .default import DefaultChatHandler
55
from .generate import GenerateChatHandler
6+
from .help import HelpChatHandler
67
from .learn import LearnChatHandler
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import time
2+
from typing import List
3+
from uuid import uuid4
4+
5+
from jupyter_ai.models import AgentChatMessage, HumanChatMessage
6+
7+
from .base import BaseChatHandler
8+
9+
HELP_MESSAGE = """Hi there! I'm Jupyternaut, your programming assistant.
10+
You can ask me a question using the text box below. You can also use these commands:
11+
* `/learn` — Teach Jupyternaut about files on your system
12+
* `/ask` — Ask a question about your learned data
13+
* `/generate` — Generate a Jupyter notebook from a text prompt
14+
* `/clear` — Clear the chat window
15+
* `/help` — Display this help message
16+
17+
Jupyter AI includes [magic commands](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#the-ai-and-ai-magic-commands) that you can use in your notebooks.
18+
For more information, see the [documentation](https://jupyter-ai.readthedocs.io).
19+
"""
20+
21+
22+
def HelpMessage():
23+
return AgentChatMessage(
24+
id=uuid4().hex,
25+
time=time.time(),
26+
body=HELP_MESSAGE,
27+
reply_to="",
28+
)
29+
30+
31+
class HelpChatHandler(BaseChatHandler):
32+
def __init__(self, *args, **kwargs):
33+
super().__init__(*args, **kwargs)
34+
35+
async def _process_message(self, message: HumanChatMessage):
36+
self.reply(HELP_MESSAGE, message)

packages/jupyter-ai/jupyter_ai/extension.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
ClearChatHandler,
1010
DefaultChatHandler,
1111
GenerateChatHandler,
12+
HelpChatHandler,
1213
LearnChatHandler,
1314
)
15+
from .chat_handlers.help import HelpMessage
1416
from .config_manager import ConfigManager
1517
from .handlers import (
1618
ChatHistoryHandler,
@@ -54,7 +56,7 @@ def initialize_settings(self):
5456
# list of chat messages to broadcast to new clients
5557
# this is only used to render the UI, and is not the conversational
5658
# memory object used by the LM chain.
57-
self.settings["chat_history"] = []
59+
self.settings["chat_history"] = [HelpMessage()]
5860

5961
# get reference to event loop
6062
# `asyncio.get_event_loop()` is deprecated in Python 3.11+, in favor of
@@ -90,6 +92,7 @@ def initialize_settings(self):
9092
root_dir=self.serverapp.root_dir,
9193
dask_client_future=dask_client_future,
9294
)
95+
help_chat_handler = HelpChatHandler(**chat_handler_kwargs)
9396
ask_chat_handler = AskChatHandler(
9497
**chat_handler_kwargs, retriever=learn_chat_handler
9598
)
@@ -99,6 +102,7 @@ def initialize_settings(self):
99102
"/clear": clear_chat_handler,
100103
"/generate": generate_chat_handler,
101104
"/learn": learn_chat_handler,
105+
"/help": help_chat_handler,
102106
}
103107

104108
latency_ms = round((time.time() - start) * 1000)

packages/jupyter-ai/src/components/chat-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function ChatInput(props: ChatInputProps): JSX.Element {
6060
variant="outlined"
6161
multiline
6262
onKeyDown={handleKeyDown}
63-
placeholder="Ask Jupyternaut anything"
63+
placeholder="Ask Jupyternaut"
6464
InputProps={{
6565
endAdornment: (
6666
<InputAdornment position="end">

packages/jupyter-ai/src/components/chat.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ function ChatBody({
127127
<Stack spacing={4}>
128128
<p className="jp-ai-ChatSettings-welcome">
129129
Welcome to Jupyter AI! To get started, please select a language
130-
model to chat with from the settings panel. You will also likely
131-
need to provide API credentials, so be sure to have those handy.
130+
model to chat with from the settings panel. You may also need to
131+
provide API credentials, so have those handy.
132132
</p>
133133
<Button
134134
variant="contained"

packages/jupyter-ai/style/react-markdown.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
padding: 0;
77
}
88

9+
.jp-RenderedHTMLCommon.jp-ai-react-markdown ul:not(.list-inline) {
10+
padding-left: 1em;
11+
}
12+
913
/* !important specifier required to override inline styles from Prism */
1014
.jp-ai-code {
1115
font-family: var(--jp-code-font-family) !important;

0 commit comments

Comments
 (0)