From a181a601d7238c69ad18871b31648954d694a8c0 Mon Sep 17 00:00:00 2001 From: ykdy3951 Date: Sat, 10 Feb 2024 04:52:31 +0900 Subject: [PATCH 1/2] Add --version command to CLI for checking the version --- cllm/main.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cllm/main.py b/cllm/main.py index 3b7b7c6..ddefaf8 100644 --- a/cllm/main.py +++ b/cllm/main.py @@ -3,14 +3,26 @@ import os import json import platform -from langchain.chains import LLMChain from langchain_openai import ChatOpenAI from langchain_core.prompts import (ChatPromptTemplate, FewShotChatMessagePromptTemplate) -app = typer.Typer(help="Empower your CLI experience with a command search tool driven by LLM magic!") +from typing import Optional +from typing_extensions import Annotated + +__version__ = "0.1.0" + +# version of the CLI +app = typer.Typer(help="Empower your CLI experience with a command search tool driven by LLM magic!", + context_settings={"help_option_names": ["-h", "--help"]} + ) app.add_typer(set_index.set_app, name="set", help="Set up configurations used in cllm") +def version_callback(value: bool): + if value: + typer.echo(f"cllm version: {__version__}") + raise typer.Exit() + @app.command() def search(query : str): """Search a command from the LLM model""" @@ -66,5 +78,11 @@ def search(query : str): typer.echo(output.content) +@app.callback() +def main( + version: Optional[bool] = typer.Option(None, "--version", "-v", callback=version_callback, help="Print cllm version") +): + pass + if __name__ == "__main__": app() From e9fa0e92990364990b68f4b22c50def39338f6cc Mon Sep 17 00:00:00 2001 From: ykdy3951 Date: Sat, 10 Feb 2024 15:13:02 +0900 Subject: [PATCH 2/2] Update version command to import from pyproject.toml file --- cllm/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cllm/main.py b/cllm/main.py index 93ec269..0b92f1e 100644 --- a/cllm/main.py +++ b/cllm/main.py @@ -3,14 +3,13 @@ import os import json import platform +import tomllib from langchain_openai import ChatOpenAI from langchain_core.prompts import (ChatPromptTemplate, FewShotChatMessagePromptTemplate) from typing import Optional from typing_extensions import Annotated -__version__ = "0.1.0" - # version of the CLI app = typer.Typer(help="Empower your CLI experience with a command search tool driven by LLM magic!", context_settings={"help_option_names": ["-h", "--help"]} @@ -20,7 +19,9 @@ def version_callback(value: bool): if value: - typer.echo(f"cllm version: {__version__}") + with open("./pyproject.toml", "rb") as f: + data = tomllib.load(f) + typer.echo(f"cllm version: {data['tool']['poetry']['version']}") raise typer.Exit() @app.command()