diff --git a/nbs/00_core.ipynb b/nbs/00_core.ipynb index 67b69ce..8866510 100644 --- a/nbs/00_core.ipynb +++ b/nbs/00_core.ipynb @@ -42,6 +42,7 @@ "from openai import OpenAI\n", "from rich.console import Console\n", "from rich.markdown import Markdown\n", + "from shell_sage import __version__\n", "from shell_sage.config import *\n", "from subprocess import check_output as co\n", "\n", @@ -447,31 +448,25 @@ { "data": { "text/html": [ - "
~~~~~^^^^^^^^^^\n", - "KeyError: None\n", - "(uv) Nathans-MacBook-Air:shell_sage nathan$ prep\n", - "(uv) Nathans-MacBook-Air:shell_sage nathan$ ssage --c How do I list all files including hidden ones?\n", - "ls -la(uv) Nathans-MacBook-Air:shell_sage nathan$ ls -la\n", - "total 112\n", - "drwxr-xr-x@ 21 nathan staff 672 Dec 24 10:55 .\n", - "drwxr-xr-x@ 47 nathan staff 1504 Dec 23 09:16 ..\n", - "drwxr-xr-x@ 15 nathan staff 480 Dec 28 10:27 .git\n", - "drwxr-xr-x@ 3 nathan staff 96 Dec 18 21:35 .github\n", - "-rw-r--r--@ 1 nathan staff 1615 Dec \n", + "\n", + "Global options:\n", + " -q, --quiet Do not print any output\n", + " -v, --verbose... Use verbose output\n", + " --color <COLOR_CHOICE> Control colors in output \n", + " --native-tls Whether to load TLS certificates from the platform's native \n", + "certificate store \n", + " --offline \n", "\n" ], "text/plain": [ - " ~~~~~^^^^^^^^^^\n", - "KeyError: \u001b[3;35mNone\u001b[0m\n", - "\u001b[1m(\u001b[0muv\u001b[1m)\u001b[0m Nathans-MacBook-Air:shell_sage nathan$ prep\n", - "\u001b[1m(\u001b[0muv\u001b[1m)\u001b[0m Nathans-MacBook-Air:shell_sage nathan$ ssage --c How do I list all files including hidden ones?\n", - "ls -\u001b[1;35mla\u001b[0m\u001b[1m(\u001b[0muv\u001b[1m)\u001b[0m Nathans-MacBook-Air:shell_sage nathan$ ls -la\n", - "total \u001b[1;36m112\u001b[0m\n", - "drwxr-xr-x@ \u001b[1;36m21\u001b[0m nathan staff \u001b[1;36m672\u001b[0m Dec \u001b[1;36m24\u001b[0m \u001b[1;92m10:55\u001b[0m .\n", - "drwxr-xr-x@ \u001b[1;36m47\u001b[0m nathan staff \u001b[1;36m1504\u001b[0m Dec \u001b[1;36m23\u001b[0m \u001b[1;92m09:16\u001b[0m ..\n", - "drwxr-xr-x@ \u001b[1;36m15\u001b[0m nathan staff \u001b[1;36m480\u001b[0m Dec \u001b[1;36m28\u001b[0m \u001b[1;92m10:27\u001b[0m .git\n", - "drwxr-xr-x@ \u001b[1;36m3\u001b[0m nathan staff \u001b[1;36m96\u001b[0m Dec \u001b[1;36m18\u001b[0m \u001b[1;92m21:35\u001b[0m .github\n", - "-rw-r--r--@ \u001b[1;36m1\u001b[0m nathan staff \u001b[1;36m1615\u001b[0m Dec \n" + "\n", + "Global options:\n", + " -q, --quiet Do not print any output\n", + " -v, --verbose\u001b[33m...\u001b[0m Use verbose output\n", + " --color \u001b[1m<\u001b[0m\u001b[1;95mCOLOR_CHOICE\u001b[0m\u001b[1m>\u001b[0m Control colors in output \n", + " --native-tls Whether to load TLS certificates from the platform's native \n", + "certificate store \n", + " --offline \n" ] }, "metadata": {}, @@ -506,31 +501,25 @@ { "data": { "text/html": [ - "<pane id=%0 active> ~~~~~^^^^^^^^^^\n", - "KeyError: None\n", - "(uv) Nathans-MacBook-Air:shell_sage nathan$ prep\n", - "(uv) Nathans-MacBook-Air:shell_sage nathan$ ssage --c How do I list all files including hidden ones?\n", - "ls -la(uv) Nathans-MacBook-Air:shell_sage nathan$ ls -la\n", - "total 112\n", - "drwxr-xr-x@ 21 nathan staff 672 Dec 24 10:55 .\n", - "drwxr-xr-x@ 47 nathan staff 1504 Dec 23 09:16 ..\n", - "drwxr-xr-x@ 15 nathan staff 480 Dec 28 10:27 .git\n", - "drwxr-xr-x@ 3 nathan staff 96 Dec 18 21:35 .github\n", - "-rw-r--r--@ 1 nathan\n", + "<pane id=%0 active>\n", + "Global options:\n", + " -q, --quiet Do not print any output\n", + " -v, --verbose... Use verbose output\n", + " --color <COLOR_CHOICE> Control colors in output \n", + " --native-tls Whether to load TLS certificates from the platform's native \n", + "certificate store [env:\n", + " UV_NATIVE_TLS=\n", "\n" ], "text/plain": [ - "\u001b[1m<\u001b[0m\u001b[1;95mpane\u001b[0m\u001b[39m \u001b[0m\u001b[33mid\u001b[0m\u001b[39m=%\u001b[0m\u001b[1;36m0\u001b[0m\u001b[39m active\u001b[0m\u001b[1m>\u001b[0m ~~~~~^^^^^^^^^^\n", - "KeyError: \u001b[3;35mNone\u001b[0m\n", - "\u001b[1m(\u001b[0muv\u001b[1m)\u001b[0m Nathans-MacBook-Air:shell_sage nathan$ prep\n", - "\u001b[1m(\u001b[0muv\u001b[1m)\u001b[0m Nathans-MacBook-Air:shell_sage nathan$ ssage --c How do I list all files including hidden ones?\n", - "ls -\u001b[1;35mla\u001b[0m\u001b[1m(\u001b[0muv\u001b[1m)\u001b[0m Nathans-MacBook-Air:shell_sage nathan$ ls -la\n", - "total \u001b[1;36m112\u001b[0m\n", - "drwxr-xr-x@ \u001b[1;36m21\u001b[0m nathan staff \u001b[1;36m672\u001b[0m Dec \u001b[1;36m24\u001b[0m \u001b[1;92m10:55\u001b[0m .\n", - "drwxr-xr-x@ \u001b[1;36m47\u001b[0m nathan staff \u001b[1;36m1504\u001b[0m Dec \u001b[1;36m23\u001b[0m \u001b[1;92m09:16\u001b[0m ..\n", - "drwxr-xr-x@ \u001b[1;36m15\u001b[0m nathan staff \u001b[1;36m480\u001b[0m Dec \u001b[1;36m28\u001b[0m \u001b[1;92m10:27\u001b[0m .git\n", - "drwxr-xr-x@ \u001b[1;36m3\u001b[0m nathan staff \u001b[1;36m96\u001b[0m Dec \u001b[1;36m18\u001b[0m \u001b[1;92m21:35\u001b[0m .github\n", - "-rw-r--r--@ \u001b[1;36m1\u001b[0m nathan\n" + "\u001b[1m<\u001b[0m\u001b[1;95mpane\u001b[0m\u001b[39m \u001b[0m\u001b[33mid\u001b[0m\u001b[39m=%\u001b[0m\u001b[1;36m0\u001b[0m\u001b[39m active>\u001b[0m\n", + "\u001b[39mGlobal options:\u001b[0m\n", + "\u001b[39m -q, --quiet Do not print any output\u001b[0m\n", + "\u001b[39m -v, --verbose\u001b[0m\u001b[33m...\u001b[0m\u001b[39m Use verbose output\u001b[0m\n", + "\u001b[39m --color\u001b[0m Control colors in output \n", + " --native-tls Whether to load TLS certificates from the platform's native \n", + "certificate store \u001b[1m[\u001b[0menv:\n", + " \u001b[33mUV_NATIVE_TLS\u001b[0m=\n" ] }, "metadata": {}, @@ -709,25 +698,27 @@ { "data": { "text/markdown": [ - "**I'm ShellSage**, your online teaching assistant. My purpose is to help you learn and master shell commands and system administration.\n", + "**ShellSage: Your Command-Line Guide**\n", + "\n", + "I'm ShellSage, a friendly AI assistant here to help you master shell commands and system administration concepts. I'll provide clear explanations, examples, and guidance on how to tackle common challenges.\n", "\n", - "**What can I assist you with today?** Do you have a specific question about shells (e.g., Bash, Zsh, or others) or need guidance on a particular topic?\n", + "What's on your mind? Need help with a specific command or problem?\n", "\n", " \n", "\n", - "- id: chatcmpl-941\n", - "- choices: [Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=\"**I'm ShellSage**, your online teaching assistant. My purpose is to help you learn and master shell commands and system administration.\\n\\n**What can I assist you with today?** Do you have a specific question about shells (e.g., Bash, Zsh, or others) or need guidance on a particular topic?\", refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))]\n", - "- created: 1735403841\n", + "- id: chatcmpl-551\n", + "- choices: [Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=\"**ShellSage: Your Command-Line Guide**\\n\\nI'm ShellSage, a friendly AI assistant here to help you master shell commands and system administration concepts. I'll provide clear explanations, examples, and guidance on how to tackle common challenges.\\n\\nWhat's on your mind? Need help with a specific command or problem?\", refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))]\n", + "- created: 1735585726\n", "- model: llama3.2\n", "- object: chat.completion\n", "- service_tier: None\n", "- system_fingerprint: fp_ollama\n", - "- usage: CompletionUsage(completion_tokens=66, prompt_tokens=344, total_tokens=410, completion_tokens_details=None, prompt_tokens_details=None)\n", + "- usage: CompletionUsage(completion_tokens=65, prompt_tokens=344, total_tokens=409, completion_tokens_details=None, prompt_tokens_details=None)\n", "\n", "" ], "text/plain": [ - "ChatCompletion(id='chatcmpl-941', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=\"**I'm ShellSage**, your online teaching assistant. My purpose is to help you learn and master shell commands and system administration.\\n\\n**What can I assist you with today?** Do you have a specific question about shells (e.g., Bash, Zsh, or others) or need guidance on a particular topic?\", refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1735403841, model='llama3.2', object='chat.completion', service_tier=None, system_fingerprint='fp_ollama', usage=In: 344; Out: 66; Total: 410)" + "ChatCompletion(id='chatcmpl-551', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=\"**ShellSage: Your Command-Line Guide**\\n\\nI'm ShellSage, a friendly AI assistant here to help you master shell commands and system administration concepts. I'll provide clear explanations, examples, and guidance on how to tackle common challenges.\\n\\nWhat's on your mind? Need help with a specific command or problem?\", refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1735585726, model='llama3.2', object='chat.completion', service_tier=None, system_fingerprint='fp_ollama', usage=In: 344; Out: 65; Total: 409)" ] }, "execution_count": null, @@ -753,27 +744,23 @@ "ls -a\n", "```\n", "\n", - "or\n", - "\n", - "```bash\n", - "ls -A\n", - "```\n", + "`# Lists all files including hidden ones`\n", "\n", "\n", "\n", - "- id: chatcmpl-502\n", - "- choices: [Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='```bash\\nls -a\\n```\\n\\nor\\n\\n```bash\\nls -A\\n```', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))]\n", - "- created: 1735403842\n", + "- id: chatcmpl-927\n", + "- choices: [Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='```bash\\nls -a\\n```\\n\\n`# Lists all files including hidden ones`', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))]\n", + "- created: 1735585727\n", "- model: llama3.2\n", "- object: chat.completion\n", "- service_tier: None\n", "- system_fingerprint: fp_ollama\n", - "- usage: CompletionUsage(completion_tokens=20, prompt_tokens=191, total_tokens=211, completion_tokens_details=None, prompt_tokens_details=None)\n", + "- usage: CompletionUsage(completion_tokens=19, prompt_tokens=191, total_tokens=210, completion_tokens_details=None, prompt_tokens_details=None)\n", "\n", "" ], "text/plain": [ - "ChatCompletion(id='chatcmpl-502', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='```bash\\nls -a\\n```\\n\\nor\\n\\n```bash\\nls -A\\n```', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1735403842, model='llama3.2', object='chat.completion', service_tier=None, system_fingerprint='fp_ollama', usage=In: 191; Out: 20; Total: 211)" + "ChatCompletion(id='chatcmpl-927', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='```bash\\nls -a\\n```\\n\\n`# Lists all files including hidden ones`', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1735585727, model='llama3.2', object='chat.completion', service_tier=None, system_fingerprint='fp_ollama', usage=In: 191; Out: 19; Total: 210)" ] }, "execution_count": null, @@ -815,23 +802,19 @@ { "data": { "text/html": [ - "**Hello! I'm ShellSage**\n", - "\n", - "I'm a friendly command-line teaching assistant here to help you learn and master shell commands, system \n", - "administration, and related topics. Feel free to ask me any question, and I'll do my best to guide you through the \n", - "process.\n", + "**Hello! I'm ShellSage**, your friendly command-line teaching assistant. I'll help you learn and master shell \n", + "commands, system administration, and more. I'm here to guide you through the intricacies of the shell and provide \n", + "practical solutions to common problems.\n", "\n", - "What's on your mind? Do you need help with a specific command or topic?\n", + "Is there something specific you'd like to learn or accomplish with your terminal?\n", "\n" ], "text/plain": [ - "**Hello! I'm ShellSage**\n", - "\n", - "I'm a friendly command-line teaching assistant here to help you learn and master shell commands, system \n", - "administration, and related topics. Feel free to ask me any question, and I'll do my best to guide you through the \n", - "process.\n", + "**Hello! I'm ShellSage**, your friendly command-line teaching assistant. I'll help you learn and master shell \n", + "commands, system administration, and more. I'm here to guide you through the intricacies of the shell and provide \n", + "practical solutions to common problems.\n", "\n", - "What's on your mind? Do you need help with a specific command or topic?\n" + "Is there something specific you'd like to learn or accomplish with your terminal?\n" ] }, "metadata": {}, @@ -898,12 +881,10 @@ " code_theme: str = None, # The code theme to use when rendering ShellSage's responses\n", " code_lexer: str = None, # The lexer to use for inline code markdown blocks\n", " verbosity: int = 0 # Level of verbosity (0 or 1)\n", - "): \n", + "):\n", " opts = get_opts(history_lines=history_lines, provider=provider, model=model,\n", " base_url=base_url, api_key=api_key, code_theme=code_theme,\n", " code_lexer=code_lexer)\n", - " if opts.history_lines is None or opts.history_lines < 0:\n", - " opts.history_lines = tmux_history_lim()\n", "\n", " mode = 'default'\n", " if s: mode = 'sassy'\n", @@ -916,8 +897,10 @@ " ctxt = '' if skip_system else _sys_info()\n", "\n", " # Get tmux history if in a tmux session\n", - " if os.environ.get('TMUX'):\n", + " if os.environ.get('TMUX', None):\n", " if verbosity>0: print(f\"{datetime.now()} | Adding TMUX history to prompt\")\n", + " if opts.history_lines is None or opts.history_lines < 0:\n", + " opts.history_lines = tmux_history_lim()\n", " history = get_history(opts.history_lines,pid)\n", " if history: ctxt += f'\\n{history}\\n '\n", "\n", diff --git a/shell_sage/core.py b/shell_sage/core.py index b67f89c..01fd9a2 100644 --- a/shell_sage/core.py +++ b/shell_sage/core.py @@ -13,6 +13,7 @@ from openai import OpenAI from rich.console import Console from rich.markdown import Markdown +from . import __version__ from .config import * from subprocess import check_output as co @@ -213,12 +214,10 @@ def main( code_theme: str = None, # The code theme to use when rendering ShellSage's responses code_lexer: str = None, # The lexer to use for inline code markdown blocks verbosity: int = 0 # Level of verbosity (0 or 1) -): +): opts = get_opts(history_lines=history_lines, provider=provider, model=model, base_url=base_url, api_key=api_key, code_theme=code_theme, code_lexer=code_lexer) - if opts.history_lines is None or opts.history_lines < 0: - opts.history_lines = tmux_history_lim() mode = 'default' if s: mode = 'sassy' @@ -231,8 +230,10 @@ def main( ctxt = '' if skip_system else _sys_info() # Get tmux history if in a tmux session - if os.environ.get('TMUX'): + if os.environ.get('TMUX', None): if verbosity>0: print(f"{datetime.now()} | Adding TMUX history to prompt") + if opts.history_lines is None or opts.history_lines < 0: + opts.history_lines = tmux_history_lim() history = get_history(opts.history_lines,pid) if history: ctxt += f'\n{history}\n '