Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 18, 2024
1 parent 31b8bce commit f492dff
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
10 changes: 4 additions & 6 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
ChatMessage,
ClosePendingMessage,
HumanChatMessage,
PendingMessage,
Message,
PendingMessage,
)
from jupyter_ai_magics import Persona
from jupyter_ai_magics.providers import BaseProvider
Expand Down Expand Up @@ -261,7 +261,7 @@ async def _default_handle_exc(self, e: Exception, message: HumanChatMessage):
f"Sorry, an error occurred. Details below:\n\n```\n{formatted_e}\n```"
)
self.reply(response, message)

def broadcast_message(self, message: Message):
"""
Broadcasts a message to all WebSocket connections. If there are no
Expand All @@ -276,10 +276,9 @@ def broadcast_message(self, message: Message):
websocket.broadcast_message(message)
broadcast = True
break

if not broadcast:
self._chat_history.append(message)


def reply(self, response: str, human_msg: Optional[HumanChatMessage] = None):
"""
Expand All @@ -296,7 +295,6 @@ def reply(self, response: str, human_msg: Optional[HumanChatMessage] = None):

self.broadcast_message(agent_msg)


@property
def persona(self):
return self.config_manager.persona
Expand Down Expand Up @@ -469,4 +467,4 @@ def send_help_message(self, human_msg: Optional[HumanChatMessage] = None) -> Non
persona=self.persona,
)

self.broadcast_message(help_message)
self.broadcast_message(help_message)
1 change: 1 addition & 0 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from jupyter_ai.models import ClearRequest

from .base import BaseChatHandler, SlashCommandRoutingType


Expand Down
5 changes: 2 additions & 3 deletions packages/jupyter-ai/jupyter_ai/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ async def on_message(self, message):
# handling messages from a websocket. instead, process each message
# as a distinct concurrent task.
self.loop.create_task(self._route(chat_message))

def on_clear_request(self, request: ClearRequest):
target = request.target

Expand All @@ -340,7 +340,7 @@ def on_clear_request(self, request: ClearRequest):
self.cleared_message_ids.add(target)
for msg in self.chat_history[::-1]:
# interrupt the single message
if (msg.type == "agent-stream" and getattr(msg, "reply_to", None) == target):
if msg.type == "agent-stream" and getattr(msg, "reply_to", None) == target:
try:
self.message_interrupted[msg.id].set()
except KeyError:
Expand Down Expand Up @@ -410,7 +410,6 @@ async def _route(self, message):
command_readable = "Default" if command == "default" else command
self.log.info(f"{command_readable} chat handler resolved in {latency_ms} ms.")


def on_close(self):
self.log.debug("Disconnecting client with user %s", self.client_id)

Expand Down
1 change: 1 addition & 0 deletions packages/jupyter-ai/jupyter_ai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ClearRequest(BaseModel):
If not provided, this requests the backend to clear all messages.
"""


class ChatUser(BaseModel):
# User ID assigned by IdentityProvider.
username: str
Expand Down

0 comments on commit f492dff

Please sign in to comment.