dhrona 0.1.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.
- dhrona/__init__.py +1 -0
- dhrona/_modidx.py +63 -0
- dhrona/core.py +223 -0
- dhrona/rounds.py +186 -0
- dhrona/seeds/fossick-github.json +45 -0
- dhrona/sessions.py +82 -0
- dhrona/tools.py +83 -0
- dhrona-0.1.1.dist-info/METADATA +142 -0
- dhrona-0.1.1.dist-info/RECORD +12 -0
- dhrona-0.1.1.dist-info/WHEEL +4 -0
- dhrona-0.1.1.dist-info/entry_points.txt +11 -0
- dhrona-0.1.1.dist-info/licenses/LICENSE +201 -0
dhrona/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.1"
|
dhrona/_modidx.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Autogenerated by nbdev
|
|
2
|
+
|
|
3
|
+
d = { 'settings': { 'branch': 'main',
|
|
4
|
+
'doc_baseurl': '/drona',
|
|
5
|
+
'doc_host': 'https://Karthik777.github.io',
|
|
6
|
+
'git_url': 'https://github.com/Karthik777/drona',
|
|
7
|
+
'lib_path': 'dhrona'},
|
|
8
|
+
'syms': { 'dhrona.core': { 'dhrona.core.Assessment': ('core.html#assessment', 'dhrona/core.py'),
|
|
9
|
+
'dhrona.core.Finding': ('core.html#finding', 'dhrona/core.py'),
|
|
10
|
+
'dhrona.core._failure_findings': ('core.html#_failure_findings', 'dhrona/core.py'),
|
|
11
|
+
'dhrona.core._failure_key': ('core.html#_failure_key', 'dhrona/core.py'),
|
|
12
|
+
'dhrona.core._first_research_finding': ('core.html#_first_research_finding', 'dhrona/core.py'),
|
|
13
|
+
'dhrona.core._is_fossick_repo': ('core.html#_is_fossick_repo', 'dhrona/core.py'),
|
|
14
|
+
'dhrona.core._loads': ('core.html#_loads', 'dhrona/core.py'),
|
|
15
|
+
'dhrona.core._segments': ('core.html#_segments', 'dhrona/core.py'),
|
|
16
|
+
'dhrona.core._tc': ('core.html#_tc', 'dhrona/core.py'),
|
|
17
|
+
'dhrona.core._tool_name': ('core.html#_tool_name', 'dhrona/core.py'),
|
|
18
|
+
'dhrona.core.as_tools': ('core.html#as_tools', 'dhrona/core.py'),
|
|
19
|
+
'dhrona.core.assess_history': ('core.html#assess_history', 'dhrona/core.py'),
|
|
20
|
+
'dhrona.core.assess_turn': ('core.html#assess_turn', 'dhrona/core.py'),
|
|
21
|
+
'dhrona.core.bypass_tool': ('core.html#bypass_tool', 'dhrona/core.py'),
|
|
22
|
+
'dhrona.core.call_valid': ('core.html#call_valid', 'dhrona/core.py'),
|
|
23
|
+
'dhrona.core.completion_valid': ('core.html#completion_valid', 'dhrona/core.py'),
|
|
24
|
+
'dhrona.core.dhrona_version': ('core.html#dhrona_version', 'dhrona/core.py'),
|
|
25
|
+
'dhrona.core.load_rounds': ('core.html#load_rounds', 'dhrona/core.py'),
|
|
26
|
+
'dhrona.core.main': ('core.html#main', 'dhrona/core.py'),
|
|
27
|
+
'dhrona.core.prepare_chat': ('core.html#prepare_chat', 'dhrona/core.py'),
|
|
28
|
+
'dhrona.core.read_history': ('core.html#read_history', 'dhrona/core.py'),
|
|
29
|
+
'dhrona.core.receipt_path': ('core.html#receipt_path', 'dhrona/core.py'),
|
|
30
|
+
'dhrona.core.register_completion': ('core.html#register_completion', 'dhrona/core.py'),
|
|
31
|
+
'dhrona.core.round_calls': ('core.html#round_calls', 'dhrona/core.py'),
|
|
32
|
+
'dhrona.core.round_msgs': ('core.html#round_msgs', 'dhrona/core.py'),
|
|
33
|
+
'dhrona.core.round_valid': ('core.html#round_valid', 'dhrona/core.py'),
|
|
34
|
+
'dhrona.core.tool_args': ('core.html#tool_args', 'dhrona/core.py'),
|
|
35
|
+
'dhrona.core.warm_start': ('core.html#warm_start', 'dhrona/core.py')},
|
|
36
|
+
'dhrona.rounds': { 'dhrona.rounds._add_review': ('rounds.html#_add_review', 'dhrona/rounds.py'),
|
|
37
|
+
'dhrona.rounds._history_dicts': ('rounds.html#_history_dicts', 'dhrona/rounds.py'),
|
|
38
|
+
'dhrona.rounds._part_dict': ('rounds.html#_part_dict', 'dhrona/rounds.py'),
|
|
39
|
+
'dhrona.rounds._print_commands': ('rounds.html#_print_commands', 'dhrona/rounds.py'),
|
|
40
|
+
'dhrona.rounds._prompts': ('rounds.html#_prompts', 'dhrona/rounds.py'),
|
|
41
|
+
'dhrona.rounds._turn_msgs': ('rounds.html#_turn_msgs', 'dhrona/rounds.py'),
|
|
42
|
+
'dhrona.rounds._write_dlg': ('rounds.html#_write_dlg', 'dhrona/rounds.py'),
|
|
43
|
+
'dhrona.rounds.accept': ('rounds.html#accept', 'dhrona/rounds.py'),
|
|
44
|
+
'dhrona.rounds.accept_cli': ('rounds.html#accept_cli', 'dhrona/rounds.py'),
|
|
45
|
+
'dhrona.rounds.bootstrap_prompt': ('rounds.html#bootstrap_prompt', 'dhrona/rounds.py'),
|
|
46
|
+
'dhrona.rounds.capture': ('rounds.html#capture', 'dhrona/rounds.py'),
|
|
47
|
+
'dhrona.rounds.capture_cli': ('rounds.html#capture_cli', 'dhrona/rounds.py'),
|
|
48
|
+
'dhrona.rounds.clean_dialog': ('rounds.html#clean_dialog', 'dhrona/rounds.py'),
|
|
49
|
+
'dhrona.rounds.compiled_history': ('rounds.html#compiled_history', 'dhrona/rounds.py'),
|
|
50
|
+
'dhrona.rounds.latest_session': ('rounds.html#latest_session', 'dhrona/rounds.py'),
|
|
51
|
+
'dhrona.rounds.read_dialog': ('rounds.html#read_dialog', 'dhrona/rounds.py'),
|
|
52
|
+
'dhrona.rounds.start_cli': ('rounds.html#start_cli', 'dhrona/rounds.py'),
|
|
53
|
+
'dhrona.rounds.start_commands': ('rounds.html#start_commands', 'dhrona/rounds.py'),
|
|
54
|
+
'dhrona.rounds.start_round': ('rounds.html#start_round', 'dhrona/rounds.py')},
|
|
55
|
+
'dhrona.sessions': { 'dhrona.sessions.export_cli': ('sessions.html#export_cli', 'dhrona/sessions.py'),
|
|
56
|
+
'dhrona.sessions.export_session': ('sessions.html#export_session', 'dhrona/sessions.py'),
|
|
57
|
+
'dhrona.sessions.import_cli': ('sessions.html#import_cli', 'dhrona/sessions.py'),
|
|
58
|
+
'dhrona.sessions.import_session': ('sessions.html#import_session', 'dhrona/sessions.py')},
|
|
59
|
+
'dhrona.tools': { 'dhrona.tools._detail_key': ('tools.html#_detail_key', 'dhrona/tools.py'),
|
|
60
|
+
'dhrona.tools._epoch': ('tools.html#_epoch', 'dhrona/tools.py'),
|
|
61
|
+
'dhrona.tools.fmt_report': ('tools.html#fmt_report', 'dhrona/tools.py'),
|
|
62
|
+
'dhrona.tools.tool_report': ('tools.html#tool_report', 'dhrona/tools.py'),
|
|
63
|
+
'dhrona.tools.tools_cli': ('tools.html#tools_cli', 'dhrona/tools.py')}}}
|
dhrona/core.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""Assess Ramabana tool routes and build a Urai warm-start history.
|
|
2
|
+
|
|
3
|
+
Docs: https://Karthik777.github.io/drona/core.html.md"""
|
|
4
|
+
|
|
5
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
|
|
6
|
+
|
|
7
|
+
# %% auto #0
|
|
8
|
+
__all__ = ['RAMABANA_HISTORY', 'SHELL_TOOLS', 'ROUND_REVISION', 'ROUNDS_DIR', 'SEEDS_DIR', 'Finding', 'Assessment',
|
|
9
|
+
'read_history', 'tool_args', 'bypass_tool', 'assess_turn', 'assess_history', 'call_valid', 'as_tools',
|
|
10
|
+
'round_calls', 'round_valid', 'load_rounds', 'round_msgs', 'warm_start', 'dhrona_version', 'receipt_path',
|
|
11
|
+
'register_completion', 'completion_valid', 'prepare_chat', 'main']
|
|
12
|
+
|
|
13
|
+
# %% ../nbs/00_core.ipynb #d04693b6
|
|
14
|
+
from dataclasses import dataclass, asdict
|
|
15
|
+
import json, re, sys, time, uuid, inspect, functools
|
|
16
|
+
from fastcore.basics import ifnone
|
|
17
|
+
from fastcore.xtras import Path
|
|
18
|
+
from fastcore.script import call_parse
|
|
19
|
+
from fastcore.xdg import xdg_state_home, xdg_config_home
|
|
20
|
+
from fastcore.foundation import L
|
|
21
|
+
from urai import ToolCall, mk_tool_res_msg
|
|
22
|
+
import dhrona
|
|
23
|
+
|
|
24
|
+
# %% ../nbs/00_core.ipynb #2edea58c
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class Finding:
|
|
27
|
+
"One tool-route problem in a recorded turn."
|
|
28
|
+
kind: str
|
|
29
|
+
tool: str
|
|
30
|
+
index: int
|
|
31
|
+
message: str
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True)
|
|
34
|
+
class Assessment:
|
|
35
|
+
"The route score and findings for one or more turns."
|
|
36
|
+
score: int
|
|
37
|
+
calls: int
|
|
38
|
+
findings: tuple[Finding, ...]
|
|
39
|
+
|
|
40
|
+
# %% ../nbs/00_core.ipynb #8e5631ea
|
|
41
|
+
RAMABANA_HISTORY = Path.home()/'.config/ramabana/agent-history.jsonl'
|
|
42
|
+
|
|
43
|
+
def _loads(s):
|
|
44
|
+
try: return json.loads(s)
|
|
45
|
+
except (json.JSONDecodeError, TypeError): return None
|
|
46
|
+
|
|
47
|
+
def read_history(
|
|
48
|
+
path=RAMABANA_HISTORY, # Ramabana `agent-history.jsonl` path
|
|
49
|
+
session=None, # optional session id
|
|
50
|
+
):
|
|
51
|
+
"Read completed Ramabana turns in append order, skipping partial lines."
|
|
52
|
+
r = L(Path(path).expanduser().readlines()).map(_loads).filter(lambda x: isinstance(x, dict))
|
|
53
|
+
return r if not session else r.filter(lambda x: x.get('session')==session)
|
|
54
|
+
|
|
55
|
+
def tool_args(action):
|
|
56
|
+
"The call arguments of `action` as a dict."
|
|
57
|
+
a = action.get('args')
|
|
58
|
+
if isinstance(a, str): a = _loads(a)
|
|
59
|
+
return a if isinstance(a, dict) else {}
|
|
60
|
+
|
|
61
|
+
# %% ../nbs/00_core.ipynb #cf182995
|
|
62
|
+
_RESEARCH_TOOLS = {'web_search', 'read_url', 'search_code', 'run_shell'}
|
|
63
|
+
_SCHEMA_ERRS = ('could not parse commands', 'JSONDecodeError', 'JSON decoder')
|
|
64
|
+
SHELL_TOOLS = (
|
|
65
|
+
(r'git\s+status\b', 'git_status'), (r'git\s+diff\b', 'git_diff'), (r'git\s+(log|show)\b', 'git_log'),
|
|
66
|
+
(r'git\s+commit\b', 'git_commit'), (r'git\s+(checkout|switch)\b', 'git_checkout'), (r'git\s+stash\b', 'git_stash'),
|
|
67
|
+
(r'git\s+(push|pull|fetch)\b', 'git_remote'), (r'(rg|grep|ag)\b', 'grep'), (r'(find|fd)\b', 'ls'), (r'(ls|tree)\b', 'ls'),
|
|
68
|
+
(r'(sed|perl)\s+-p?i\b', 'replace_text'), (r'(cat\s*>|tee\b)', 'create_file'), (r'sed\s+-n\b|(cat|head|tail|nl)\b', 'view_file'),
|
|
69
|
+
(r'(curl|wget)\b', 'read_url'))
|
|
70
|
+
_PREFIX = re.compile(r'^(env(\s+-u\s+\S+|\s+\w+=\S+)*\s+|(\w+=\S+\s+)+)')
|
|
71
|
+
_GIT_OPTS = re.compile(r'^git\s+((-[Cc]\s+\S+|--\S+)\s+)+')
|
|
72
|
+
|
|
73
|
+
def _segments(command):
|
|
74
|
+
for s in re.split(r'&&|;|\|\|', command):
|
|
75
|
+
s = _GIT_OPTS.sub('git ', _PREFIX.sub('', s.strip()))
|
|
76
|
+
if s and not s.startswith('cd '): yield s.split('|')[0].strip()
|
|
77
|
+
|
|
78
|
+
def bypass_tool(command, offered=None):
|
|
79
|
+
"The dedicated tool `command` stands in for, if any."
|
|
80
|
+
if not command: return None
|
|
81
|
+
if re.search(r'&\s*$', command.strip()) and not command.strip().endswith('&&'): hit = 'run_shell_bg'
|
|
82
|
+
else: hit = next((t for s in _segments(command) for rx,t in SHELL_TOOLS if re.match(rx, s)), None)
|
|
83
|
+
return hit if hit and (offered is None or hit in offered) else None
|
|
84
|
+
|
|
85
|
+
def _is_fossick_repo(action):
|
|
86
|
+
text = ' '.join(str(v) for v in tool_args(action).values())
|
|
87
|
+
return action.get('tool') == 'run_shell' and 'fossick read-gh-repo' in text
|
|
88
|
+
|
|
89
|
+
def _first_research_finding(prompt, activities):
|
|
90
|
+
if 'github' not in prompt.lower() or 'fossick' not in prompt.lower(): return None
|
|
91
|
+
research = ((i, action) for i, action in enumerate(activities) if action.get('tool') in _RESEARCH_TOOLS)
|
|
92
|
+
index, action = next(research, (None, None))
|
|
93
|
+
if action is None or _is_fossick_repo(action): return None
|
|
94
|
+
return Finding('route', action.get('tool', ''), index, 'Use fossick read-gh-repo as the first repository research call.')
|
|
95
|
+
|
|
96
|
+
def _failure_key(action): return (action.get('tool', ''), json.dumps(tool_args(action), sort_keys=True, default=str))
|
|
97
|
+
|
|
98
|
+
def _failure_findings(index, action, failed):
|
|
99
|
+
if action.get('ok') is not False: return ()
|
|
100
|
+
tool, detail, findings = action.get('tool', ''), str(action.get('detail', '')), []
|
|
101
|
+
key = _failure_key(action)
|
|
102
|
+
if key in failed: findings.append(Finding('repeat_failure', tool, index, 'Diagnose or change route before repeating a failed call.'))
|
|
103
|
+
failed.add(key)
|
|
104
|
+
if any(s in detail for s in _SCHEMA_ERRS):
|
|
105
|
+
findings.append(Finding('schema', tool, index, 'Send arguments that match the tool schema exactly.'))
|
|
106
|
+
if tool == 'run_shell' and ('usage:' in detail or 'unrecognized arguments' in detail):
|
|
107
|
+
findings.append(Finding('tool_protocol', tool, index, 'Read the project command contract before retrying.'))
|
|
108
|
+
return tuple(findings)
|
|
109
|
+
|
|
110
|
+
def assess_turn(turn):
|
|
111
|
+
"Assess the tool route recorded in one Ramabana turn."
|
|
112
|
+
activities, findings, failed, bypassed = turn.get('activity') or [], [], set(), set()
|
|
113
|
+
route_finding = _first_research_finding(turn.get('prompt', ''), activities)
|
|
114
|
+
if route_finding: findings.append(route_finding)
|
|
115
|
+
for ind, a in enumerate(activities):
|
|
116
|
+
if a.get('tool') == 'run_shell' and (t := bypass_tool(str(tool_args(a).get('command', '')))) and t not in bypassed:
|
|
117
|
+
bypassed.add(t); findings.append(Finding('bypass', 'run_shell', ind, f'Use {t} instead of run_shell for this.'))
|
|
118
|
+
findings.extend(_failure_findings(ind, a, failed))
|
|
119
|
+
return Assessment(max(0, 100 - 20*len(findings)), len(activities), tuple(findings))
|
|
120
|
+
|
|
121
|
+
def assess_history(turns):
|
|
122
|
+
"Assess several turns as one route corpus."
|
|
123
|
+
assessments = [assess_turn(t) for t in turns]
|
|
124
|
+
findings = tuple(f for a in assessments for f in a.findings)
|
|
125
|
+
return Assessment(max(0, 100 - 20*len(findings)), sum(a.calls for a in assessments), findings)
|
|
126
|
+
|
|
127
|
+
# %% ../nbs/00_core.ipynb #2d9bf58b
|
|
128
|
+
ROUND_REVISION = 1
|
|
129
|
+
ROUNDS_DIR = xdg_config_home()/'dhrona/rounds'
|
|
130
|
+
SEEDS_DIR = Path(dhrona.__file__).parent/'seeds'
|
|
131
|
+
|
|
132
|
+
def call_valid(args, fn):
|
|
133
|
+
"Would `fn` accept `args` as keyword arguments?"
|
|
134
|
+
try: inspect.signature(fn).bind(**args); return True
|
|
135
|
+
except (TypeError, ValueError): return False
|
|
136
|
+
|
|
137
|
+
def _tool_name(f):
|
|
138
|
+
if isinstance(f, str): return f
|
|
139
|
+
if isinstance(f, functools.partial): return _tool_name(f.func)
|
|
140
|
+
if callable(f): return getattr(f, '__name__', type(f).__name__)
|
|
141
|
+
raise TypeError('tools must be tool callables, names, or a name→callable dict')
|
|
142
|
+
|
|
143
|
+
def as_tools(tools):
|
|
144
|
+
"Tools keyed by name, from a dict or an iterable of callables, partials, or names (a name maps to `None`)."
|
|
145
|
+
return dict(tools) if isinstance(tools, dict) else {_tool_name(f): None if isinstance(f, str) else f for f in tools}
|
|
146
|
+
|
|
147
|
+
def round_calls(rnd):
|
|
148
|
+
"The `(tool, arguments)` pairs an accepted round makes."
|
|
149
|
+
return [(p['name'], p.get('arguments') or {}) for m in rnd['history'] for p in m['content'] if p['type']=='tool_use']
|
|
150
|
+
|
|
151
|
+
def round_valid(rnd, tools):
|
|
152
|
+
"Do all of `rnd`'s calls bind to `tools`? A `None` tool checks the name only."
|
|
153
|
+
return all(n in tools and (tools[n] is None or call_valid(a, tools[n])) for n,a in round_calls(rnd))
|
|
154
|
+
|
|
155
|
+
def load_rounds(dirs=None):
|
|
156
|
+
"Accepted rounds from the library and packaged seeds, skipping unreadable files."
|
|
157
|
+
rs = [_loads(p.read_text()) for d in ifnone(dirs, [ROUNDS_DIR, SEEDS_DIR]) for p in sorted(Path(d).glob('*.json'))]
|
|
158
|
+
return [r for r in rs if isinstance(r, dict) and r.get('meta', {}).get('status')=='accepted']
|
|
159
|
+
|
|
160
|
+
def _tc(p): return ToolCall(p['name'], p.get('arguments') or {}, **({'id': p['id']} if p.get('id') else {}))
|
|
161
|
+
|
|
162
|
+
def round_msgs(rnd):
|
|
163
|
+
"Canonical Urai messages from an accepted round."
|
|
164
|
+
res, tcs = [], {}
|
|
165
|
+
for m in rnd['history']:
|
|
166
|
+
parts = m['content']
|
|
167
|
+
if m['role']=='tool':
|
|
168
|
+
res += [mk_tool_res_msg(tcs.get(p.get('id')) or _tc(p), p.get('text', '')) for p in parts if p['type']=='tool_result']
|
|
169
|
+
continue
|
|
170
|
+
msg = {'role': m['role'], 'content': '\n'.join(p['text'] for p in parts if p['type']=='text' and p.get('text'))}
|
|
171
|
+
if calls := [_tc(p) for p in parts if p['type']=='tool_use']:
|
|
172
|
+
tcs.update({tc['id']: tc for tc in calls}); msg['tool_calls'] = calls
|
|
173
|
+
res.append(msg)
|
|
174
|
+
return res
|
|
175
|
+
|
|
176
|
+
def warm_start(tools=None, model=None, limit=2, dirs=None):
|
|
177
|
+
"Canonical Urai history from accepted rounds that fit the offered tools."
|
|
178
|
+
rs = load_rounds(dirs)
|
|
179
|
+
if tools is not None:
|
|
180
|
+
tools = as_tools(tools)
|
|
181
|
+
rs = [r for r in rs if round_valid(r, tools)]
|
|
182
|
+
rs = sorted(rs, key=lambda r: r['meta'].get('model') != model)[:limit]
|
|
183
|
+
return [m for r in rs for m in round_msgs(r)]
|
|
184
|
+
|
|
185
|
+
def dhrona_version():
|
|
186
|
+
"The warm-start revision."
|
|
187
|
+
return f'{dhrona.__version__}:{ROUND_REVISION}'
|
|
188
|
+
|
|
189
|
+
def receipt_path(state=None):
|
|
190
|
+
"The completion receipt file."
|
|
191
|
+
return Path(state) if state else xdg_state_home()/'dhrona/completions.json'
|
|
192
|
+
|
|
193
|
+
def register_completion(state=None):
|
|
194
|
+
"Record one clean round and return its completion id."
|
|
195
|
+
path, cid = receipt_path(state), uuid.uuid4().hex
|
|
196
|
+
records = path.read_json() if path.exists() else {}
|
|
197
|
+
records[cid] = {'version': dhrona_version(), 'at': time.time()}
|
|
198
|
+
path.write_json(records, indent=2)
|
|
199
|
+
return cid
|
|
200
|
+
|
|
201
|
+
def completion_valid(cid, state=None):
|
|
202
|
+
"Does `cid` name a completion for the current round?"
|
|
203
|
+
path = receipt_path(state)
|
|
204
|
+
if not cid or not path.exists(): return False
|
|
205
|
+
return (path.read_json().get(cid) or {}).get('version') == dhrona_version()
|
|
206
|
+
|
|
207
|
+
def prepare_chat(chat, tools=None, model=None):
|
|
208
|
+
"Prepend the Dhrona warm start to an empty Urai-compatible chat."
|
|
209
|
+
if chat.hist: raise ValueError('Dhrona prepares an empty chat only')
|
|
210
|
+
chat.hist = chat.fmt2hist(warm_start(tools, model))
|
|
211
|
+
if hasattr(chat, '_recreate_conv'): chat._recreate_conv()
|
|
212
|
+
return chat
|
|
213
|
+
|
|
214
|
+
# %% ../nbs/00_core.ipynb #f4e8294d
|
|
215
|
+
@call_parse
|
|
216
|
+
def main(
|
|
217
|
+
history: str=str(RAMABANA_HISTORY), # Ramabana history path
|
|
218
|
+
session: str=None, # optional session id
|
|
219
|
+
):
|
|
220
|
+
"Assess persisted Ramabana tool routes."
|
|
221
|
+
if not Path(history).expanduser().exists(): sys.exit(f'No history at {history}')
|
|
222
|
+
a = assess_history(read_history(history, session))
|
|
223
|
+
print(json.dumps({'score': a.score, 'calls': a.calls, 'findings': [asdict(f) for f in a.findings]}, indent=2))
|
dhrona/rounds.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Capture, review, accept, and start curated tool-use rounds.
|
|
2
|
+
|
|
3
|
+
Docs: https://Karthik777.github.io/drona/rounds.html.md"""
|
|
4
|
+
|
|
5
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_rounds.ipynb.
|
|
6
|
+
|
|
7
|
+
# %% auto #0
|
|
8
|
+
__all__ = ['REVIEW_KEY', 'read_dialog', 'clean_dialog', 'latest_session', 'capture', 'compiled_history', 'accept',
|
|
9
|
+
'bootstrap_prompt', 'start_commands', 'start_round', 'capture_cli', 'accept_cli', 'start_cli']
|
|
10
|
+
|
|
11
|
+
# %% ../nbs/01_rounds.ipynb #af82ef79
|
|
12
|
+
from dataclasses import asdict
|
|
13
|
+
from fastcore.xtras import Path
|
|
14
|
+
import json, shlex, subprocess
|
|
15
|
+
from aidialog.dialog import Dialog, snote, sprompt
|
|
16
|
+
from aidialog.hist import chat2dlg, dlg2chat
|
|
17
|
+
from aidialog.ipynb import read_ipynb, write_ipynb
|
|
18
|
+
from aidialog.msg_parts import Msg, Text, ToolUse, ToolResult
|
|
19
|
+
from fastcore.script import call_parse
|
|
20
|
+
from .core import RAMABANA_HISTORY, ROUNDS_DIR, assess_history, dhrona_version, read_history
|
|
21
|
+
|
|
22
|
+
# %% ../nbs/01_rounds.ipynb #d4f6b8c0
|
|
23
|
+
REVIEW_KEY = 'dhrona'
|
|
24
|
+
|
|
25
|
+
def read_dialog(source):
|
|
26
|
+
"Read a Dhrona dialog notebook."
|
|
27
|
+
if not (dlg := read_ipynb(source)): raise ValueError(f'Could not read dialog {source}')
|
|
28
|
+
return dlg
|
|
29
|
+
|
|
30
|
+
def _prompts(dlg): return [m for m in dlg if m.msg_type == sprompt and not m.skipped]
|
|
31
|
+
|
|
32
|
+
def clean_dialog(source):
|
|
33
|
+
"Prompt messages from a Dhrona notebook, without review notes."
|
|
34
|
+
dlg = read_dialog(source)
|
|
35
|
+
if not (prompts := _prompts(dlg)): raise ValueError('Dialog contains no prompt turns')
|
|
36
|
+
return Dialog(prompts, name=dlg.name, meta=dlg.meta)
|
|
37
|
+
|
|
38
|
+
def _add_review(dlg, report, text):
|
|
39
|
+
dlg.meta[REVIEW_KEY] = report
|
|
40
|
+
dlg.mk_message(f'# Dhrona review\n\n{text}', idx=0, msg_type=snote, skipped=1, meta={REVIEW_KEY: report})
|
|
41
|
+
|
|
42
|
+
def _write_dlg(dlg, output):
|
|
43
|
+
output = Path(output)
|
|
44
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
45
|
+
write_ipynb(dlg, output)
|
|
46
|
+
return output
|
|
47
|
+
|
|
48
|
+
# %% ../nbs/01_rounds.ipynb #252210fa
|
|
49
|
+
def latest_session(turns):
|
|
50
|
+
"The newest session id in `turns`."
|
|
51
|
+
return turns[-1].get('session') if turns else None
|
|
52
|
+
|
|
53
|
+
def _turn_msgs(turn, ti=0):
|
|
54
|
+
"One Ramabana archive turn as typed Aidialog messages; `ti` keeps fallback call ids unique across turns."
|
|
55
|
+
user = Msg('user', [Text(turn.get('prompt', ''))])
|
|
56
|
+
replies = []
|
|
57
|
+
for i, action in enumerate(turn.get('activity') or []):
|
|
58
|
+
call_id = action.get('action_id') or action.get('id') or f'call_{ti}_{i}'
|
|
59
|
+
tool = action.get('tool', '')
|
|
60
|
+
args = action.get('args') or {}
|
|
61
|
+
replies += [
|
|
62
|
+
Msg('assistant', [ToolUse(id=call_id, name=tool, arguments=args)]),
|
|
63
|
+
Msg('tool', [ToolResult(id=call_id, name=tool, arguments=args, text=str(action.get('detail', '')))]),
|
|
64
|
+
]
|
|
65
|
+
if text := turn.get('reply', ''): replies.append(Msg('assistant', [Text(text)]))
|
|
66
|
+
return [user, *replies]
|
|
67
|
+
|
|
68
|
+
def capture(
|
|
69
|
+
output, # review notebook path
|
|
70
|
+
session='latest', # Ramabana session id, prefix, or `latest`
|
|
71
|
+
history=RAMABANA_HISTORY, # Ramabana history path
|
|
72
|
+
name=None, # round name; output stem when omitted
|
|
73
|
+
):
|
|
74
|
+
"Capture one persisted Ramabana session as a review notebook."
|
|
75
|
+
turns = read_history(history)
|
|
76
|
+
if not turns: raise ValueError('Ramabana history has no completed turns')
|
|
77
|
+
if session == 'latest': session = latest_session(turns)
|
|
78
|
+
matches = [t for t in turns if str(t.get('session', '')).startswith(session)]
|
|
79
|
+
ids = {t.get('session') for t in matches}
|
|
80
|
+
if not matches: raise ValueError(f'No Ramabana session matches {session!r}')
|
|
81
|
+
if len(ids) > 1: raise ValueError(f'Ramabana session prefix {session!r} is ambiguous')
|
|
82
|
+
assessment = assess_history(matches)
|
|
83
|
+
msgs = [m for ti, turn in enumerate(matches) for m in _turn_msgs(turn, ti)]
|
|
84
|
+
dlg = chat2dlg(msgs, name or Path(output).stem, mx=None)
|
|
85
|
+
report = {'version': dhrona_version(), 'session': matches[0].get('session'), 'model': matches[-1].get('model'),
|
|
86
|
+
'status': 'review', 'score': assessment.score,
|
|
87
|
+
'findings': [asdict(f) for f in assessment.findings]}
|
|
88
|
+
_add_review(dlg, report, 'Edit this dialog in Leela. Remove poor routes and sensitive content. Set `reviewer` when accepting.')
|
|
89
|
+
return _write_dlg(dlg, output)
|
|
90
|
+
|
|
91
|
+
# %% ../nbs/01_rounds.ipynb #c2ca7765
|
|
92
|
+
def compiled_history(source):
|
|
93
|
+
"Canonical Aidialog history from an accepted round."
|
|
94
|
+
dlg = clean_dialog(source)
|
|
95
|
+
if (dlg.meta.get(REVIEW_KEY) or {}).get('status') != 'accepted': raise ValueError('Round has not been accepted')
|
|
96
|
+
return dlg2chat(dlg, plain=True)
|
|
97
|
+
|
|
98
|
+
def accept(
|
|
99
|
+
source, # reviewed dialog notebook
|
|
100
|
+
reviewer, # person accepting the round
|
|
101
|
+
output=None, # compiled JSON path; `<source>.json` when omitted
|
|
102
|
+
install=False, # also write to the rounds library (`True` for `ROUNDS_DIR`, or a directory)
|
|
103
|
+
):
|
|
104
|
+
"Accept a reviewed dialog and write its canonical history."
|
|
105
|
+
if not reviewer.strip(): raise ValueError('reviewer is required')
|
|
106
|
+
dlg = read_dialog(source)
|
|
107
|
+
if not (prompts := _prompts(dlg)): raise ValueError('Round contains no prompt turns')
|
|
108
|
+
history = dlg2chat(Dialog(prompts, name=dlg.name), plain=True)
|
|
109
|
+
if not history or history[0].role != 'user': raise ValueError('Round must start with a user turn')
|
|
110
|
+
meta = dict(dlg.meta.get(REVIEW_KEY) or {})
|
|
111
|
+
tools = sorted({p.name for m in history for p in m.content if isinstance(p, ToolUse)})
|
|
112
|
+
meta.update(status='accepted', reviewer=reviewer, accepted_version=dhrona_version(), tools=tools)
|
|
113
|
+
dlg.meta[REVIEW_KEY] = meta
|
|
114
|
+
dlg.save(source)
|
|
115
|
+
output = Path(output) if output else Path(source).with_suffix('.json')
|
|
116
|
+
data = {'meta': meta, 'history': _history_dicts(history)}
|
|
117
|
+
output.write_json(data, indent=2)
|
|
118
|
+
if install:
|
|
119
|
+
lib = (ROUNDS_DIR if install is True else Path(install))/f'{dlg.name or Path(source).stem}.json'
|
|
120
|
+
lib.parent.mkdir(parents=True, exist_ok=True)
|
|
121
|
+
lib.write_json(data, indent=2)
|
|
122
|
+
return output
|
|
123
|
+
|
|
124
|
+
def _part_dict(part):
|
|
125
|
+
data = {'type': str(getattr(part.type, 'value', part.type))}
|
|
126
|
+
data.update({k:v for k,v in vars(part).items() if v not in (None, False, {}, []) and k != 'raw'})
|
|
127
|
+
return data
|
|
128
|
+
|
|
129
|
+
def _history_dicts(history):
|
|
130
|
+
return [{'role': m.role, 'content': [_part_dict(p) for p in m.content]} for m in history]
|
|
131
|
+
|
|
132
|
+
# %% ../nbs/01_rounds.ipynb #7df69513
|
|
133
|
+
def bootstrap_prompt(source):
|
|
134
|
+
"A compact prompt containing one accepted worked round."
|
|
135
|
+
history = compiled_history(source)
|
|
136
|
+
rows = ['The following reviewed Dhrona round demonstrates the tool route to follow.']
|
|
137
|
+
for m in history:
|
|
138
|
+
if m.role == 'user': rows.append(f'User: {m.text}')
|
|
139
|
+
elif m.role == 'assistant':
|
|
140
|
+
for p in m.content:
|
|
141
|
+
if isinstance(p, Text) and p.text: rows.append(f'Assistant: {p.text}')
|
|
142
|
+
elif isinstance(p, ToolUse): rows.append(f'Assistant tool: {p.name}({json.dumps(p.arguments, sort_keys=True)})')
|
|
143
|
+
elif m.role == 'tool':
|
|
144
|
+
for p in m.content:
|
|
145
|
+
if isinstance(p, ToolResult): rows.append(f'Tool result: {p.text}')
|
|
146
|
+
rows.append('Reply with exactly: DHRONA_READY')
|
|
147
|
+
return '\n\n'.join(rows)
|
|
148
|
+
|
|
149
|
+
def start_commands(
|
|
150
|
+
source, # accepted review notebook
|
|
151
|
+
root='.', # Ramabana root
|
|
152
|
+
model=None, # optional model name
|
|
153
|
+
):
|
|
154
|
+
"The bootstrap and resume commands for an accepted round."
|
|
155
|
+
prompt = bootstrap_prompt(source)
|
|
156
|
+
cmd = ['ramabana', '--root', root]
|
|
157
|
+
if model: cmd += ['--model', model]
|
|
158
|
+
cmd += [prompt]
|
|
159
|
+
return cmd, ['ramabana', '--root', root, '--resume', 'latest']
|
|
160
|
+
|
|
161
|
+
def start_round(source, root='.', model=None, launch=False):
|
|
162
|
+
"Prepare or launch Ramabana with an accepted Dhrona round."
|
|
163
|
+
first, resume = start_commands(source, root, model)
|
|
164
|
+
if not launch: return {'bootstrap': first, 'resume': resume}
|
|
165
|
+
subprocess.run(first, check=True)
|
|
166
|
+
return subprocess.run(resume, check=True).returncode
|
|
167
|
+
|
|
168
|
+
# %% ../nbs/01_rounds.ipynb #5f8482bd
|
|
169
|
+
def _print_commands(commands):
|
|
170
|
+
for name, command in commands.items(): print(f'{name}: {shlex.join(command)}')
|
|
171
|
+
|
|
172
|
+
@call_parse
|
|
173
|
+
def capture_cli(output: str, session: str='latest', history: str=str(RAMABANA_HISTORY), name: str=None):
|
|
174
|
+
"Capture a saved Ramabana session for review."
|
|
175
|
+
print(capture(output, session, history, name))
|
|
176
|
+
|
|
177
|
+
@call_parse
|
|
178
|
+
def accept_cli(source: str, reviewer: str='', output: str=None, install: bool=False):
|
|
179
|
+
"Accept a reviewed round and compile its history."
|
|
180
|
+
print(accept(source, reviewer, output, install))
|
|
181
|
+
|
|
182
|
+
@call_parse
|
|
183
|
+
def start_cli(source: str, root: str='.', model: str=None, launch: bool=False):
|
|
184
|
+
"Prepare or launch Ramabana with an accepted round."
|
|
185
|
+
result = start_round(source, root, model, launch)
|
|
186
|
+
if isinstance(result, dict): _print_commands(result)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"name": "fossick-github",
|
|
4
|
+
"status": "accepted",
|
|
5
|
+
"reviewer": "Karthik",
|
|
6
|
+
"tools": ["run_shell"],
|
|
7
|
+
"model": null
|
|
8
|
+
},
|
|
9
|
+
"history": [
|
|
10
|
+
{
|
|
11
|
+
"role": "user",
|
|
12
|
+
"content": [
|
|
13
|
+
{"type": "text", "text": "Use FOSSICK to research the AnswerDotAI llmdojo GitHub repository."}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"role": "assistant",
|
|
18
|
+
"content": [
|
|
19
|
+
{"type": "text", "text": "The request names a GitHub repository and FOSSICK, so use its repository reader first."},
|
|
20
|
+
{
|
|
21
|
+
"type": "tool_use",
|
|
22
|
+
"id": "call_fossick",
|
|
23
|
+
"name": "run_shell",
|
|
24
|
+
"arguments": {
|
|
25
|
+
"command": "fossick read-gh-repo https://github.com/AnswerDotAI/llmdojo --globs 'README*,llmdojo/*.py,pyproject.toml' --limit 30",
|
|
26
|
+
"cwd": ".",
|
|
27
|
+
"timeout": 120
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"role": "tool",
|
|
34
|
+
"content": [
|
|
35
|
+
{"type": "tool_result", "id": "call_fossick", "name": "run_shell", "text": "# llmdojo\nLLM coding agents imitate what their context shows."}
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"role": "assistant",
|
|
40
|
+
"content": [
|
|
41
|
+
{"type": "text", "text": "FOSSICK read the repository directly. I will use its source files as the evidence."}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
dhrona/sessions.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Move reviewed dialogs between Ramabana, Claude Code, and Codex.
|
|
2
|
+
|
|
3
|
+
Docs: https://Karthik777.github.io/drona/sessions.html.md"""
|
|
4
|
+
|
|
5
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_sessions.ipynb.
|
|
6
|
+
|
|
7
|
+
# %% auto #0
|
|
8
|
+
__all__ = ['HOSTS', 'import_session', 'export_session', 'import_cli', 'export_cli', 'clean_dialog']
|
|
9
|
+
|
|
10
|
+
# %% ../nbs/02_sessions.ipynb #9ba09521
|
|
11
|
+
from fastcore.xtras import Path
|
|
12
|
+
import json
|
|
13
|
+
|
|
14
|
+
from fastcore.script import call_parse
|
|
15
|
+
from llmsurgery import ant, oai
|
|
16
|
+
from llmsurgery.sess import path_dlg, sess_dlg
|
|
17
|
+
|
|
18
|
+
from .rounds import REVIEW_KEY, capture, clean_dialog, bootstrap_prompt, _add_review, _write_dlg
|
|
19
|
+
_all_ = ['clean_dialog']
|
|
20
|
+
|
|
21
|
+
# %% ../nbs/02_sessions.ipynb #aa0b5b0e
|
|
22
|
+
HOSTS = ('ramabana', 'claude', 'codex')
|
|
23
|
+
|
|
24
|
+
def import_session(
|
|
25
|
+
host, # `ramabana`, `claude`, or `codex`
|
|
26
|
+
output, # review notebook path
|
|
27
|
+
session='latest', # session id, prefix, or `latest`
|
|
28
|
+
cwd=None, # project directory for Claude or newest-session lookup
|
|
29
|
+
history=None, # Ramabana history path
|
|
30
|
+
codex_home=None, # optional Codex home
|
|
31
|
+
name=None, # dialog name
|
|
32
|
+
):
|
|
33
|
+
"Import one host session as an Aidialog review notebook."
|
|
34
|
+
if host not in HOSTS: raise ValueError(f'host must be one of {HOSTS}')
|
|
35
|
+
if host == 'ramabana':
|
|
36
|
+
kwargs = {} if history is None else {'history': history}
|
|
37
|
+
return capture(output, session=session, name=name, **kwargs)
|
|
38
|
+
if session == 'latest':
|
|
39
|
+
if host == 'claude':
|
|
40
|
+
path = max(ant.sess_dir(cwd).glob('*.jsonl'), key=lambda p:p.stat().st_mtime)
|
|
41
|
+
else: _, path = oai.project_thread(cwd or '.', codex_home or oai.CODEX_HOME)
|
|
42
|
+
dlg = path_dlg('ant' if host == 'claude' else 'oai', path, name=name, mx=None)
|
|
43
|
+
else: dlg = sess_dlg(session, cwd=cwd, codex_home=codex_home, name=name, mx=None)
|
|
44
|
+
source = dict(dlg.meta.get('llmsurgery') or {})
|
|
45
|
+
source['host'] = host
|
|
46
|
+
review = {'status': 'review', 'source': source}
|
|
47
|
+
_add_review(dlg, review, 'Edit this dialog in Leela before exporting it.')
|
|
48
|
+
return _write_dlg(dlg, output)
|
|
49
|
+
|
|
50
|
+
# %% ../nbs/02_sessions.ipynb #d8739129
|
|
51
|
+
def export_session(
|
|
52
|
+
source, # Dhrona review notebook
|
|
53
|
+
host, # `ramabana`, `claude`, or `codex`
|
|
54
|
+
output=None, # JSON output for Ramabana or Codex
|
|
55
|
+
cwd=None, # Claude project directory
|
|
56
|
+
):
|
|
57
|
+
"Compile one Dhrona notebook for a target host."
|
|
58
|
+
if host not in HOSTS: raise ValueError(f'host must be one of {HOSTS}')
|
|
59
|
+
dlg = clean_dialog(source)
|
|
60
|
+
if host == 'claude': return ant.dlg2sess(dlg, cwd=cwd)
|
|
61
|
+
if host == 'codex':
|
|
62
|
+
items = list(oai.dlg2items(dlg))
|
|
63
|
+
if output: Path(output).write_json(items, indent=2)
|
|
64
|
+
return items
|
|
65
|
+
prompt = bootstrap_prompt(source)
|
|
66
|
+
if output: Path(output).write_text(prompt)
|
|
67
|
+
return prompt
|
|
68
|
+
|
|
69
|
+
# %% ../nbs/02_sessions.ipynb #b895cc91
|
|
70
|
+
@call_parse
|
|
71
|
+
def import_cli(host: str, output: str, session: str='latest', cwd: str=None,
|
|
72
|
+
history: str=None, codex_home: str=None, name: str=None):
|
|
73
|
+
"Import a host session as a review notebook."
|
|
74
|
+
print(import_session(host, output, session, cwd, history, codex_home, name))
|
|
75
|
+
|
|
76
|
+
@call_parse
|
|
77
|
+
def export_cli(source: str, host: str, output: str=None, cwd: str=None):
|
|
78
|
+
"Compile a review notebook for another host."
|
|
79
|
+
result = export_session(source, host, output, cwd)
|
|
80
|
+
if host == 'claude': print(result)
|
|
81
|
+
elif output: print(output)
|
|
82
|
+
else: print(json.dumps(result, indent=2) if host == 'codex' else result)
|
dhrona/tools.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Measure which tools agents call, how often they fail, and where the shell stands in for a dedicated tool.
|
|
2
|
+
|
|
3
|
+
Docs: https://Karthik777.github.io/drona/tools.html.md"""
|
|
4
|
+
|
|
5
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/03_tools.ipynb.
|
|
6
|
+
|
|
7
|
+
# %% auto #0
|
|
8
|
+
__all__ = ['HISTORIES', 'tool_report', 'fmt_report', 'tools_cli']
|
|
9
|
+
|
|
10
|
+
# %% ../nbs/03_tools.ipynb #ba1f72ae
|
|
11
|
+
from collections import Counter, defaultdict
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
from json import dumps
|
|
14
|
+
import re, sys
|
|
15
|
+
from fastcore.xtras import Path
|
|
16
|
+
from fastcore.foundation import L
|
|
17
|
+
from fastcore.script import call_parse
|
|
18
|
+
|
|
19
|
+
from .core import read_history, tool_args, bypass_tool
|
|
20
|
+
|
|
21
|
+
# %% ../nbs/03_tools.ipynb #55021db5
|
|
22
|
+
HISTORIES = L(Path.home()/f'.config/{app}/{kind}-history.jsonl' for app in ('ramabana', 'leela') for kind in ('agent', 'inline')).filter(Path.exists)
|
|
23
|
+
|
|
24
|
+
def _epoch(t):
|
|
25
|
+
"`t` as seconds since the epoch, from a number, numeric string, or ISO date."
|
|
26
|
+
if t in (None, ''): return None
|
|
27
|
+
try: return float(t)
|
|
28
|
+
except ValueError:
|
|
29
|
+
try: return datetime.fromisoformat(t).timestamp()
|
|
30
|
+
except ValueError: raise ValueError(f'--since must be an epoch or ISO date, got {t!r}') from None
|
|
31
|
+
|
|
32
|
+
def _detail_key(detail):
|
|
33
|
+
"The first line of `detail` with digits normalised, so repeated failures group together."
|
|
34
|
+
return re.sub(r'\d+', 'N', str(detail or '').partition('\n')[0])[:80]
|
|
35
|
+
|
|
36
|
+
def tool_report(
|
|
37
|
+
turns, # history turns from `read_history`
|
|
38
|
+
since=None, # epoch or ISO date lower bound on `at`
|
|
39
|
+
model=None, # restrict to one model name
|
|
40
|
+
):
|
|
41
|
+
"Per-tool call and failure counts, shell bypasses, and the same split per model."
|
|
42
|
+
since, calls, fails, details, bypass = _epoch(since), Counter(), Counter(), defaultdict(Counter), Counter()
|
|
43
|
+
models = defaultdict(lambda: dict(calls=0, shell=0, bypass=0))
|
|
44
|
+
for t in turns:
|
|
45
|
+
if (since and (t.get('at') or 0) < since) or (model and t.get('model') != model): continue
|
|
46
|
+
m = models[t.get('model') or '?']
|
|
47
|
+
for a in t.get('activity') or []:
|
|
48
|
+
tool = a.get('tool') or '?'
|
|
49
|
+
calls[tool] += 1; m['calls'] += 1
|
|
50
|
+
if a.get('ok') is False: fails[tool] += 1; details[tool][_detail_key(a.get('detail'))] += 1
|
|
51
|
+
if tool == 'run_shell':
|
|
52
|
+
m['shell'] += 1
|
|
53
|
+
if b := bypass_tool(tool_args(a).get('command')): bypass[b] += 1; m['bypass'] += 1
|
|
54
|
+
tools = {k: dict(calls=v, fails=fails[k], fail_rate=round(fails[k]/v, 3), failures=[[d,n] for d,n in details[k].most_common(3)])
|
|
55
|
+
for k,v in calls.most_common()}
|
|
56
|
+
return dict(calls=sum(calls.values()), tools=tools, bypass=dict(bypass.most_common()), models=dict(models))
|
|
57
|
+
|
|
58
|
+
def fmt_report(r):
|
|
59
|
+
"`r` as a text table followed by bypass and per-model summary lines."
|
|
60
|
+
w = max(map(len, r['tools']), default=4)
|
|
61
|
+
rows = [f"{'tool':<{w}} calls fail% top failure"]
|
|
62
|
+
rows += [f"{t:<{w}} {v['calls']:>5} {100*v['fail_rate']:>4.0f}% {v['failures'][0][0] if v['failures'] else ''}" for t,v in r['tools'].items()]
|
|
63
|
+
rows.append(f"\n{r['calls']} calls; bypass: " + (', '.join(f'{k}={v}' for k,v in r['bypass'].items()) or 'none'))
|
|
64
|
+
rows += [f"{m}: {v['calls']} calls, {v['shell']} shell, {v['bypass']} bypass" for m,v in r['models'].items()]
|
|
65
|
+
return '\n'.join(rows)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# %% ../nbs/03_tools.ipynb #ce493ed0
|
|
69
|
+
@call_parse
|
|
70
|
+
def tools_cli(
|
|
71
|
+
history: str='', # comma-separated history paths (default: every known history)
|
|
72
|
+
since: str='', # epoch or ISO date lower bound
|
|
73
|
+
model: str='', # restrict to one model
|
|
74
|
+
json: bool=False, # print the report as JSON
|
|
75
|
+
):
|
|
76
|
+
"Report tool usage, failures and shell bypasses across agent histories."
|
|
77
|
+
paths = L(history.split(',')).filter().map(lambda p: Path(p).expanduser()) if history else HISTORIES
|
|
78
|
+
if missing := paths.filter(Path.exists, negate=True): print(f"No history at {', '.join(map(str, missing))}", file=sys.stderr)
|
|
79
|
+
if not (paths := paths.filter(Path.exists)): sys.exit('No history files found')
|
|
80
|
+
try: r = tool_report(paths.map(read_history).concat(), since or None, model or None)
|
|
81
|
+
except ValueError as e: sys.exit(str(e))
|
|
82
|
+
print(dumps(r, indent=2) if json else fmt_report(r))
|
|
83
|
+
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dhrona
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: train agents to choose and use the right tools
|
|
5
|
+
Project-URL: Repository, https://github.com/Karthik777/drona
|
|
6
|
+
Project-URL: Documentation, https://Karthik777.github.io/drona/
|
|
7
|
+
Author-email: Karthik <karthik.rajgopal@hotmail.com>
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: nbdev
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Requires-Python: >=3.12
|
|
14
|
+
Requires-Dist: aidialog>=0.0.27
|
|
15
|
+
Requires-Dist: fastcore>=2.1.16
|
|
16
|
+
Requires-Dist: llmsurgery>=0.0.16
|
|
17
|
+
Requires-Dist: uraiyadal>=0.0.1
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# dhrona
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
|
24
|
+
|
|
25
|
+
Dhrona measures how agents use their tools and teaches better routes. It reads Ramabana and Leela session history, reports tool use and failures, flags poor routes, and turns reviewed sessions into a library of accepted rounds that any Urai chat can replay as a warm start.
|
|
26
|
+
|
|
27
|
+
## The loop
|
|
28
|
+
|
|
29
|
+
1. **Measure** — `dhrona-tools` reports calls, failure rate and shell bypasses per tool and per model; `dhrona` scores routes in a session.
|
|
30
|
+
2. **Capture** — `dhrona-capture` turns a finished Ramabana session into an Aidialog review notebook.
|
|
31
|
+
3. **Review in Leela** — open the notebook, remove detours and sensitive content, keep the route future models should imitate.
|
|
32
|
+
4. **Accept** — `dhrona-accept --install` records the reviewer, the tools used and the model, compiles canonical history, and installs it in the rounds library.
|
|
33
|
+
5. **Warm start** — `warm_start(tools, model)` replays accepted rounds whose recorded calls still bind to the offered tools’ live signatures, same-model rounds first.
|
|
34
|
+
|
|
35
|
+
Re-run `dhrona-tools` after a change to see whether tool use moved.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
``` sh
|
|
40
|
+
pip install dhrona
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Measure tool use
|
|
44
|
+
|
|
45
|
+
`dhrona-tools` measures tool use across the Ramabana and Leela histories: calls and failure rate per tool, shell commands that bypass a dedicated tool, and the same split per model. It is the before/after instrument for tool culling.
|
|
46
|
+
|
|
47
|
+
``` sh
|
|
48
|
+
dhrona-tools --since 2026-09-19
|
|
49
|
+
dhrona-tools --json > baselines/tools.json
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
[`assess_turn`](https://Karthik777.github.io/drona/core.html#assess_turn) scores observable tool actions. It does not infer quality from the assistant narrative.
|
|
53
|
+
|
|
54
|
+
``` python
|
|
55
|
+
turn = {
|
|
56
|
+
'prompt': 'Use fossick to research https://github.com/AnswerDotAI/llmdojo',
|
|
57
|
+
'activity': [{'tool': 'web_search', 'ok': True, 'args': {'query': 'llmdojo'}}],
|
|
58
|
+
}
|
|
59
|
+
assessment = assess_turn(turn)
|
|
60
|
+
assessment
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Findings are `route` (generic search before FOSSICK), `schema` (arguments that failed to decode), `bypass` (a shell command a dedicated tool covers), `tool_protocol` (command-line usage error) and `repeat_failure`. Every finding lowers the score by 20 points, including each distinct `bypass` in a turn, so shelling out for `git diff` or `cat` costs points. Run `dhrona` to assess the default Ramabana history. Pass `--session` to limit the report to one session.
|
|
64
|
+
|
|
65
|
+
## Curate a round
|
|
66
|
+
|
|
67
|
+
Ramabana already records completed turns. Capture reads that archive after the conversation ends. It does not monitor a live process.
|
|
68
|
+
|
|
69
|
+
``` sh
|
|
70
|
+
ramabana --root /path/to/project
|
|
71
|
+
# finish the useful conversation, then quit
|
|
72
|
+
dhrona-capture training/github-research.ipynb --session latest
|
|
73
|
+
leela training
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Open `github-research.ipynb` in Leela. Remove detours and sensitive content. Keep the route that future models should imitate. Save the notebook, then accept it with a reviewer name.
|
|
77
|
+
|
|
78
|
+
``` sh
|
|
79
|
+
dhrona-accept training/github-research.ipynb --reviewer Karthik --install
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Acceptance updates the notebook metadata with the reviewer, the tools the round calls and the session model, and writes `github-research.json` as derived canonical history. `--install` also copies it into the rounds library (`~/.config/dhrona/rounds/`), where [`warm_start`](https://Karthik777.github.io/drona/core.html#warm_start) finds it. An unaccepted notebook cannot start a session.
|
|
83
|
+
|
|
84
|
+
`dhrona-start` prints the Ramabana bootstrap and resume commands by default. `--launch` runs them.
|
|
85
|
+
|
|
86
|
+
``` sh
|
|
87
|
+
dhrona-start training/github-research.ipynb --root /path/to/project
|
|
88
|
+
dhrona-start training/github-research.ipynb --root /path/to/project --launch
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Ramabana receives the accepted round as its first bootstrap turn and saves it. Dhrona then resumes that session. Leela can use [`compiled_history`](https://Karthik777.github.io/drona/rounds.html#compiled_history) directly when it adds prepared-history support.
|
|
92
|
+
|
|
93
|
+
## Warm start a chat
|
|
94
|
+
|
|
95
|
+
[`warm_start`](https://Karthik777.github.io/drona/core.html#warm_start) returns canonical Urai history from the accepted rounds in the library and the seeds packaged with dhrona. Pass the tools you offer (a list of callables or tool names, or a name → callable dict) and only rounds whose recorded calls bind to those signatures ([`call_valid`](https://Karthik777.github.io/drona/core.html#call_valid)) are replayed; a round for a renamed or re-parameterised tool is skipped rather than taught. Pass it to any Urai or Rishi chat through `messages=`, or call [`prepare_chat`](https://Karthik777.github.io/drona/core.html#prepare_chat) on an empty chat.
|
|
96
|
+
|
|
97
|
+
``` python
|
|
98
|
+
def run_shell(command, cwd='.', timeout=60): ...
|
|
99
|
+
history = warm_start([run_shell])
|
|
100
|
+
[(message['role'], message.get('name')) for message in history]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
A completion receipt includes the package version and round revision. [`completion_valid`](https://Karthik777.github.io/drona/core.html#completion_valid) rejects receipts from an older round.
|
|
104
|
+
|
|
105
|
+
## Move sessions between hosts
|
|
106
|
+
|
|
107
|
+
Aidialog notebooks are the interchange format. Ramabana, Claude, and Codex sessions can all be imported for review in Leela.
|
|
108
|
+
|
|
109
|
+
``` sh
|
|
110
|
+
dhrona-import ramabana training/round.ipynb --session latest
|
|
111
|
+
dhrona-import claude training/round.ipynb --session latest --cwd /path/to/project
|
|
112
|
+
dhrona-import codex training/round.ipynb --session latest --cwd /path/to/project
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The same reviewed notebook can become a Ramabana bootstrap, a resumable Claude session, or Codex-native Responses items.
|
|
116
|
+
|
|
117
|
+
``` sh
|
|
118
|
+
dhrona-export training/round.ipynb ramabana --output training/round.txt
|
|
119
|
+
dhrona-export training/round.ipynb claude --cwd /path/to/project
|
|
120
|
+
dhrona-export training/round.ipynb codex --output training/round-items.json
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Claude Code can resume the id printed by the Claude export. Codex export does not create a resumable rollout because llmsurgery has no public rollout writer. The exported items remain suitable for inspection, datasets, and a future Codex launcher.
|
|
124
|
+
|
|
125
|
+
## Command line
|
|
126
|
+
|
|
127
|
+
| Command | Purpose |
|
|
128
|
+
|----|----|
|
|
129
|
+
| `dhrona` | Score tool routes in Ramabana history |
|
|
130
|
+
| `dhrona-tools` | Tool use, failures and bypasses per tool and per model |
|
|
131
|
+
| `dhrona-capture` | Save a Ramabana session as a review notebook |
|
|
132
|
+
| `dhrona-accept` | Accept a reviewed round; `--install` adds it to the library |
|
|
133
|
+
| `dhrona-start` | Bootstrap and resume Ramabana with an accepted round |
|
|
134
|
+
| `dhrona-import` | Import a Ramabana, Claude or Codex session as a notebook |
|
|
135
|
+
| `dhrona-export` | Export a notebook for Ramabana, Claude or Codex |
|
|
136
|
+
|
|
137
|
+
## Develop
|
|
138
|
+
|
|
139
|
+
``` sh
|
|
140
|
+
uv sync --all-extras --group dev
|
|
141
|
+
uv run nbdev-prepare
|
|
142
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
dhrona/__init__.py,sha256=rnObPjuBcEStqSO0S6gsdS_ot8ITOQjVj_-P1LUUYpg,22
|
|
2
|
+
dhrona/_modidx.py,sha256=qqQWLZRzj2NYCDTEU5FHilB2-5ztW3PQRnPIH56ocfo,6191
|
|
3
|
+
dhrona/core.py,sha256=GXcWf2qb03MokbcDIsF3IWZ3NMpK6Bek3nSdBE60L8c,10647
|
|
4
|
+
dhrona/rounds.py,sha256=UFjTEVSz9cDt2z_YvEe1Lsf0R2jg-ep6GMvrHfpPRVs,8634
|
|
5
|
+
dhrona/sessions.py,sha256=y4tzw3KpCxdKaGzLFe5dFGGmbpeK49fkki5HLG5EDtg,3459
|
|
6
|
+
dhrona/tools.py,sha256=7BG9kU_NK55PD2a1QU_zT9hRQEEkA_wEaCkXL5ZuNbM,4141
|
|
7
|
+
dhrona/seeds/fossick-github.json,sha256=ZslyC5f-Jl7lQhGbrAXAf6euXWvdfr69mbjTKOi8Wg4,1265
|
|
8
|
+
dhrona-0.1.1.dist-info/METADATA,sha256=eMF4mNsxtqS7BL8Bad49VbRicL_paa4HjeKwC_WhEw8,7186
|
|
9
|
+
dhrona-0.1.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
10
|
+
dhrona-0.1.1.dist-info/entry_points.txt,sha256=MNOLhRlEcNP4wYv2iZlUvLQwdeA-rtHQFjpmLvjAgQI,326
|
|
11
|
+
dhrona-0.1.1.dist-info/licenses/LICENSE,sha256=xV8xoN4VOL0uw9X8RSs2IMuD_Ss_a9yAbtGNeBWZwnw,11337
|
|
12
|
+
dhrona-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[console_scripts]
|
|
2
|
+
dhrona = dhrona.core:main
|
|
3
|
+
dhrona-accept = dhrona.rounds:accept_cli
|
|
4
|
+
dhrona-capture = dhrona.rounds:capture_cli
|
|
5
|
+
dhrona-export = dhrona.sessions:export_cli
|
|
6
|
+
dhrona-import = dhrona.sessions:import_cli
|
|
7
|
+
dhrona-start = dhrona.rounds:start_cli
|
|
8
|
+
dhrona-tools = dhrona.tools:tools_cli
|
|
9
|
+
|
|
10
|
+
[nbdev]
|
|
11
|
+
dhrona = dhrona._modidx:d
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2022, fastai
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|