Skip to content

Commit

Permalink
Update ShellSage core module with multi-provider support and configur…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
ncoop57 committed Dec 7, 2024
1 parent 88a0d1c commit 26b211d
Show file tree
Hide file tree
Showing 6 changed files with 569 additions and 94 deletions.
316 changes: 247 additions & 69 deletions nbs/00_core.ipynb

Large diffs are not rendered by default.

224 changes: 224 additions & 0 deletions nbs/01_config.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "929f165e",
"metadata": {},
"outputs": [],
"source": [
"#|default_exp config"
]
},
{
"cell_type": "markdown",
"id": "8d5eaf1e",
"metadata": {},
"source": [
"# ShellSage Configuration"
]
},
{
"cell_type": "markdown",
"id": "11feb5d9",
"metadata": {},
"source": [
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9501ca27",
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"from dataclasses import dataclass\n",
"from fastcore.all import *\n",
"from fastcore.xdg import *\n",
"from typing import get_type_hints\n",
"\n",
"import claudette as cla, cosette as cos"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a3f34f9f",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"_shell_sage_home_dir = 'shell_sage' # sub-directory of xdg base dir\n",
"_shell_sage_cfg_name = 'shell_sage.conf'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c132dc0",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"def _cfg_path(): return xdg_config_home() / _shell_sage_home_dir / _shell_sage_cfg_name"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bbf3100d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Path('/Users/nathan/.config/shell_sage/shell_sage.conf')"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"_cfg_path()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "25b71dc6",
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"providers = {\n",
" 'anthropic': cla.models,\n",
" 'openai': cos.models\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d7c2100c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'anthropic': ['claude-3-opus-20240229',\n",
" 'claude-3-5-sonnet-20241022',\n",
" 'claude-3-haiku-20240307',\n",
" 'claude-3-5-haiku-20241022'],\n",
" 'openai': ('o1-preview',\n",
" 'o1-mini',\n",
" 'gpt-4o',\n",
" 'gpt-4o-mini',\n",
" 'gpt-4-turbo',\n",
" 'gpt-4',\n",
" 'gpt-4-32k',\n",
" 'gpt-3.5-turbo',\n",
" 'gpt-3.5-turbo-instruct')}"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"providers"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a8ce1d2",
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"@dataclass\n",
"class ShellSageConfig:\n",
" model: str = providers['anthropic'][1]\n",
" provider: str = \"anthropic\"\n",
" history_lines: int = -1\n",
" code_theme: str = \"monokai\"\n",
" code_lexer: str = \"python\"\n",
" sassy_mode: bool = False\n",
" verbosity: int = 0"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2575f09b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ShellSageConfig(model='claude-3-5-sonnet-20241022', provider='anthropic', history_lines=-1, code_theme='monokai', code_lexer='python', sassy_mode=False, verbosity=0)"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cfg = ShellSageConfig()\n",
"cfg"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "38e35cce",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"def get_cfg():\n",
" path = _cfg_path()\n",
" path.parent.mkdir(parents=True, exist_ok=True)\n",
" _types = get_type_hints(ShellSageConfig)\n",
" return Config(path.parent, path.name, create=asdict(ShellSageConfig()), types=_types)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "efd3d92c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'model': 'claude-3-5-sonnet-20241022', 'provider': 'anthropic', 'history_lines': '-1', 'code_theme': 'monokai', 'code_lexer': 'python', 'sassy_mode': 'False', 'verbosity': '0'}"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cfg = get_cfg()\n",
"cfg"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ keywords = nbdev jupyter notebook python
language = English
status = 3
user = AnswerDotAI
requirements = claudette fastcore rich
requirements = claudette cosette fastcore rich
console_scripts = ssage=shell_sage.core:main
readme_nb = index.ipynb
allowed_metadata_keys =
Expand Down
7 changes: 6 additions & 1 deletion shell_sage/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
'doc_host': 'https://AnswerDotAI.github.io',
'git_url': 'https://github.com/AnswerDotAI/shell_sage',
'lib_path': 'shell_sage'},
'syms': { 'shell_sage.core': { 'shell_sage.core.get_history': ('core.html#get_history', 'shell_sage/core.py'),
'syms': { 'shell_sage.config': { 'shell_sage.config.ShellSageConfig': ('config.html#shellsageconfig', 'shell_sage/config.py'),
'shell_sage.config._cfg_path': ('config.html#_cfg_path', 'shell_sage/config.py'),
'shell_sage.config.get_cfg': ('config.html#get_cfg', 'shell_sage/config.py')},
'shell_sage.core': { 'shell_sage.core.get_history': ('core.html#get_history', 'shell_sage/core.py'),
'shell_sage.core.get_opts': ('core.html#get_opts', 'shell_sage/core.py'),
'shell_sage.core.get_pane': ('core.html#get_pane', 'shell_sage/core.py'),
'shell_sage.core.get_panes': ('core.html#get_panes', 'shell_sage/core.py'),
'shell_sage.core.get_sage': ('core.html#get_sage', 'shell_sage/core.py'),
'shell_sage.core.main': ('core.html#main', 'shell_sage/core.py')}}}
43 changes: 43 additions & 0 deletions shell_sage/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_config.ipynb.

# %% auto 0
__all__ = ['providers', 'ShellSageConfig', 'get_cfg']

# %% ../nbs/01_config.ipynb 3
from dataclasses import dataclass
from fastcore.all import *
from fastcore.xdg import *
from typing import get_type_hints

import claudette as cla, cosette as cos

# %% ../nbs/01_config.ipynb 4
_shell_sage_home_dir = 'shell_sage' # sub-directory of xdg base dir
_shell_sage_cfg_name = 'shell_sage.conf'

# %% ../nbs/01_config.ipynb 5
def _cfg_path(): return xdg_config_home() / _shell_sage_home_dir / _shell_sage_cfg_name

# %% ../nbs/01_config.ipynb 7
providers = {
'anthropic': cla.models,
'openai': cos.models
}

# %% ../nbs/01_config.ipynb 9
@dataclass
class ShellSageConfig:
model: str = providers['anthropic'][1]
provider: str = "anthropic"
history_lines: int = -1
code_theme: str = "monokai"
code_lexer: str = "python"
sassy_mode: bool = False
verbosity: int = 0

# %% ../nbs/01_config.ipynb 11
def get_cfg():
path = _cfg_path()
path.parent.mkdir(parents=True, exist_ok=True)
_types = get_type_hints(ShellSageConfig)
return Config(path.parent, path.name, create=asdict(ShellSageConfig()), types=_types)
Loading

0 comments on commit 26b211d

Please sign in to comment.