Skip to content

Commit

Permalink
%ai version added (jupyterlab#665)
Browse files Browse the repository at this point in the history
* version reporting added through ai

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and Marchlak committed Oct 28, 2024
1 parent c05500f commit d576ba8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/jupyter-ai-magics/jupyter_ai_magics/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from langchain.chains import LLMChain
from langchain.schema import HumanMessage

from ._version import __version__
from .parsers import (
CellArgs,
DeleteArgs,
Expand All @@ -24,6 +25,7 @@
ListArgs,
RegisterArgs,
UpdateArgs,
VersionArgs,
cell_magic_parser,
line_magic_parser,
)
Expand Down Expand Up @@ -473,6 +475,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)

Expand Down Expand Up @@ -588,6 +593,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
Expand Down
12 changes: 12 additions & 0 deletions packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class HelpArgs(BaseModel):
type: Literal["help"] = "help"


class VersionArgs(BaseModel):
type: Literal["version"] = "version"


class ListArgs(BaseModel):
type: Literal["list"] = "list"
provider_id: Optional[str]
Expand Down Expand Up @@ -215,6 +219,14 @@ 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():
"""Show this message and exit."""
Expand Down

0 comments on commit d576ba8

Please sign in to comment.