janito 3.6.1__py3-none-any.whl → 3.8.0__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/README.md +4 -7
- janito/cli/chat_mode/bindings.py +0 -50
- janito/cli/chat_mode/session.py +1 -12
- janito/cli/chat_mode/shell/commands/multi.py +0 -5
- janito/cli/chat_mode/shell/commands/security/allowed_sites.py +33 -47
- janito/cli/cli_commands/list_plugins.py +43 -52
- janito/cli/cli_commands/list_tools.py +1 -6
- janito/cli/core/getters.py +0 -3
- janito/cli/core/model_guesser.py +24 -40
- janito/cli/main_cli.py +13 -10
- janito/cli/prompt_core.py +9 -47
- janito/cli/rich_terminal_reporter.py +4 -4
- janito/docs/GETTING_STARTED.md +9 -8
- janito/drivers/openai/driver.py +0 -1
- janito/drivers/zai/driver.py +0 -1
- janito/i18n/it.py +46 -46
- janito/llm/agent.py +16 -32
- janito/llm/auth_utils.py +5 -14
- janito/llm/driver.py +0 -8
- janito/plugins/__init__.py +12 -31
- janito/plugins/auto_loader.py +11 -12
- janito/plugins/auto_loader_fixed.py +11 -12
- janito/{plugin_system → plugins}/base.py +2 -5
- janito/plugins/builtin.py +1 -15
- janito/plugins/core_adapter.py +11 -89
- janito/plugins/core_loader.py +120 -0
- janito/plugins/core_loader_fixed.py +125 -0
- janito/plugins/discovery.py +5 -5
- janito/plugins/discovery_core.py +9 -14
- janito/plugins/manager.py +1 -1
- janito/providers/__init__.py +0 -1
- janito/providers/alibaba/model_info.py +10 -0
- janito/providers/alibaba/provider.py +1 -3
- janito/providers/moonshot/model_info.py +7 -7
- janito/providers/moonshot/provider.py +1 -1
- janito/tools/__init__.py +7 -41
- janito/tools/adapters/__init__.py +1 -6
- janito/tools/adapters/local/__init__.py +70 -7
- janito/{plugins/tools/core → tools/adapters/local}/ask_user.py +3 -3
- janito/tools/adapters/local/copy_file.py +87 -0
- janito/tools/adapters/local/create_file.py +138 -0
- janito/{plugins/tools/core → tools/adapters/local}/fetch_url.py +23 -20
- janito/tools/adapters/local/move_file.py +131 -0
- janito/{plugins/tools/core → tools/adapters/local}/python_code_run.py +7 -23
- janito/{plugins/tools/core → tools/adapters/local}/python_command_run.py +5 -21
- janito/{plugins/tools/core → tools/adapters/local}/python_file_run.py +5 -21
- janito/tools/adapters/local/remove_file.py +58 -0
- janito/{plugins/tools/core → tools/adapters/local}/replace_text_in_file.py +4 -4
- janito/{plugins/tools/core → tools/adapters/local}/run_bash_command.py +3 -3
- janito/{plugins/tools/core → tools/adapters/local}/run_powershell_command.py +3 -3
- janito/{plugins/tools/core → tools/adapters/local}/show_image.py +6 -15
- janito/{plugins/core/imagedisplay/tools → tools/adapters/local}/show_image_grid.py +5 -13
- janito/tools/adapters/local/view_file.py +172 -0
- janito/tools/function_adapter.py +65 -0
- janito/tools/loop_protection_decorator.py +117 -114
- janito-3.8.0.dist-info/METADATA +84 -0
- janito-3.8.0.dist-info/RECORD +264 -0
- janito/cli/cli_commands/check_tools.py +0 -212
- janito/data/blocked.txt +0 -96
- janito/llm/cancellation_manager.py +0 -63
- janito/llm/enter_cancellation.py +0 -107
- janito/plugin_system/__init__.py +0 -10
- janito/plugin_system/core_loader.py +0 -217
- janito/plugin_system/core_loader_fixed.py +0 -225
- janito/plugins/core/__init__.py +0 -7
- janito/plugins/core/codeanalyzer/__init__.py +0 -43
- janito/plugins/core/filemanager/__init__.py +0 -124
- janito/plugins/core/filemanager/tools/copy_file.py +0 -87
- janito/plugins/core/filemanager/tools/create_file.py +0 -87
- janito/plugins/core/filemanager/tools/move_file.py +0 -131
- janito/plugins/core/filemanager/tools/remove_file.py +0 -58
- janito/plugins/core/filemanager/tools/replace_text_in_file.py +0 -270
- janito/plugins/core/filemanager/tools/view_file.py +0 -172
- janito/plugins/core/imagedisplay/__init__.py +0 -14
- janito/plugins/core/imagedisplay/plugin.py +0 -51
- janito/plugins/core/imagedisplay/tools/__init__.py +0 -1
- janito/plugins/core/imagedisplay/tools/show_image.py +0 -83
- janito/plugins/core/system/__init__.py +0 -23
- janito/plugins/core/system/tools/run_bash_command.py +0 -204
- janito/plugins/core/system/tools/run_powershell_command.py +0 -234
- janito/plugins/dev/__init__.py +0 -7
- janito/plugins/dev/pythondev/__init__.py +0 -37
- janito/plugins/dev/visualization/__init__.py +0 -23
- janito/plugins/example_plugin.py +0 -108
- janito/plugins/tools/__init__.py +0 -39
- janito/plugins/tools/core/__init__.py +0 -65
- janito/plugins/tools/core/copy_file.py +0 -87
- janito/plugins/tools/core/create_directory.py +0 -70
- janito/plugins/tools/core/create_file.py +0 -138
- janito/plugins/tools/core/decorators.py +0 -19
- janito/plugins/tools/core/delete_text_in_file.py +0 -134
- janito/plugins/tools/core/find_files.py +0 -143
- janito/plugins/tools/core/get_file_outline/__init__.py +0 -7
- janito/plugins/tools/core/get_file_outline/core.py +0 -122
- janito/plugins/tools/core/get_file_outline/java_outline.py +0 -47
- janito/plugins/tools/core/get_file_outline/markdown_outline.py +0 -14
- janito/plugins/tools/core/get_file_outline/python_outline.py +0 -303
- janito/plugins/tools/core/get_file_outline/search_outline.py +0 -36
- janito/plugins/tools/core/move_file.py +0 -131
- janito/plugins/tools/core/open_html_in_browser.py +0 -51
- janito/plugins/tools/core/open_url.py +0 -37
- janito/plugins/tools/core/read_chart.py +0 -259
- janito/plugins/tools/core/read_files.py +0 -58
- janito/plugins/tools/core/remove_directory.py +0 -55
- janito/plugins/tools/core/remove_file.py +0 -58
- janito/plugins/tools/core/search_text/__init__.py +0 -7
- janito/plugins/tools/core/search_text/core.py +0 -205
- janito/plugins/tools/core/search_text/match_lines.py +0 -67
- janito/plugins/tools/core/search_text/pattern_utils.py +0 -73
- janito/plugins/tools/core/search_text/traverse_directory.py +0 -145
- janito/plugins/tools/core/show_image_grid.py +0 -85
- janito/plugins/tools/core/validate_file_syntax/__init__.py +0 -7
- janito/plugins/tools/core/validate_file_syntax/core.py +0 -114
- janito/plugins/tools/core/validate_file_syntax/css_validator.py +0 -35
- janito/plugins/tools/core/validate_file_syntax/html_validator.py +0 -100
- janito/plugins/tools/core/validate_file_syntax/jinja2_validator.py +0 -50
- janito/plugins/tools/core/validate_file_syntax/js_validator.py +0 -27
- janito/plugins/tools/core/validate_file_syntax/json_validator.py +0 -6
- janito/plugins/tools/core/validate_file_syntax/markdown_validator.py +0 -109
- janito/plugins/tools/core/validate_file_syntax/ps1_validator.py +0 -32
- janito/plugins/tools/core/validate_file_syntax/python_validator.py +0 -5
- janito/plugins/tools/core/validate_file_syntax/xml_validator.py +0 -11
- janito/plugins/tools/core/validate_file_syntax/yaml_validator.py +0 -6
- janito/plugins/tools/core/view_file.py +0 -172
- janito/plugins/ui/__init__.py +0 -7
- janito/plugins/ui/userinterface/__init__.py +0 -16
- janito/plugins/ui/userinterface/tools/ask_user.py +0 -110
- janito/plugins/web/__init__.py +0 -7
- janito/plugins/web/webtools/__init__.py +0 -23
- janito/providers/together/__init__.py +0 -1
- janito/providers/together/model_info.py +0 -69
- janito/providers/together/provider.py +0 -108
- janito/tools/blocked_sites.py +0 -74
- janito/tools/cli_initializer.py +0 -88
- janito/tools/initialize.py +0 -70
- janito-3.6.1.dist-info/METADATA +0 -228
- janito-3.6.1.dist-info/RECORD +0 -339
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/create_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/delete_text_in_file.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/find_files.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/java_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/markdown_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/python_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/search_outline.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_html_in_browser.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_url.py +0 -0
- /janito/{plugins/dev/visualization/tools → tools/adapters/local}/read_chart.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/read_files.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_directory.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/match_lines.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/pattern_utils.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/traverse_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/__init__.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/core.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/css_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/html_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/js_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/json_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/python_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/xml_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/yaml_validator.py +0 -0
- {janito-3.6.1.dist-info → janito-3.8.0.dist-info}/WHEEL +0 -0
- {janito-3.6.1.dist-info → janito-3.8.0.dist-info}/entry_points.txt +0 -0
- {janito-3.6.1.dist-info → janito-3.8.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.6.1.dist-info → janito-3.8.0.dist-info}/top_level.txt +0 -0
@@ -1,110 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.tools.adapters.local.adapter import register_local_tool
|
3
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
4
|
-
|
5
|
-
from rich import print as rich_print
|
6
|
-
from janito.i18n import tr
|
7
|
-
from rich.panel import Panel
|
8
|
-
from prompt_toolkit import PromptSession
|
9
|
-
from prompt_toolkit.key_binding import KeyBindings
|
10
|
-
from prompt_toolkit.enums import EditingMode
|
11
|
-
from prompt_toolkit.formatted_text import HTML
|
12
|
-
from janito.cli.chat_mode.prompt_style import chat_shell_style
|
13
|
-
from prompt_toolkit.styles import Style
|
14
|
-
|
15
|
-
toolbar_style = Style.from_dict({"bottom-toolbar": "fg:yellow bg:darkred"})
|
16
|
-
|
17
|
-
|
18
|
-
@register_local_tool
|
19
|
-
class AskUserTool(ToolBase):
|
20
|
-
"""
|
21
|
-
Prompts the user for clarification or input with a question.
|
22
|
-
|
23
|
-
Args:
|
24
|
-
question (str): The question to ask the user. This parameter is required and should be a string containing the prompt or question to display to the user.
|
25
|
-
Returns:
|
26
|
-
str: The user's response as a string. Example:
|
27
|
-
- "Yes"
|
28
|
-
- "No"
|
29
|
-
- "Some detailed answer..."
|
30
|
-
"""
|
31
|
-
|
32
|
-
permissions = ToolPermissions(read=True)
|
33
|
-
tool_name = "ask_user"
|
34
|
-
|
35
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="question")
|
36
|
-
def run(self, question: str) -> str:
|
37
|
-
|
38
|
-
print() # Print an empty line before the question panel
|
39
|
-
rich_print(Panel.fit(question, title=tr("Question"), style="cyan"))
|
40
|
-
|
41
|
-
bindings = KeyBindings()
|
42
|
-
mode = {"multiline": False}
|
43
|
-
|
44
|
-
@bindings.add("c-r")
|
45
|
-
def _(event):
|
46
|
-
pass
|
47
|
-
|
48
|
-
@bindings.add("f12")
|
49
|
-
def _(event):
|
50
|
-
buf = event.app.current_buffer
|
51
|
-
buf.text = "Do It"
|
52
|
-
buf.validate_and_handle()
|
53
|
-
|
54
|
-
@bindings.add("f2")
|
55
|
-
def _(event):
|
56
|
-
buf = event.app.current_buffer
|
57
|
-
buf.text = "F2"
|
58
|
-
buf.validate_and_handle()
|
59
|
-
|
60
|
-
# Use shared CLI styles
|
61
|
-
|
62
|
-
# prompt_style contains the prompt area and input background
|
63
|
-
# toolbar_style contains the bottom-toolbar styling
|
64
|
-
|
65
|
-
# Use the shared chat_shell_style for input styling only
|
66
|
-
style = chat_shell_style
|
67
|
-
|
68
|
-
def get_toolbar():
|
69
|
-
f12_hint = " F2: F2 | F12: Do It"
|
70
|
-
if mode["multiline"]:
|
71
|
-
return HTML(
|
72
|
-
f"<b>Multiline mode (Esc+Enter to submit). Type /single to switch.</b>{f12_hint}"
|
73
|
-
)
|
74
|
-
else:
|
75
|
-
return HTML(
|
76
|
-
f"<b>Single-line mode (Enter to submit). Type /multi for multiline.</b>{f12_hint}"
|
77
|
-
)
|
78
|
-
|
79
|
-
session = PromptSession(
|
80
|
-
multiline=False,
|
81
|
-
key_bindings=bindings,
|
82
|
-
editing_mode=EditingMode.EMACS,
|
83
|
-
bottom_toolbar=get_toolbar,
|
84
|
-
style=style,
|
85
|
-
)
|
86
|
-
|
87
|
-
prompt_icon = HTML("<inputline>💬 </inputline>")
|
88
|
-
|
89
|
-
while True:
|
90
|
-
response = session.prompt(prompt_icon)
|
91
|
-
if not mode["multiline"] and response.strip() == "/multi":
|
92
|
-
mode["multiline"] = True
|
93
|
-
session.multiline = True
|
94
|
-
continue
|
95
|
-
elif mode["multiline"] and response.strip() == "/single":
|
96
|
-
mode["multiline"] = False
|
97
|
-
session.multiline = False
|
98
|
-
continue
|
99
|
-
else:
|
100
|
-
sanitized = response.strip()
|
101
|
-
try:
|
102
|
-
sanitized.encode("utf-8")
|
103
|
-
except UnicodeEncodeError:
|
104
|
-
sanitized = sanitized.encode("utf-8", errors="replace").decode(
|
105
|
-
"utf-8"
|
106
|
-
)
|
107
|
-
rich_print(
|
108
|
-
"[yellow]Warning: Some characters in your input were not valid UTF-8 and have been replaced.[/yellow]"
|
109
|
-
)
|
110
|
-
return sanitized
|
janito/plugins/web/__init__.py
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Web Tools Plugin
|
3
|
-
|
4
|
-
Web scraping, browsing, and URL operations.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from typing import Optional, Dict, List
|
8
|
-
|
9
|
-
|
10
|
-
def open_url(url: str) -> str:
|
11
|
-
"""Open URLs in default browser"""
|
12
|
-
return f"open_url(url='{url}')"
|
13
|
-
|
14
|
-
|
15
|
-
def open_html_in_browser(path: str) -> str:
|
16
|
-
"""Open local HTML files in browser"""
|
17
|
-
return f"open_html_in_browser(path='{path}')"
|
18
|
-
|
19
|
-
|
20
|
-
# Plugin metadata
|
21
|
-
__plugin_name__ = "web.webtools"
|
22
|
-
__plugin_description__ = "Web scraping, browsing, and URL operations"
|
23
|
-
__plugin_tools__ = [open_url, open_html_in_browser]
|
@@ -1 +0,0 @@
|
|
1
|
-
# Together AI provider for Janito
|
@@ -1,69 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Model specifications for Together AI provider.
|
3
|
-
"""
|
4
|
-
|
5
|
-
MODEL_SPECS = {
|
6
|
-
"allenai/OLMo-2-0325-32B-Instruct": {
|
7
|
-
"max_tokens": 32768,
|
8
|
-
"max_input_tokens": 32768,
|
9
|
-
"max_output_tokens": 32768,
|
10
|
-
"description": "OLMo 2 32B Instruct - Fully open language model from AllenAI",
|
11
|
-
"supports_tools": True,
|
12
|
-
"supports_system_prompt": True,
|
13
|
-
"supports_streaming": True,
|
14
|
-
},
|
15
|
-
"allenai/OLMo-2-1124-7B-Instruct": {
|
16
|
-
"max_tokens": 32768,
|
17
|
-
"max_input_tokens": 32768,
|
18
|
-
"max_output_tokens": 32768,
|
19
|
-
"description": "OLMo 2 7B Instruct - Fully open language model from AllenAI",
|
20
|
-
"supports_tools": True,
|
21
|
-
"supports_system_prompt": True,
|
22
|
-
"supports_streaming": True,
|
23
|
-
},
|
24
|
-
"allenai/OLMo-2-0425-1B": {
|
25
|
-
"max_tokens": 32768,
|
26
|
-
"max_input_tokens": 32768,
|
27
|
-
"max_output_tokens": 32768,
|
28
|
-
"description": "OLMo 2 1B - Fully open language model from AllenAI",
|
29
|
-
"supports_tools": True,
|
30
|
-
"supports_system_prompt": True,
|
31
|
-
"supports_streaming": True,
|
32
|
-
},
|
33
|
-
"meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo": {
|
34
|
-
"max_tokens": 8192,
|
35
|
-
"max_input_tokens": 128000,
|
36
|
-
"max_output_tokens": 8192,
|
37
|
-
"description": "Llama 3.1 8B Instruct Turbo",
|
38
|
-
"supports_tools": True,
|
39
|
-
"supports_system_prompt": True,
|
40
|
-
"supports_streaming": True,
|
41
|
-
},
|
42
|
-
"meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo": {
|
43
|
-
"max_tokens": 8192,
|
44
|
-
"max_input_tokens": 128000,
|
45
|
-
"max_output_tokens": 8192,
|
46
|
-
"description": "Llama 3.1 70B Instruct Turbo",
|
47
|
-
"supports_tools": True,
|
48
|
-
"supports_system_prompt": True,
|
49
|
-
"supports_streaming": True,
|
50
|
-
},
|
51
|
-
"mistralai/Mixtral-8x7B-Instruct-v0.1": {
|
52
|
-
"max_tokens": 32768,
|
53
|
-
"max_input_tokens": 32768,
|
54
|
-
"max_output_tokens": 32768,
|
55
|
-
"description": "Mixtral 8x7B Instruct",
|
56
|
-
"supports_tools": True,
|
57
|
-
"supports_system_prompt": True,
|
58
|
-
"supports_streaming": True,
|
59
|
-
},
|
60
|
-
"deepseek-ai/deepseek-llm-67b-chat": {
|
61
|
-
"max_tokens": 4096,
|
62
|
-
"max_input_tokens": 4096,
|
63
|
-
"max_output_tokens": 4096,
|
64
|
-
"description": "DeepSeek LLM 67B Chat",
|
65
|
-
"supports_tools": True,
|
66
|
-
"supports_system_prompt": True,
|
67
|
-
"supports_streaming": True,
|
68
|
-
},
|
69
|
-
}
|
@@ -1,108 +0,0 @@
|
|
1
|
-
from janito.llm.provider import LLMProvider
|
2
|
-
from janito.llm.model import LLMModelInfo
|
3
|
-
from janito.llm.auth import LLMAuthManager
|
4
|
-
from janito.llm.driver_config import LLMDriverConfig
|
5
|
-
from janito.drivers.openai.driver import OpenAIModelDriver
|
6
|
-
from janito.tools import get_local_tools_adapter
|
7
|
-
from janito.providers.registry import LLMProviderRegistry
|
8
|
-
from .model_info import MODEL_SPECS
|
9
|
-
from queue import Queue
|
10
|
-
|
11
|
-
available = OpenAIModelDriver.available
|
12
|
-
unavailable_reason = OpenAIModelDriver.unavailable_reason
|
13
|
-
|
14
|
-
|
15
|
-
class TogetherProvider(LLMProvider):
|
16
|
-
name = 'together'
|
17
|
-
NAME = 'together'
|
18
|
-
MAINTAINER = 'Janito Team'
|
19
|
-
MODEL_SPECS = MODEL_SPECS
|
20
|
-
DEFAULT_MODEL = 'allenai/OLMo-2-0325-32B-Instruct'
|
21
|
-
|
22
|
-
def __init__(
|
23
|
-
self, auth_manager: LLMAuthManager = None, config: LLMDriverConfig = None
|
24
|
-
):
|
25
|
-
self._tools_adapter = get_local_tools_adapter()
|
26
|
-
self._driver = None
|
27
|
-
|
28
|
-
if not self.available:
|
29
|
-
return
|
30
|
-
|
31
|
-
self._initialize_config(auth_manager, config)
|
32
|
-
self._setup_model_config()
|
33
|
-
|
34
|
-
def _initialize_config(self, auth_manager, config):
|
35
|
-
self.auth_manager = auth_manager or LLMAuthManager()
|
36
|
-
self._api_key = self.auth_manager.get_credentials(type(self).NAME)
|
37
|
-
if not self._api_key:
|
38
|
-
from janito.llm.auth_utils import handle_missing_api_key
|
39
|
-
handle_missing_api_key(self.name, 'TOGETHER_API_KEY')
|
40
|
-
|
41
|
-
self._driver_config = config or LLMDriverConfig(model=None)
|
42
|
-
if not self._driver_config.model:
|
43
|
-
self._driver_config.model = self.DEFAULT_MODEL
|
44
|
-
if not self._driver_config.api_key:
|
45
|
-
self._driver_config.api_key = self._api_key
|
46
|
-
|
47
|
-
self._driver_config.base_url = 'https://api.together.xyz/v1'
|
48
|
-
|
49
|
-
def _setup_model_config(self):
|
50
|
-
model_name = self._driver_config.model
|
51
|
-
model_spec = self.MODEL_SPECS.get(model_name)
|
52
|
-
|
53
|
-
if hasattr(self._driver_config, 'max_tokens'):
|
54
|
-
self._driver_config.max_tokens = None
|
55
|
-
if hasattr(self._driver_config, 'max_completion_tokens'):
|
56
|
-
self._driver_config.max_completion_tokens = None
|
57
|
-
|
58
|
-
if model_spec:
|
59
|
-
max_tokens = getattr(model_spec, 'max_tokens', None)
|
60
|
-
if max_tokens and max_tokens != 'N/A':
|
61
|
-
self._driver_config.max_tokens = int(max_tokens)
|
62
|
-
|
63
|
-
self.fill_missing_device_info(self._driver_config)
|
64
|
-
|
65
|
-
@property
|
66
|
-
def driver(self) -> OpenAIModelDriver:
|
67
|
-
if not self.available:
|
68
|
-
raise ImportError(f'TogetherProvider unavailable: {self.unavailable_reason}')
|
69
|
-
return self._driver
|
70
|
-
|
71
|
-
@property
|
72
|
-
def available(self):
|
73
|
-
return available
|
74
|
-
|
75
|
-
@property
|
76
|
-
def unavailable_reason(self):
|
77
|
-
return unavailable_reason
|
78
|
-
|
79
|
-
def create_driver(self):
|
80
|
-
driver = OpenAIModelDriver(
|
81
|
-
tools_adapter=self._tools_adapter, provider_name=self.NAME
|
82
|
-
)
|
83
|
-
driver.config = self._driver_config
|
84
|
-
return driver
|
85
|
-
|
86
|
-
def create_agent(self, tools_adapter=None, agent_name: str = None, **kwargs):
|
87
|
-
from janito.llm.agent import LLMAgent
|
88
|
-
if tools_adapter is None:
|
89
|
-
tools_adapter = get_local_tools_adapter()
|
90
|
-
raise NotImplementedError(
|
91
|
-
'create_agent must be constructed via new factory using input/output queues and config.'
|
92
|
-
)
|
93
|
-
|
94
|
-
@property
|
95
|
-
def model_name(self):
|
96
|
-
return self._driver_config.model
|
97
|
-
|
98
|
-
@property
|
99
|
-
def driver_config(self):
|
100
|
-
return self._driver_config
|
101
|
-
|
102
|
-
def execute_tool(self, tool_name: str, event_bus, *args, **kwargs):
|
103
|
-
self._tools_adapter.event_bus = event_bus
|
104
|
-
return self._tools_adapter.execute_by_name(tool_name, *args, **kwargs)
|
105
|
-
|
106
|
-
|
107
|
-
LLMProviderRegistry.register(TogetherProvider.NAME, TogetherProvider)
|
108
|
-
|
janito/tools/blocked_sites.py
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
"""Blocked sites management for fetch_url tool to prevent access to known problematic sites."""
|
2
|
-
|
3
|
-
from pathlib import Path
|
4
|
-
from typing import Set
|
5
|
-
from urllib.parse import urlparse
|
6
|
-
|
7
|
-
|
8
|
-
class BlockedSitesManager:
|
9
|
-
"""Manages blocked sites for the fetch_url tool using the local blocked.txt file."""
|
10
|
-
|
11
|
-
def __init__(self):
|
12
|
-
# Use package data directory for blocked.txt
|
13
|
-
import janito
|
14
|
-
package_dir = Path(janito.__file__).parent
|
15
|
-
self.blocked_file_path = package_dir / "data" / "blocked.txt"
|
16
|
-
self._blocked_sites = self._load_blocked_sites()
|
17
|
-
|
18
|
-
def _load_blocked_sites(self) -> Set[str]:
|
19
|
-
"""Load blocked sites from the blocked.txt file."""
|
20
|
-
blocked = set()
|
21
|
-
|
22
|
-
if self.blocked_file_path.exists():
|
23
|
-
try:
|
24
|
-
with open(self.blocked_file_path, "r", encoding="utf-8") as f:
|
25
|
-
for line in f:
|
26
|
-
line = line.strip()
|
27
|
-
if line and not line.startswith("#"):
|
28
|
-
# Extract domain from URL if it's a full URL
|
29
|
-
if line.startswith("http://") or line.startswith("https://"):
|
30
|
-
parsed = urlparse(line)
|
31
|
-
domain = parsed.netloc
|
32
|
-
if domain:
|
33
|
-
blocked.add(domain.lower())
|
34
|
-
else:
|
35
|
-
# Assume it's already a domain
|
36
|
-
blocked.add(line.lower())
|
37
|
-
except IOError:
|
38
|
-
pass
|
39
|
-
|
40
|
-
return blocked
|
41
|
-
|
42
|
-
def is_url_blocked(self, url: str) -> bool:
|
43
|
-
"""Check if a URL is blocked."""
|
44
|
-
if not self._blocked_sites:
|
45
|
-
return False
|
46
|
-
|
47
|
-
try:
|
48
|
-
parsed = urlparse(url)
|
49
|
-
domain = parsed.netloc.lower()
|
50
|
-
|
51
|
-
# Check exact matches and subdomain matches
|
52
|
-
for blocked in self._blocked_sites:
|
53
|
-
if domain == blocked or domain.endswith("." + blocked):
|
54
|
-
return True
|
55
|
-
|
56
|
-
return False
|
57
|
-
except Exception:
|
58
|
-
return False # Invalid URLs are not blocked by default
|
59
|
-
|
60
|
-
def get_blocked_sites(self) -> list[str]:
|
61
|
-
"""Get the list of blocked sites."""
|
62
|
-
return sorted(self._blocked_sites)
|
63
|
-
|
64
|
-
|
65
|
-
# Global singleton
|
66
|
-
_blocked_sites_manager = None
|
67
|
-
|
68
|
-
|
69
|
-
def get_blocked_sites_manager() -> BlockedSitesManager:
|
70
|
-
"""Get the global blocked sites manager instance."""
|
71
|
-
global _blocked_sites_manager
|
72
|
-
if _blocked_sites_manager is None:
|
73
|
-
_blocked_sites_manager = BlockedSitesManager()
|
74
|
-
return _blocked_sites_manager
|
janito/tools/cli_initializer.py
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
CLI-specific tool initialization for janito.
|
3
|
-
|
4
|
-
This module provides functions to initialize tools specifically for CLI usage,
|
5
|
-
handling circular imports and ensuring proper registration.
|
6
|
-
"""
|
7
|
-
|
8
|
-
import sys
|
9
|
-
from pathlib import Path
|
10
|
-
from typing import List, Optional
|
11
|
-
|
12
|
-
# Ensure current directory is in path
|
13
|
-
sys.path.insert(0, str(Path.cwd()))
|
14
|
-
|
15
|
-
|
16
|
-
def initialize_cli_tools():
|
17
|
-
"""Initialize tools for CLI usage, avoiding circular imports."""
|
18
|
-
try:
|
19
|
-
from janito.tools.adapters.local.adapter import LocalToolsAdapter
|
20
|
-
from janito.plugin_system.core_loader_fixed import load_core_plugin
|
21
|
-
from janito.tools.permissions import set_global_allowed_permissions
|
22
|
-
from janito.tools.tool_base import ToolPermissions
|
23
|
-
|
24
|
-
# Create adapter
|
25
|
-
adapter = LocalToolsAdapter()
|
26
|
-
|
27
|
-
# Set permissions for CLI
|
28
|
-
set_global_allowed_permissions(
|
29
|
-
ToolPermissions(read=True, write=True, execute=True)
|
30
|
-
)
|
31
|
-
|
32
|
-
# Core plugins to load
|
33
|
-
core_plugins = [
|
34
|
-
"core.filemanager",
|
35
|
-
"core.codeanalyzer",
|
36
|
-
"core.system",
|
37
|
-
"core.imagedisplay",
|
38
|
-
"dev.pythondev",
|
39
|
-
"dev.visualization",
|
40
|
-
]
|
41
|
-
|
42
|
-
loaded_count = 0
|
43
|
-
for plugin_name in core_plugins:
|
44
|
-
plugin = load_core_plugin(plugin_name)
|
45
|
-
if plugin:
|
46
|
-
tools = plugin.get_tools()
|
47
|
-
for tool_class in tools:
|
48
|
-
try:
|
49
|
-
adapter.register_tool(tool_class)
|
50
|
-
loaded_count += 1
|
51
|
-
except ValueError:
|
52
|
-
# Tool already registered, skip
|
53
|
-
pass
|
54
|
-
|
55
|
-
return adapter, loaded_count
|
56
|
-
|
57
|
-
except Exception as e:
|
58
|
-
print(f"Error initializing CLI tools: {e}", file=sys.stderr)
|
59
|
-
return None, 0
|
60
|
-
|
61
|
-
|
62
|
-
def get_cli_tools_adapter():
|
63
|
-
"""Get a CLI-initialized tools adapter."""
|
64
|
-
adapter, count = initialize_cli_tools()
|
65
|
-
if adapter and count > 0:
|
66
|
-
return adapter
|
67
|
-
return None
|
68
|
-
|
69
|
-
|
70
|
-
def list_cli_tools():
|
71
|
-
"""List all available CLI tools."""
|
72
|
-
adapter = get_cli_tools_adapter()
|
73
|
-
if not adapter:
|
74
|
-
return []
|
75
|
-
|
76
|
-
return adapter.list_tools()
|
77
|
-
|
78
|
-
|
79
|
-
if __name__ == "__main__":
|
80
|
-
adapter, count = initialize_cli_tools()
|
81
|
-
if adapter:
|
82
|
-
tools = adapter.list_tools()
|
83
|
-
print(f"CLI initialized {count} tools")
|
84
|
-
print(f"Available tools: {len(tools)}")
|
85
|
-
for tool in sorted(tools):
|
86
|
-
print(f" - {tool}")
|
87
|
-
else:
|
88
|
-
print("Failed to initialize CLI tools")
|
janito/tools/initialize.py
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Initialize janito tools for CLI and programmatic usage.
|
3
|
-
|
4
|
-
This module provides functions to load core plugins and register their tools
|
5
|
-
with the local tools adapter.
|
6
|
-
"""
|
7
|
-
|
8
|
-
import sys
|
9
|
-
from pathlib import Path
|
10
|
-
from typing import List, Optional
|
11
|
-
|
12
|
-
from janito.plugin_system.core_loader_fixed import load_core_plugin
|
13
|
-
from janito.tools.adapters.local.adapter import LocalToolsAdapter
|
14
|
-
|
15
|
-
|
16
|
-
def initialize_tools(adapter: Optional[LocalToolsAdapter] = None) -> LocalToolsAdapter:
|
17
|
-
"""
|
18
|
-
Initialize all janito tools by loading core plugins and registering tools.
|
19
|
-
|
20
|
-
Args:
|
21
|
-
adapter: LocalToolsAdapter instance to register tools with.
|
22
|
-
If None, creates a new instance.
|
23
|
-
|
24
|
-
Returns:
|
25
|
-
LocalToolsAdapter with all tools registered.
|
26
|
-
"""
|
27
|
-
if adapter is None:
|
28
|
-
adapter = LocalToolsAdapter()
|
29
|
-
|
30
|
-
# Core plugins to load
|
31
|
-
core_plugins = [
|
32
|
-
"core.filemanager",
|
33
|
-
"core.codeanalyzer",
|
34
|
-
"core.system",
|
35
|
-
"core.imagedisplay",
|
36
|
-
"dev.pythondev",
|
37
|
-
"dev.visualization",
|
38
|
-
]
|
39
|
-
|
40
|
-
loaded_count = 0
|
41
|
-
for plugin_name in core_plugins:
|
42
|
-
plugin = load_core_plugin(plugin_name)
|
43
|
-
if plugin:
|
44
|
-
tools = plugin.get_tools()
|
45
|
-
for tool_class in tools:
|
46
|
-
adapter.register_tool(tool_class)
|
47
|
-
loaded_count += 1
|
48
|
-
|
49
|
-
return adapter
|
50
|
-
|
51
|
-
|
52
|
-
def get_initialized_adapter() -> LocalToolsAdapter:
|
53
|
-
"""Get a pre-initialized LocalToolsAdapter with all tools registered."""
|
54
|
-
return initialize_tools()
|
55
|
-
|
56
|
-
|
57
|
-
def list_available_tools() -> List[str]:
|
58
|
-
"""Get a list of all available tool names."""
|
59
|
-
adapter = get_initialized_adapter()
|
60
|
-
return sorted(list(adapter._tools.keys()))
|
61
|
-
|
62
|
-
|
63
|
-
if __name__ == "__main__":
|
64
|
-
adapter = initialize_tools()
|
65
|
-
tools = sorted(list(adapter._tools.keys()))
|
66
|
-
|
67
|
-
print(f"Initialized {len(tools)} tools")
|
68
|
-
print("Available tools:")
|
69
|
-
for tool_name in tools:
|
70
|
-
print(f" - {tool_name}")
|