-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ShellSage core module with multi-provider support and configur…
…ation
- Loading branch information
ncoop57
committed
Dec 7, 2024
1 parent
88a0d1c
commit 26b211d
Showing
6 changed files
with
569 additions
and
94 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.