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

[v3-dev] Initial migration to jupyterlab-chat #1043

Merged
merged 28 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2ad85bc
Very first version of the AI working in jupyterlab_collaborative_chat
brichet Sep 10, 2024
a51840b
Allows both collaborative and regular chat to work with AI
brichet Sep 10, 2024
ac00c97
handle the help message in the chat too
brichet Sep 10, 2024
689b7b3
Autocompletion (#2)
brichet Sep 10, 2024
b7e25f4
Stream messages (#3)
brichet Sep 19, 2024
8095691
AI settings (#4)
brichet Oct 15, 2024
06de46a
Merge branch 'main' into jupyter-chat
brichet Oct 21, 2024
14543f2
pre-commit
brichet Oct 21, 2024
b21064d
linting
brichet Oct 21, 2024
eaedce9
Homogeneize typing for optional arguments
brichet Oct 21, 2024
bb39d2c
Fix import
brichet Oct 21, 2024
2805efb
Showing that the bot is writing (answering) (#5)
brichet Oct 22, 2024
7ea32a7
Merge branch 'main' into jupyter-chat
brichet Oct 22, 2024
3564bd5
Some typing
brichet Oct 22, 2024
1b95d2f
Merge branch 'v3-dev' into jupyter-chat
brichet Oct 29, 2024
f784fc8
Merge branch 'v3-dev' into jupyter-chat
brichet Nov 22, 2024
7b62b61
Update extension to jupyterlab_chat (0.6.0) (#8)
brichet Nov 22, 2024
f7f0298
Fix linting
brichet Nov 25, 2024
36afbe5
Remove try/except to import jupyterlab_chat (not optional anymore), a…
brichet Nov 25, 2024
d4fea5f
linter
brichet Nov 25, 2024
4679ceb
Python unit tests
brichet Nov 25, 2024
3d27d24
Fix typing
brichet Nov 25, 2024
15ea496
lint
brichet Nov 25, 2024
29f92d8
Fix lint and mypy all together
brichet Nov 25, 2024
ed334de
Fix web_app settings accessor
brichet Dec 3, 2024
02cedfd
Fix jupyter_collaboration version
brichet Dec 3, 2024
7498eb5
Remove unecessary try/except
brichet Dec 3, 2024
c1b3d5d
Dedicate one set of chat handlers per room (#9)
dlqqq Dec 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from jupyter_ai.chat_handlers.base import BaseChatHandler, SlashCommandRoutingType
from jupyter_ai.models import HumanChatMessage
from jupyterlab_chat.ychat import YChat


class TestSlashCommand(BaseChatHandler):
Expand All @@ -25,5 +26,5 @@ class TestSlashCommand(BaseChatHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

async def process_message(self, message: HumanChatMessage):
async def process_message(self, message: HumanChatMessage, chat: YChat):
self.reply("This is the `/test` slash command.")
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from jupyter_ai.chat_handlers.base import BaseChatHandler, SlashCommandRoutingType
from jupyter_ai.models import HumanChatMessage
from jupyterlab_chat.ychat import YChat


class TestSlashCommand(BaseChatHandler):
Expand All @@ -25,5 +26,5 @@ class TestSlashCommand(BaseChatHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

async def process_message(self, message: HumanChatMessage):
self.reply("This is the `/test` slash command.")
async def process_message(self, message: HumanChatMessage, chat: YChat):
self.reply("This is the `/test` slash command.", chat)
5 changes: 5 additions & 0 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# The following import is to make sure jupyter_ydoc is imported before
# jupyterlab_chat, otherwise it leads to circular import because of the
# YChat relying on YBaseDoc, and jupyter_ydoc registering YChat from the entry point.
import jupyter_ydoc

from .ask import AskChatHandler
from .base import BaseChatHandler, SlashCommandRoutingType
from .clear import ClearChatHandler
Expand Down
15 changes: 8 additions & 7 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/ask.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import argparse
from typing import Dict, Type
from typing import Dict, Optional, Type

from jupyter_ai.models import HumanChatMessage
from jupyter_ai_magics.providers import BaseProvider
from jupyterlab_chat.ychat import YChat
from langchain.chains import ConversationalRetrievalChain
from langchain.memory import ConversationBufferWindowMemory
from langchain_core.prompts import PromptTemplate
Expand Down Expand Up @@ -59,32 +60,32 @@ def create_llm_chain(
verbose=False,
)

async def process_message(self, message: HumanChatMessage):
args = self.parse_args(message)
async def process_message(self, message: HumanChatMessage, chat: Optional[YChat]):
args = self.parse_args(message, chat)
if args is None:
return
query = " ".join(args.query)
if not query:
self.reply(f"{self.parser.format_usage()}", message)
self.reply(f"{self.parser.format_usage()}", chat, message)
return

self.get_llm_chain()

try:
with self.pending("Searching learned documents", message):
with self.pending("Searching learned documents", message, chat=chat):
assert self.llm_chain
# TODO: migrate this class to use a LCEL `Runnable` instead of
# `Chain`, then remove the below ignore comment.
result = await self.llm_chain.acall( # type:ignore[attr-defined]
{"question": query}
)
response = result["answer"]
self.reply(response, message)
self.reply(response, chat, message)
except AssertionError as e:
self.log.error(e)
response = """Sorry, an error occurred while reading the from the learned documents.
If you have changed the embedding provider, try deleting the existing index by running
`/learn -d` command and then re-submitting the `learn <directory>` to learn the documents,
and then asking the question again.
"""
self.reply(response, message)
self.reply(response, chat, message)
Loading
Loading