From 74d5ea3a0341a80805e634fad0bb5e232a08eb79 Mon Sep 17 00:00:00 2001 From: apurvakhatri Date: Fri, 1 Mar 2024 19:56:56 -0500 Subject: [PATCH] version reporting added through ai --- packages/jupyter-ai-magics/jupyter_ai_magics/magics.py | 9 +++++++++ packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py b/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py index f1efcd1eb..0bded79ce 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py @@ -16,6 +16,9 @@ from langchain.chains import LLMChain from langchain.schema import HumanMessage +from ._version import __version__ + + from .parsers import ( CellArgs, DeleteArgs, @@ -24,6 +27,7 @@ ListArgs, RegisterArgs, UpdateArgs, + VersionArgs, cell_magic_parser, line_magic_parser, ) @@ -473,6 +477,9 @@ def handle_list(self, args: ListArgs): self._ai_list_command_markdown(args.provider_id), ) + def handle_version(self, args: VersionArgs): + return __version__ + def run_ai_cell(self, args: CellArgs, prompt: str): provider_id, local_model_id = self._decompose_model_id(args.model_id) @@ -588,6 +595,8 @@ def ai(self, line, cell=None): return self.handle_delete(args) if args.type == "update": return self.handle_update(args) + if args.type == "version": + return self.handle_version(args) except ValueError as e: print(e, file=sys.stderr) return diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py b/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py index 51a9127eb..9637856cd 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py @@ -68,6 +68,8 @@ class ErrorArgs(BaseModel): class HelpArgs(BaseModel): type: Literal["help"] = "help" +class VersionArgs(BaseModel): + type: Literal["version"] = "version" class ListArgs(BaseModel): type: Literal["list"] = "list" @@ -214,6 +216,13 @@ def error_subparser(**kwargs): """ return ErrorArgs(**kwargs) +@line_magic_parser.command(name="version") +def version_subparser(**kwargs): + """ + Prints Jupyter-AI version + """ + return VersionArgs(**kwargs) + @line_magic_parser.command(name="help") def help_subparser():