From 49779f145941bd32eb05c40cab2d3dba56b1ac2b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:17:18 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../jupyter_ai/chat_handlers/base.py | 2 +- .../jupyter_ai/chat_handlers/default.py | 2 +- .../jupyter_ai/context_providers/__init__.py | 2 +- .../jupyter_ai/context_providers/_examples.py | 8 +++---- .../jupyter_ai/context_providers/base.py | 23 ++++--------------- .../jupyter_ai/context_providers/file.py | 4 ++-- .../jupyter_ai/context_providers/learned.py | 3 +-- packages/jupyter-ai/jupyter_ai/extension.py | 4 ++-- packages/jupyter-ai/jupyter_ai/handlers.py | 6 ++--- .../tests/test_context_providers.py | 8 ++----- 10 files changed, 21 insertions(+), 41 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py index 2e5786f57..faa357087 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py @@ -33,9 +33,9 @@ from langchain.pydantic_v1 import BaseModel if TYPE_CHECKING: + from jupyter_ai.context_providers import BaseContextProvider from jupyter_ai.handlers import RootChatHandler from jupyter_ai.history import BoundedChatHistory - from jupyter_ai.context_providers import BaseContextProvider from langchain_core.chat_history import BaseChatMessageHistory diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/default.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/default.py index 6b7d1afa2..e178c3e4f 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/default.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/default.py @@ -13,8 +13,8 @@ from langchain_core.runnables import ConfigurableFieldSpec from langchain_core.runnables.history import RunnableWithMessageHistory -from ..models import HumanChatMessage from ..context_providers import ContextProviderException +from ..models import HumanChatMessage from .base import BaseChatHandler, SlashCommandRoutingType diff --git a/packages/jupyter-ai/jupyter_ai/context_providers/__init__.py b/packages/jupyter-ai/jupyter_ai/context_providers/__init__.py index cca2251a9..225e01998 100644 --- a/packages/jupyter-ai/jupyter_ai/context_providers/__init__.py +++ b/packages/jupyter-ai/jupyter_ai/context_providers/__init__.py @@ -1,6 +1,6 @@ from .base import ( - BaseContextProvider, BaseCommandContextProvider, + BaseContextProvider, ContextProviderException, ) from .file import FileContextProvider diff --git a/packages/jupyter-ai/jupyter_ai/context_providers/_examples.py b/packages/jupyter-ai/jupyter_ai/context_providers/_examples.py index 6a8328f3c..760066706 100644 --- a/packages/jupyter-ai/jupyter_ai/context_providers/_examples.py +++ b/packages/jupyter-ai/jupyter_ai/context_providers/_examples.py @@ -1,13 +1,11 @@ # This file is for illustrative purposes # It is to be deleted before merging from jupyter_ai.models import HumanChatMessage -from langchain_community.retrievers import WikipediaRetriever -from langchain_community.retrievers import ArxivRetriever -from langchain_core.prompts import ChatPromptTemplate +from langchain_community.retrievers import ArxivRetriever, WikipediaRetriever from langchain_core.output_parsers import StrOutputParser +from langchain_core.prompts import ChatPromptTemplate -from .base import BaseContextProvider, BaseCommandContextProvider - +from .base import BaseCommandContextProvider, BaseContextProvider # Examples of the ease of implementing retriever based context providers ARXIV_TEMPLATE = """ diff --git a/packages/jupyter-ai/jupyter_ai/context_providers/base.py b/packages/jupyter-ai/jupyter_ai/context_providers/base.py index eb61b0342..3153d5a3a 100644 --- a/packages/jupyter-ai/jupyter_ai/context_providers/base.py +++ b/packages/jupyter-ai/jupyter_ai/context_providers/base.py @@ -1,29 +1,16 @@ import abc -import re -from typing import ClassVar, List - import os -from typing import ( - TYPE_CHECKING, - Awaitable, - ClassVar, - Dict, - List, - Optional, -) +import re +from typing import TYPE_CHECKING, Awaitable, ClassVar, Dict, List, Optional from dask.distributed import Client as DaskClient -from jupyter_ai.config_manager import ConfigManager, Logger -from jupyter_ai.models import ( - ChatMessage, - HumanChatMessage, -) from jupyter_ai.chat_handlers.base import get_preferred_dir -from jupyter_ai.models import ListOptionsEntry, HumanChatMessage +from jupyter_ai.config_manager import ConfigManager, Logger +from jupyter_ai.models import ChatMessage, HumanChatMessage, ListOptionsEntry if TYPE_CHECKING: - from jupyter_ai.history import BoundedChatHistory from jupyter_ai.chat_handlers import BaseChatHandler + from jupyter_ai.history import BoundedChatHistory class BaseContextProvider(abc.ABC): diff --git a/packages/jupyter-ai/jupyter_ai/context_providers/file.py b/packages/jupyter-ai/jupyter_ai/context_providers/file.py index 32742c303..9f043e111 100644 --- a/packages/jupyter-ai/jupyter_ai/context_providers/file.py +++ b/packages/jupyter-ai/jupyter_ai/context_providers/file.py @@ -1,11 +1,11 @@ -import os import glob +import os import re from typing import List import nbformat -from jupyter_ai.models import ListOptionsEntry, HumanChatMessage from jupyter_ai.document_loaders.directory import SUPPORTED_EXTS +from jupyter_ai.models import HumanChatMessage, ListOptionsEntry from .base import BaseCommandContextProvider, ContextProviderException diff --git a/packages/jupyter-ai/jupyter_ai/context_providers/learned.py b/packages/jupyter-ai/jupyter_ai/context_providers/learned.py index 906f4663c..0e06e7480 100644 --- a/packages/jupyter-ai/jupyter_ai/context_providers/learned.py +++ b/packages/jupyter-ai/jupyter_ai/context_providers/learned.py @@ -1,12 +1,11 @@ from typing import List -from jupyter_ai.models import HumanChatMessage from jupyter_ai.chat_handlers.learn import Retriever +from jupyter_ai.models import HumanChatMessage from .base import BaseCommandContextProvider from .file import FileContextProvider - FILE_CHUNK_TEMPLATE = """ Snippet from file: {filepath} ``` diff --git a/packages/jupyter-ai/jupyter_ai/extension.py b/packages/jupyter-ai/jupyter_ai/extension.py index 038585529..7f3e46cd6 100644 --- a/packages/jupyter-ai/jupyter_ai/extension.py +++ b/packages/jupyter-ai/jupyter_ai/extension.py @@ -22,18 +22,18 @@ HelpChatHandler, LearnChatHandler, ) -from .context_providers import FileContextProvider, LearnedContextProvider from .completions.handlers import DefaultInlineCompletionHandler from .config_manager import ConfigManager +from .context_providers import FileContextProvider, LearnedContextProvider from .handlers import ( ApiKeysHandler, + AutocompleteOptionsHandler, ChatHistoryHandler, EmbeddingsModelProviderHandler, GlobalConfigHandler, ModelProviderHandler, RootChatHandler, SlashCommandsInfoHandler, - AutocompleteOptionsHandler, ) from .history import BoundedChatHistory diff --git a/packages/jupyter-ai/jupyter_ai/handlers.py b/packages/jupyter-ai/jupyter_ai/handlers.py index ba6be6f5c..359afce6d 100644 --- a/packages/jupyter-ai/jupyter_ai/handlers.py +++ b/packages/jupyter-ai/jupyter_ai/handlers.py @@ -30,12 +30,12 @@ ClosePendingMessage, ConnectionMessage, HumanChatMessage, + ListOptionsEntry, + ListOptionsResponse, ListProvidersEntry, ListProvidersResponse, ListSlashCommandsEntry, ListSlashCommandsResponse, - ListOptionsEntry, - ListOptionsResponse, Message, PendingMessage, UpdateConfigRequest, @@ -45,8 +45,8 @@ from jupyter_ai_magics.embedding_providers import BaseEmbeddingsProvider from jupyter_ai_magics.providers import BaseProvider - from .history import BoundedChatHistory from .context_providers import BaseContextProvider + from .history import BoundedChatHistory class ChatHistoryHandler(BaseAPIHandler): diff --git a/packages/jupyter-ai/jupyter_ai/tests/test_context_providers.py b/packages/jupyter-ai/jupyter_ai/tests/test_context_providers.py index a7d5fdbaa..fa7896532 100644 --- a/packages/jupyter-ai/jupyter_ai/tests/test_context_providers.py +++ b/packages/jupyter-ai/jupyter_ai/tests/test_context_providers.py @@ -2,14 +2,10 @@ from unittest import mock import pytest -from jupyter_ai.context_providers import FileContextProvider from jupyter_ai.config_manager import ConfigManager +from jupyter_ai.context_providers import FileContextProvider from jupyter_ai.history import BoundedChatHistory -from jupyter_ai.models import ( - ChatClient, - HumanChatMessage, - Persona, -) +from jupyter_ai.models import ChatClient, HumanChatMessage, Persona @pytest.fixture