janito 0.10.0__py3-none-any.whl → 0.11.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/__init__.py +1 -1
- janito/__main__.py +205 -151
- janito/callbacks.py +132 -130
- janito/chat_history.py +117 -0
- janito/config.py +64 -6
- janito/data/instructions.txt +4 -6
- janito/token_report.py +145 -73
- janito/tools/__init__.py +21 -10
- janito/tools/bash.py +22 -0
- janito/tools/decorators.py +101 -84
- janito/tools/delete_file.py +47 -44
- janito/tools/find_files.py +11 -7
- janito/tools/prompt_user.py +26 -0
- janito/tools/replace_file.py +36 -0
- janito/tools/search_text.py +226 -196
- janito/tools/str_replace_editor/editor.py +52 -43
- janito/tools/str_replace_editor/handlers.py +102 -105
- janito/tools/str_replace_editor/utils.py +8 -62
- {janito-0.10.0.dist-info → janito-0.11.0.dist-info}/METADATA +86 -88
- janito-0.11.0.dist-info/RECORD +26 -0
- {janito-0.10.0.dist-info → janito-0.11.0.dist-info}/WHEEL +1 -2
- janito/cli.py +0 -202
- janito-0.10.0.dist-info/RECORD +0 -23
- janito-0.10.0.dist-info/top_level.txt +0 -1
- {janito-0.10.0.dist-info → janito-0.11.0.dist-info}/entry_points.txt +0 -0
- {janito-0.10.0.dist-info → janito-0.11.0.dist-info/licenses}/LICENSE +0 -0
janito/cli.py
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
CLI functionality for the janito tool.
|
3
|
-
"""
|
4
|
-
|
5
|
-
import os
|
6
|
-
import sys
|
7
|
-
from pathlib import Path
|
8
|
-
from typing import Optional
|
9
|
-
import typer
|
10
|
-
from rich.console import Console
|
11
|
-
from rich.markdown import Markdown
|
12
|
-
from rich import print as rprint
|
13
|
-
import claudine
|
14
|
-
from claudine.exceptions import MaxTokensExceededException, MaxRoundsExceededException
|
15
|
-
|
16
|
-
from janito.config import get_config
|
17
|
-
from janito.tools import find_files
|
18
|
-
from janito.tools.str_replace_editor.editor import str_replace_editor
|
19
|
-
from janito.tools.delete_file import delete_file
|
20
|
-
from janito.tools.search_text import search_text
|
21
|
-
from janito.callbacks import pre_tool_callback, post_tool_callback
|
22
|
-
|
23
|
-
app = typer.Typer(help="Janito CLI tool")
|
24
|
-
|
25
|
-
@app.command()
|
26
|
-
def hello(name: str = typer.Argument("World", help="Name to greet")):
|
27
|
-
"""
|
28
|
-
Say hello to someone.
|
29
|
-
"""
|
30
|
-
rprint(f"[bold green]Hello {name}[/bold green]")
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def debug_tokens(agent):
|
35
|
-
"""
|
36
|
-
Display detailed token usage and pricing information.
|
37
|
-
"""
|
38
|
-
from claudine.token_tracking import MODEL_PRICING, DEFAULT_MODEL
|
39
|
-
|
40
|
-
console = Console()
|
41
|
-
usage = agent.get_token_usage()
|
42
|
-
text_usage = usage.text_usage
|
43
|
-
tools_usage = usage.tools_usage
|
44
|
-
total_usage = usage.total_usage
|
45
|
-
|
46
|
-
# Get the pricing model
|
47
|
-
pricing = MODEL_PRICING.get(DEFAULT_MODEL)
|
48
|
-
|
49
|
-
# Calculate costs manually
|
50
|
-
text_input_cost = pricing.input_tokens.calculate_cost(text_usage.input_tokens)
|
51
|
-
text_output_cost = pricing.output_tokens.calculate_cost(text_usage.output_tokens)
|
52
|
-
tools_input_cost = pricing.input_tokens.calculate_cost(tools_usage.input_tokens)
|
53
|
-
tools_output_cost = pricing.output_tokens.calculate_cost(tools_usage.output_tokens)
|
54
|
-
|
55
|
-
# Format costs
|
56
|
-
format_cost = lambda cost: f"{cost * 100:.2f}¢" if cost < 1.0 else f"${cost:.6f}"
|
57
|
-
|
58
|
-
console.print("\n[bold blue]Detailed Token Usage:[/bold blue]")
|
59
|
-
console.print(f"Text Input tokens: {text_usage.input_tokens}")
|
60
|
-
console.print(f"Text Output tokens: {text_usage.output_tokens}")
|
61
|
-
console.print(f"Text Total tokens: {text_usage.input_tokens + text_usage.output_tokens}")
|
62
|
-
console.print(f"Tool Input tokens: {tools_usage.input_tokens}")
|
63
|
-
console.print(f"Tool Output tokens: {tools_usage.output_tokens}")
|
64
|
-
console.print(f"Tool Total tokens: {tools_usage.input_tokens + tools_usage.output_tokens}")
|
65
|
-
console.print(f"Total tokens: {total_usage.input_tokens + total_usage.output_tokens}")
|
66
|
-
|
67
|
-
console.print("\n[bold blue]Pricing Information:[/bold blue]")
|
68
|
-
console.print(f"Input pricing: ${pricing.input_tokens.cost_per_million_tokens}/million tokens")
|
69
|
-
console.print(f"Output pricing: ${pricing.output_tokens.cost_per_million_tokens}/million tokens")
|
70
|
-
console.print(f"Text Input cost: {format_cost(text_input_cost)}")
|
71
|
-
console.print(f"Text Output cost: {format_cost(text_output_cost)}")
|
72
|
-
console.print(f"Text Total cost: {format_cost(text_input_cost + text_output_cost)}")
|
73
|
-
console.print(f"Tool Input cost: {format_cost(tools_input_cost)}")
|
74
|
-
console.print(f"Tool Output cost: {format_cost(tools_output_cost)}")
|
75
|
-
console.print(f"Tool Total cost: {format_cost(tools_input_cost + tools_output_cost)}")
|
76
|
-
console.print(f"Total cost: {format_cost(text_input_cost + text_output_cost + tools_input_cost + tools_output_cost)}")
|
77
|
-
|
78
|
-
# Display per-tool breakdown if available
|
79
|
-
if usage.by_tool:
|
80
|
-
console.print("\n[bold blue]Per-Tool Breakdown:[/bold blue]")
|
81
|
-
for tool_name, tool_usage in usage.by_tool.items():
|
82
|
-
tool_input_cost = pricing.input_tokens.calculate_cost(tool_usage.input_tokens)
|
83
|
-
tool_output_cost = pricing.output_tokens.calculate_cost(tool_usage.output_tokens)
|
84
|
-
console.print(f" Tool: {tool_name}")
|
85
|
-
console.print(f" Input tokens: {tool_usage.input_tokens}")
|
86
|
-
console.print(f" Output tokens: {tool_usage.output_tokens}")
|
87
|
-
console.print(f" Total tokens: {tool_usage.input_tokens + tool_usage.output_tokens}")
|
88
|
-
console.print(f" Total cost: {format_cost(tool_input_cost + tool_output_cost)}")
|
89
|
-
|
90
|
-
def process_query(query: str, debug: bool, verbose: bool):
|
91
|
-
"""
|
92
|
-
Process a query using the claudine agent.
|
93
|
-
"""
|
94
|
-
console = Console()
|
95
|
-
|
96
|
-
# Get API key from environment variable or ask the user
|
97
|
-
api_key = os.environ.get("ANTHROPIC_API_KEY")
|
98
|
-
if not api_key:
|
99
|
-
console.print("[bold yellow]Warning:[/bold yellow] ANTHROPIC_API_KEY environment variable not set.")
|
100
|
-
console.print("Please set it or provide your API key now:")
|
101
|
-
api_key = typer.prompt("Anthropic API Key", hide_input=True)
|
102
|
-
|
103
|
-
# Load instructions from file
|
104
|
-
import importlib.resources as pkg_resources
|
105
|
-
try:
|
106
|
-
# For Python 3.9+
|
107
|
-
try:
|
108
|
-
from importlib.resources import files
|
109
|
-
instructions = files('janito.data').joinpath('instructions.txt').read_text()
|
110
|
-
# Fallback for older Python versions
|
111
|
-
except (ImportError, AttributeError):
|
112
|
-
instructions = pkg_resources.read_text('janito.data', 'instructions.txt')
|
113
|
-
instructions = instructions.strip()
|
114
|
-
except Exception as e:
|
115
|
-
console.print(f"[bold yellow]Warning:[/bold yellow] Could not load instructions file: {str(e)}")
|
116
|
-
console.print("[dim]Using default instructions instead.[/dim]")
|
117
|
-
instructions = "You are a helpful AI assistant. Answer the user's questions to the best of your ability."
|
118
|
-
|
119
|
-
# Initialize the agent with the tools
|
120
|
-
agent = claudine.Agent(
|
121
|
-
api_key=api_key,
|
122
|
-
tools=[
|
123
|
-
delete_file,
|
124
|
-
find_files,
|
125
|
-
search_text
|
126
|
-
],
|
127
|
-
text_editor_tool=str_replace_editor,
|
128
|
-
tool_callbacks=(pre_tool_callback, post_tool_callback),
|
129
|
-
max_tokens=4096,
|
130
|
-
temperature=0.7,
|
131
|
-
instructions=instructions,
|
132
|
-
debug_mode=debug # Enable debug mode
|
133
|
-
)
|
134
|
-
|
135
|
-
# Process the query
|
136
|
-
console.print(f"[bold blue]Query:[/bold blue] {query}")
|
137
|
-
console.print("[bold blue]Generating response...[/bold blue]")
|
138
|
-
|
139
|
-
try:
|
140
|
-
response = agent.process_prompt(query)
|
141
|
-
|
142
|
-
console.print("\n[bold magenta]Janito:[/bold magenta] ", end="")
|
143
|
-
# Use rich's enhanced Markdown rendering for the response
|
144
|
-
console.print(Markdown(response, code_theme="monokai"))
|
145
|
-
|
146
|
-
except MaxTokensExceededException as e:
|
147
|
-
# Display the partial response if available
|
148
|
-
if e.response_text:
|
149
|
-
console.print("\n[bold magenta]Janito:[/bold magenta] ", end="")
|
150
|
-
console.print(Markdown(e.response_text, code_theme="monokai"))
|
151
|
-
|
152
|
-
console.print("\n[bold red]Error:[/bold red] Response was truncated because it reached the maximum token limit.")
|
153
|
-
console.print("[dim]Consider increasing the max_tokens parameter or simplifying your query.[/dim]")
|
154
|
-
|
155
|
-
except MaxRoundsExceededException as e:
|
156
|
-
# Display the final response if available
|
157
|
-
if e.response_text:
|
158
|
-
console.print("\n[bold magenta]Janito:[/bold magenta] ", end="")
|
159
|
-
console.print(Markdown(e.response_text, code_theme="monokai"))
|
160
|
-
|
161
|
-
console.print(f"\n[bold red]Error:[/bold red] Maximum number of tool execution rounds ({e.rounds}) reached. Some tasks may be incomplete.")
|
162
|
-
console.print("[dim]Consider increasing the max_rounds parameter or breaking down your task into smaller steps.[/dim]")
|
163
|
-
|
164
|
-
# Show token usage
|
165
|
-
usage = agent.get_token_usage()
|
166
|
-
text_usage = usage.text_usage
|
167
|
-
tools_usage = usage.tools_usage
|
168
|
-
|
169
|
-
if verbose:
|
170
|
-
debug_tokens(agent)
|
171
|
-
else:
|
172
|
-
total_tokens = text_usage.input_tokens + text_usage.output_tokens + tools_usage.input_tokens + tools_usage.output_tokens
|
173
|
-
cost_info = agent.get_cost()
|
174
|
-
cost_display = cost_info.format_total_cost() if hasattr(cost_info, 'format_total_cost') else ""
|
175
|
-
# Consolidated tokens and cost in a single line with a ruler
|
176
|
-
console.print(Rule(f"Tokens: {total_tokens} | Cost: {cost_display}", style="dim", align="center"))
|
177
|
-
|
178
|
-
@app.callback(invoke_without_command=True)
|
179
|
-
def main(ctx: typer.Context,
|
180
|
-
query: Optional[str] = typer.Argument(None, help="Query to send to the claudine agent"),
|
181
|
-
debug: bool = typer.Option(False, "--debug", "-d", help="Enable debug mode"),
|
182
|
-
verbose: bool = typer.Option(False, "--verbose", "-v", help="Show detailed token usage and pricing information"),
|
183
|
-
workspace: Optional[str] = typer.Option(None, "--workspace", "-w", help="Set the workspace directory")):
|
184
|
-
"""
|
185
|
-
Janito CLI tool. If a query is provided without a command, it will be sent to the claudine agent.
|
186
|
-
"""
|
187
|
-
console = Console()
|
188
|
-
|
189
|
-
# Set debug mode in config
|
190
|
-
get_config().debug_mode = debug
|
191
|
-
|
192
|
-
if workspace:
|
193
|
-
try:
|
194
|
-
print(f"Setting workspace directory to: {workspace}")
|
195
|
-
get_config().workspace_dir = workspace
|
196
|
-
print(f"Workspace directory set to: {get_config().workspace_dir}")
|
197
|
-
except ValueError as e:
|
198
|
-
console.print(f"[bold red]Error:[/bold red] {str(e)}")
|
199
|
-
sys.exit(1)
|
200
|
-
|
201
|
-
if ctx.invoked_subcommand is None and query:
|
202
|
-
process_query(query, debug, verbose)
|
janito-0.10.0.dist-info/RECORD
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
janito/__init__.py,sha256=IZCdvdMRsovsijH7ahMc57anBJCZ7P_ZvPuYfAqSjx0,53
|
2
|
-
janito/__main__.py,sha256=gskP0c2f1Zu9VwZ9V5QjdGf20wginiuGWa33qeZVDyY,6867
|
3
|
-
janito/callbacks.py,sha256=_kmoRR2lDPQzNLfWPPibilbna4W-abj6hMO1VFICmwY,5288
|
4
|
-
janito/cli.py,sha256=Vbg8W79d-LEB2b4cc58a2HE-8jmZrTvaNoEg2J2543k,9381
|
5
|
-
janito/config.py,sha256=SYaMg3sqWroTaByfxGASleMLxux3s6b-fYZnT-ggqFw,2097
|
6
|
-
janito/test_file.py,sha256=c6GWGdTYG3z-Y5XBao9Tmhmq3G-v0L37OfwLgBo8zIU,126
|
7
|
-
janito/token_report.py,sha256=qLCAPce90Pgh_Q5qssA7irRB1C9e9pOfBC01Wi-ZUug,4006
|
8
|
-
janito/data/instructions.txt,sha256=WkPubK1wPnLG2PpsPikEf7lWQrRW8t1C5p65PV-1qC8,311
|
9
|
-
janito/tools/__init__.py,sha256=izLbyETR5piuFjQZ6ZY6zRgS7Tlx0yXk_wzhPn_CVYc,279
|
10
|
-
janito/tools/decorators.py,sha256=VzUHsoxtxmsd5ic1KAW42eCOT56gjjSzWbEZTcv0RZs,2617
|
11
|
-
janito/tools/delete_file.py,sha256=5JgSFtiF8bpfo0Z15ifj_RFHEHkl9cto1BES9TxIBIA,1245
|
12
|
-
janito/tools/find_files.py,sha256=bN97u3VbFBA78ssXCaEo_cFloni5PE1UW6cSDP9kvjw,5993
|
13
|
-
janito/tools/search_text.py,sha256=nABJJM_vEnMpVPfuLd_tIlVwCfXHTfo1e-K31a8IyJE,7674
|
14
|
-
janito/tools/str_replace_editor/__init__.py,sha256=kYmscmQgft3Jzt3oCNz7k2FiRbJvku6OFDDC3Q_zoAA,144
|
15
|
-
janito/tools/str_replace_editor/editor.py,sha256=XGrBADTlKwlcXat38T5th_KOPrspb9CBCP0g9KRuqmg,1345
|
16
|
-
janito/tools/str_replace_editor/handlers.py,sha256=-7HJinfiJP2s-XHHVAS6TtrNwoNtTH8IJHxuLlYH2pA,12423
|
17
|
-
janito/tools/str_replace_editor/utils.py,sha256=WOkos4bZ5Pe9U_UES6bS_QNISob0GvGN8TQVaRi6RbM,2670
|
18
|
-
janito-0.10.0.dist-info/LICENSE,sha256=6-H8LXExbBIAuT4cyiE-Qy8Bad1K4pagQRVTWr6wkhk,1096
|
19
|
-
janito-0.10.0.dist-info/METADATA,sha256=uCsbgd9tXAWPxt_1WDhRfnk3caPzpfIMVxVDUGaLqUI,2164
|
20
|
-
janito-0.10.0.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
21
|
-
janito-0.10.0.dist-info/entry_points.txt,sha256=JMbF_1jg-xQddidpAYkzjOKdw70fy_ymJfcmerY2wIY,47
|
22
|
-
janito-0.10.0.dist-info/top_level.txt,sha256=m0NaVCq0-ivxbazE2-ND0EA9Hmuijj_OGkmCbnBcCig,7
|
23
|
-
janito-0.10.0.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
janito
|
File without changes
|
File without changes
|