Skip to content

Commit 26dc9be

Browse files
author
ncoop57
committed
Add system environment functions and update config
1 parent fca30df commit 26dc9be

File tree

5 files changed

+212
-23
lines changed

5 files changed

+212
-23
lines changed

nbs/00_core.ipynb

Lines changed: 180 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,181 @@
162162
"</important>'''"
163163
]
164164
},
165+
{
166+
"cell_type": "markdown",
167+
"id": "739736b1",
168+
"metadata": {},
169+
"source": [
170+
"## System Environment"
171+
]
172+
},
173+
{
174+
"cell_type": "code",
175+
"execution_count": null,
176+
"id": "2514ebb0",
177+
"metadata": {},
178+
"outputs": [],
179+
"source": [
180+
"#| export\n",
181+
"def _aliases(shell):\n",
182+
" return co([shell, '-ic', 'alias'], text=True).strip()"
183+
]
184+
},
185+
{
186+
"cell_type": "code",
187+
"execution_count": null,
188+
"id": "568b5429",
189+
"metadata": {},
190+
"outputs": [
191+
{
192+
"data": {
193+
"text/html": [
194+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">ans</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'ssh answer'</span>\n",
195+
"<span style=\"color: #808000; text-decoration-color: #808000\">bug</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'gh issue create --label bug --title'</span>\n",
196+
"<span style=\"color: #808000; text-decoration-color: #808000\">cdg</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'cd ~/git'</span>\n",
197+
"<span style=\"color: #808000; text-decoration-color: #808000\">gaa</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'git add -A'</span>\n",
198+
"<span style=\"color: #808000; text-decoration-color: #808000\">gc</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'git checkout'</span>\n",
199+
"<span style=\"color: #808000; text-decoration-color: #808000\">gd</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'git diff'</span>\n",
200+
"<span style=\"color: #808000; text-decoration-color: #808000\">gp</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'git pull'</span>\n",
201+
"<span style=\"color: #808000; text-decoration-color: #808000\">gpu</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'git push'</span>\n",
202+
"<span style=\"color: #808000; text-decoration-color: #808000\">gs</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'git status'</span>\n",
203+
"<span style=\"color: #808000; text-decoration-color: #808000\">jnb</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'jupyter nbclassic'</span>\n",
204+
"<span style=\"color: #808000; text-decoration-color: #808000\">pi</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'pip install -e .'</span>\n",
205+
"<span style=\"color: #808000; text-decoration-color: #808000\">pr</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'pip install -r requirements.txt'</span>\n",
206+
"<span style=\"color: #808000; text-decoration-color: #808000\">prep</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'nbdev_export &amp;&amp; nbdev_clean &amp;&amp; nbdev_trust'</span>\n",
207+
"run-<span style=\"color: #808000; text-decoration-color: #808000\">help</span>=<span style=\"color: #800080; text-decoration-color: #800080\">man</span>\n",
208+
"<span style=\"color: #808000; text-decoration-color: #808000\">tb1</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'ssh tb1'</span>\n",
209+
"<span style=\"color: #808000; text-decoration-color: #808000\">tb2</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'ssh tb2'</span>\n",
210+
"<span style=\"color: #808000; text-decoration-color: #808000\">ur</span>=<span style=\"color: #800080; text-decoration-color: #800080\">update_repos</span>\n",
211+
"<span style=\"color: #808000; text-decoration-color: #808000\">we</span>=<span style=\"color: #800080; text-decoration-color: #800080\">watch_export</span>\n",
212+
"which-<span style=\"color: #808000; text-decoration-color: #808000\">command</span>=<span style=\"color: #800080; text-decoration-color: #800080\">whence</span>\n",
213+
"\n",
214+
"</pre>\n"
215+
],
216+
"text/plain": [
217+
"\u001b[33mans\u001b[0m=\u001b[32m'ssh answer'\u001b[0m\n",
218+
"\u001b[33mbug\u001b[0m=\u001b[32m'gh issue create --label bug --title'\u001b[0m\n",
219+
"\u001b[33mcdg\u001b[0m=\u001b[32m'cd ~/git'\u001b[0m\n",
220+
"\u001b[33mgaa\u001b[0m=\u001b[32m'git add -A'\u001b[0m\n",
221+
"\u001b[33mgc\u001b[0m=\u001b[32m'git checkout'\u001b[0m\n",
222+
"\u001b[33mgd\u001b[0m=\u001b[32m'git diff'\u001b[0m\n",
223+
"\u001b[33mgp\u001b[0m=\u001b[32m'git pull'\u001b[0m\n",
224+
"\u001b[33mgpu\u001b[0m=\u001b[32m'git push'\u001b[0m\n",
225+
"\u001b[33mgs\u001b[0m=\u001b[32m'git status'\u001b[0m\n",
226+
"\u001b[33mjnb\u001b[0m=\u001b[32m'jupyter nbclassic'\u001b[0m\n",
227+
"\u001b[33mpi\u001b[0m=\u001b[32m'pip install -e .'\u001b[0m\n",
228+
"\u001b[33mpr\u001b[0m=\u001b[32m'pip install -r requirements.txt'\u001b[0m\n",
229+
"\u001b[33mprep\u001b[0m=\u001b[32m'nbdev_export && nbdev_clean && nbdev_trust'\u001b[0m\n",
230+
"run-\u001b[33mhelp\u001b[0m=\u001b[35mman\u001b[0m\n",
231+
"\u001b[33mtb1\u001b[0m=\u001b[32m'ssh tb1'\u001b[0m\n",
232+
"\u001b[33mtb2\u001b[0m=\u001b[32m'ssh tb2'\u001b[0m\n",
233+
"\u001b[33mur\u001b[0m=\u001b[35mupdate_repos\u001b[0m\n",
234+
"\u001b[33mwe\u001b[0m=\u001b[35mwatch_export\u001b[0m\n",
235+
"which-\u001b[33mcommand\u001b[0m=\u001b[35mwhence\u001b[0m\n",
236+
"\n"
237+
]
238+
},
239+
"metadata": {},
240+
"output_type": "display_data"
241+
}
242+
],
243+
"source": [
244+
"aliases = _aliases(shell)\n",
245+
"print(aliases)"
246+
]
247+
},
248+
{
249+
"cell_type": "code",
250+
"execution_count": null,
251+
"id": "8b7343b1",
252+
"metadata": {},
253+
"outputs": [],
254+
"source": [
255+
"#| export\n",
256+
"def _sys_info():\n",
257+
" sys = co(['uname', '-a'], text=True).strip()\n",
258+
" ssys = f'<system>{sys}</system>'\n",
259+
" shell = co('echo $SHELL', shell=True, text=True).strip()\n",
260+
" sshell = f'<shell>{shell}</shell>'\n",
261+
" aliases = _aliases(shell)\n",
262+
" saliases = f'<aliases>\\n{aliases}\\n</aliases>'\n",
263+
" return f'<system_info>\\n{ssys}\\n{sshell}\\n{saliases}\\n</system_info>'"
264+
]
265+
},
266+
{
267+
"cell_type": "code",
268+
"execution_count": null,
269+
"id": "bc002bdd",
270+
"metadata": {},
271+
"outputs": [
272+
{
273+
"data": {
274+
"text/html": [
275+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">system_info</span><span style=\"color: #000000; text-decoration-color: #000000\">&gt;</span>\n",
276+
"<span style=\"color: #000000; text-decoration-color: #000000\">&lt;system&gt;Darwin Nathans-MacBook-Air.local </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">24.1</span><span style=\"color: #000000; text-decoration-color: #000000\">.</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"color: #000000; text-decoration-color: #000000\"> Darwin Kernel Version </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">24.1</span><span style=\"color: #000000; text-decoration-color: #000000\">.</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"color: #000000; text-decoration-color: #000000\">: Thu Oct </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">10</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #00ff00; text-decoration-color: #00ff00; font-weight: bold\">21:02:26</span><span style=\"color: #000000; text-decoration-color: #000000\"> PDT </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2024</span><span style=\"color: #000000; text-decoration-color: #000000\">; </span>\n",
277+
"<span style=\"color: #000000; text-decoration-color: #000000\">root:xnu-</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">11215.41</span><span style=\"color: #000000; text-decoration-color: #000000\">.</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span><span style=\"color: #000000; text-decoration-color: #000000\">~</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span><span style=\"color: #000000; text-decoration-color: #000000\">/RELEASE_ARM64_T8122 arm64&lt;</span><span style=\"color: #800080; text-decoration-color: #800080\">/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">system</span><span style=\"color: #000000; text-decoration-color: #000000\">&gt;</span>\n",
278+
"<span style=\"color: #000000; text-decoration-color: #000000\">&lt;shell&gt;</span><span style=\"color: #800080; text-decoration-color: #800080\">/bin/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">zsh</span><span style=\"color: #000000; text-decoration-color: #000000\">&lt;</span><span style=\"color: #800080; text-decoration-color: #800080\">/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">shell</span><span style=\"color: #000000; text-decoration-color: #000000\">&gt;</span>\n",
279+
"<span style=\"color: #000000; text-decoration-color: #000000\">&lt;aliases&gt;</span>\n",
280+
"<span style=\"color: #808000; text-decoration-color: #808000\">ans</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'ssh answer'</span>\n",
281+
"<span style=\"color: #808000; text-decoration-color: #808000\">bug</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'gh issue create --label bug --title'</span>\n",
282+
"<span style=\"color: #808000; text-decoration-color: #808000\">cdg</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'cd ~/git'</span>\n",
283+
"<span style=\"color: #808000; text-decoration-color: #808000\">gaa</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'git add -A'</span>\n",
284+
"<span style=\"color: #808000; text-decoration-color: #808000\">gc</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'git checkout'</span>\n",
285+
"<span style=\"color: #808000; text-decoration-color: #808000\">gd</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'git diff'</span>\n",
286+
"<span style=\"color: #808000; text-decoration-color: #808000\">gp</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'git pull'</span>\n",
287+
"<span style=\"color: #808000; text-decoration-color: #808000\">gpu</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'git push'</span>\n",
288+
"<span style=\"color: #808000; text-decoration-color: #808000\">gs</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'git status'</span>\n",
289+
"<span style=\"color: #808000; text-decoration-color: #808000\">jnb</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'jupyter nbclassic'</span>\n",
290+
"<span style=\"color: #808000; text-decoration-color: #808000\">pi</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'pip install -e .'</span>\n",
291+
"<span style=\"color: #808000; text-decoration-color: #808000\">pr</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'pip install -r requirements.txt'</span>\n",
292+
"<span style=\"color: #808000; text-decoration-color: #808000\">prep</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'nbdev_export &amp;&amp; nbdev_clean &amp;&amp; nbdev_trust'</span>\n",
293+
"<span style=\"color: #000000; text-decoration-color: #000000\">run-</span><span style=\"color: #808000; text-decoration-color: #808000\">help</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #800080; text-decoration-color: #800080\">man</span>\n",
294+
"<span style=\"color: #808000; text-decoration-color: #808000\">tb1</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'ssh tb1'</span>\n",
295+
"<span style=\"color: #808000; text-decoration-color: #808000\">tb2</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'ssh tb2'</span>\n",
296+
"<span style=\"color: #808000; text-decoration-color: #808000\">ur</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #800080; text-decoration-color: #800080\">update_repos</span>\n",
297+
"<span style=\"color: #808000; text-decoration-color: #808000\">we</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #800080; text-decoration-color: #800080\">watch_export</span>\n",
298+
"<span style=\"color: #000000; text-decoration-color: #000000\">which-</span><span style=\"color: #808000; text-decoration-color: #808000\">command</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #800080; text-decoration-color: #800080\">whence</span>\n",
299+
"<span style=\"color: #000000; text-decoration-color: #000000\">&lt;</span><span style=\"color: #800080; text-decoration-color: #800080\">/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">aliases</span><span style=\"color: #000000; text-decoration-color: #000000\">&gt;</span>\n",
300+
"<span style=\"color: #000000; text-decoration-color: #000000\">&lt;</span><span style=\"color: #800080; text-decoration-color: #800080\">/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">system_info</span><span style=\"font-weight: bold\">&gt;</span>\n",
301+
"</pre>\n"
302+
],
303+
"text/plain": [
304+
"\u001b[1m<\u001b[0m\u001b[1;95msystem_info\u001b[0m\u001b[39m>\u001b[0m\n",
305+
"\u001b[39m<system>Darwin Nathans-MacBook-Air.local \u001b[0m\u001b[1;36m24.1\u001b[0m\u001b[39m.\u001b[0m\u001b[1;36m0\u001b[0m\u001b[39m Darwin Kernel Version \u001b[0m\u001b[1;36m24.1\u001b[0m\u001b[39m.\u001b[0m\u001b[1;36m0\u001b[0m\u001b[39m: Thu Oct \u001b[0m\u001b[1;36m10\u001b[0m\u001b[39m \u001b[0m\u001b[1;92m21:02:26\u001b[0m\u001b[39m PDT \u001b[0m\u001b[1;36m2024\u001b[0m\u001b[39m; \u001b[0m\n",
306+
"\u001b[39mroot:xnu-\u001b[0m\u001b[1;36m11215.41\u001b[0m\u001b[39m.\u001b[0m\u001b[1;36m3\u001b[0m\u001b[39m~\u001b[0m\u001b[1;36m2\u001b[0m\u001b[39m/RELEASE_ARM64_T8122 arm64<\u001b[0m\u001b[35m/\u001b[0m\u001b[95msystem\u001b[0m\u001b[39m>\u001b[0m\n",
307+
"\u001b[39m<shell>\u001b[0m\u001b[35m/bin/\u001b[0m\u001b[95mzsh\u001b[0m\u001b[39m<\u001b[0m\u001b[35m/\u001b[0m\u001b[95mshell\u001b[0m\u001b[39m>\u001b[0m\n",
308+
"\u001b[39m<aliases>\u001b[0m\n",
309+
"\u001b[33mans\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'ssh answer'\u001b[0m\n",
310+
"\u001b[33mbug\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'gh issue create --label bug --title'\u001b[0m\n",
311+
"\u001b[33mcdg\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'cd ~/git'\u001b[0m\n",
312+
"\u001b[33mgaa\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'git add -A'\u001b[0m\n",
313+
"\u001b[33mgc\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'git checkout'\u001b[0m\n",
314+
"\u001b[33mgd\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'git diff'\u001b[0m\n",
315+
"\u001b[33mgp\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'git pull'\u001b[0m\n",
316+
"\u001b[33mgpu\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'git push'\u001b[0m\n",
317+
"\u001b[33mgs\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'git status'\u001b[0m\n",
318+
"\u001b[33mjnb\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'jupyter nbclassic'\u001b[0m\n",
319+
"\u001b[33mpi\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'pip install -e .'\u001b[0m\n",
320+
"\u001b[33mpr\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'pip install -r requirements.txt'\u001b[0m\n",
321+
"\u001b[33mprep\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'nbdev_export && nbdev_clean && nbdev_trust'\u001b[0m\n",
322+
"\u001b[39mrun-\u001b[0m\u001b[33mhelp\u001b[0m\u001b[39m=\u001b[0m\u001b[35mman\u001b[0m\n",
323+
"\u001b[33mtb1\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'ssh tb1'\u001b[0m\n",
324+
"\u001b[33mtb2\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'ssh tb2'\u001b[0m\n",
325+
"\u001b[33mur\u001b[0m\u001b[39m=\u001b[0m\u001b[35mupdate_repos\u001b[0m\n",
326+
"\u001b[33mwe\u001b[0m\u001b[39m=\u001b[0m\u001b[35mwatch_export\u001b[0m\n",
327+
"\u001b[39mwhich-\u001b[0m\u001b[33mcommand\u001b[0m\u001b[39m=\u001b[0m\u001b[35mwhence\u001b[0m\n",
328+
"\u001b[39m<\u001b[0m\u001b[35m/\u001b[0m\u001b[95maliases\u001b[0m\u001b[39m>\u001b[0m\n",
329+
"\u001b[39m<\u001b[0m\u001b[35m/\u001b[0m\u001b[95msystem_info\u001b[0m\u001b[1m>\u001b[0m\n"
330+
]
331+
},
332+
"metadata": {},
333+
"output_type": "display_data"
334+
}
335+
],
336+
"source": [
337+
"print(_sys_info())"
338+
]
339+
},
165340
{
166341
"cell_type": "markdown",
167342
"id": "b2912805",
@@ -425,22 +600,23 @@
425600
"def main(\n",
426601
" query: Param('The query to send to the LLM', str, nargs='+'),\n",
427602
" pid: str = 'current', # `current`, `all` or tmux pane_id (e.g. %0) for context\n",
603+
" skip_system: bool = False, # Whether to skip system information in the AI's context\n",
428604
" n: int = None, # Number of history lines. Defaults to tmux scrollback history length\n",
429-
" s: bool = None, # Enable sassy mode\n",
605+
" s: bool = False, # Enable sassy mode\n",
430606
" provider: str = None, # The LLM Provider\n",
431607
" model: str = None, # The LLM model that will be invoked on the LLM provider\n",
432608
" code_theme: str = None, # The code theme to use when rendering ShellSage's responses\n",
433609
" code_lexer: str = None, # The lexer to use for inline code markdown blocks\n",
434610
" verbosity: int = 0 # Level of verbosity (0 or 1)\n",
435611
"): \n",
436612
" opts = get_opts(history_lines=n, provider=provider, model=model,\n",
437-
" sassy_mode=s, code_theme=code_theme, code_lexer=code_lexer)\n",
613+
" code_theme=code_theme, code_lexer=code_lexer)\n",
438614
" \n",
439615
" if verbosity>0:\n",
440616
" print(f\"{datetime.now()} | Starting ShellSage request with options {opts}\")\n",
441617
" md = partial(Markdown, code_theme=opts.code_theme, inline_code_lexer=opts.code_lexer, inline_code_theme=opts.code_theme)\n",
442618
" query = ' '.join(query)\n",
443-
" ctxt = ''\n",
619+
" ctxt = '' if skip_system else _sys_info()\n",
444620
"\n",
445621
" # Get tmux history if in a tmux session\n",
446622
" if os.environ.get('TMUX'):\n",
@@ -458,7 +634,7 @@
458634
" query = [mk_msg(query)] if opts.provider == 'openai' else query\n",
459635
"\n",
460636
" if verbosity>0: print(f\"{datetime.now()} | Sending prompt to model\")\n",
461-
" sage, contents = get_sage(opts.provider, opts.model, opts.sassy_mode)\n",
637+
" sage, contents = get_sage(opts.provider, opts.model, s)\n",
462638
" print(md(contents(sage(query))))"
463639
]
464640
},

0 commit comments

Comments
 (0)