Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat help message on load #277

Merged
merged 14 commits into from
Jul 22, 2023
1 change: 1 addition & 0 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
from .clear import ClearChatHandler
from .default import DefaultChatHandler
from .generate import GenerateChatHandler
from .help import HelpChatHandler
from .learn import LearnChatHandler
36 changes: 36 additions & 0 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import time
from typing import List
from uuid import uuid4

from jupyter_ai.models import AgentChatMessage, HumanChatMessage

from .base import BaseChatHandler

HELP_MESSAGE = """Hi there! I'm Jupyternaut, your programming assistant.
You can ask me a question using the text box below. You can also use these commands:
* `/learn` — Teach Jupyternaut about files on your system
* `/ask` — Ask a question about your learned data
* `/generate` — Generate a Jupyter notebook from a text prompt
* `/clear` — Clear the chat window
* `/help` — Display this help message

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.
For more information, see the [documentation](https://jupyter-ai.readthedocs.io).
"""


def HelpMessage():
return AgentChatMessage(
id=uuid4().hex,
time=time.time(),
body=HELP_MESSAGE,
reply_to="",
)


class HelpChatHandler(BaseChatHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

async def _process_message(self, message: HumanChatMessage):
self.reply(HELP_MESSAGE, message)
6 changes: 5 additions & 1 deletion packages/jupyter-ai/jupyter_ai/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
ClearChatHandler,
DefaultChatHandler,
GenerateChatHandler,
HelpChatHandler,
LearnChatHandler,
)
from .chat_handlers.help import HelpMessage
from .config_manager import ConfigManager
from .handlers import (
ChatHistoryHandler,
Expand Down Expand Up @@ -54,7 +56,7 @@ def initialize_settings(self):
# list of chat messages to broadcast to new clients
# this is only used to render the UI, and is not the conversational
# memory object used by the LM chain.
self.settings["chat_history"] = []
self.settings["chat_history"] = [HelpMessage()]

# get reference to event loop
# `asyncio.get_event_loop()` is deprecated in Python 3.11+, in favor of
Expand Down Expand Up @@ -90,6 +92,7 @@ def initialize_settings(self):
root_dir=self.serverapp.root_dir,
dask_client_future=dask_client_future,
)
help_chat_handler = HelpChatHandler(**chat_handler_kwargs)
ask_chat_handler = AskChatHandler(
**chat_handler_kwargs, retriever=learn_chat_handler
)
Expand All @@ -99,6 +102,7 @@ def initialize_settings(self):
"/clear": clear_chat_handler,
"/generate": generate_chat_handler,
"/learn": learn_chat_handler,
"/help": help_chat_handler,
}

latency_ms = round((time.time() - start) * 1000)
Expand Down
2 changes: 1 addition & 1 deletion packages/jupyter-ai/src/components/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function ChatInput(props: ChatInputProps): JSX.Element {
variant="outlined"
multiline
onKeyDown={handleKeyDown}
placeholder="Ask Jupyternaut anything"
placeholder="Ask Jupyternaut"
InputProps={{
endAdornment: (
<InputAdornment position="end">
Expand Down
4 changes: 2 additions & 2 deletions packages/jupyter-ai/src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function ChatBody({
<Stack spacing={4}>
<p className="jp-ai-ChatSettings-welcome">
Welcome to Jupyter AI! To get started, please select a language
model to chat with from the settings panel. You will also likely
need to provide API credentials, so be sure to have those handy.
model to chat with from the settings panel. You may also need to
provide API credentials, so have those handy.
</p>
<Button
variant="contained"
Expand Down
4 changes: 4 additions & 0 deletions packages/jupyter-ai/style/react-markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
padding: 0;
}

.jp-RenderedHTMLCommon.jp-ai-react-markdown ul:not(.list-inline) {
padding-left: 1em;
}

/* !important specifier required to override inline styles from Prism */
.jp-ai-code {
font-family: var(--jp-code-font-family) !important;
Expand Down
Loading