janito 2.3.0__py3-none-any.whl → 2.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- janito/__init__.py +6 -6
- janito/cli/chat_mode/shell/autocomplete.py +21 -21
- janito/cli/chat_mode/shell/commands/clear.py +12 -12
- janito/cli/chat_mode/shell/commands/multi.py +51 -51
- janito/cli/chat_mode/shell/input_history.py +62 -62
- janito/cli/cli_commands/list_models.py +35 -35
- janito/cli/cli_commands/list_providers.py +9 -9
- janito/cli/cli_commands/list_tools.py +53 -53
- janito/cli/cli_commands/model_selection.py +50 -50
- janito/cli/cli_commands/model_utils.py +95 -95
- janito/cli/cli_commands/set_api_key.py +19 -19
- janito/cli/cli_commands/show_config.py +51 -51
- janito/cli/cli_commands/show_system_prompt.py +62 -62
- janito/cli/core/__init__.py +4 -4
- janito/cli/core/event_logger.py +59 -59
- janito/cli/core/getters.py +33 -33
- janito/cli/core/unsetters.py +54 -54
- janito/cli/single_shot_mode/__init__.py +6 -6
- janito/config.py +5 -5
- janito/config_manager.py +112 -112
- janito/drivers/anthropic/driver.py +113 -113
- janito/formatting_token.py +54 -54
- janito/i18n/__init__.py +35 -35
- janito/i18n/messages.py +23 -23
- janito/i18n/pt.py +47 -47
- janito/llm/__init__.py +5 -5
- janito/llm/agent.py +443 -443
- janito/llm/auth.py +63 -63
- janito/llm/driver_config_builder.py +34 -34
- janito/llm/driver_input.py +12 -12
- janito/llm/message_parts.py +60 -60
- janito/llm/model.py +38 -38
- janito/llm/provider.py +196 -196
- janito/provider_registry.py +176 -176
- janito/providers/anthropic/model_info.py +22 -22
- janito/providers/anthropic/provider.py +2 -0
- janito/providers/azure_openai/model_info.py +16 -16
- janito/providers/azure_openai/provider.py +3 -0
- janito/providers/deepseek/__init__.py +1 -1
- janito/providers/deepseek/model_info.py +16 -16
- janito/providers/deepseek/provider.py +94 -91
- janito/providers/google/provider.py +3 -0
- janito/providers/mistralai/provider.py +3 -0
- janito/providers/openai/provider.py +4 -0
- janito/tools/adapters/__init__.py +1 -1
- janito/tools/adapters/local/ask_user.py +102 -102
- janito/tools/adapters/local/copy_file.py +84 -84
- janito/tools/adapters/local/create_directory.py +69 -69
- janito/tools/adapters/local/create_file.py +82 -82
- janito/tools/adapters/local/fetch_url.py +97 -97
- janito/tools/adapters/local/find_files.py +138 -138
- janito/tools/adapters/local/get_file_outline/__init__.py +1 -1
- janito/tools/adapters/local/get_file_outline/core.py +117 -117
- janito/tools/adapters/local/get_file_outline/java_outline.py +40 -40
- janito/tools/adapters/local/get_file_outline/markdown_outline.py +14 -14
- janito/tools/adapters/local/get_file_outline/python_outline.py +303 -303
- janito/tools/adapters/local/get_file_outline/python_outline_v2.py +156 -156
- janito/tools/adapters/local/get_file_outline/search_outline.py +33 -33
- janito/tools/adapters/local/python_code_run.py +166 -166
- janito/tools/adapters/local/python_command_run.py +164 -164
- janito/tools/adapters/local/python_file_run.py +163 -163
- janito/tools/adapters/local/run_bash_command.py +176 -176
- janito/tools/adapters/local/run_powershell_command.py +219 -219
- janito/tools/adapters/local/search_text/__init__.py +1 -1
- janito/tools/adapters/local/search_text/core.py +201 -201
- janito/tools/adapters/local/search_text/pattern_utils.py +73 -73
- janito/tools/adapters/local/search_text/traverse_directory.py +145 -145
- janito/tools/adapters/local/validate_file_syntax/__init__.py +1 -1
- janito/tools/adapters/local/validate_file_syntax/core.py +106 -106
- janito/tools/adapters/local/validate_file_syntax/css_validator.py +35 -35
- janito/tools/adapters/local/validate_file_syntax/html_validator.py +93 -93
- janito/tools/adapters/local/validate_file_syntax/js_validator.py +27 -27
- janito/tools/adapters/local/validate_file_syntax/json_validator.py +6 -6
- janito/tools/adapters/local/validate_file_syntax/markdown_validator.py +109 -109
- janito/tools/adapters/local/validate_file_syntax/ps1_validator.py +32 -32
- janito/tools/adapters/local/validate_file_syntax/python_validator.py +5 -5
- janito/tools/adapters/local/validate_file_syntax/xml_validator.py +11 -11
- janito/tools/adapters/local/validate_file_syntax/yaml_validator.py +6 -6
- janito/tools/adapters/local/view_file.py +167 -167
- janito/tools/inspect_registry.py +17 -17
- janito/tools/tool_base.py +105 -105
- janito/tools/tool_events.py +58 -58
- janito/tools/tool_run_exception.py +12 -12
- janito/tools/tool_use_tracker.py +81 -81
- janito/tools/tool_utils.py +45 -45
- janito/tools/tools_schema.py +104 -104
- janito/version.py +4 -4
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/METADATA +390 -388
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/RECORD +93 -93
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/WHEEL +0 -0
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/entry_points.txt +0 -0
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/licenses/LICENSE +0 -0
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/top_level.txt +0 -0
janito/__init__.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
"""
|
2
|
-
janito: A Python package for managing and interacting with Large Language Model (LLM) providers and their APIs.
|
3
|
-
Provides a CLI for credential management and an extensible driver system for LLMs.
|
4
|
-
"""
|
5
|
-
|
6
|
-
__version__ = "2.3.
|
1
|
+
"""
|
2
|
+
janito: A Python package for managing and interacting with Large Language Model (LLM) providers and their APIs.
|
3
|
+
Provides a CLI for credential management and an extensible driver system for LLMs.
|
4
|
+
"""
|
5
|
+
|
6
|
+
__version__ = "2.3.1"
|
@@ -1,21 +1,21 @@
|
|
1
|
-
from prompt_toolkit.completion import Completer, Completion
|
2
|
-
from janito.cli.chat_mode.shell.commands import get_shell_command_names
|
3
|
-
|
4
|
-
|
5
|
-
class ShellCommandCompleter(Completer):
|
6
|
-
"""
|
7
|
-
Provides autocomplete suggestions for shell commands starting with '/'.
|
8
|
-
Uses the COMMAND_HANDLERS registry for available commands.
|
9
|
-
"""
|
10
|
-
|
11
|
-
def __init__(self):
|
12
|
-
# Only commands starting with '/'
|
13
|
-
self.commands = get_shell_command_names()
|
14
|
-
|
15
|
-
def get_completions(self, document, complete_event):
|
16
|
-
text = document.text_before_cursor
|
17
|
-
if text.startswith("/"):
|
18
|
-
prefix = text[1:]
|
19
|
-
for cmd in self.commands:
|
20
|
-
if cmd[1:].startswith(prefix):
|
21
|
-
yield Completion(cmd, start_position=-(len(prefix) + 1))
|
1
|
+
from prompt_toolkit.completion import Completer, Completion
|
2
|
+
from janito.cli.chat_mode.shell.commands import get_shell_command_names
|
3
|
+
|
4
|
+
|
5
|
+
class ShellCommandCompleter(Completer):
|
6
|
+
"""
|
7
|
+
Provides autocomplete suggestions for shell commands starting with '/'.
|
8
|
+
Uses the COMMAND_HANDLERS registry for available commands.
|
9
|
+
"""
|
10
|
+
|
11
|
+
def __init__(self):
|
12
|
+
# Only commands starting with '/'
|
13
|
+
self.commands = get_shell_command_names()
|
14
|
+
|
15
|
+
def get_completions(self, document, complete_event):
|
16
|
+
text = document.text_before_cursor
|
17
|
+
if text.startswith("/"):
|
18
|
+
prefix = text[1:]
|
19
|
+
for cmd in self.commands:
|
20
|
+
if cmd[1:].startswith(prefix):
|
21
|
+
yield Completion(cmd, start_position=-(len(prefix) + 1))
|
@@ -1,12 +1,12 @@
|
|
1
|
-
from janito.cli.chat_mode.shell.commands.base import ShellCmdHandler
|
2
|
-
from janito.cli.console import shared_console
|
3
|
-
|
4
|
-
|
5
|
-
class ClearShellHandler(ShellCmdHandler):
|
6
|
-
help_text = "Clear the terminal screen using Rich console."
|
7
|
-
|
8
|
-
def run(self):
|
9
|
-
shared_console.clear()
|
10
|
-
# Optionally show a message after clearing
|
11
|
-
# shared_console.print("[green]Screen cleared.[/green]")
|
12
|
-
return None
|
1
|
+
from janito.cli.chat_mode.shell.commands.base import ShellCmdHandler
|
2
|
+
from janito.cli.console import shared_console
|
3
|
+
|
4
|
+
|
5
|
+
class ClearShellHandler(ShellCmdHandler):
|
6
|
+
help_text = "Clear the terminal screen using Rich console."
|
7
|
+
|
8
|
+
def run(self):
|
9
|
+
shared_console.clear()
|
10
|
+
# Optionally show a message after clearing
|
11
|
+
# shared_console.print("[green]Screen cleared.[/green]")
|
12
|
+
return None
|
@@ -1,51 +1,51 @@
|
|
1
|
-
from prompt_toolkit.shortcuts import prompt
|
2
|
-
from prompt_toolkit.application.current import get_app
|
3
|
-
from prompt_toolkit.document import Document
|
4
|
-
from prompt_toolkit.key_binding import KeyBindings
|
5
|
-
from janito.cli.console import shared_console
|
6
|
-
from janito.cli.chat_mode.shell.commands.base import ShellCmdHandler
|
7
|
-
|
8
|
-
|
9
|
-
class MultiShellHandler(ShellCmdHandler):
|
10
|
-
help_text = "Prompt for multi-line input and display the result. Usage: /multi"
|
11
|
-
|
12
|
-
def run(self):
|
13
|
-
shared_console.print(
|
14
|
-
"[bold blue]Entering multi-line input mode. Press Esc+Enter or Ctrl+D to submit, Ctrl+C to cancel.[/bold blue]"
|
15
|
-
)
|
16
|
-
# Prompt for multi-line input
|
17
|
-
bindings = KeyBindings()
|
18
|
-
submitted = {"value": None}
|
19
|
-
|
20
|
-
@bindings.add("escape", "enter")
|
21
|
-
def _(event):
|
22
|
-
buffer = event.app.current_buffer
|
23
|
-
submitted["value"] = buffer.text
|
24
|
-
event.app.exit(result=buffer.text)
|
25
|
-
|
26
|
-
# Support Ctrl+D
|
27
|
-
@bindings.add("c-d")
|
28
|
-
def _(event):
|
29
|
-
buffer = event.app.current_buffer
|
30
|
-
submitted["value"] = buffer.text
|
31
|
-
event.app.exit(result=buffer.text)
|
32
|
-
|
33
|
-
try:
|
34
|
-
user_input = prompt(
|
35
|
-
"Multi-line > ",
|
36
|
-
multiline=True,
|
37
|
-
key_bindings=bindings,
|
38
|
-
)
|
39
|
-
except (EOFError, KeyboardInterrupt):
|
40
|
-
shared_console.print("[red]Multi-line input cancelled.[/red]")
|
41
|
-
return
|
42
|
-
|
43
|
-
# Save input to history if available
|
44
|
-
user_input_history = getattr(self.shell_state, "user_input_history", None)
|
45
|
-
if user_input_history is not None:
|
46
|
-
user_input_history.append(user_input)
|
47
|
-
# Store input for main chat loop to consume as if just entered by the user
|
48
|
-
self.shell_state.injected_input = user_input
|
49
|
-
shared_console.print(
|
50
|
-
"[green]Multi-line input will be sent as your next chat prompt.[/green]"
|
51
|
-
)
|
1
|
+
from prompt_toolkit.shortcuts import prompt
|
2
|
+
from prompt_toolkit.application.current import get_app
|
3
|
+
from prompt_toolkit.document import Document
|
4
|
+
from prompt_toolkit.key_binding import KeyBindings
|
5
|
+
from janito.cli.console import shared_console
|
6
|
+
from janito.cli.chat_mode.shell.commands.base import ShellCmdHandler
|
7
|
+
|
8
|
+
|
9
|
+
class MultiShellHandler(ShellCmdHandler):
|
10
|
+
help_text = "Prompt for multi-line input and display the result. Usage: /multi"
|
11
|
+
|
12
|
+
def run(self):
|
13
|
+
shared_console.print(
|
14
|
+
"[bold blue]Entering multi-line input mode. Press Esc+Enter or Ctrl+D to submit, Ctrl+C to cancel.[/bold blue]"
|
15
|
+
)
|
16
|
+
# Prompt for multi-line input
|
17
|
+
bindings = KeyBindings()
|
18
|
+
submitted = {"value": None}
|
19
|
+
|
20
|
+
@bindings.add("escape", "enter")
|
21
|
+
def _(event):
|
22
|
+
buffer = event.app.current_buffer
|
23
|
+
submitted["value"] = buffer.text
|
24
|
+
event.app.exit(result=buffer.text)
|
25
|
+
|
26
|
+
# Support Ctrl+D
|
27
|
+
@bindings.add("c-d")
|
28
|
+
def _(event):
|
29
|
+
buffer = event.app.current_buffer
|
30
|
+
submitted["value"] = buffer.text
|
31
|
+
event.app.exit(result=buffer.text)
|
32
|
+
|
33
|
+
try:
|
34
|
+
user_input = prompt(
|
35
|
+
"Multi-line > ",
|
36
|
+
multiline=True,
|
37
|
+
key_bindings=bindings,
|
38
|
+
)
|
39
|
+
except (EOFError, KeyboardInterrupt):
|
40
|
+
shared_console.print("[red]Multi-line input cancelled.[/red]")
|
41
|
+
return
|
42
|
+
|
43
|
+
# Save input to history if available
|
44
|
+
user_input_history = getattr(self.shell_state, "user_input_history", None)
|
45
|
+
if user_input_history is not None:
|
46
|
+
user_input_history.append(user_input)
|
47
|
+
# Store input for main chat loop to consume as if just entered by the user
|
48
|
+
self.shell_state.injected_input = user_input
|
49
|
+
shared_console.print(
|
50
|
+
"[green]Multi-line input will be sent as your next chat prompt.[/green]"
|
51
|
+
)
|
@@ -1,62 +1,62 @@
|
|
1
|
-
import os
|
2
|
-
import json
|
3
|
-
from datetime import datetime
|
4
|
-
from typing import List, Any, Dict
|
5
|
-
|
6
|
-
|
7
|
-
class UserInputHistory:
|
8
|
-
"""
|
9
|
-
Handles loading, saving, and appending of user input history for the shell.
|
10
|
-
Each day's history is stored in a line-delimited JSONL file (.jsonl) under .janito/input_history/.
|
11
|
-
Each line is a JSON dict, e.g., {"input": ..., "ts": ...}
|
12
|
-
"""
|
13
|
-
|
14
|
-
def __init__(self, history_dir=None):
|
15
|
-
self.history_dir = history_dir or os.path.join(".janito", "input_history")
|
16
|
-
os.makedirs(self.history_dir, exist_ok=True)
|
17
|
-
|
18
|
-
def _get_today_file(self):
|
19
|
-
today_str = datetime.now().strftime("%y%m%d")
|
20
|
-
return os.path.join(self.history_dir, f"{today_str}.jsonl")
|
21
|
-
|
22
|
-
def load(self) -> List[Dict[str, Any]]:
|
23
|
-
"""Load today's input history as a list of dicts."""
|
24
|
-
history_file = self._get_today_file()
|
25
|
-
history = []
|
26
|
-
try:
|
27
|
-
with open(history_file, "r", encoding="utf-8") as f:
|
28
|
-
for line in f:
|
29
|
-
line = line.strip()
|
30
|
-
if not line:
|
31
|
-
continue
|
32
|
-
try:
|
33
|
-
history.append(json.loads(line))
|
34
|
-
except json.JSONDecodeError:
|
35
|
-
continue
|
36
|
-
except FileNotFoundError:
|
37
|
-
pass
|
38
|
-
return history
|
39
|
-
|
40
|
-
def sanitize_surrogates(self, s):
|
41
|
-
if isinstance(s, str):
|
42
|
-
return s.encode("utf-8", errors="replace").decode("utf-8")
|
43
|
-
return s
|
44
|
-
|
45
|
-
def append(self, input_str: str):
|
46
|
-
"""Append a new input as a JSON dict to today's history file."""
|
47
|
-
history_file = self._get_today_file()
|
48
|
-
input_str = self.sanitize_surrogates(input_str)
|
49
|
-
entry = {"input": input_str, "ts": datetime.now().isoformat()}
|
50
|
-
with open(history_file, "a", encoding="utf-8") as f:
|
51
|
-
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
|
52
|
-
|
53
|
-
def save(self, history_list: List[Any]):
|
54
|
-
"""Overwrite today's history file with the given list (for compatibility)."""
|
55
|
-
history_file = self._get_today_file()
|
56
|
-
with open(history_file, "w", encoding="utf-8") as f:
|
57
|
-
for item in history_list:
|
58
|
-
if isinstance(item, dict):
|
59
|
-
f.write(json.dumps(item, ensure_ascii=False) + "\n")
|
60
|
-
else:
|
61
|
-
entry = {"input": str(item), "ts": datetime.now().isoformat()}
|
62
|
-
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
|
1
|
+
import os
|
2
|
+
import json
|
3
|
+
from datetime import datetime
|
4
|
+
from typing import List, Any, Dict
|
5
|
+
|
6
|
+
|
7
|
+
class UserInputHistory:
|
8
|
+
"""
|
9
|
+
Handles loading, saving, and appending of user input history for the shell.
|
10
|
+
Each day's history is stored in a line-delimited JSONL file (.jsonl) under .janito/input_history/.
|
11
|
+
Each line is a JSON dict, e.g., {"input": ..., "ts": ...}
|
12
|
+
"""
|
13
|
+
|
14
|
+
def __init__(self, history_dir=None):
|
15
|
+
self.history_dir = history_dir or os.path.join(".janito", "input_history")
|
16
|
+
os.makedirs(self.history_dir, exist_ok=True)
|
17
|
+
|
18
|
+
def _get_today_file(self):
|
19
|
+
today_str = datetime.now().strftime("%y%m%d")
|
20
|
+
return os.path.join(self.history_dir, f"{today_str}.jsonl")
|
21
|
+
|
22
|
+
def load(self) -> List[Dict[str, Any]]:
|
23
|
+
"""Load today's input history as a list of dicts."""
|
24
|
+
history_file = self._get_today_file()
|
25
|
+
history = []
|
26
|
+
try:
|
27
|
+
with open(history_file, "r", encoding="utf-8") as f:
|
28
|
+
for line in f:
|
29
|
+
line = line.strip()
|
30
|
+
if not line:
|
31
|
+
continue
|
32
|
+
try:
|
33
|
+
history.append(json.loads(line))
|
34
|
+
except json.JSONDecodeError:
|
35
|
+
continue
|
36
|
+
except FileNotFoundError:
|
37
|
+
pass
|
38
|
+
return history
|
39
|
+
|
40
|
+
def sanitize_surrogates(self, s):
|
41
|
+
if isinstance(s, str):
|
42
|
+
return s.encode("utf-8", errors="replace").decode("utf-8")
|
43
|
+
return s
|
44
|
+
|
45
|
+
def append(self, input_str: str):
|
46
|
+
"""Append a new input as a JSON dict to today's history file."""
|
47
|
+
history_file = self._get_today_file()
|
48
|
+
input_str = self.sanitize_surrogates(input_str)
|
49
|
+
entry = {"input": input_str, "ts": datetime.now().isoformat()}
|
50
|
+
with open(history_file, "a", encoding="utf-8") as f:
|
51
|
+
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
|
52
|
+
|
53
|
+
def save(self, history_list: List[Any]):
|
54
|
+
"""Overwrite today's history file with the given list (for compatibility)."""
|
55
|
+
history_file = self._get_today_file()
|
56
|
+
with open(history_file, "w", encoding="utf-8") as f:
|
57
|
+
for item in history_list:
|
58
|
+
if isinstance(item, dict):
|
59
|
+
f.write(json.dumps(item, ensure_ascii=False) + "\n")
|
60
|
+
else:
|
61
|
+
entry = {"input": str(item), "ts": datetime.now().isoformat()}
|
62
|
+
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
|
@@ -1,35 +1,35 @@
|
|
1
|
-
"""
|
2
|
-
CLI Command: List models for the specified/current provider
|
3
|
-
"""
|
4
|
-
|
5
|
-
from janito.cli.cli_commands.model_utils import _print_models_table
|
6
|
-
import sys
|
7
|
-
|
8
|
-
_provider_instance = None
|
9
|
-
|
10
|
-
|
11
|
-
def get_provider_instance():
|
12
|
-
global _provider_instance
|
13
|
-
if _provider_instance is None:
|
14
|
-
_provider_instance = setup_provider()
|
15
|
-
return _provider_instance
|
16
|
-
|
17
|
-
|
18
|
-
def handle_list_models(args, provider_instance):
|
19
|
-
provider_name = getattr(provider_instance, "name", None)
|
20
|
-
if not provider_name:
|
21
|
-
print(
|
22
|
-
"Error: Provider must be specified with --provider or set as default before listing models."
|
23
|
-
)
|
24
|
-
sys.exit(1)
|
25
|
-
try:
|
26
|
-
models = list(provider_instance.get_model_info().values())
|
27
|
-
if models and isinstance(models[0], dict):
|
28
|
-
_print_models_table(models, provider_name)
|
29
|
-
else:
|
30
|
-
print(f"Supported models for provider '{provider_name}':")
|
31
|
-
for m in models:
|
32
|
-
print(f"- {m}")
|
33
|
-
except Exception as e:
|
34
|
-
print(f"Error listing models for provider '{provider_name}': {e}")
|
35
|
-
sys.exit(0)
|
1
|
+
"""
|
2
|
+
CLI Command: List models for the specified/current provider
|
3
|
+
"""
|
4
|
+
|
5
|
+
from janito.cli.cli_commands.model_utils import _print_models_table
|
6
|
+
import sys
|
7
|
+
|
8
|
+
_provider_instance = None
|
9
|
+
|
10
|
+
|
11
|
+
def get_provider_instance():
|
12
|
+
global _provider_instance
|
13
|
+
if _provider_instance is None:
|
14
|
+
_provider_instance = setup_provider()
|
15
|
+
return _provider_instance
|
16
|
+
|
17
|
+
|
18
|
+
def handle_list_models(args, provider_instance):
|
19
|
+
provider_name = getattr(provider_instance, "name", None)
|
20
|
+
if not provider_name:
|
21
|
+
print(
|
22
|
+
"Error: Provider must be specified with --provider or set as default before listing models."
|
23
|
+
)
|
24
|
+
sys.exit(1)
|
25
|
+
try:
|
26
|
+
models = list(provider_instance.get_model_info().values())
|
27
|
+
if models and isinstance(models[0], dict):
|
28
|
+
_print_models_table(models, provider_name)
|
29
|
+
else:
|
30
|
+
print(f"Supported models for provider '{provider_name}':")
|
31
|
+
for m in models:
|
32
|
+
print(f"- {m}")
|
33
|
+
except Exception as e:
|
34
|
+
print(f"Error listing models for provider '{provider_name}': {e}")
|
35
|
+
sys.exit(0)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
"""
|
2
|
-
CLI Command: List supported LLM providers
|
3
|
-
"""
|
4
|
-
|
5
|
-
from janito.provider_registry import list_providers
|
6
|
-
|
7
|
-
|
8
|
-
def handle_list_providers(args=None):
|
9
|
-
list_providers()
|
1
|
+
"""
|
2
|
+
CLI Command: List supported LLM providers
|
3
|
+
"""
|
4
|
+
|
5
|
+
from janito.provider_registry import list_providers
|
6
|
+
|
7
|
+
|
8
|
+
def handle_list_providers(args=None):
|
9
|
+
list_providers()
|
@@ -1,53 +1,53 @@
|
|
1
|
-
"""
|
2
|
-
CLI Command: List available tools
|
3
|
-
"""
|
4
|
-
|
5
|
-
|
6
|
-
def handle_list_tools(args=None):
|
7
|
-
from janito.tools.adapters.local.adapter import LocalToolsAdapter
|
8
|
-
import janito.tools # Ensure all tools are registered
|
9
|
-
|
10
|
-
registry = janito.tools.get_local_tools_adapter()
|
11
|
-
tools = registry.list_tools()
|
12
|
-
if tools:
|
13
|
-
from rich.table import Table
|
14
|
-
from rich.console import Console
|
15
|
-
console = Console()
|
16
|
-
# Get tool instances to check provides_execution and get info
|
17
|
-
tool_instances = {t.tool_name: t for t in registry.get_tools()}
|
18
|
-
normal_tools = []
|
19
|
-
exec_tools = []
|
20
|
-
for tool in tools:
|
21
|
-
inst = tool_instances.get(tool, None)
|
22
|
-
# Extract parameter names from run signature
|
23
|
-
param_names = []
|
24
|
-
if inst and hasattr(inst, "run"):
|
25
|
-
import inspect
|
26
|
-
sig = inspect.signature(inst.run)
|
27
|
-
param_names = [p for p in sig.parameters if p != "self"]
|
28
|
-
info = {
|
29
|
-
"name": tool,
|
30
|
-
"params": ", ".join(param_names),
|
31
|
-
}
|
32
|
-
if getattr(inst, "provides_execution", False):
|
33
|
-
exec_tools.append(info)
|
34
|
-
else:
|
35
|
-
normal_tools.append(info)
|
36
|
-
table = Table(title="Registered tools", show_header=True, header_style="bold", show_lines=False, box=None)
|
37
|
-
table.add_column("Name", style="cyan", no_wrap=True)
|
38
|
-
table.add_column("Parameters", style="yellow")
|
39
|
-
for info in normal_tools:
|
40
|
-
table.add_row(info["name"], info["params"] or "-")
|
41
|
-
console.print(table)
|
42
|
-
if exec_tools:
|
43
|
-
exec_table = Table(title="Execution tools (only available with -x)", show_header=True, header_style="bold", show_lines=False, box=None)
|
44
|
-
exec_table.add_column("Name", style="cyan", no_wrap=True)
|
45
|
-
exec_table.add_column("Parameters", style="yellow")
|
46
|
-
for info in exec_tools:
|
47
|
-
exec_table.add_row(info["name"], info["params"] or "-")
|
48
|
-
console.print(exec_table)
|
49
|
-
else:
|
50
|
-
print("No tools registered.")
|
51
|
-
import sys
|
52
|
-
|
53
|
-
sys.exit(0)
|
1
|
+
"""
|
2
|
+
CLI Command: List available tools
|
3
|
+
"""
|
4
|
+
|
5
|
+
|
6
|
+
def handle_list_tools(args=None):
|
7
|
+
from janito.tools.adapters.local.adapter import LocalToolsAdapter
|
8
|
+
import janito.tools # Ensure all tools are registered
|
9
|
+
|
10
|
+
registry = janito.tools.get_local_tools_adapter()
|
11
|
+
tools = registry.list_tools()
|
12
|
+
if tools:
|
13
|
+
from rich.table import Table
|
14
|
+
from rich.console import Console
|
15
|
+
console = Console()
|
16
|
+
# Get tool instances to check provides_execution and get info
|
17
|
+
tool_instances = {t.tool_name: t for t in registry.get_tools()}
|
18
|
+
normal_tools = []
|
19
|
+
exec_tools = []
|
20
|
+
for tool in tools:
|
21
|
+
inst = tool_instances.get(tool, None)
|
22
|
+
# Extract parameter names from run signature
|
23
|
+
param_names = []
|
24
|
+
if inst and hasattr(inst, "run"):
|
25
|
+
import inspect
|
26
|
+
sig = inspect.signature(inst.run)
|
27
|
+
param_names = [p for p in sig.parameters if p != "self"]
|
28
|
+
info = {
|
29
|
+
"name": tool,
|
30
|
+
"params": ", ".join(param_names),
|
31
|
+
}
|
32
|
+
if getattr(inst, "provides_execution", False):
|
33
|
+
exec_tools.append(info)
|
34
|
+
else:
|
35
|
+
normal_tools.append(info)
|
36
|
+
table = Table(title="Registered tools", show_header=True, header_style="bold", show_lines=False, box=None)
|
37
|
+
table.add_column("Name", style="cyan", no_wrap=True)
|
38
|
+
table.add_column("Parameters", style="yellow")
|
39
|
+
for info in normal_tools:
|
40
|
+
table.add_row(info["name"], info["params"] or "-")
|
41
|
+
console.print(table)
|
42
|
+
if exec_tools:
|
43
|
+
exec_table = Table(title="Execution tools (only available with -x)", show_header=True, header_style="bold", show_lines=False, box=None)
|
44
|
+
exec_table.add_column("Name", style="cyan", no_wrap=True)
|
45
|
+
exec_table.add_column("Parameters", style="yellow")
|
46
|
+
for info in exec_tools:
|
47
|
+
exec_table.add_row(info["name"], info["params"] or "-")
|
48
|
+
console.print(exec_table)
|
49
|
+
else:
|
50
|
+
print("No tools registered.")
|
51
|
+
import sys
|
52
|
+
|
53
|
+
sys.exit(0)
|
@@ -1,50 +1,50 @@
|
|
1
|
-
"""
|
2
|
-
CLI Command: Validate and set the model provider selection
|
3
|
-
"""
|
4
|
-
|
5
|
-
from janito.cli.config import config
|
6
|
-
|
7
|
-
_provider_instance = None
|
8
|
-
|
9
|
-
|
10
|
-
def get_provider_instance():
|
11
|
-
global _provider_instance
|
12
|
-
if _provider_instance is None:
|
13
|
-
_provider_instance = setup_provider()
|
14
|
-
return _provider_instance
|
15
|
-
|
16
|
-
|
17
|
-
def handle_model_selection(args):
|
18
|
-
if getattr(args, "model", None):
|
19
|
-
provider_instance = get_provider_instance()
|
20
|
-
provider_name = getattr(provider_instance, "name", None)
|
21
|
-
if not provider_name:
|
22
|
-
print(
|
23
|
-
"Error: Provider must be specified with --provider or set as default before selecting a model."
|
24
|
-
)
|
25
|
-
import sys
|
26
|
-
|
27
|
-
sys.exit(1)
|
28
|
-
if not validate_model_for_provider(provider_name, args.model):
|
29
|
-
sys.exit(1)
|
30
|
-
config.runtime_set("model", args.model)
|
31
|
-
|
32
|
-
|
33
|
-
def validate_model_for_provider(provider_name, model_name):
|
34
|
-
try:
|
35
|
-
provider_instance = get_provider_instance()
|
36
|
-
info_dict = provider_instance.get_model_info()
|
37
|
-
available_names = [
|
38
|
-
m["name"] for m in info_dict.values() if isinstance(m, dict) and "name" in m
|
39
|
-
]
|
40
|
-
if model_name in available_names:
|
41
|
-
return True
|
42
|
-
else:
|
43
|
-
print(
|
44
|
-
f"Error: Model '{model_name}' is not available for provider '{provider_name}'."
|
45
|
-
)
|
46
|
-
print(f"Available models: {', '.join(available_names)}")
|
47
|
-
return False
|
48
|
-
except Exception as e:
|
49
|
-
print(f"Error validating model for provider '{provider_name}': {e}")
|
50
|
-
return False
|
1
|
+
"""
|
2
|
+
CLI Command: Validate and set the model provider selection
|
3
|
+
"""
|
4
|
+
|
5
|
+
from janito.cli.config import config
|
6
|
+
|
7
|
+
_provider_instance = None
|
8
|
+
|
9
|
+
|
10
|
+
def get_provider_instance():
|
11
|
+
global _provider_instance
|
12
|
+
if _provider_instance is None:
|
13
|
+
_provider_instance = setup_provider()
|
14
|
+
return _provider_instance
|
15
|
+
|
16
|
+
|
17
|
+
def handle_model_selection(args):
|
18
|
+
if getattr(args, "model", None):
|
19
|
+
provider_instance = get_provider_instance()
|
20
|
+
provider_name = getattr(provider_instance, "name", None)
|
21
|
+
if not provider_name:
|
22
|
+
print(
|
23
|
+
"Error: Provider must be specified with --provider or set as default before selecting a model."
|
24
|
+
)
|
25
|
+
import sys
|
26
|
+
|
27
|
+
sys.exit(1)
|
28
|
+
if not validate_model_for_provider(provider_name, args.model):
|
29
|
+
sys.exit(1)
|
30
|
+
config.runtime_set("model", args.model)
|
31
|
+
|
32
|
+
|
33
|
+
def validate_model_for_provider(provider_name, model_name):
|
34
|
+
try:
|
35
|
+
provider_instance = get_provider_instance()
|
36
|
+
info_dict = provider_instance.get_model_info()
|
37
|
+
available_names = [
|
38
|
+
m["name"] for m in info_dict.values() if isinstance(m, dict) and "name" in m
|
39
|
+
]
|
40
|
+
if model_name in available_names:
|
41
|
+
return True
|
42
|
+
else:
|
43
|
+
print(
|
44
|
+
f"Error: Model '{model_name}' is not available for provider '{provider_name}'."
|
45
|
+
)
|
46
|
+
print(f"Available models: {', '.join(available_names)}")
|
47
|
+
return False
|
48
|
+
except Exception as e:
|
49
|
+
print(f"Error validating model for provider '{provider_name}': {e}")
|
50
|
+
return False
|