Skip to content

Commit

Permalink
Backport PR jupyterlab#665: %ai version added
Browse files Browse the repository at this point in the history
  • Loading branch information
apurvakhatri authored and meeseeksmachine committed Mar 5, 2024
1 parent 2ddfcd8 commit 00211b3
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 @@ -486,6 +488,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):
# Apply a prompt template.
prompt = PROMPT_TEMPLATES_BY_FORMAT[args.format].format(prompt=prompt)
Expand Down Expand Up @@ -619,6 +624,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 00211b3

Please sign in to comment.