Skip to content

Commit

Permalink
Removes redundant code, style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonWeill committed Oct 24, 2023
1 parent 864bd5a commit 21039e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
14 changes: 6 additions & 8 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class BaseChatHandler(Configurable):
multiple chat handler classes."""

# Class attributes
id: ClassVar[str] = "base"
id: ClassVar[str] = ...
"""ID for this chat handler; should be unique"""

name: ClassVar[str] = "Base Chat Handler" # TODO: make NotImplemented
name: ClassVar[str] = ...
"""User-facing name of this handler"""

description: ClassVar[Optional[str]]
Expand All @@ -32,15 +32,13 @@ class BaseChatHandler(Configurable):
optimized for model interpretation, not human-facing help.
Not necessary when the routing method is "slash_command"."""

# TODO: make NotImplemented
help: ClassVar[
str
] = "This is used when the message in the chat interface is not a command"
help: ClassVar[str] = ...
"""What this chat handler does, which third-party models it contacts,
the format of the data it returns to the user, etc. Used in the UI."""

# TODO: make NotImplemented
routing_method: ClassVar[str] = "slash_command"
routing_method: ClassVar[str] = ...
"""The routing method that sends commands to this handler.
Either "natural_language" or "slash_command"."""

slash_id: ClassVar[Optional[str]]
"""Slash ID for routing a chat command to this handler. Only one handler
Expand Down
14 changes: 3 additions & 11 deletions packages/jupyter-ai/jupyter_ai/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def initialize_settings(self):

eps = entry_points()
# initialize chat handlers
self.log.info("Found entry point groups " + ", ".join(sorted(eps.groups)))
chat_handler_eps = eps.select(group="jupyter_ai.chat_handlers")

chat_handler_kwargs = {
Expand Down Expand Up @@ -157,14 +156,9 @@ def initialize_settings(self):
# Slash IDs may contain only alphanumerics and underscores.
slash_id = chat_handler.slash_id

if slash_id:
# TODO: Validate slash ID (/^[A-Za-z0-9_]+$/)
command_name = f"/{slash_id}"
else:
command_name = "default"
self.log.info(
f"Trying to register chat handler `{chat_handler.id}` with command `{command_name}`"
)
# TODO: Validate slash ID (/^[A-Za-z0-9_]+$/)
# The "default" handler above takes precedence over any "default" command here
command_name = f"/{chat_handler.slash_id}" if chat_handler.slash_id else "default"

if command_name in jai_chat_handlers:
self.log.error(
Expand All @@ -179,8 +173,6 @@ def initialize_settings(self):

self.settings["jai_chat_handlers"] = jai_chat_handlers

retriever = Retriever(learn_chat_handler=learn_chat_handler)
ask_chat_handler = AskChatHandler(**chat_handler_kwargs, retriever=retriever)
latency_ms = round((time.time() - start) * 1000)
self.log.info(f"Initialized Jupyter AI server extension in {latency_ms} ms.")

Expand Down

0 comments on commit 21039e7

Please sign in to comment.