diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/__init__.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/__init__.py index 25c3f1a4c..3e7e45aa8 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/__init__.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/__init__.py @@ -6,7 +6,6 @@ from .ask import AskChatHandler from .base import BaseChatHandler, SlashCommandRoutingType from .default import DefaultChatHandler -from .fix import FixChatHandler from .generate import GenerateChatHandler from .help import HelpChatHandler from .learn import LearnChatHandler diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/fix.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/fix.py deleted file mode 100644 index 390b93cf6..000000000 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/fix.py +++ /dev/null @@ -1,106 +0,0 @@ -from typing import Dict, Type - -from jupyter_ai.models import CellWithErrorSelection, HumanChatMessage -from jupyter_ai_magics.providers import BaseProvider -from langchain.prompts import PromptTemplate - -from .base import BaseChatHandler, SlashCommandRoutingType - -FIX_STRING_TEMPLATE = """ -You are Jupyternaut, a conversational assistant living in JupyterLab. Please fix -the notebook cell described below. - -Additional instructions: - -{extra_instructions} - -Input cell: - -``` -{cell_content} -``` - -Output error: - -``` -{traceback} - -{error_name}: {error_value} -``` -""".strip() - -FIX_PROMPT_TEMPLATE = PromptTemplate( - input_variables=[ - "extra_instructions", - "cell_content", - "traceback", - "error_name", - "error_value", - ], - template=FIX_STRING_TEMPLATE, -) - - -class FixChatHandler(BaseChatHandler): - """ - Accepts a `HumanChatMessage` that includes a cell with error output and - recommends a fix as a reply. If a cell with error output is not included, - this chat handler does nothing. - - `/fix` also accepts additional instructions in natural language as an - arbitrary number of arguments, e.g. - - ``` - /fix use the numpy library to implement this function instead. - ``` - """ - - id = "fix" - name = "Fix error cell" - help = "Fix an error cell selected in your notebook" - routing_type = SlashCommandRoutingType(slash_id="fix") - uses_llm = True - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.prompt_template = None - - def create_llm_chain( - self, provider: Type[BaseProvider], provider_params: Dict[str, str] - ): - unified_parameters = { - **provider_params, - **(self.get_model_parameters(provider, provider_params)), - } - llm = provider(**unified_parameters) - self.llm = llm - prompt_template = FIX_PROMPT_TEMPLATE - - runnable = prompt_template | llm # type:ignore - self.llm_chain = runnable - - async def process_message(self, message: HumanChatMessage): - if not (message.selection and message.selection.type == "cell-with-error"): - self.reply( - "`/fix` requires an active code cell with error output. Please click on a cell with error output and retry.", - message, - ) - return - - # hint type of selection - selection: CellWithErrorSelection = message.selection - - # parse additional instructions specified after `/fix` - extra_instructions = message.prompt[4:].strip() or "None." - - self.get_llm_chain() - assert self.llm_chain - - inputs = { - "extra_instructions": extra_instructions, - "cell_content": selection.source, - "traceback": "\n".join(selection.error.traceback), - "error_name": selection.error.name, - "error_value": selection.error.value, - } - await self.stream_reply(inputs, message, pending_msg="Analyzing error") diff --git a/packages/jupyter-ai/jupyter_ai/extension.py b/packages/jupyter-ai/jupyter_ai/extension.py index 5f6e4228d..7c02b9e40 100644 --- a/packages/jupyter-ai/jupyter_ai/extension.py +++ b/packages/jupyter-ai/jupyter_ai/extension.py @@ -24,7 +24,6 @@ AskChatHandler, BaseChatHandler, DefaultChatHandler, - FixChatHandler, GenerateChatHandler, HelpChatHandler, LearnChatHandler, @@ -538,13 +537,10 @@ def _init_chat_handlers( retriever = Retriever(learn_chat_handler=learn_chat_handler) ask_chat_handler = AskChatHandler(**chat_handler_kwargs, retriever=retriever) - fix_chat_handler = FixChatHandler(**chat_handler_kwargs) - chat_handlers["default"] = default_chat_handler chat_handlers["/ask"] = ask_chat_handler chat_handlers["/generate"] = generate_chat_handler chat_handlers["/learn"] = learn_chat_handler - chat_handlers["/fix"] = fix_chat_handler slash_command_pattern = r"^[a-zA-Z0-9_]+$" for chat_handler_ep in chat_handler_eps: