janito 3.12.1__py3-none-any.whl → 3.12.3__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/agent/setup_agent.py +378 -377
- janito/cli/chat_mode/session.py +505 -505
- janito/cli/cli_commands/list_profiles.py +104 -107
- janito/cli/cli_commands/show_system_prompt.py +166 -166
- janito/cli/core/runner.py +250 -266
- janito/cli/main_cli.py +520 -519
- janito/cli/single_shot_mode/handler.py +167 -167
- janito/llm/__init__.py +6 -5
- janito/llm/driver.py +290 -254
- janito/llm/response_cache.py +57 -0
- janito/plugins/builtin.py +64 -88
- janito/plugins/tools/local/__init__.py +82 -80
- janito/plugins/tools/local/markdown_view.py +94 -0
- janito/plugins/tools/local/read_files.py +1 -1
- janito/plugins/tools/local/replace_text_in_file.py +1 -1
- janito/plugins/tools/local/search_text/core.py +2 -2
- janito/plugins/tools/local/show_image.py +119 -74
- janito/plugins/tools/local/show_image_grid.py +134 -76
- janito/plugins/tools/local/view_file.py +3 -3
- janito/providers/alibaba/model_info.py +136 -105
- janito/providers/alibaba/provider.py +104 -104
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/METADATA +1 -1
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/RECORD +27 -25
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/WHEEL +0 -0
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/entry_points.txt +0 -0
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/licenses/LICENSE +0 -0
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/top_level.txt +0 -0
@@ -1,167 +1,167 @@
|
|
1
|
-
"""
|
2
|
-
PromptHandler: Handles prompt submission and response formatting for janito CLI (one-shot prompt execution).
|
3
|
-
"""
|
4
|
-
|
5
|
-
from __future__ import annotations
|
6
|
-
|
7
|
-
from janito.cli.prompt_setup import setup_agent_and_prompt_handler
|
8
|
-
import janito.tools # Ensure all tools are registered
|
9
|
-
from janito.cli.console import shared_console
|
10
|
-
import time
|
11
|
-
|
12
|
-
|
13
|
-
class PromptHandler:
|
14
|
-
def __init__(
|
15
|
-
self,
|
16
|
-
args,
|
17
|
-
provider_instance,
|
18
|
-
llm_driver_config,
|
19
|
-
role=None,
|
20
|
-
allowed_permissions=None,
|
21
|
-
):
|
22
|
-
self.args = args
|
23
|
-
self.provider_instance = provider_instance
|
24
|
-
self.llm_driver_config = llm_driver_config
|
25
|
-
self.role = role
|
26
|
-
# Instantiate agent together with prompt handler using the shared helper
|
27
|
-
# Handle --developer and --market flags for single shot mode
|
28
|
-
profile = getattr(args, "profile", None)
|
29
|
-
if profile is None and getattr(args, "developer", False):
|
30
|
-
profile = "Developer
|
31
|
-
if profile is None and getattr(args, "market", False):
|
32
|
-
profile = "Market Analyst"
|
33
|
-
|
34
|
-
self.agent, self.generic_handler = setup_agent_and_prompt_handler(
|
35
|
-
args=args,
|
36
|
-
provider_instance=provider_instance,
|
37
|
-
llm_driver_config=llm_driver_config,
|
38
|
-
role=role,
|
39
|
-
verbose_tools=getattr(args, "verbose_tools", False),
|
40
|
-
verbose_agent=getattr(args, "verbose_agent", False),
|
41
|
-
allowed_permissions=allowed_permissions,
|
42
|
-
profile=profile,
|
43
|
-
)
|
44
|
-
|
45
|
-
def handle(self) -> None:
|
46
|
-
import traceback
|
47
|
-
|
48
|
-
# Check if interactive mode is requested - if so, switch to chat mode
|
49
|
-
if getattr(self.args, "interactive", False):
|
50
|
-
from janito.cli.chat_mode.session import ChatSession
|
51
|
-
from rich.console import Console
|
52
|
-
|
53
|
-
console = Console()
|
54
|
-
session = ChatSession(
|
55
|
-
console,
|
56
|
-
self.provider_instance,
|
57
|
-
self.llm_driver_config,
|
58
|
-
role=self.role,
|
59
|
-
args=self.args,
|
60
|
-
verbose_tools=getattr(self.args, "verbose_tools", False),
|
61
|
-
verbose_agent=getattr(self.args, "verbose_agent", False),
|
62
|
-
allowed_permissions=getattr(self, 'allowed_permissions', None),
|
63
|
-
)
|
64
|
-
session.run()
|
65
|
-
return
|
66
|
-
|
67
|
-
user_prompt = " ".join(getattr(self.args, "user_prompt", [])).strip()
|
68
|
-
# UTF-8 sanitize user_prompt
|
69
|
-
sanitized = user_prompt
|
70
|
-
try:
|
71
|
-
sanitized.encode("utf-8")
|
72
|
-
except UnicodeEncodeError:
|
73
|
-
sanitized = sanitized.encode("utf-8", errors="replace").decode("utf-8")
|
74
|
-
shared_console.print(
|
75
|
-
"[yellow]Warning: Some characters in your input were not valid UTF-8 and have been replaced.[/yellow]"
|
76
|
-
)
|
77
|
-
import time
|
78
|
-
|
79
|
-
try:
|
80
|
-
start_time = time.time()
|
81
|
-
|
82
|
-
# Print rule line with model info before processing prompt
|
83
|
-
model_name = (
|
84
|
-
self.agent.get_model_name()
|
85
|
-
if hasattr(self.agent, "get_model_name")
|
86
|
-
else "Unknown"
|
87
|
-
)
|
88
|
-
provider_name = (
|
89
|
-
self.agent.get_provider_name()
|
90
|
-
if hasattr(self.agent, "get_provider_name")
|
91
|
-
else "Unknown"
|
92
|
-
)
|
93
|
-
|
94
|
-
# Get backend hostname if available
|
95
|
-
backend_hostname = "Unknown"
|
96
|
-
if hasattr(self.agent, "driver") and self.agent.driver:
|
97
|
-
if hasattr(self.agent.driver, "config") and hasattr(
|
98
|
-
self.agent.driver.config, "base_url"
|
99
|
-
):
|
100
|
-
base_url = self.agent.driver.config.base_url
|
101
|
-
if base_url:
|
102
|
-
try:
|
103
|
-
from urllib.parse import urlparse
|
104
|
-
|
105
|
-
parsed = urlparse(base_url)
|
106
|
-
backend_hostname = parsed.netloc
|
107
|
-
except Exception:
|
108
|
-
backend_hostname = base_url
|
109
|
-
|
110
|
-
from rich.rule import Rule
|
111
|
-
|
112
|
-
shared_console.print(
|
113
|
-
Rule(
|
114
|
-
f"[bold blue]Model: {model_name} ({provider_name}) | Backend: {backend_hostname}[/bold blue]"
|
115
|
-
)
|
116
|
-
)
|
117
|
-
|
118
|
-
self.generic_handler.handle_prompt(
|
119
|
-
sanitized,
|
120
|
-
args=self.args,
|
121
|
-
print_header=True,
|
122
|
-
raw=getattr(self.args, "raw", False),
|
123
|
-
)
|
124
|
-
end_time = time.time()
|
125
|
-
elapsed = end_time - start_time
|
126
|
-
self._post_prompt_actions(elapsed=elapsed)
|
127
|
-
if hasattr(self.args, "verbose_agent") and self.args.verbose_agent:
|
128
|
-
print("[debug] handle_prompt() completed without exception.")
|
129
|
-
except Exception as e:
|
130
|
-
print(
|
131
|
-
f"[error] Exception occurred in handle_prompt: {type(e).__name__}: {e}"
|
132
|
-
)
|
133
|
-
traceback.print_exc()
|
134
|
-
|
135
|
-
def _post_prompt_actions(self, elapsed=None):
|
136
|
-
# Align with chat mode: only print token usage summary
|
137
|
-
import sys
|
138
|
-
from janito.formatting_token import print_token_message_summary
|
139
|
-
from janito.perf_singleton import performance_collector
|
140
|
-
|
141
|
-
usage = performance_collector.get_last_request_usage()
|
142
|
-
# If running in stdin mode, do not print token usage
|
143
|
-
if sys.stdin.isatty():
|
144
|
-
print_token_message_summary(
|
145
|
-
shared_console, msg_count=1, usage=usage, elapsed=elapsed
|
146
|
-
)
|
147
|
-
self._cleanup_driver_and_console()
|
148
|
-
|
149
|
-
def _cleanup_driver_and_console(self):
|
150
|
-
if hasattr(self.agent, "join_driver"):
|
151
|
-
if (
|
152
|
-
hasattr(self.agent, "input_queue")
|
153
|
-
and self.agent.input_queue is not None
|
154
|
-
):
|
155
|
-
self.agent.input_queue.put(None)
|
156
|
-
self.agent.join_driver()
|
157
|
-
try:
|
158
|
-
shared_console.file.flush()
|
159
|
-
except Exception:
|
160
|
-
pass
|
161
|
-
try:
|
162
|
-
import sys
|
163
|
-
|
164
|
-
sys.stdout.flush()
|
165
|
-
except Exception:
|
166
|
-
pass
|
167
|
-
# If event logger is active, flush event log
|
1
|
+
"""
|
2
|
+
PromptHandler: Handles prompt submission and response formatting for janito CLI (one-shot prompt execution).
|
3
|
+
"""
|
4
|
+
|
5
|
+
from __future__ import annotations
|
6
|
+
|
7
|
+
from janito.cli.prompt_setup import setup_agent_and_prompt_handler
|
8
|
+
import janito.tools # Ensure all tools are registered
|
9
|
+
from janito.cli.console import shared_console
|
10
|
+
import time
|
11
|
+
|
12
|
+
|
13
|
+
class PromptHandler:
|
14
|
+
def __init__(
|
15
|
+
self,
|
16
|
+
args,
|
17
|
+
provider_instance,
|
18
|
+
llm_driver_config,
|
19
|
+
role=None,
|
20
|
+
allowed_permissions=None,
|
21
|
+
):
|
22
|
+
self.args = args
|
23
|
+
self.provider_instance = provider_instance
|
24
|
+
self.llm_driver_config = llm_driver_config
|
25
|
+
self.role = role
|
26
|
+
# Instantiate agent together with prompt handler using the shared helper
|
27
|
+
# Handle --developer and --market flags for single shot mode
|
28
|
+
profile = getattr(args, "profile", None)
|
29
|
+
if profile is None and getattr(args, "developer", False):
|
30
|
+
profile = "Developer"
|
31
|
+
if profile is None and getattr(args, "market", False):
|
32
|
+
profile = "Market Analyst"
|
33
|
+
|
34
|
+
self.agent, self.generic_handler = setup_agent_and_prompt_handler(
|
35
|
+
args=args,
|
36
|
+
provider_instance=provider_instance,
|
37
|
+
llm_driver_config=llm_driver_config,
|
38
|
+
role=role,
|
39
|
+
verbose_tools=getattr(args, "verbose_tools", False),
|
40
|
+
verbose_agent=getattr(args, "verbose_agent", False),
|
41
|
+
allowed_permissions=allowed_permissions,
|
42
|
+
profile=profile,
|
43
|
+
)
|
44
|
+
|
45
|
+
def handle(self) -> None:
|
46
|
+
import traceback
|
47
|
+
|
48
|
+
# Check if interactive mode is requested - if so, switch to chat mode
|
49
|
+
if getattr(self.args, "interactive", False):
|
50
|
+
from janito.cli.chat_mode.session import ChatSession
|
51
|
+
from rich.console import Console
|
52
|
+
|
53
|
+
console = Console()
|
54
|
+
session = ChatSession(
|
55
|
+
console,
|
56
|
+
self.provider_instance,
|
57
|
+
self.llm_driver_config,
|
58
|
+
role=self.role,
|
59
|
+
args=self.args,
|
60
|
+
verbose_tools=getattr(self.args, "verbose_tools", False),
|
61
|
+
verbose_agent=getattr(self.args, "verbose_agent", False),
|
62
|
+
allowed_permissions=getattr(self, 'allowed_permissions', None),
|
63
|
+
)
|
64
|
+
session.run()
|
65
|
+
return
|
66
|
+
|
67
|
+
user_prompt = " ".join(getattr(self.args, "user_prompt", [])).strip()
|
68
|
+
# UTF-8 sanitize user_prompt
|
69
|
+
sanitized = user_prompt
|
70
|
+
try:
|
71
|
+
sanitized.encode("utf-8")
|
72
|
+
except UnicodeEncodeError:
|
73
|
+
sanitized = sanitized.encode("utf-8", errors="replace").decode("utf-8")
|
74
|
+
shared_console.print(
|
75
|
+
"[yellow]Warning: Some characters in your input were not valid UTF-8 and have been replaced.[/yellow]"
|
76
|
+
)
|
77
|
+
import time
|
78
|
+
|
79
|
+
try:
|
80
|
+
start_time = time.time()
|
81
|
+
|
82
|
+
# Print rule line with model info before processing prompt
|
83
|
+
model_name = (
|
84
|
+
self.agent.get_model_name()
|
85
|
+
if hasattr(self.agent, "get_model_name")
|
86
|
+
else "Unknown"
|
87
|
+
)
|
88
|
+
provider_name = (
|
89
|
+
self.agent.get_provider_name()
|
90
|
+
if hasattr(self.agent, "get_provider_name")
|
91
|
+
else "Unknown"
|
92
|
+
)
|
93
|
+
|
94
|
+
# Get backend hostname if available
|
95
|
+
backend_hostname = "Unknown"
|
96
|
+
if hasattr(self.agent, "driver") and self.agent.driver:
|
97
|
+
if hasattr(self.agent.driver, "config") and hasattr(
|
98
|
+
self.agent.driver.config, "base_url"
|
99
|
+
):
|
100
|
+
base_url = self.agent.driver.config.base_url
|
101
|
+
if base_url:
|
102
|
+
try:
|
103
|
+
from urllib.parse import urlparse
|
104
|
+
|
105
|
+
parsed = urlparse(base_url)
|
106
|
+
backend_hostname = parsed.netloc
|
107
|
+
except Exception:
|
108
|
+
backend_hostname = base_url
|
109
|
+
|
110
|
+
from rich.rule import Rule
|
111
|
+
|
112
|
+
shared_console.print(
|
113
|
+
Rule(
|
114
|
+
f"[bold blue]Model: {model_name} ({provider_name}) | Backend: {backend_hostname}[/bold blue]"
|
115
|
+
)
|
116
|
+
)
|
117
|
+
|
118
|
+
self.generic_handler.handle_prompt(
|
119
|
+
sanitized,
|
120
|
+
args=self.args,
|
121
|
+
print_header=True,
|
122
|
+
raw=getattr(self.args, "raw", False),
|
123
|
+
)
|
124
|
+
end_time = time.time()
|
125
|
+
elapsed = end_time - start_time
|
126
|
+
self._post_prompt_actions(elapsed=elapsed)
|
127
|
+
if hasattr(self.args, "verbose_agent") and self.args.verbose_agent:
|
128
|
+
print("[debug] handle_prompt() completed without exception.")
|
129
|
+
except Exception as e:
|
130
|
+
print(
|
131
|
+
f"[error] Exception occurred in handle_prompt: {type(e).__name__}: {e}"
|
132
|
+
)
|
133
|
+
traceback.print_exc()
|
134
|
+
|
135
|
+
def _post_prompt_actions(self, elapsed=None):
|
136
|
+
# Align with chat mode: only print token usage summary
|
137
|
+
import sys
|
138
|
+
from janito.formatting_token import print_token_message_summary
|
139
|
+
from janito.perf_singleton import performance_collector
|
140
|
+
|
141
|
+
usage = performance_collector.get_last_request_usage()
|
142
|
+
# If running in stdin mode, do not print token usage
|
143
|
+
if sys.stdin.isatty():
|
144
|
+
print_token_message_summary(
|
145
|
+
shared_console, msg_count=1, usage=usage, elapsed=elapsed
|
146
|
+
)
|
147
|
+
self._cleanup_driver_and_console()
|
148
|
+
|
149
|
+
def _cleanup_driver_and_console(self):
|
150
|
+
if hasattr(self.agent, "join_driver"):
|
151
|
+
if (
|
152
|
+
hasattr(self.agent, "input_queue")
|
153
|
+
and self.agent.input_queue is not None
|
154
|
+
):
|
155
|
+
self.agent.input_queue.put(None)
|
156
|
+
self.agent.join_driver()
|
157
|
+
try:
|
158
|
+
shared_console.file.flush()
|
159
|
+
except Exception:
|
160
|
+
pass
|
161
|
+
try:
|
162
|
+
import sys
|
163
|
+
|
164
|
+
sys.stdout.flush()
|
165
|
+
except Exception:
|
166
|
+
pass
|
167
|
+
# If event logger is active, flush event log
|
janito/llm/__init__.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
# janito.llm package
|
2
|
-
|
3
|
-
from .driver import LLMDriver
|
4
|
-
from .provider import LLMProvider
|
5
|
-
from .driver_config import LLMDriverConfig
|
1
|
+
# janito.llm package
|
2
|
+
|
3
|
+
from .driver import LLMDriver
|
4
|
+
from .provider import LLMProvider
|
5
|
+
from .driver_config import LLMDriverConfig
|
6
|
+
from .response_cache import ResponseCache
|