Skip to content

Commit

Permalink
Updates docs, removes custom handler from source and config
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonWeill committed Dec 4, 2023
1 parent 05a3068 commit 6542def
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
3 changes: 2 additions & 1 deletion docs/source/contributors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

This page is intended for people interested in building new or modified functionality for Jupyter AI.

If you would like to build applications that enhance Jupyter AI, please see the {doc}`developer's guide </developers/index>`.
If you would like to build applications that enhance Jupyter AI,
please see the {doc}`developer's guide </developers/index>`.

## Design principles

Expand Down
40 changes: 40 additions & 0 deletions docs/source/developers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,43 @@ class MyProvider(BaseProvider, FakeListLLM):
```

Please note that this will only work with Jupyter AI magics (the `%ai` and `%%ai` magic commands). Custom prompt templates are not used in the chat interface yet.

## Custom slash commands in the chat UI

You can add a custom slash command to the chat interface by
creating a new class that inherits from `BaseChatHandler`. Set
its `id`, `name`, `help` message for display in the user interface,
and `routing_type`. Each custom slash command must have a unique
slash command. Slash commands can only contain ASCII letters, numerals,
and underscores. Each slash command must be unique; custom slash
commands cannot replace built-in slash commands.

Add your custom handler in Python code:

```python
from jupyter_ai.base import BaseChatHandler, SlashCommandRoutingType

class CustomChatHandler(BaseChatHandler):
id = "custom"
name = "Custom"
help = "A chat handler that does something custom"
routing_type = SlashCommandRoutingType(slash_id="custom")

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

async def _process_message(self, message: HumanChatMessage):
# Put your custom logic here
```

Jupyter AI uses entry points to support custom slash commands.
In the `pyproject.toml` file, add your custom handler to the
`[project.entry-points."jupyter_ai.chat_handlers"]` section:

```
[project.entry-points."jupyter_ai.chat_handlers"]
custom = "custom_package:chat_handlers.CustomChatHandler"
```

Then, install your package so that Jupyter AI adds custom chat handlers
to the existing chat handlers.
1 change: 0 additions & 1 deletion packages/jupyter-ai/jupyter_ai/chat_handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .ask import AskChatHandler
from .base import BaseChatHandler, SlashCommandRoutingType
from .clear import ClearChatHandler
from .custom import CustomChatHandler
from .default import DefaultChatHandler
from .generate import GenerateChatHandler
from .help import HelpChatHandler
Expand Down
23 changes: 0 additions & 23 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/custom.py

This file was deleted.

3 changes: 0 additions & 3 deletions packages/jupyter-ai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ dependencies = [

dynamic = ["version", "description", "authors", "urls", "keywords"]

[project.entry-points."jupyter_ai.chat_handlers"]
custom = "jupyter_ai:chat_handlers.CustomChatHandler"

[project.entry-points."jupyter_ai.default_tasks"]
core_default_tasks = "jupyter_ai:tasks"

Expand Down

0 comments on commit 6542def

Please sign in to comment.