From 95ccbf01ddd3ae5348e237bb3e6c1829f2540d53 Mon Sep 17 00:00:00 2001 From: LNTisNotaTree <62611670+LNTisNotaTree@users.noreply.github.com> Date: Sun, 3 Nov 2024 14:56:35 +0800 Subject: [PATCH] start refactor --- examples/code.ipynb | 62 +++++++++- packages/jupyter-ai-test/LICENSE | 29 ----- packages/jupyter-ai-test/README.md | 58 --------- .../jupyter_ai_test/__init__.py | 1 - .../jupyter_ai_test/test_llms.py | 58 --------- .../jupyter_ai_test/test_providers.py | 115 ------------------ .../jupyter_ai_test/test_slash_commands.py | 29 ----- .../jupyter_ai_test/tests/__init__.py | 1 - packages/jupyter-ai-test/package.json | 25 ---- packages/jupyter-ai-test/project.json | 4 - packages/jupyter-ai-test/pyproject.toml | 43 ------- packages/jupyter-ai-test/setup.py | 1 - 12 files changed, 56 insertions(+), 370 deletions(-) delete mode 100644 packages/jupyter-ai-test/LICENSE delete mode 100644 packages/jupyter-ai-test/README.md delete mode 100644 packages/jupyter-ai-test/jupyter_ai_test/__init__.py delete mode 100644 packages/jupyter-ai-test/jupyter_ai_test/test_llms.py delete mode 100644 packages/jupyter-ai-test/jupyter_ai_test/test_providers.py delete mode 100644 packages/jupyter-ai-test/jupyter_ai_test/test_slash_commands.py delete mode 100644 packages/jupyter-ai-test/jupyter_ai_test/tests/__init__.py delete mode 100644 packages/jupyter-ai-test/package.json delete mode 100644 packages/jupyter-ai-test/project.json delete mode 100644 packages/jupyter-ai-test/pyproject.toml delete mode 100644 packages/jupyter-ai-test/setup.py diff --git a/examples/code.ipynb b/examples/code.ipynb index 5dbb16089..90fe2cb5a 100644 --- a/examples/code.ipynb +++ b/examples/code.ipynb @@ -19,7 +19,29 @@ "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "Cannot determine model provider from model ID `chatgpt`.\n", + "\n", + "To see a list of models you can use, run `%ai list`\n", + "\n", + "If you were trying to run a command, run `%ai help` to see a list of commands." + ], + "text/plain": [ + "Cannot determine model provider from model ID 'chatgpt'.\n", + "\n", + "To see a list of models you can use, run '%ai list'\n", + "\n", + "If you were trying to run a command, run '%ai help' to see a list of commands." + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "%%ai chatgpt --format code\n", "A program that asks me for my name and then greets me by my name, in Polish" @@ -37,14 +59,14 @@ "name": "stdin", "output_type": "stream", "text": [ - "Jak masz na imię? foo\n" + "Jak masz na imię? 1``\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Cześć foo!\n" + "Cześć 1``!\n" ] } ], @@ -57,8 +79,36 @@ "cell_type": "code", "execution_count": 4, "id": "7e187e37-9abd-4ed2-9959-fb3acdb3acfe", - "metadata": {}, - "outputs": [], + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/markdown": [ + "Cannot determine model provider from model ID `chatgpt`.\n", + "\n", + "To see a list of models you can use, run `%ai list`\n", + "\n", + "If you were trying to run a command, run `%ai help` to see a list of commands." + ], + "text/plain": [ + "Cannot determine model provider from model ID 'chatgpt'.\n", + "\n", + "To see a list of models you can use, run '%ai list'\n", + "\n", + "If you were trying to run a command, run '%ai help' to see a list of commands." + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "%%ai chatgpt --format code\n", "A function that computes the lowest common multiples of two integers, and a function that runs 5 test cases of the lowest common multiple function" @@ -122,7 +172,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.12.7" } }, "nbformat": 4, diff --git a/packages/jupyter-ai-test/LICENSE b/packages/jupyter-ai-test/LICENSE deleted file mode 100644 index eb0d24e83..000000000 --- a/packages/jupyter-ai-test/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2024, Project Jupyter -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/jupyter-ai-test/README.md b/packages/jupyter-ai-test/README.md deleted file mode 100644 index 64e9fbffb..000000000 --- a/packages/jupyter-ai-test/README.md +++ /dev/null @@ -1,58 +0,0 @@ -# jupyter_ai_test - -`jupyter_ai_test` is a Jupyter AI module that registers additional model -providers and slash commands for testing Jupyter AI in a local development -environment. This package should never published on NPM or PyPI. - -## Requirements - -- Python 3.8 - 3.12 -- JupyterLab 4 - -## Install - -To install the extension, execute: - -```bash -pip install jupyter_ai_test -``` - -## Uninstall - -To remove the extension, execute: - -```bash -pip uninstall jupyter_ai_test -``` - -## Contributing - -### Development install - -```bash -cd jupyter-ai-test -pip install -e "." -``` - -### Development uninstall - -```bash -pip uninstall jupyter_ai_test -``` - -#### Backend tests - -This package uses [Pytest](https://docs.pytest.org/) for Python testing. - -Install test dependencies (needed only once): - -```sh -cd jupyter-ai-test -pip install -e ".[test]" -``` - -To execute them, run: - -```sh -pytest -vv -r ap --cov jupyter_ai_test -``` diff --git a/packages/jupyter-ai-test/jupyter_ai_test/__init__.py b/packages/jupyter-ai-test/jupyter_ai_test/__init__.py deleted file mode 100644 index 8dee4bf82..000000000 --- a/packages/jupyter-ai-test/jupyter_ai_test/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from ._version import __version__ diff --git a/packages/jupyter-ai-test/jupyter_ai_test/test_llms.py b/packages/jupyter-ai-test/jupyter_ai_test/test_llms.py deleted file mode 100644 index 17fa42656..000000000 --- a/packages/jupyter-ai-test/jupyter_ai_test/test_llms.py +++ /dev/null @@ -1,58 +0,0 @@ -import time -from typing import Any, Iterator, List, Optional - -from langchain_core.callbacks.manager import CallbackManagerForLLMRun -from langchain_core.language_models.llms import LLM -from langchain_core.outputs.generation import GenerationChunk - - -class TestLLM(LLM): - model_id: str = "test" - - @property - def _llm_type(self) -> str: - return "custom" - - def _call( - self, - prompt: str, - stop: Optional[List[str]] = None, - run_manager: Optional[CallbackManagerForLLMRun] = None, - **kwargs: Any, - ) -> str: - time.sleep(3) - return f"Hello! This is a dummy response from a test LLM." - - -class TestLLMWithStreaming(LLM): - model_id: str = "test" - - @property - def _llm_type(self) -> str: - return "custom" - - def _call( - self, - prompt: str, - stop: Optional[List[str]] = None, - run_manager: Optional[CallbackManagerForLLMRun] = None, - **kwargs: Any, - ) -> str: - time.sleep(3) - return f"Hello! This is a dummy response from a test LLM." - - def _stream( - self, - prompt: str, - stop: Optional[List[str]] = None, - run_manager: Optional[CallbackManagerForLLMRun] = None, - **kwargs: Any, - ) -> Iterator[GenerationChunk]: - time.sleep(1) - yield GenerationChunk( - text="Hello! This is a dummy response from a test LLM. I will now count from 1 to 5.\n\n", - generation_info={"test_metadata_field": "foobar"}, - ) - for i in range(1, 6): - time.sleep(0.2) - yield GenerationChunk(text=f"{i}, ") diff --git a/packages/jupyter-ai-test/jupyter_ai_test/test_providers.py b/packages/jupyter-ai-test/jupyter_ai_test/test_providers.py deleted file mode 100644 index 1ec042afb..000000000 --- a/packages/jupyter-ai-test/jupyter_ai_test/test_providers.py +++ /dev/null @@ -1,115 +0,0 @@ -from typing import ClassVar, List - -from jupyter_ai import AuthStrategy, BaseProvider, Field - -from .test_llms import TestLLM, TestLLMWithStreaming - - -class TestProvider(BaseProvider, TestLLM): - id: ClassVar[str] = "test-provider" - """ID for this provider class.""" - - name: ClassVar[str] = "Test Provider" - """User-facing name of this provider.""" - - models: ClassVar[List[str]] = ["test"] - """List of supported models by their IDs. For registry providers, this will - be just ["*"].""" - - help: ClassVar[str] = None - """Text to display in lieu of a model list for a registry provider that does - not provide a list of models.""" - - model_id_key: ClassVar[str] = "model_id" - """Kwarg expected by the upstream LangChain provider.""" - - model_id_label: ClassVar[str] = "Model ID" - """Human-readable label of the model ID.""" - - pypi_package_deps: ClassVar[List[str]] = [] - """List of PyPi package dependencies.""" - - auth_strategy: ClassVar[AuthStrategy] = None - """Authentication/authorization strategy. Declares what credentials are - required to use this model provider. Generally should not be `None`.""" - - registry: ClassVar[bool] = False - """Whether this provider is a registry provider.""" - - fields: ClassVar[List[Field]] = [] - """User inputs expected by this provider when initializing it. Each `Field` `f` - should be passed in the constructor as a keyword argument, keyed by `f.key`.""" - - -class TestProviderWithStreaming(BaseProvider, TestLLMWithStreaming): - id: ClassVar[str] = "test-provider-with-streaming" - """ID for this provider class.""" - - name: ClassVar[str] = "Test Provider (streaming)" - """User-facing name of this provider.""" - - models: ClassVar[List[str]] = ["test"] - """List of supported models by their IDs. For registry providers, this will - be just ["*"].""" - - help: ClassVar[str] = None - """Text to display in lieu of a model list for a registry provider that does - not provide a list of models.""" - - model_id_key: ClassVar[str] = "model_id" - """Kwarg expected by the upstream LangChain provider.""" - - model_id_label: ClassVar[str] = "Model ID" - """Human-readable label of the model ID.""" - - pypi_package_deps: ClassVar[List[str]] = [] - """List of PyPi package dependencies.""" - - auth_strategy: ClassVar[AuthStrategy] = None - """Authentication/authorization strategy. Declares what credentials are - required to use this model provider. Generally should not be `None`.""" - - registry: ClassVar[bool] = False - """Whether this provider is a registry provider.""" - - fields: ClassVar[List[Field]] = [] - """User inputs expected by this provider when initializing it. Each `Field` `f` - should be passed in the constructor as a keyword argument, keyed by `f.key`.""" - - -class TestProviderAskLearnUnsupported(BaseProvider, TestLLMWithStreaming): - id: ClassVar[str] = "test-provider-ask-learn-unsupported" - """ID for this provider class.""" - - name: ClassVar[str] = "Test Provider (/learn and /ask unsupported)" - """User-facing name of this provider.""" - - models: ClassVar[List[str]] = ["test"] - """List of supported models by their IDs. For registry providers, this will - be just ["*"].""" - - help: ClassVar[str] = None - """Text to display in lieu of a model list for a registry provider that does - not provide a list of models.""" - - model_id_key: ClassVar[str] = "model_id" - """Kwarg expected by the upstream LangChain provider.""" - - model_id_label: ClassVar[str] = "Model ID" - """Human-readable label of the model ID.""" - - pypi_package_deps: ClassVar[List[str]] = [] - """List of PyPi package dependencies.""" - - auth_strategy: ClassVar[AuthStrategy] = None - """Authentication/authorization strategy. Declares what credentials are - required to use this model provider. Generally should not be `None`.""" - - registry: ClassVar[bool] = False - """Whether this provider is a registry provider.""" - - fields: ClassVar[List[Field]] = [] - """User inputs expected by this provider when initializing it. Each `Field` `f` - should be passed in the constructor as a keyword argument, keyed by `f.key`.""" - - unsupported_slash_commands = {"/learn", "/ask"} diff --git a/packages/jupyter-ai-test/jupyter_ai_test/test_slash_commands.py b/packages/jupyter-ai-test/jupyter_ai_test/test_slash_commands.py deleted file mode 100644 index f82bd5531..000000000 --- a/packages/jupyter-ai-test/jupyter_ai_test/test_slash_commands.py +++ /dev/null @@ -1,29 +0,0 @@ -from jupyter_ai.chat_handlers.base import BaseChatHandler, SlashCommandRoutingType -from jupyter_ai.models import HumanChatMessage - - -class TestSlashCommand(BaseChatHandler): - """ - A test slash command implementation that developers should build from. The - string used to invoke this command is set by the `slash_id` keyword argument - in the `routing_type` attribute. The command is mainly implemented in the - `process_message()` method. See built-in implementations under - `jupyter_ai/handlers` for further reference. - - The provider is made available to Jupyter AI by the entry point declared in - `pyproject.toml`. If this class or parent module is renamed, make sure the - update the entry point there as well. - """ - - id = "test" - name = "Test" - help = "A test slash command." - routing_type = SlashCommandRoutingType(slash_id="test") - - uses_llm = False - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - async def process_message(self, message: HumanChatMessage): - self.reply("This is the `/test` slash command.") diff --git a/packages/jupyter-ai-test/jupyter_ai_test/tests/__init__.py b/packages/jupyter-ai-test/jupyter_ai_test/tests/__init__.py deleted file mode 100644 index bfecc1ade..000000000 --- a/packages/jupyter-ai-test/jupyter_ai_test/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Python unit tests for jupyter_ai_test.""" diff --git a/packages/jupyter-ai-test/package.json b/packages/jupyter-ai-test/package.json deleted file mode 100644 index 46afe6459..000000000 --- a/packages/jupyter-ai-test/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "@jupyter-ai/test", - "version": "2.27.0", - "description": "Jupyter AI test package. Not published on NPM or PyPI.", - "private": true, - "homepage": "https://github.com/jupyterlab/jupyter-ai", - "bugs": { - "url": "https://github.com/jupyterlab/jupyter-ai/issues", - "email": "jupyter@googlegroups.com" - }, - "license": "BSD-3-Clause", - "author": { - "name": "Project Jupyter", - "email": "jupyter@googlegroups.com" - }, - "repository": { - "type": "git", - "url": "https://github.com/jupyterlab/jupyter-ai.git" - }, - "scripts": { - "dev-install": "pip install -e .", - "dev-uninstall": "pip uninstall jupyter_ai_test -y", - "install-from-src": "pip install ." - } -} diff --git a/packages/jupyter-ai-test/project.json b/packages/jupyter-ai-test/project.json deleted file mode 100644 index 9af45c206..000000000 --- a/packages/jupyter-ai-test/project.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "@jupyter-ai/test", - "implicitDependencies": ["@jupyter-ai/core"] -} diff --git a/packages/jupyter-ai-test/pyproject.toml b/packages/jupyter-ai-test/pyproject.toml deleted file mode 100644 index eaecc09d3..000000000 --- a/packages/jupyter-ai-test/pyproject.toml +++ /dev/null @@ -1,43 +0,0 @@ -[build-system] -requires = ["hatchling>=1.4.0", "jupyterlab~=4.0"] -build-backend = "hatchling.build" - -[project] -name = "jupyter_ai_test" -readme = "README.md" -license = { file = "LICENSE" } -requires-python = ">=3.8" -classifiers = [ - "Framework :: Jupyter", - "Framework :: Jupyter :: JupyterLab", - "Framework :: Jupyter :: JupyterLab :: 4", - "License :: OSI Approved :: BSD License", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", -] -version = "0.1.0" -description = "A Jupyter AI extension." -authors = [{ name = "Project Jupyter", email = "jupyter@googlegroups.com" }] -dependencies = ["jupyter_ai"] - -[project.optional-dependencies] -test = ["coverage", "pytest", "pytest-asyncio", "pytest-cov"] - -[project.entry-points."jupyter_ai.model_providers"] -test-provider = "jupyter_ai_test.test_providers:TestProvider" -test-provider-with-streaming = "jupyter_ai_test.test_providers:TestProviderWithStreaming" -test-provider-ask-learn-unsupported = "jupyter_ai_test.test_providers:TestProviderAskLearnUnsupported" - -[project.entry-points."jupyter_ai.chat_handlers"] -test-slash-command = "jupyter_ai_test.test_slash_commands:TestSlashCommand" - -[tool.hatch.build.hooks.version] -path = "jupyter_ai_test/_version.py" - -[tool.check-wheel-contents] -ignore = ["W002"] diff --git a/packages/jupyter-ai-test/setup.py b/packages/jupyter-ai-test/setup.py deleted file mode 100644 index aefdf20db..000000000 --- a/packages/jupyter-ai-test/setup.py +++ /dev/null @@ -1 +0,0 @@ -__import__("setuptools").setup()